From e62473b629b362808fe6dd3958389454ac854519 Mon Sep 17 00:00:00 2001 From: ulrich@undisclosed <ulrich@ulrich-vaio> Date: Tue, 19 May 2020 13:12:08 +0000 Subject: [PATCH] In Arbeit: Piktogramme, Abmelden, Stile verfeinert --- web/ui2/js/app.js | 74 +++++++++++++++--------------------- 1 files changed, 31 insertions(+), 43 deletions(-) diff --git a/web/ui2/js/app.js b/web/ui2/js/app.js index d6a208d..a817006 100644 --- a/web/ui2/js/app.js +++ b/web/ui2/js/app.js @@ -1,11 +1,10 @@ function NutzerApp() { var self = this; - var vorlagen; var userid; - var loc; + this.cache = {}; // mustache template cache this.init = function () { - self.vorlagen = new Vorlagen(); + //self.vorlagen = new Vorlagen(); var dlg = document.querySelector(".dialog"); dlg.style.flexBasis = '0em'; document.querySelector('#top-neu-btn').addEventListener('click', self.nutzer_neu_dialog_zeigen); @@ -13,7 +12,6 @@ document.querySelector('.ost').style.flexBasis = '0em'; self.get_login(); self.get_user_list(); - self.loc = window.location.protocol + '//' + window.location.host; }; /* Nutzerverwaltung */ @@ -76,7 +74,7 @@ } else { rollen = 'keine'; } - self.vorlagen.html_erzeugen( + self.html_erzeugen( 'data/tpl/nutzer-rollen-dlg.tpl', rollen, function (html) { @@ -111,7 +109,7 @@ var m = 'getRoleNamesGranted'; var u = '../svc/' + m; self.http_get(u, function (antwort2) { - self.vorlagen.html_erzeugen( + self.html_erzeugen( 'data/tpl/alle-rollen.tpl', JSON.parse(antwort2), function (html) { @@ -237,7 +235,7 @@ */ this.dialog_zeigen = function (vurl, inhalt, renderCallback) { var dlg = document.querySelector(".dialog"); - self.vorlagen.html_erzeugen( + self.html_erzeugen( vurl, inhalt, function (html) { @@ -267,7 +265,7 @@ var m = 'getUserNameList'; var u = '../svc/' + m; self.http_get(u, function (antwort) { - self.vorlagen.html_erzeugen( + self.html_erzeugen( 'data/tpl/inhalt.tpl', JSON.parse(antwort), function (h) { @@ -334,29 +332,30 @@ }; /* -------- ajax helper functions ----------- */ + + this.http_get = function(u, cb) { + self.http_call('GET', u, null, cb); + }; + + this.http_post = function(u, data, cb) { + self.http_call('POST', u, data, cb); + }; - this.http_get = function (u, scallback) { - var xmlhttp = new XMLHttpRequest(); + this.http_call = function (method, u, data, scallback) { + var xhr = new XMLHttpRequest(); var url = u; - xmlhttp.onreadystatechange = function() { + xhr.onreadystatechange = function() { if (this.readyState === 4 && this.status === 200) { scallback(this.responseText); } }; - xmlhttp.open("GET", url, true); - 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); + xhr.open(method, url); + if(method === 'GET') { + xhr.send(); + } else if(method === 'POST' || method === 'PUT') { + xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xhr.send(data); + } }; /* ----- Hilfsfunktionen ----- */ @@ -377,15 +376,9 @@ var el = document.getElementById(elementId); elClone = el.cloneNode(true); el.parentNode.replaceChild(elClone, el); - }; + }; // https://stackoverflow.com/questions/19469881/remove-all-event-listeners-of-specific-type -} - -/* ----- Vorlagen ----- */ - -function Vorlagen() { - var self = this; - this.cache = {}; // mustache template cache + /* ---- Vorlagen ---- */ this.html_erzeugen = function(vurl, inhalt, cb) { var vorlage = self.cache[vurl]; @@ -401,18 +394,13 @@ }; this.vorlage_laden_und_fuellen = function(vurl, inhalt, cb) { - var xmlhttp = new XMLHttpRequest(); - xmlhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - self.cache[vurl] = this.responseText; - self.vorlage_fuellen(vurl, inhalt, cb); - } - }; - xmlhttp.open("GET", vurl, true); - xmlhttp.send(); + app.http_get(vurl, function(antwort) { + self.cache[vurl] = antwort; + self.vorlage_fuellen(vurl, inhalt, cb); + }); }; -} +} /* ----- Objekte ----- */ -- Gitblit v1.9.3