From 25ae9b2dc4d2a2a5bd2e1920e1ee82dfbef4162e Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 8 Jun 2011 15:29:50 +0000 Subject: gfse: initial support for grammars in the cloud This lets the user access the same set of grammars from multiple devices. Sharing grammars between multiple users is possible but discouraged at the moment. There is no version handling, so concurrent editing of the same grammar by different users might result in one user overwriting changes made by another user. (The same goes for cuncurrent editing on multiple devices by a single user, of course.) --- src/editor/simple/editor.js | 197 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 177 insertions(+), 20 deletions(-) (limited to 'src/editor/simple/editor.js') diff --git a/src/editor/simple/editor.js b/src/editor/simple/editor.js index 30e989940..21a04dcb4 100644 --- a/src/editor/simple/editor.js +++ b/src/editor/simple/editor.js @@ -12,9 +12,16 @@ 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() { @@ -27,7 +34,24 @@ function initial_view() { function draw_grammar_list() { local.put("current",0); editor.innerHTML=""; - editor.appendChild(node("h3",{},[text("Your grammars")])); + var cloud_upload= + a(jsurl("upload_json()"), + [node("img",{"class":"cloud", + src:"P/1306856253_weather_06.png",alt:"[Up Cloud]", + title:"Click to store your grammars in the cloud"}, + [])]); + var home=div_class("home",[node("h3",{}, + [text("Your grammars"),cloud_upload])]); + if(local.get("json_uploaded")) { + var cloud_download= + a(jsurl("download_json()"), + [node("img",{"class":"cloud", + src:"P/1307545089_weather_04.png",alt:"[Down Cloud]", + title:"Click to download grammar updates from the cloud"}, + [])]); + insertAfter(cloud_download,cloud_upload); + } + editor.appendChild(home) var gs=ul([]); function del(i) { return function () { delete_grammar(i); } } for(var i=0;i0) get_file(i+".json",file_ok,file_err) + else { + local.count=new_count; + //alert("Download finished"); + setTimeout(function(){location.href="."},3000); + } + } + function download_files(count) { + new_count=count; + local.put("current",0); + download_files_from(count); + } + get_file("count.json",download_files); +} + +function download_from_cloud() { + var olddir=local.get("dir",null) + var newdir="/tmp/"+location.hash.substr(1) + if(newdir==olddir || confirm("Cloud grammars will replace your local grammars")) { + local.put("dir",newdir); + download_json(newdir) + } +} + +function timestamp(obj,prop) { + obj[prop || "timestamp"]=Date.now(); +} + +function draw_timestamp(obj) { + var t=obj.timestamp; + return node("small",{"class":"modtime"}, + [text(t ? " -- "+new Date(t).toLocaleString() : "")]); } /* -------------------------------------------------------------------------- */ @@ -919,5 +1074,7 @@ function touch_edit() { //document.body.appendChild(empty_id("div","debug")); -initial_view(); -touch_edit(); +if(editor) { + initial_view(); + touch_edit(); +} -- cgit v1.2.3