mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-15 14:12:51 -06:00
gfse: use "gf -server" mode instead of upload.cgi
Work in progress on making the online grammar editor use the new "gf -server" mode instead of the old upload.cgi script. A first benefit is that the editor now calls the server to check the syntax of lin & lincat definitions. (But the links to minibar/gfshell/quiz are not available at the moment.)
This commit is contained in:
@@ -570,13 +570,18 @@ function draw_lincats(g,i) {
|
|||||||
var conc=g.concretes[i];
|
var conc=g.concretes[i];
|
||||||
function edit(c) {
|
function edit(c) {
|
||||||
return function(g,el) {
|
return function(g,el) {
|
||||||
function ok(s) {
|
function check(s,cont) {
|
||||||
|
function check2(msg) {
|
||||||
|
if(!msg) {
|
||||||
if(c.template) conc.lincats.push({cat:c.cat,type:s});
|
if(c.template) conc.lincats.push({cat:c.cat,type:s});
|
||||||
else c.type=s;
|
else c.type=s;
|
||||||
reload_grammar(g);
|
reload_grammar(g);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
string_editor(el,c.type,ok)
|
cont(msg);
|
||||||
|
}
|
||||||
|
check_exp(s,check2);
|
||||||
|
}
|
||||||
|
string_editor(el,c.type,check,true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function del(c) { return function() { delete_lincat(g,i,c); } }
|
function del(c) { return function() { delete_lincat(g,i,c); } }
|
||||||
@@ -703,14 +708,19 @@ function draw_lins(g,i) {
|
|||||||
var conc=g.concretes[i];
|
var conc=g.concretes[i];
|
||||||
function edit(f) {
|
function edit(f) {
|
||||||
return function(g,el) {
|
return function(g,el) {
|
||||||
function ok(s) {
|
function check(s,cont) {
|
||||||
|
function check2(msg) {
|
||||||
|
if(!msg) {
|
||||||
if(f.template)
|
if(f.template)
|
||||||
conc.lins.push({fun:f.fun,args:f.args,lin:s});
|
conc.lins.push({fun:f.fun,args:f.args,lin:s});
|
||||||
else f.lin=s;
|
else f.lin=s;
|
||||||
reload_grammar(g);
|
reload_grammar(g);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
string_editor(el,f.lin,ok)
|
cont(msg);
|
||||||
|
}
|
||||||
|
check_exp(s,check2);
|
||||||
|
}
|
||||||
|
string_editor(el,f.lin,check,true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function del(fun) { return function () { delete_lin(g,i,fun); } }
|
function del(fun) { return function () { delete_lin(g,i,fun); } }
|
||||||
@@ -755,25 +765,55 @@ function draw_lins(g,i) {
|
|||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
function upload(g) {
|
function with_dir(cont) {
|
||||||
var dir=local.get("dir","");
|
var dir=local.get("dir","");
|
||||||
if(dir) upload2(g,dir);
|
if(/^\/tmp\//.test(dir)) cont(dir);
|
||||||
else ajax_http_get("upload.cgi?dir",
|
else ajax_http_get("/new",
|
||||||
function(dir) {
|
function(dir) {
|
||||||
local.put("dir",dir);
|
local.put("dir",dir);
|
||||||
upload2(g,dir);
|
cont(dir);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload2(g,dir) {
|
// Send a command to the GF shell
|
||||||
var form=node("form",{method:"post",action:"upload.cgi"+dir},
|
function gfshell(cmd,cont) {
|
||||||
[hidden(g.basename,show_abstract(g))])
|
with_dir(function(dir) {
|
||||||
for(var i in g.concretes)
|
var enc=encodeURIComponent;
|
||||||
form.appendChild(hidden(g.basename+g.concretes[i].langcode,
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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])));
|
show_concrete(g.basename)(g.concretes[i])));
|
||||||
|
}
|
||||||
editor.appendChild(form);
|
editor.appendChild(form);
|
||||||
form.submit();
|
form.submit();
|
||||||
form.parentNode.removeChild(form);
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
function hidden(name,value) {
|
function hidden(name,value) {
|
||||||
@@ -812,7 +852,7 @@ function sort_list(list,olditems,key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function string_editor(el,init,ok) {
|
function string_editor(el,init,ok,async) {
|
||||||
var p=el.parentNode;
|
var p=el.parentNode;
|
||||||
function restore() {
|
function restore() {
|
||||||
e.parentNode.removeChild(e);
|
e.parentNode.removeChild(e);
|
||||||
@@ -821,8 +861,9 @@ function string_editor(el,init,ok) {
|
|||||||
function done() {
|
function done() {
|
||||||
var edited=e.it.value;
|
var edited=e.it.value;
|
||||||
restore();
|
restore();
|
||||||
var msg=ok(edited);
|
function cont(msg) { if(msg) start(msg); }
|
||||||
if(msg) start(msg);
|
if(async) ok(edited,cont)
|
||||||
|
else cont(ok(edited));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
function start(msg) {
|
function start(msg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user