mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-28 22:12:51 -06:00
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.
This commit is contained in:
70
src/editor/simple/cloud2.js
Normal file
70
src/editor/simple/cloud2.js
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user