]> matita.cs.unibo.it Git - helm.git/blobdiff - matitaB/matita/matitaweb.js
1) removed many debug prints
[helm.git] / matitaB / matita / matitaweb.js
index 221ef90b56f3c6361d5338d48c71d5a89548498e..d9bd38aa80e94dac072b197f10cb86b1d0555032 100644 (file)
@@ -535,6 +535,27 @@ function gotoBottom()
 }
 
 
+function gotoTop()
+{
+       processor = function(xml) {
+               if (is_defined(xml)) {
+                 if (xml.childNodes[0].textContent != "ok") {
+                     debug("goto top failed");
+                  }
+                  else
+                     unlocked.innerHTML = locked.innerHTML + unlocked.innerHTML
+                     locked.innerHTML = ""
+                     hideSequent();
+                     unlocked.scrollIntoView(true);
+               } else {
+                       debug("goto top failed");
+               } 
+                resume();
+       };
+       pause();
+       callServer("top",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
+  
+}
 function gotoPos(offset)
 {
         if (!is_defined(offset)) {
@@ -685,6 +706,36 @@ function showLibrary(title,callback)
   
 }
 
+function uploadDialog()
+{  
+        uploadBox.style.display = "block";
+}
+
+function uploadOK()
+{   
+   var file = document.getElementById("uploadFilename").files[0];
+   if (file) { 
+       var filecontent = file.getAsText("UTF-8");
+       locked.innerHTML = lockedbackup;
+       unlocked.innerHTML = filecontent;
+       uploadBox.style.display = "none";
+   }
+//   if (file) { 
+//      var reader = new FileReader();
+//      reader.readAsText(file, "UTF-8");
+//       reader.onloadend = function (evt) {
+//        lockedbackup = "";
+//           locked.innerHTML = lockedbackup
+//           unlocked.innerHTML = evt.target.result;
+//           uploadBox.style.display = "none";
+//       }
+//       reader.onerror = function (evt) {
+//        debug("file open failed");
+//           uploadBox.style.display = "none";
+//      }
+//   }
+}
+
 function openDialog()
 {  
        callback = function (fname) { retrieveFile(fname); };
@@ -693,25 +744,49 @@ function openDialog()
 
 function saveDialog()
 {  
-       callback = function (fname) { saveFile(fname,false); };
+       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 saveFile(fname,force)
+function newDialog()
+{
+       callback = function (fname) { 
+         dialogBox.style.display = "none";
+         saveFile(fname,"","",false,newDialog,true);
+       };
+       showLibrary("Create new file", callback);
+}
+
+
+function saveFile(fname,lockedtxt,unlockedtxt,force,reloadDialog,reloadFile)
 {
-        if (!is_defined(fname) {
+        if (!is_defined(reloadFile)) { reloadFile = true };
+        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,reloadDialog,reloadFile);
                    } else {
-                      saveDialog();
+                      reloadDialog();
                    }
-                 } else
-                       debug("file saved!");
+                 } else {
+                   current_fname = fname;
+                   debug("file saved!");
+                    if (reloadFile) { retrieveFile(fname); }
+                 }
                } else {
                        debug("save file failed");
                }
@@ -720,8 +795,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"); }
@@ -744,20 +819,32 @@ function commitAll()
 var goalcell;
 
 function hideSequent() {
-  goalcell.parentNode.removeChild(goalcell);
-  scriptcell.setAttribute("colspan","2");
+  goalcell.style.display = "none";
+  scriptcell.style.width = "100%";
+  scriptcell.style.minWidth = "100%";
+  scriptcell.style.maxWidth = "100%";
 }
 
 function showSequent() {
-  scriptcell.setAttribute("colspan","1");
-  workarea.appendChild(goalcell);
+  scriptcell.style.width = "67%";
+  scriptcell.style.minWidth = "67%";
+  scriptcell.style.maxWidth = "67%";
+  goalcell.style.display = "inline-block";
 }
 
 function showDialog(title,content,callback) {
   dialogTitle.innerHTML = title;
   dialogContent.innerHTML = content;
-  dialogBox.style.display = "block";
   dialogBox.callback = callback;
+  dialogBox.style.display = "block";
+}
+
+function abortDialog() {
+  dialogBox.style.display = "none";
+}
+
+function abortUpload() {
+  uploadBox.style.display = "none";
 }
 
 function removeElement(id) {