| | |
| | | function NutzerApp() { |
| | | var self = this; |
| | | var vorlagen; |
| | | //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); |
| | |
| | | } else { |
| | | rollen = 'keine'; |
| | | } |
| | | self.vorlagen.html_erzeugen( |
| | | self.html_erzeugen( |
| | | 'data/tpl/nutzer-rollen-dlg.tpl', |
| | | rollen, |
| | | function (html) { |
| | |
| | | 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) { |
| | |
| | | */ |
| | | this.dialog_zeigen = function (vurl, inhalt, renderCallback) { |
| | | var dlg = document.querySelector(".dialog"); |
| | | self.vorlagen.html_erzeugen( |
| | | self.html_erzeugen( |
| | | vurl, |
| | | inhalt, |
| | | function (html) { |
| | |
| | | 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) { |
| | |
| | | }; |
| | | |
| | | /* -------- 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.send(data); |
| | | } |
| | | }; |
| | | |
| | | /* ----- Hilfsfunktionen ----- */ |
| | |
| | | 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]; |
| | |
| | | }; |
| | | |
| | | 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 ----- */ |
| | | |