From 7c6f6110ebf8ebf446b8414e035b1118908d5bed Mon Sep 17 00:00:00 2001 From: hallgren Date: Fri, 29 Jul 2011 13:45:37 +0000 Subject: gfse: refactoring Factor out functions that interface to the old cloud service (upload.cgi) from editor.js into cloud.js. Merge changes from editor2.js into editor.js and factor out functions that interface to gf -server into clouds2.js. --- src/editor/simple/editor.js | 250 ++++++++++++-------------------------------- 1 file changed, 69 insertions(+), 181 deletions(-) (limited to 'src/editor/simple/editor.js') diff --git a/src/editor/simple/editor.js b/src/editor/simple/editor.js index 5c08078fe..bbd4b7c9b 100644 --- a/src/editor/simple/editor.js +++ b/src/editor/simple/editor.js @@ -2,26 +2,6 @@ var editor=element("editor"); -/* -------------------------------------------------------------------------- */ -function div_id(id,cs) { return node("div",{id:id},cs); } -function div_class(cls,cs) { return node("div",{"class":cls},cs); } -function a(url,linked) { return node("a",{href:url},linked); } -function ul(lis) { return node("ul",{},lis); } -function li(xs) { return node("li",{},xs); } -function table(rows) { return node("table",{},rows); } -function td_right(cs) { return node("td",{"class":"right"},cs); } -function jsurl(js) { return "javascript:"+js; } - -function hidden(name,value) { - return node("input",{type:"hidden",name:name,value:value},[]) -} - -function insertBefore(el,ref) { ref.parentNode.insertBefore(el,ref); } - -function insertAfter(el,ref) { - ref.parentNode.insertBefore(el,ref.nextSibling); -} - /* -------------------------------------------------------------------------- */ function initial_view() { @@ -95,11 +75,7 @@ function delete_grammar(i) { var ok=confirm("Do you really want to delete the grammar "+g.basename+"?") if(ok) { remove_local_grammar(i) - var dir=local.get("dir") - if(dir && g.unique_name) { - var path=dir+"/"+g.unique_name+".json" - ajax_http_get("upload.cgi?rm="+encodeURIComponent(path),debug); - } + remove_cloud_grammar(g) initial_view(); } } @@ -643,14 +619,18 @@ function draw_lincats(g,i) { var conc=g.concretes[i]; function edit(c) { return function(g,el) { - function ok(s) { - if(c.template) conc.lincats.push({cat:c.cat,type:s}); - else c.type=s; - timestamp(conc); - reload_grammar(g); - return null; + function check(s,cont) { + function check2(msg) { + if(!msg) { + if(c.template) conc.lincats.push({cat:c.cat,type:s}); + else c.type=s; + reload_grammar(g); + } + cont(msg); + } + check_exp(s,check2); } - string_editor(el,c.type,ok) + string_editor(el,c.type,check,true) } } function del(c) { return function() { delete_lincat(g,i,c); } } @@ -783,15 +763,19 @@ function draw_lins(g,i) { var conc=g.concretes[i]; function edit(f) { return function(g,el) { - function ok(s) { - if(f.template) - conc.lins.push({fun:f.fun,args:f.args,lin:s}); - else f.lin=s; - timestamp(conc); - reload_grammar(g); - return null; + function check(s,cont) { + function check2(msg) { + if(!msg) { + if(f.template) + conc.lins.push({fun:f.fun,args:f.args,lin:s}); + else f.lin=s; + reload_grammar(g); + } + cont(msg); + } + check_exp(s,check2); } - string_editor(el,f.lin,ok) + string_editor(el,f.lin,check,true) } } function del(fun) { return function () { delete_lin(g,i,fun); } } @@ -837,68 +821,6 @@ function draw_lins(g,i) { /* -------------------------------------------------------------------------- */ -function get_dir(cont) { - var dir=local.get("dir",""); - if(dir) cont(dir); - else ajax_http_get("upload.cgi?dir", - function(dir) { - local.put("dir",dir); - cont(dir); - }); -} - -function upload(g) { - - function upload2(dir) { - var form=node("form",{method:"post",action:"upload.cgi"+dir}, - [hidden(g.basename+".gf",show_abstract(g))]) - for(var i in g.concretes) - form.appendChild(hidden(g.basename+g.concretes[i].langcode+".gf", - show_concrete(g.basename)(g.concretes[i]))); - editor.appendChild(form); - form.submit(); - form.parentNode.removeChild(form); - } - - get_dir(upload2); -} - -function upload_json(cont) { - function upload3(resptext,status) { - local.put("json_uploaded",Date.now()); - //debug("Upload complete") - if(cont) cont(); - else { - var sharing=element("sharing"); - if(sharing) sharing.innerHTML=resptext; - } - } - function upload2(dir) { - var prefix=dir.substr(10)+"-" // skip "/tmp/gfse." - //debug("New form data"); - //var form=new FormData(); // !!! Doesn't work on Android 2.2! - var form="",sep=""; - //debug("Preparing form data"); - for(var i=0;i