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/cloud.js | 141 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/editor/simple/cloud.js (limited to 'src/editor/simple/cloud.js') diff --git a/src/editor/simple/cloud.js b/src/editor/simple/cloud.js new file mode 100644 index 000000000..cd2b9a442 --- /dev/null +++ b/src/editor/simple/cloud.js @@ -0,0 +1,141 @@ + +function with_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 remove_cloud_grammar(g) { + 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); + } +} + +// Upload the grammar to the server and check it for errors +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); + } + + with_dir(upload2); +} + +// Upload the grammar to store it in the cloud +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