summaryrefslogtreecommitdiff
path: root/src/editor/simple/cloud2.js
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-07-29 13:45:37 +0000
committerhallgren <hallgren@chalmers.se>2011-07-29 13:45:37 +0000
commit7c6f6110ebf8ebf446b8414e035b1118908d5bed (patch)
tree4178b50dc70c0f4d7b95f8aa0440fb24b3471ea7 /src/editor/simple/cloud2.js
parent9d547fbdca865785d23c1211610391d39464d507 (diff)
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.
Diffstat (limited to 'src/editor/simple/cloud2.js')
-rw-r--r--src/editor/simple/cloud2.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/editor/simple/cloud2.js b/src/editor/simple/cloud2.js
new file mode 100644
index 000000000..2331b39f2
--- /dev/null
+++ b/src/editor/simple/cloud2.js
@@ -0,0 +1,70 @@
+
+function with_dir(cont) {
+ var dir=local.get("dir","");
+ if(/^\/tmp\//.test(dir)) cont(dir);
+ else ajax_http_get("/new",
+ function(dir) {
+ local.put("dir",dir);
+ cont(dir);
+ });
+}
+
+function remove_cloud_grammar(g) {
+ alert("remove_cloud_grammar(g) not implemented yet!!!")
+}
+
+// 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"},
+ [hidden("dir",dir),hidden(g.basename,show_abstract(g))])
+ var files = [g.basename+".gf"]
+ for(var i in g.concretes) {
+ var cname=g.basename+g.concretes[i].langcode;
+ files.push(cname+".gf");
+ form.appendChild(hidden(cname,
+ show_concrete(g.basename)(g.concretes[i])));
+ }
+ editor.appendChild(form);
+ form.submit();
+ form.parentNode.removeChild(form);
+ /* wait until upload is done */
+ gfshell("i -retain "+files.join(" "),upload3)
+ }
+
+ function upload3(message) { if(message) alert(message); }
+
+ with_dir(upload2)
+}
+
+// Upload the grammar to store it in the cloud
+function upload_json(cont) {
+ alert("upload_json() not implemented yet!!!")
+}
+
+function download_json() {
+ alert("download_json() not implemented yet!!!")
+}
+
+function link_directories(olddir,newdir,cont) {
+ alert("link_directories(...) not implemented yet!!!")
+}
+
+/* -------------------------------------------------------------------------- */
+
+// Send a command to the GF shell
+function gfshell(cmd,cont) {
+ with_dir(function(dir) {
+ var enc=encodeURIComponent;
+ ajax_http_get("/gfshell?dir="+enc(dir)+"&command="+enc(cmd),cont)
+ })
+}
+
+// Check the syntax of an expression
+function check_exp(s,cont) {
+ function check(gf_message) {
+ debug("cc "+s+" = "+gf_message);
+ cont(/parse error/.test(gf_message) ? "parse error" : null);
+ }
+ gfshell("cc "+s,check);
+}