Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

translator: keep cloud docs and local docs apart

Ignore-this: aea5dcf755768b6402b8e846d1a77f9e
+ show a cloud icon next to the document name if it is stored in the cloud
+ in addition to the name of the current document, remember if it is stored in
  the cloud, so that the right document is loaded next time you open the
  translator.

darcs-hash:20120802125415-bae10-e6e66c7fc233898cd0c7eb8d9987e9450ab496bd.gz
  • Loading branch information...
commit 93fec771b1da81ac09f04ded479fa4d8d95d9110 1 parent 66a850c
Thomas H authored August 02, 2012
BIN  src/www/P/cloud.png
28  src/www/translator/translator.js
@@ -10,8 +10,6 @@ function Translator() {
10 10
 	var warning=span_class("error",text("It appears that localStorage is unsupported or disabled in this browser. Documents will not be preserved after you leave or reload this page!"))
11 11
 	insertAfter(warning,t.view)
12 12
     }
13  
-    t.current=t.local.get("current")
14  
-    t.document=t.current && t.current!="/" && t.local.get("/"+t.current) || empty_document()
15 13
     t.servers={}; //The API is stateful, use one pgf_online object per grammar
16 14
     t.grammar_info={};
17 15
     pgf_online({}).get_grammarlist(bind(t.extend_methods,t))
@@ -19,7 +17,12 @@ function Translator() {
19 17
     update_language_menu(t,"target")
20 18
     if(apertium) t.add_apertium()
21 19
     //initialize_sorting(["TR"],["segment"])
22  
-    t.redraw();
  20
+    t.document=empty_document();
  21
+    t.current=t.local.get("current")
  22
+    if(t.current && t.current!="/") {
  23
+	if(t.local.get("current_in_cloud")) t.open_from_cloud(t.current)
  24
+	else t.open(t.current)
  25
+    }
23 26
 }
24 27
 
25 28
 function update_language_menu(t,id) {
@@ -309,7 +312,8 @@ Translator.prototype.browse=function(el) {
309 312
 	    var filenames=JSON.parse(result)
310 313
 	    var files=map(strip_cloudext,filenames)
311 314
 	    if(files.length>0) {
312  
-		t.view.appendChild(wrap("h3",text("Documents in the cloud")))
  315
+		t.view.appendChild(wrap("h3",[text("Documents in the cloud "),
  316
+					      img("../P/cloud.png")]))
313 317
 		t.view.appendChild(ls(files,"translator.open_from_cloud"))
314 318
 	    }
315 319
 	}
@@ -325,15 +329,17 @@ Translator.prototype.open=function(name) {
325 329
     if(name) {
326 330
 	var path="/"+name
327 331
 	var document=t.local.get(path);
328  
-	if(document) t.load(name,document)
  332
+	if(document) t.load(name,document,false)
329 333
 	else alert("No such document: "+name)
330 334
     }
331 335
 }
332 336
 
333  
-Translator.prototype.load=function(name,document) {
  337
+Translator.prototype.load=function(name,document,in_cloud) {
334 338
     var t=this
335 339
     t.current=name;
  340
+    t.current_in_cloud=in_cloud;
336 341
     t.local.put("current",name)
  342
+    t.local.put("current_in_cloud",in_cloud)
337 343
     t.document=document;
338 344
     t.redraw();
339 345
 }
@@ -343,7 +349,7 @@ Translator.prototype.open_from_cloud=function(name) {
343 349
     var filename=name+cloudext
344 350
     function ok(result) {
345 351
 	var document=JSON.parse(result)
346  
-	if(document) t.load(name,document)
  352
+	if(document) t.load(name,document,true)
347 353
     }
348 354
     gfcloud("download",{file:encodeURIComponent(filename)},ok);
349 355
 }
@@ -355,7 +361,10 @@ Translator.prototype.save=function(el) {
355 361
 	if(t.current) {
356 362
 	    var path="/"+t.current
357 363
 	    if(t.document.options.cloud) {
358  
-		function done() { /*t.local.remove(path)*/ }
  364
+		function done() {
  365
+		    //t.local.remove(path)
  366
+		    t.local.put("current_in_cloud",true)
  367
+		}
359 368
 		save_in_cloud(t.current+cloudext,t.document,done)
360 369
 	    }
361 370
 	    else
@@ -601,7 +610,7 @@ function hide_menu(el) {
601 610
 /*
602 611
 type Document = { name:String, options:DocOptions, segments:[Segment] }
603 612
 type Segment = { source:String, target:String, options:Options }
604  
-type DocOptions = Options & { view:View }
  613
+type DocOptions = Options & { view:View, cloud:Bool }
605 614
 type Options = {from: Lang, to: Lang, method:Method}
606 615
 type Lang = String // Eng, Swe, Ita, etc
607 616
 type Method = "Manual" | "Apertium" | GFGrammarName
@@ -619,6 +628,7 @@ Translator.prototype.draw_document=function() {
619 628
     var o=doc.options;
620 629
     var hdr=wrap("h2",[text(doc.name),text(" "),
621 630
 		       wrap("small",draw_translation(o))])
  631
+    if(doc.options.cloud) insertFirst(hdr,img("../P/cloud.png"))
622 632
     switch(o.view || "segmentbysegment") {
623 633
     case "paralleltexts":
624 634
 	function src(seg) { return seg.source }

0 notes on commit 93fec77

Please sign in to comment.
Something went wrong with that request. Please try again.