]> matita.cs.unibo.it Git - helm.git/blobdiff - matitaB/matita/matitaweb.js
initial commit of lambda_delta web site
[helm.git] / matitaB / matita / matitaweb.js
index c0b9458425ccde715e620507f978bb74b9de3b1b..ec19562b248e819a0ab1bb3fb25e35aa59c318d1 100644 (file)
@@ -644,7 +644,7 @@ function retrieveFile(thefile)
        callServer("open",processor,"file=" + escape(thefile)); 
 }
 
-function showLibrary()
+function showLibrary(title,callback)
 { 
        var req = null; 
         // pause();
@@ -675,7 +675,7 @@ function showLibrary()
                        if(stat == 200)
                        {
                          debug(req.responseText);
-                         showDialog("<H2>Library</H2>",req.responseText);
+                         showDialog("<H2>" + title + "</H2>",req.responseText, callback);
                        } 
                } 
        };
@@ -685,21 +685,67 @@ function showLibrary()
   
 }
 
-function saveFile()
+function openDialog()
+{  
+       callback = function (fname) { retrieveFile(fname); };
+       showLibrary("Open file", callback);
+}
+
+function saveDialog()
+{  
+       callback = function (fname) { 
+         dialogBox.style.display = "none";
+          saveFile(fname,
+                  (locked.innerHTML.html_to_matita()).sescape(),
+                  (unlocked.innerHTML.html_to_matita()).sescape(),
+                  false,saveDialog); 
+        };
+       showLibrary("Save file as", callback);
+}
+
+function newDialog()
+{
+       callback = function (fname) { 
+         dialogBox.style.display = "none";
+         saveFile(fname,"","",false,newDialog);
+          retrieveFile(fname);
+       };
+       showLibrary("Create new file", callback);
+}
+
+
+function saveFile(fname,lockedtxt,unlockedtxt,force,reloadDialog)
 {
+        if (!is_defined(fname)) {
+            fname = current_fname;
+           lockedtxt = (locked.innerHTML.html_to_matita()).sescape();
+           unlockedtxt = (unlocked.innerHTML.html_to_matita()).sescape();
+           force = true;
+           // when force is true, reloadDialog is not needed 
+        }
        processor = function(xml) {
                if (is_defined(xml)) {
-                       debug("file saved!");
+                 if (xml.childNodes[0].textContent != "ok") {
+                    if (confirm("File already exists. All existing data will be lost.\nDo you want to proceed anyway?")) {
+                       saveFile(fname,lockedtxt,unlockedtxt,true);
+                   } else {
+                      reloadDialog();
+                   }
+                 } else {
+                   current_fname = fname;
+                   debug("file saved!");
+                 }
                } else {
                        debug("save file failed");
                }
                resume();
        };
-       if (is_defined(current_fname)) {
+       if (is_defined(fname)) {
           pause();
-          callServer("save",processor,"file=" + escape(current_fname) + 
-                                   "&locked=" + (locked.innerHTML.html_to_matita()).sescape() +
-                                   "&unlocked=" + (unlocked.innerHTML.html_to_matita()).sescape());
+          callServer("save",processor,"file=" + escape(fname) + 
+                                   "&locked=" + lockedtxt +
+                                   "&unlocked=" + unlockedtxt +
+                                   "&force=" + force);
        }
        else { debug("no file selected"); }
 }
@@ -730,10 +776,11 @@ function showSequent() {
   workarea.appendChild(goalcell);
 }
 
-function showDialog(title,content) {
+function showDialog(title,content,callback) {
   dialogTitle.innerHTML = title;
   dialogContent.innerHTML = content;
   dialogBox.style.display = "block";
+  dialogBox.callback = callback;
 }
 
 function removeElement(id) {