From 51edf4cdf3d517ff79150d26d35d819d96f0cbd1 Mon Sep 17 00:00:00 2001 From: ulrich <not disclosed> Date: Tue, 27 Dec 2016 12:40:36 +0000 Subject: [PATCH] Vergebene Rollen zeigen --- web/WEB-INF/sql.properties | 2 web/ui/ui.js | 62 ++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/web/WEB-INF/sql.properties b/web/WEB-INF/sql.properties index ad9b286..3a60687 100644 --- a/web/WEB-INF/sql.properties +++ b/web/WEB-INF/sql.properties @@ -33,7 +33,7 @@ select distinct role_name from app.user_roles order by role_name </entry> <entry key="getUserRoles"> - select role_name from app.user_roles where user_name = ? + select role_name from app.user_roles where user_name = ? order by role_name </entry> <entry key="getDateList"> select substr(or_zeit,1,8) as tag, count(*) as anz from app.orte as orte diff --git a/web/ui/ui.js b/web/ui/ui.js index 4a7daf9..c6e9098 100644 --- a/web/ui/ui.js +++ b/web/ui/ui.js @@ -6,9 +6,13 @@ $('#nutzerNeu').click(um_new_user); $('#nutzerLoeschen').prop( "disabled", true ); $('#nutzerRolleEntziehen').prop( "disabled", true ); + $('#rolleErteilen').prop( "disabled", true ); $('#neueRolle').click(um_new_role); + $('#rollen').click(um_role_list_click); + $('#nutzerrollen').click(um_user_role_list_click); um_clear_user_form(); um_apicall_get_user_list(); + um_apicall_get_granted_roles(); } /* ----- user functions ------ */ @@ -19,18 +23,11 @@ if(user.pw != kww) { alert('Kennworte stimmen nicht ueberein.'); } else { - //alert('user-save ' + user.id); um_apicall_create_user(self.serialisieren(user)); } } function um_del_user() { - /*var users = []; - $('#nutzerliste :selected').each(function(i, selected){ - users[i] = $(selected).text(); - });*/ - - //alert('delete user ' + users[0]); var userId = um_get_first_selected_user_id(); if(userId !== 'none') { var antwort = confirm("Wollen Sie den Nutzer " + userId + " loeschen?"); @@ -48,6 +45,7 @@ /* ----------- role functions ------------ */ function um_new_role() { + var roleIsNew = true; var userId = um_get_first_selected_user_id(); if(userId === 'none') { alert('Es wurde kein Benutzer ausgewaehlt.'); @@ -56,8 +54,7 @@ if (answer === null) { alert("Es wurde Cancel betaetigt."); } else if(answer !== "") { - //alert("Rolle fuer Benutzer " + userId + " anlegen: " + answer); - um_apicall_grant_role(userId, answer); + um_apicall_grant_role(userId, answer, roleIsNew); } else { alert("OK betaetigt, aber Keine Rolle angegeben."); } @@ -70,6 +67,14 @@ $('#nutzerLoeschen').prop( "disabled", false ); var userId = um_get_first_selected_user_id(); um_apicall_get_user_roles(userId); +} + +function um_role_list_click() { + $('#rolleErteilen').prop( "disabled", false ); +} + +function um_user_role_list_click() { + $('#nutzerRolleEntziehen').prop( "disabled", false ); } @@ -90,9 +95,6 @@ $("#nutzerliste").append('<option value=' + user.String + '>' + user.String + '</option>'); } $('#nutzerLoeschen').prop( "disabled", true ); - //var user1 = users.List[1]; - //var username = user1.String; - //alert(username); } function um_clear_user_form() { @@ -124,6 +126,16 @@ $('#nutzerRolleEntziehen').prop( "disabled", true ); } +function um_show_role_list(resp) { + $("#rollen").empty(); + var rollen = resp.List[0]; + for(var i = 1; i < rollen.List.length; i++) { + var rolle = rollen.List[i]; + $("#rollen").append('<option value=' + rolle.String + '>' + rolle.String + '</option>'); + } + //$('#neueRolle').prop( "disabled", true ); + $('#rolleErteilen').prop( "disabled", true ); +} /* ---- api calls ----- */ function um_apicall_create_user(user) { @@ -192,7 +204,7 @@ } // public UserRole grantRole(String userId, String roleName) -function um_apicall_grant_role(userId, roleName) { +function um_apicall_grant_role(userId, roleName, isNewRole) { var m = 'grantRole'; var u = '../svc/' + m; $.ajax({ @@ -204,8 +216,10 @@ type: "POST", dataType : "html", success: function( resp ) { - // Liste der Rollen des Benutzers neu anzeigen bzw. die neue Rolle dort hinzufuegen um_apicall_get_user_roles(userId); + if(isNewRole) { + um_apicall_get_granted_roles(); + } }, error: function( xhr, status, errorThrown ) { $('#fehler').html("Error: " + errorThrown + " Status: " + status); @@ -237,6 +251,26 @@ }); } +function um_apicall_get_granted_roles() { + var m = 'getRoleNamesGranted'; + var u = '../svc/' + m; + $.ajax({ + url: u, + type: "GET", + dataType : "json", + success: function( resp ) { + // Antwort in Liste anzeigen + um_show_role_list(resp); + }, + error: function( xhr, status, errorThrown ) { + $('#fehler').html("Error: " + errorThrown + " Status: " + status); + }, + complete: function( xhr, status ) { + //alert( "The request is complete!" ); + } + }); +} + /* ----- Hilfsfunktionen ----- */ function serialisieren(obj) { -- Gitblit v1.9.3