From d65863f4765853660eab4197ac4caa00f893f0b1 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sat, 16 May 2020 12:23:00 +0000 Subject: [PATCH] Wechsel zurueck zu 'Neuer Benutzer' bei Anzeige Nutzerliste --- web/ui2/js/app.js | 64 +++++++++++++++++++++++++------- 1 files changed, 50 insertions(+), 14 deletions(-) diff --git a/web/ui2/js/app.js b/web/ui2/js/app.js index 6c407e7..36c9fcf 100644 --- a/web/ui2/js/app.js +++ b/web/ui2/js/app.js @@ -8,7 +8,7 @@ self.vorlagen = new Vorlagen(); var dlg = document.querySelector(".dialog"); dlg.style.flexBasis = '0em'; - document.querySelector('#nutzer-neu-btn').addEventListener('click', self.nutzer_neu_dialog_zeigen); + document.querySelector('#top-neu-btn').addEventListener('click', self.nutzer_neu_dialog_zeigen); document.querySelector('.west').style.flexBasis = '0em'; document.querySelector('.ost').style.flexBasis = '0em'; self.get_login(); @@ -61,6 +61,11 @@ /* Rollen erteilen und entziehen */ this.rollen_zeigen = function(nutzerId) { + var topBtn = document.querySelector('#top-neu-btn'); + topBtn.removeEventListener('click', self.nutzer_neu_dialog_zeigen); + topBtn.addEventListener('click', self.rolle_neu_dialog_zeigen); + topBtn.title = "Neue Rolle"; + var m = 'getUserRoleNames'; var u = '../svc/' + m + '?p=' + nutzerId; self.http_get(u, function (antwort) { @@ -103,13 +108,17 @@ this.grant_role_klick = function(event) { self.alter_role(event, 'grantRole', function(roleId) { - var btn = document.createElement("button"); - btn.type = "button"; - btn.classList.add("granted-role-btn"); - btn.id = roleId; - btn.textContent = roleId; - document.querySelector('.rollen-behaelter').appendChild(btn); + self.add_role_to_user_roles(roleId); }); + }; + + this.add_role_to_user_roles = function(roleId) { + var btn = document.createElement("button"); + btn.type = "button"; + btn.classList.add("granted-role-btn"); + btn.id = roleId; + btn.textContent = roleId; + document.querySelector('.rollen-behaelter').appendChild(btn); }; this.revoke_role_klick = function(event) { @@ -123,14 +132,24 @@ var target = event.target; var nutzerId = document.querySelector("#nutzer-id").textContent; var roleId = target.textContent; - var u = '../svc/' + method; - var data = "p=" + self.serialisieren(new UserRole(nutzerId, roleId)); - self.http_post(u, data, function (antwort) { - updateCallback(roleId); - }); + self.alter_role_call(method, nutzerId, roleId, updateCallback); }; - + this.rolle_neu_dialog_zeigen = function () { + self.dialog_zeigen('data/tpl/dlg-rolle-neu.tpl', '', function(){ + var btn = document.getElementById('rolle-speichern-btn'); + if(btn !== null) { + btn.addEventListener('click', function() { + var nutzerId = document.querySelector("#nutzer-id").textContent; + var rolle = document.getElementById('rollen-id').value; + self.alter_role_call('grantRole', nutzerId, rolle, function(roleId) { + self.add_role_to_user_roles(roleId); + self.dialog_schliessen(); + }); + }); + } + }); + }; /* Funktionen aus App-Vorlage */ @@ -227,7 +246,6 @@ /* API functions */ this.get_user_list = function() { - //var m = 'getUserNameList'; var m = 'getUserNameList'; var u = '../svc/' + m; self.http_get(u, function (antwort) { @@ -239,6 +257,10 @@ elem.innerHTML = h; self.addEvtListener('p.nutzer-liste-eintrag', 'click', self.nutzerliste_klick); document.querySelector('.zurueck-btn').style.color = '#eee'; + self.removeAllListeners('top-neu-btn'); + var topBtn = document.querySelector('#top-neu-btn'); + topBtn.title = "Neuer Benutzer"; + topBtn.addEventListener('click', self.nutzer_neu_dialog_zeigen); }); }); }; @@ -253,6 +275,14 @@ }); }; + this.alter_role_call = function(method, nutzerId, roleId, updateCallback) { + var u = '../svc/' + method; + var data = "p=" + self.serialisieren(new UserRole(nutzerId, roleId)); + self.http_post(u, data, function (antwort) { + updateCallback(roleId); + }); + }; + /* -------- An- und Abmelden ------------- */ this.get_login = function() { @@ -313,6 +343,12 @@ elems[index].addEventListener(eventName, func); } }; + + this.removeAllListeners = function(elementId) { + var el = document.getElementById(elementId); + elClone = el.cloneNode(true); + el.parentNode.replaceChild(elClone, el); + }; } -- Gitblit v1.9.3