From d1b8b275ab33a0d38f2ac0ede6ae9fa4a6f798f8 Mon Sep 17 00:00:00 2001
From: undisclosed
Date: Mon, 11 May 2020 16:04:49 +0000
Subject: [PATCH] Neuen Nutzer speichern

---
 web/ui2/js/app.js                   |   66 ++++++++++++++++++++++++++++----
 web/ui2/data/tpl/dlg-nutzer-neu.tpl |    2 
 web/ui2/stile.css                   |    4 ++
 3 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/web/ui2/data/tpl/dlg-nutzer-neu.tpl b/web/ui2/data/tpl/dlg-nutzer-neu.tpl
index e74c6e5..5e024d6 100644
--- a/web/ui2/data/tpl/dlg-nutzer-neu.tpl
+++ b/web/ui2/data/tpl/dlg-nutzer-neu.tpl
@@ -13,7 +13,7 @@
       <input id="nutzer-kw" placeholder="Kennwort" type="text" class="nutzer-eingabe"></br>
       <input id="nutzer-wkw" placeholder="Wiederholung Kennwort" type="text" class="nutzer-eingabe"></br>
       <div class="form-button-footer">
-        <button type="button" id="nutzer-speichern">Speichern</button>
+        <button type="button" id="nutzer-speichern-btn">Speichern</button>
       </div>
     </form>
   </div>
diff --git a/web/ui2/js/app.js b/web/ui2/js/app.js
index 85488db..38e6909 100644
--- a/web/ui2/js/app.js
+++ b/web/ui2/js/app.js
@@ -22,6 +22,26 @@
     }
     target.classList.add("nutzer-gewaehlt");
   };
+  
+  this.nutzer_speichern = function() {
+    var user = self.nutzer_dialog_lesen();
+    var kww = document.getElementById('nutzer-wkw').value;
+    if(user.pw !== kww) {
+      self.meldung_mit_timeout("Kennworte stimmen nicht ueberein.", 1500);
+    } else {
+      self.neuen_nutzer_speichern('p=' + self.serialisieren(user));
+    }
+  };
+  
+  this.nutzer_dialog_lesen = function() {
+    var id = document.getElementById('nutzer-id').value;
+    var vname = document.getElementById('nutzer-vorname').value;
+    var nname = document.getElementById('nutzer-name').value;
+    var email = document.getElementById('nutzer-email').value;
+    var kw = document.getElementById('nutzer-kw').value;
+    var user = new User(id, kw, vname, nname, email);
+    return user;
+  };
 
   /* Funktionen aus App-Vorlage */
 
@@ -40,8 +60,8 @@
     var dlg = document.querySelector(".dialog");
     dlg.style.flexBasis = '0em';
     self.seitenleiste_umschalten();
-    self.um_get_login();
-    self.um_get_user_list();
+    self.get_login();
+    self.get_user_list();
     self.loc = window.location.protocol + '//' + window.location.host;
   };
 
@@ -92,6 +112,10 @@
   this.meldung_mit_timeout = function (meldung, timeout) {
     var s = document.querySelector('.sued');
     s.textContent = meldung;
+    if (!s.classList.contains('sued-open')) {
+      s.classList.add('sued-open');
+      s.style.height = '1.5em';
+    }
     setTimeout(function () {
       s.textContent = 'Bereit.';
       setTimeout(function () {
@@ -136,6 +160,10 @@
               setTimeout(function () {
                 dlg.innerHTML = html;
                 document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen);
+                var btn = document.getElementById('nutzer-speichern-btn');
+                if(btn !== null) {
+                  btn.addEventListener('click', self.nutzer_speichern);                         
+                }                
               }, 300);
             });
   };
@@ -149,11 +177,11 @@
 
   /* API functions */
   
-  this.um_get_user_list = function() {
+  this.get_user_list = function() {
     //var m = 'getUserNameList';
     var m = 'getUserNameList';
     var u = '../svc/' + m;
-    self.um_get(u, "json", function (antwort) {
+    self.http_get(u, function (antwort) {
     self.vorlagen.html_erzeugen(
       'data/tpl/inhalt.tpl',
       JSON.parse(antwort),
@@ -170,13 +198,21 @@
       });
     });
   };
+  
+  this.neuen_nutzer_speichern = function(u) {
+    var url = '../svc/createUser';
+    self.http_post(url, u, function (antwort) {
+      self.get_user_list();
+      self.dialog_schliessen();
+    });
+  };
 
   /* -------- An- und Abmelden ------------- */
 
-  this.um_get_login = function() {
+  this.get_login = function() {
     var m = '?c=de.uhilger.um.pub.SessionManager&m=getSessionUser';
     var u = '../pub' + m;
-    self.um_get(u, "text", function (resp) {
+    self.http_get(u, function (resp) {
       self.userid = resp;
       self.login_zeigen();
       //document.querySelector("#userMenu").textContent = resp;
@@ -186,7 +222,7 @@
   this.um_logout = function() {
     var m = '?c=de.uhilger.um.pub.SessionManager&m=expireSession';
     var u = '../pub' + m;
-    self.um_get(u, "text", function (resp) {
+    self.http_get(u, function (resp) {
       //$('#userMenu').text('nicht angemeldet');
       window.location.href = '../logout.html';
     });
@@ -194,11 +230,11 @@
 
   /* -------- ajax helper functions ----------- */
 
-  this.um_get = function (u, dtype, scallback) {    
+  this.http_get = function (u, scallback) {    
     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);
       }
     };
@@ -206,6 +242,18 @@
     xmlhttp.send();
   };
   
+  this.http_post = function (url, data, callback) {
+    var xhr = new XMLHttpRequest();
+    xhr.onreadystatechange = function() {
+      if (this.readyState === 4 && this.status === 200) {
+        callback(this.responseText);
+      }
+    };
+    xhr.open("POST", url, true);
+    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
+    xhr.send(data);
+  };
+  
 /* ----- Hilfsfunktionen ----- */
 
   this.serialisieren = function(obj) {
diff --git a/web/ui2/stile.css b/web/ui2/stile.css
index cb4abb0..1b26e5a 100644
--- a/web/ui2/stile.css
+++ b/web/ui2/stile.css
@@ -160,6 +160,10 @@
 
 /* Nutzerliste */
 
+.nutzer-liste-eintrag {
+  cursor: pointer;
+}
+
 .nutzer-gewaehlt {
   background-color: lightsteelblue;
 }

--
Gitblit v1.9.3