From ab2b54c221c5be0fd7ee12c0cecf2951265ba050 Mon Sep 17 00:00:00 2001 From: undisclosed Date: Thu, 14 May 2020 18:12:50 +0000 Subject: [PATCH] Funktionen des Rollen-Dialogs fertig, design muss noch geaendert werden --- web/ui2/js/app.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-------- web/ui2/data/tpl/nutzer-rollen-dlg.tpl | 2 +- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/web/ui2/data/tpl/nutzer-rollen-dlg.tpl b/web/ui2/data/tpl/nutzer-rollen-dlg.tpl index 4e0dcf3..558f286 100644 --- a/web/ui2/data/tpl/nutzer-rollen-dlg.tpl +++ b/web/ui2/data/tpl/nutzer-rollen-dlg.tpl @@ -3,7 +3,7 @@ <div class="rollen-behaelter"> {{#List}} {{#List}} - <button type="button" class="granted-role-btn">{{String}}</button> + <button type="button" class="granted-role-btn" id="{{String}}">{{String}}</button> {{/List}} {{/List}} </div> diff --git a/web/ui2/js/app.js b/web/ui2/js/app.js index 56ea01c..0548b27 100644 --- a/web/ui2/js/app.js +++ b/web/ui2/js/app.js @@ -86,7 +86,8 @@ JSON.parse(antwort), function (html) { document.querySelector("#nutzer").innerHTML = html; - document.querySelector("#nutzer-id").textContent = nutzerId; + document.querySelector("#nutzer-id").textContent = nutzerId; + self.addEvtListener('.granted-role-btn', 'click', self.revoke_role_klick); var m = 'getRoleNamesGranted'; var u = '../svc/' + m; self.http_get(u, function (antwort2) { @@ -95,10 +96,43 @@ JSON.parse(antwort2), function (html) { document.querySelector(".alle-rollen-behaelter").innerHTML = html; + document.querySelector('.zurueck-btn').addEventListener('click', function (e) { + self.get_user_list(); + }); + self.addEvtListener('.avl-role-btn', 'click', self.grant_role_klick); }); }); }); }); + }; + + 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); + }); + }; + + this.revoke_role_klick = function(event) { + self.alter_role(event, 'revokeRole', function(roleId) { + var btn = document.querySelector("#" + roleId); + btn.parentNode.removeChild(btn); + }); + }; + + this.alter_role = function(event, method, updateCallback) { + 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); + }); }; this.info_dialog_zeigen = function () { @@ -212,13 +246,7 @@ function (h) { var elem = document.getElementById('nutzer'); elem.innerHTML = h; - - var absaetze = document.querySelectorAll('p.nutzer-liste-eintrag'); - var index; - for (index = 0; index < absaetze.length; index++) { - absaetze[index].addEventListener("click", self.nutzerliste_klick); - } - + self.addEvtListener('p.nutzer-liste-eintrag', 'click', self.nutzerliste_klick); }); }); }; @@ -285,6 +313,14 @@ this.serialisieren = function(obj) { return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; }; + + this.addEvtListener = function(selector, eventName, func) { + var elems = document.querySelectorAll(selector); + var index; + for (index = 0; index < elems.length; index++) { + elems[index].addEventListener(eventName, func); + } + }; } @@ -299,3 +335,7 @@ this.email = em; } +function UserRole(u, r) { + this.userId = u; + this.role = r; +} \ No newline at end of file -- Gitblit v1.9.3