]> matita.cs.unibo.it Git - helm.git/blobdiff - matitaB/matita/matitaweb.js
Matitaweb: New File functionality.
[helm.git] / matitaB / matita / matitaweb.js
index 48acfe13e223a0118b03b5d96ddc7b1a36250513..fc90080d255a16cd18ed359ef624a2f8e8e83046 100644 (file)
@@ -695,27 +695,45 @@ function saveDialog()
 {  
        callback = function (fname) { 
          dialogBox.style.display = "none";
-         current_fname = fname;
-          saveFile(fname,false); 
+          saveFile(fname,
+                  (locked.innerHTML.html_to_matita()).sescape(),
+                  (unlocked.innerHTML.html_to_matita()).sescape(),
+                  false,saveDialog); 
         };
        showLibrary("Save file as", callback);
 }
 
-function saveFile(fname,force)
+function newDialog()
+{
+       callback = function (fname) { 
+         dialogBox.style.display = "none";
+         saveFile(fname,"","",false,newDialog); 
+       };
+       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)) {
                  if (xml.childNodes[0].textContent != "ok") {
-                    if (confirm("File already exists. Do you want to proceed anyway?")) {
-                       saveFile(fname,true);
+                    if (confirm("File already exists. All existing data will be lost.\nDo you want to proceed anyway?")) {
+                       saveFile(fname,lockedtxt,unlockedtxt,true);
                    } else {
-                      saveDialog();
+                      reloadDialog();
                    }
-                 } else
-                       debug("file saved!");
+                 } else {
+                   current_fname = fname;
+                   debug("file saved!");
+                 }
                } else {
                        debug("save file failed");
                }
@@ -724,8 +742,8 @@ function saveFile(fname,force)
        if (is_defined(fname)) {
           pause();
           callServer("save",processor,"file=" + escape(fname) + 
-                                   "&locked=" + (locked.innerHTML.html_to_matita()).sescape() +
-                                   "&unlocked=" + (unlocked.innerHTML.html_to_matita()).sescape() +
+                                   "&locked=" + lockedtxt +
+                                   "&unlocked=" + unlockedtxt +
                                    "&force=" + force);
        }
        else { debug("no file selected"); }