forked from GitHub/gf-core
translator: documents can now be saved in the cloud
some other small fixes
This commit is contained in:
@@ -165,7 +165,7 @@ handle state0 cache execute1
|
||||
case cmd of
|
||||
"make" -> make dir qs
|
||||
"upload" -> upload qs
|
||||
"ls" -> jsonList
|
||||
"ls" -> jsonList (maybe ".json" id $ lookup "ext" qs)
|
||||
"rm" -> look "file" rm qs
|
||||
"download" -> look "file" download qs
|
||||
"link_directories" -> look "newdir" (link_directories dir) qs
|
||||
@@ -183,8 +183,8 @@ handle state0 cache execute1
|
||||
do mapM_ (uncurry updateFile) files
|
||||
return (state,resp204)
|
||||
|
||||
jsonList =
|
||||
do jsons <- ls_ext "." ".json"
|
||||
jsonList ext =
|
||||
do jsons <- ls_ext "." ext
|
||||
return (state,json200 jsons)
|
||||
|
||||
rm path _ | takeExtension path==".json" =
|
||||
|
||||
@@ -216,7 +216,7 @@ function parse_oper(s) {
|
||||
|
||||
}
|
||||
|
||||
/* --- Print as plain text (normal GF source syntax) ------------------------- */
|
||||
/* --- Print as plain text (normal GF source syntax) ------------------------ */
|
||||
|
||||
function show_type(t) {
|
||||
var s="";
|
||||
|
||||
@@ -33,8 +33,8 @@ grammar to use from a menu of available grammars. Through menu options,
|
||||
the user also sets the source and target language for the document.
|
||||
|
||||
<p>
|
||||
The tool handles a set of documents. Documents can be named, saved (locally),
|
||||
closed and reopened later.
|
||||
The tool handles a set of documents. Documents can be named, saved,
|
||||
closed and reopened later. Documents can be saved locally or in the cloud.
|
||||
|
||||
<h2>TODO</h2>
|
||||
<ul>
|
||||
@@ -43,7 +43,7 @@ closed and reopened later.
|
||||
<li>GF's lexer/unlexer is used to allow for more natural looking text, but
|
||||
the unlexer does the wrong thing if the first word of a sentence is supposed
|
||||
to be capitalized, e.g. "I am ready." and "Spanish wine is good."
|
||||
<li>Cloud service.
|
||||
<li>Document sharing in the cloud.
|
||||
<li>Interface to other translation services.
|
||||
<li>Interface to the grammar editor for grammar extension.
|
||||
<li>More browser compatibility testing (Chrome, Firefox & Safari tested
|
||||
@@ -55,7 +55,7 @@ closed and reopened later.
|
||||
|
||||
<hr>
|
||||
<div class=modtime><small>
|
||||
<!-- hhmts start --> Last modified: Mon Jun 11 17:25:39 CEST 2012 <!-- hhmts end -->
|
||||
<!-- hhmts start --> Last modified: Tue Jun 12 17:32:46 CEST 2012 <!-- hhmts end -->
|
||||
</small></div>
|
||||
<address>
|
||||
<a href="http://www.cse.chalmers.se/~hallgren/">TH</a>
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
<dt><label><input name=method value=Manual type=radio onchange="translator.change(this)">Manual</label>
|
||||
</dl>
|
||||
</table>
|
||||
<dt><label><input name=cloud type=checkbox onchange="translator.change(this)"> Save in the cloud</label>
|
||||
</dl>
|
||||
</table>
|
||||
</form>
|
||||
@@ -70,7 +71,7 @@
|
||||
</div>
|
||||
<hr>
|
||||
<div class=modtime><small>HMTL
|
||||
<!-- hhmts start --> Last modified: Sat May 26 13:23:57 CEST 2012 <!-- hhmts end -->
|
||||
<!-- hhmts start --> Last modified: Tue Jun 12 16:08:01 CEST 2012 <!-- hhmts end -->
|
||||
</small></div>
|
||||
<a href="about.html">About</a>
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ Translator.prototype.redraw=function() {
|
||||
update_radiobutton("source",o.from)
|
||||
update_radiobutton("target",o.to)
|
||||
update_radiobutton("view",o.view || "segmentbysegment")
|
||||
update_checkbox("cloud",o.cloud || false)
|
||||
if(o.method!="Manual") {
|
||||
function cont2(gr_info) {
|
||||
t.grammar_info=gr_info
|
||||
@@ -148,11 +149,18 @@ Translator.prototype.change=function(el) {
|
||||
t.redraw()
|
||||
}
|
||||
}
|
||||
function update_checkbox(field) {
|
||||
if(el.checked!=o[field]) {
|
||||
o[field]=el.checked
|
||||
t.redraw()
|
||||
}
|
||||
}
|
||||
switch(el.name) {
|
||||
case "method": update("method"); break;
|
||||
case "source": update("from"); break;
|
||||
case "target": update("to"); break;
|
||||
case "view": update("view"); break;
|
||||
case "view" : update("view"); break;
|
||||
case "cloud" : update_checkbox("cloud"); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,17 +175,32 @@ Translator.prototype.new=function(el) {
|
||||
Translator.prototype.browse=function(el) {
|
||||
hide_menu(el);
|
||||
var t=this
|
||||
function browse() {
|
||||
var files=t.local.ls("/")
|
||||
function ls(files,op) {
|
||||
var ul=empty_class("ul","files")
|
||||
for(var i in files) {
|
||||
var name=files[i]
|
||||
var link=a(jsurl("translator.open('"+name+"')"),[text(name)])
|
||||
var link=a(jsurl(op+"('"+name+"')"),[text(name)])
|
||||
ul.appendChild(li(link))
|
||||
}
|
||||
return ul
|
||||
}
|
||||
function browse() {
|
||||
clear(t.view)
|
||||
t.view.appendChild(wrap("h2",text("Your translator documents")))
|
||||
t.view.appendChild(ul)
|
||||
var files=t.local.ls("/")
|
||||
if(files.length>0) {
|
||||
t.view.appendChild(wrap("h3",text("Local documents")))
|
||||
t.view.appendChild(ls(files,"translator.open"))
|
||||
}
|
||||
function lscloud(result) {
|
||||
var filenames=JSON.parse(result)
|
||||
var files=map(strip_cloudext,filenames)
|
||||
if(files.length>0) {
|
||||
t.view.appendChild(wrap("h3",text("Documents in the cloud")))
|
||||
t.view.appendChild(ls(files,"translator.open_from_cloud"))
|
||||
}
|
||||
}
|
||||
if(navigator.onLine) gfcloud("ls",{ext:cloudext},lscloud)
|
||||
t.current="/"
|
||||
t.local.put("current","/")
|
||||
}
|
||||
@@ -189,33 +212,52 @@ Translator.prototype.open=function(name) {
|
||||
if(name) {
|
||||
var path="/"+name
|
||||
var document=t.local.get(path);
|
||||
if(document) {
|
||||
t.current=name;
|
||||
t.local.put("current",name)
|
||||
t.document=document;
|
||||
t.redraw();
|
||||
}
|
||||
if(document) t.load(name,document)
|
||||
else alert("No such document: "+name)
|
||||
}
|
||||
}
|
||||
Translator.prototype.load=function(name,document) {
|
||||
var t=this
|
||||
t.current=name;
|
||||
t.local.put("current",name)
|
||||
t.document=document;
|
||||
t.redraw();
|
||||
}
|
||||
|
||||
Translator.prototype.open_from_cloud=function(name) {
|
||||
var t=this
|
||||
var filename=name+cloudext
|
||||
function ok(result) {
|
||||
var document=JSON.parse(result)
|
||||
if(document) t.load(name,document)
|
||||
}
|
||||
gfcloud("download",{file:encodeURIComponent(filename)},ok);
|
||||
}
|
||||
|
||||
Translator.prototype.save=function(el) {
|
||||
var t=this
|
||||
hide_menu(el);
|
||||
if(this.current!="/") {
|
||||
if(this.current) this.local.put("/"+this.current,this.document)
|
||||
else this.saveAs()
|
||||
if(t.current!="/") {
|
||||
if(t.current) {
|
||||
if(t.document.options.cloud)
|
||||
save_in_cloud(t.current+cloudext,t.document)
|
||||
else
|
||||
t.local.put("/"+t.current,t.document)
|
||||
}
|
||||
else t.saveAs()
|
||||
}
|
||||
}
|
||||
|
||||
Translator.prototype.saveAs=function(el) {
|
||||
var t=this
|
||||
hide_menu(el);
|
||||
if(this.current!="/") {
|
||||
if(t.current!="/") {
|
||||
var name=prompt("File name?")
|
||||
if(name) {
|
||||
this.current=this.document.name=name;
|
||||
this.local.put("current",name)
|
||||
this.save();
|
||||
this.redraw();
|
||||
t.current=t.document.name=name;
|
||||
t.local.put("current",name)
|
||||
t.save();
|
||||
t.redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,7 +306,7 @@ Translator.prototype.add_segment=function(el) {
|
||||
e.onsubmit=done
|
||||
inp.focus();
|
||||
}
|
||||
setTimeout(imp,100)
|
||||
if(t.current!="/") setTimeout(imp,100)
|
||||
}
|
||||
|
||||
Translator.prototype.import=function(el) {
|
||||
@@ -306,7 +348,7 @@ Translator.prototype.import=function(el) {
|
||||
e.onsubmit=done
|
||||
inp.focus();
|
||||
}
|
||||
setTimeout(imp,100)
|
||||
if(t.current!="/") setTimeout(imp,100)
|
||||
}
|
||||
|
||||
Translator.prototype.remove=function(el) {
|
||||
@@ -397,11 +439,13 @@ function hide_menu(el) {
|
||||
/* --- Documents ------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
type Document = { name:String, options: Options, segments:[Segment] }
|
||||
type Document = { name:String, options:DocOptions, segments:[Segment] }
|
||||
type Segment = { source:String, target:String, options:Options }
|
||||
type DocOptions = Options & { view:View }
|
||||
type Options = {from: Lang, to: Lang, method:Method}
|
||||
type Lang = String // Eng, Swe, Ita, etc
|
||||
type Method = "Manual" | GrammarName
|
||||
type View = "segmentbysegment" | "paralleltexts"
|
||||
type GrammarName = String // e.g. "Foods.pgf"
|
||||
*/
|
||||
|
||||
@@ -595,6 +639,23 @@ function split_punct(text,punct) {
|
||||
return segs
|
||||
}
|
||||
|
||||
/* --- Cloud Support -------------------------------------------------------- */
|
||||
|
||||
|
||||
var cloudext=".gfstdoc"
|
||||
function strip_cloudext(s) { return s.substr(0,s.length-cloudext.length) }
|
||||
|
||||
function save_in_cloud(filename,document) {
|
||||
function done() { }
|
||||
function save(dir) {
|
||||
var form={dir:dir}
|
||||
form[filename]=JSON.stringify(document);
|
||||
ajax_http_post("/cloud","command=upload"+encodeArgs(form),done)
|
||||
}
|
||||
with_dir(save)
|
||||
}
|
||||
|
||||
|
||||
/* --- DOM Support ---------------------------------------------------------- */
|
||||
|
||||
function a(url,linked) { return node("a",{href:url},linked); }
|
||||
@@ -615,6 +676,10 @@ function update_radiobutton(name,value) {
|
||||
for(var i in bs) if(bs[i].value==value) bs[i].checked=true
|
||||
}
|
||||
|
||||
function update_checkbox(name,checked) {
|
||||
document.forms.options[name].checked=checked
|
||||
}
|
||||
|
||||
function submit(label) {
|
||||
return node("input",{type:"submit",value:label||"OK"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user