simple translator: make it possible to delete documents

This commit is contained in:
hallgren
2012-09-21 09:07:31 +00:00
parent db39fdaa68
commit b3f6d3612b
2 changed files with 34 additions and 7 deletions

View File

@@ -7,7 +7,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
</head> </head>
<body> <body class=hover>
<div class=pagehead> <div class=pagehead>
<h1>Simple Translation Tool</h1> <h1>Simple Translation Tool</h1>
<form name=options> <form name=options>
@@ -72,7 +72,7 @@
</div> </div>
<hr> <hr>
<div class=modtime><small>HMTL <div class=modtime><small>HMTL
<!-- hhmts start -->Last modified: Mon Sep 10 22:22:00 CEST 2012 <!-- hhmts end --> <!-- hhmts start -->Last modified: Fri Sep 21 10:12:52 CEST 2012 <!-- hhmts end -->
</small></div> </small></div>
<a href="about.html">About</a> <a href="about.html">About</a>

View File

@@ -313,22 +313,37 @@ Translator.prototype.new=function(el) {
Translator.prototype.browse=function(el) { Translator.prototype.browse=function(el) {
hide_menu(el); hide_menu(el);
var t=this var t=this
function ls(files,op) { function ls(files,open,del) {
var ul=empty_class("ul","files") var ul=empty_class("ul","files")
for(var i in files) { for(var i in files) {
var name=files[i] var name=files[i]
var link=a(jsurl(op+"('"+name+"')"),[text(name)]) var link=a(jsurl(open+"('"+name+"')"),[text(name)])
ul.appendChild(li(link)) ul.appendChild(li(deletable(del(name),link)))
} }
return ul return ul
} }
function delete_local(name) {
return function() {
if(confirm("Are you sure you want to delete the local document "+name+"?")) {
t.local.remove("/"+name)
browse();
}
}
}
function delete_from_cloud(name) {
return function() {
if(confirm("Are you sure you want to delete the cloud document "+name+"?")) {
gfcloud("rm",{file:name+cloudext},browse)
}
}
}
function browse() { function browse() {
clear(t.view) clear(t.view)
t.view.appendChild(wrap("h2",text("Your translator documents"))) t.view.appendChild(wrap("h2",text("Your translator documents")))
var files=t.local.ls("/") var files=t.local.ls("/")
if(files.length>0) { if(files.length>0) {
t.view.appendChild(wrap("h3",text("Local documents"))) t.view.appendChild(wrap("h3",text("Local documents")))
t.view.appendChild(ls(files,"translator.open")) t.view.appendChild(ls(files,"translator.open",delete_local))
} }
function lscloud(result) { function lscloud(result) {
var filenames=JSON.parse(result) var filenames=JSON.parse(result)
@@ -336,7 +351,7 @@ Translator.prototype.browse=function(el) {
if(files.length>0) { if(files.length>0) {
t.view.appendChild(wrap("h3",[text("Documents in the cloud "), t.view.appendChild(wrap("h3",[text("Documents in the cloud "),
img("../P/cloud.png")])) img("../P/cloud.png")]))
t.view.appendChild(ls(files,"translator.open_from_cloud")) t.view.appendChild(ls(files,"translator.open_from_cloud",delete_from_cloud))
} }
} }
if(navigator.onLine) gfcloud("ls",{ext:cloudext},lscloud) if(navigator.onLine) gfcloud("ls",{ext:cloudext},lscloud)
@@ -1085,3 +1100,15 @@ function update_checkbox(name,checked) {
function submit(label) { function submit(label) {
return node("input",{type:"submit",value:label||"OK"}) return node("input",{type:"submit",value:label||"OK"})
} }
function deletable(del,el,hint) {
var b=delete_button(del,hint)
return node("span",{"class":"deletable"},[b,el])
}
function delete_button(action,hint) {
var b=node("span",{"class":"delete",title:hint || "Delete"},[text("×")])
b.onclick=action;
return b;
}