From 5b4d03923d33998372e339cfe21b7b87f22af290 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Fri, 15 Jan 2021 18:54:15 +0000
Subject: [PATCH] Text bearbeiten und speichern, weiter in arbeit

---
 web/ui2/js/app.js |   80 ++++++++++++++++++---------------------
 1 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/web/ui2/js/app.js b/web/ui2/js/app.js
index 44685f2..303b5af 100644
--- a/web/ui2/js/app.js
+++ b/web/ui2/js/app.js
@@ -34,7 +34,7 @@
     
     // Hide and show an element by changing "display" to block and none
     document.querySelector(".codeeditor-space").style.display = "none";
-    document.querySelector(".code-editor-container").style.display = "none";
+    //document.querySelector(".code-editor-container").style.display = "none";
     document.querySelector("#mce-editor").style.display = "none";
     //document.querySelector(".box").style.display = "block";
     
@@ -167,7 +167,18 @@
   
   this.fm_menu_datei_speichern_unter = function(callback) {  
     self.dialog_laden_und_zeigen('data/tpl/dlg-save-as.tpl', '', function() {
-
+      document.querySelector('#cancel-btn').addEventListener('click', function() {
+        //self.fm_do_close();
+        self.dialog_schliessen();
+      });
+      document.querySelector('#speichern-btn').addEventListener('click', function() {
+        self.fm_menu_datei_speichern(function() {
+          console.log(document.querySelector('#datei-name-in').value);
+          self.fm_save_file(document.querySelector('#datei-name-in').value, 'saveTextFileAs', callback);
+          self.fm_do_close();
+          self.dialog_schliessen();
+        });
+      });
     });    
     
     
@@ -243,6 +254,8 @@
     //dlg.style.display = "none";
     dlg.style.height = '0';
     dlg.innerHTML = '';
+    self.removeAllListeners('#cancel-btn');
+    self.removeAllListeners('#speichern-btn');
   };
  
   this.fm_dateiwahl = function(ev) {
@@ -573,20 +586,11 @@
       tinymce.activeEditor.undoManager.clear();
     }
     var m = '?c=de.uhilger.filecms.api.FileMgr&m=' + method;
-    var u = '../svc'; // + m;
-    //var data = [self.pfad, saveFileName, content];
-    //var data = "p=" + self.serialisieren(self.pfad);
-    //data += "&p=" + self.serialisieren(saveFileName);
-    //data += "&p=" + self.serialisieren(content);
-    var data = 'c=de.uhilger.filecms.api.FileMgr&m=' + method + '&p=' + self.pfad + '&p=' + saveFileName + 'p3=' + content;
-    self.http_post(u, data, function(resp) {
-      // hier scheint nichts zurueckzukommen..
+    var u = '../svc' + m;
+    var data = '&p=' + self.pfad + '&p=' + saveFileName + '&p=' + encodeURIComponent(content);
+    self.fm_post(u, data, "text", function(resp) {
+      // ...
     });
-    /*
-    self.fm_post(u, {p: self.pfad, p: saveFileName, p: content}, '', function(resp) {
-      // hier scheint nichts zurueckzukommen..
-    });
-    */
     self.openFileName = saveFileName;
     if(typeof (callback) !== 'function') {
 
@@ -673,8 +677,10 @@
   
   this.fm_text_edit = function(content, mode) {
     document.querySelector(".codeeditor-space").style.display = "block";
-    document.querySelector(".code-editor-container").style.display = "block";
-    document.querySelector(".zentrum-behaelter").style.display = "none";
+    //document.querySelector(".code-editor-container").style.display = "block";
+    //document.querySelector(".zentrum-behaelter").style.display = "none";
+    document.querySelector(".breadcrumb").style.display = "none";
+    document.querySelector(".zentrum").style.display = "none";
     self.fm_code_edit(content, mode);  
     self.openEditor = 'text';
   };
@@ -696,8 +702,10 @@
   
   this.fm_do_close = function() {
     document.querySelector(".codeeditor-space").style.display = "none";
-    document.querySelector(".code-editor-container").style.display = "none";
-    document.querySelector(".zentrum-behaelter").style.display = "block";
+    //document.querySelector(".code-editor-container").style.display = "none";
+    //document.querySelector(".zentrum-behaelter").style.display = "block";
+    document.querySelector(".breadcrumb").style.display = "block";
+    document.querySelector(".zentrum").style.display = "block";
     if(self.cm !== undefined) {
       self.cm.toTextArea();
     }
@@ -739,8 +747,10 @@
   
   this.removeAllListeners = function(id) {
     var el = document.getElementById(id);
-    elClone = el.cloneNode(true);
-    el.parentNode.replaceChild(elClone, el);
+    if(el !== null) {
+      elClone = el.cloneNode(true);
+      el.parentNode.replaceChild(elClone, el);
+    }
   }; // https://stackoverflow.com/questions/19469881/remove-all-event-listeners-of-specific-type
 
   this.escapeHtml = function(text) {
@@ -795,7 +805,7 @@
     var xmlhttp = new XMLHttpRequest();
     var url = u;
     xmlhttp.onreadystatechange = function() {
-      if (this.readyState == 4 && this.status == 200) {
+      if (this.readyState === 4 && this.status === 200) {
         scallback(this.responseText);
       }
     };
@@ -807,32 +817,16 @@
     var xmlhttp = new XMLHttpRequest();
     var url = u;
     xmlhttp.onreadystatechange = function() {
-      if (this.readyState == 4 && this.status == 200) {
+      if (this.readyState === 4 && this.status === 200) {
         scallback(this.responseText);
       }
     };
     xmlhttp.open("POST", url, true);
     xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
-    //xmlhttp.send(d);
-    xmlhttp.send(self.serialisieren(d));
-
-    /*
-    $.ajax({
-      url: u,
-      data: d,
-      type: "POST",
-      dataType: dtype,
-      success: scallback,
-      error: function (xhr, status, errorThrown) {
-        $('#fehler').html("Error: " + errorThrown + " Status: " + status);
-      },
-      complete: function (xhr, status) {
-        //alert( "The request is complete!" );
-      }
-    });
-     */
+    xmlhttp.send(d);
   };
 
+  /*
   this.http_get = function(u, cb)  {
     self.http_call('GET', u, null, cb);
   };
@@ -849,7 +843,7 @@
         scallback(this.responseText);
       }
     };
-    xhr.open(method, url);
+    xhr.open(method, url, false);
     if(method === 'GET')  {
       xhr.send();
     } else if(method === 'POST' || method === 'PUT') {
@@ -857,7 +851,7 @@
       xhr.send(data);
     }
   };
-  
+  */
 
 
 }

--
Gitblit v1.9.3