From c79c120dae38042f0f5d5c31d9b7413b0a8a3e7e Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Tue, 27 Dec 2016 12:21:53 +0000
Subject: [PATCH] Neue Rolle speichern und zeigen

---
 web/ui/user.jsp                         |   16 +++++---
 web/WEB-INF/sql.properties              |    3 +
 web/ui/stile.css                        |    9 ----
 src/java/de/uhilger/um/api/UserMgr.java |   15 +++++++
 web/ui/ui.js                            |   72 +++++++++++++++++++++++++++++++----
 5 files changed, 92 insertions(+), 23 deletions(-)

diff --git a/src/java/de/uhilger/um/api/UserMgr.java b/src/java/de/uhilger/um/api/UserMgr.java
index e183a68..0c2dd04 100644
--- a/src/java/de/uhilger/um/api/UserMgr.java
+++ b/src/java/de/uhilger/um/api/UserMgr.java
@@ -24,6 +24,7 @@
   public static final String SQL_GET_USER_LIST = "getUserList";
   public static final String SQL_GET_USER_NAME_LIST = "getUserNameList";
   public static final String SQL_GET_ROLE_LIST = "getRoleList";
+  public static final String SQL_GET_USER_ROLES = "getUserRoles";
   public static final String SQL_DELETE_USER = "deleteUser";
   
   /* ----------- Benutzer -------------- */
@@ -78,6 +79,20 @@
     return roleNames;
   }
   
+  /**
+   * 
+   * 
+   * list.get(recordno).get(fieldno)
+   * 
+   * @param userId  ID des Benutzers
+   * @return List<List<String>> Rollennamen des Benutzers
+   */
+  public List getUserRoleNames(String userId) {
+    String sql = App.getSqlStatement(SQL_GET_USER_ROLES);
+    List roleNames = App.getDatabase().select(sql, App.WITHOUT_BLOBS, userId);
+    return roleNames;
+  }
+  
   /* ------------ sonstige Methoden -------------- */
   
   public String hallo() {
diff --git a/web/WEB-INF/sql.properties b/web/WEB-INF/sql.properties
index a95d457..ad9b286 100644
--- a/web/WEB-INF/sql.properties
+++ b/web/WEB-INF/sql.properties
@@ -32,6 +32,9 @@
   <entry key="getRoleList">
     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 = ?
+  </entry>
   <entry key="getDateList">
     select substr(or_zeit,1,8) as tag, count(*) as anz from app.orte as orte 
     where or_pers_id = ?  
diff --git a/web/ui/stile.css b/web/ui/stile.css
index af069d6..3836af3 100644
--- a/web/ui/stile.css
+++ b/web/ui/stile.css
@@ -14,13 +14,7 @@
   height: 100%;
 }
 
-#user-list-form {
-  height: 20em;
-}
 
-#nutzerliste {
-  height: 100%;
-}
 
 
 /* Buttons
@@ -91,8 +85,7 @@
 input[type="tel"],
 input[type="url"],
 input[type="password"],
-textarea,
-select {
+textarea {
   height: 38px;
   padding: 6px 10px; /* The 6px vertically centers text on FF, ignored by Webkit */
   background-color: #fff;
diff --git a/web/ui/ui.js b/web/ui/ui.js
index ce2d447..4a7daf9 100644
--- a/web/ui/ui.js
+++ b/web/ui/ui.js
@@ -5,6 +5,7 @@
   $('#nutzerLoeschen').click(um_del_user);
   $('#nutzerNeu').click(um_new_user);
   $('#nutzerLoeschen').prop( "disabled", true );
+  $('#nutzerRolleEntziehen').prop( "disabled", true );
   $('#neueRolle').click(um_new_role);
   um_clear_user_form();
   um_apicall_get_user_list();
@@ -32,7 +33,7 @@
   //alert('delete user ' + users[0]);
   var userId = um_get_first_selected_user_id();
   if(userId !== 'none') {
-    var antwort = confirm("Wollen Sie den Nutzer " + usersId + " loeschen?"); 
+    var antwort = confirm("Wollen Sie den Nutzer " + userId + " loeschen?"); 
     if (antwort === true) {
       var user = new User(userId, '-', '-', '-', '-');
       um_apicall_del_user(self.serialisieren(user));
@@ -55,7 +56,8 @@
     if (answer === null) {
       alert("Es wurde Cancel betaetigt.");
     } else if(answer !== "") {
-      alert("Rolle fuer Benutzer " + userId + " anlegen: " + answer);
+      //alert("Rolle fuer Benutzer " + userId + " anlegen: " + answer);
+      um_apicall_grant_role(userId, answer);
     } else {
       alert("OK betaetigt, aber Keine Rolle angegeben.");
     }
@@ -66,13 +68,8 @@
 
 function um_user_list_click() {
   $('#nutzerLoeschen').prop( "disabled", false );
-  /*
-   var users = [];
-   $('#nutzerliste :selected').each(function(i, selected){
-     users[i] = $(selected).text();
-   });
-  */
-   //alert(users[0]);
+  var userId = um_get_first_selected_user_id();
+  um_apicall_get_user_roles(userId);
 }
 
 
@@ -114,6 +111,17 @@
     userId = userIds[0];
   }
   return userId;
+}
+
+// {"List":[{"List":[{"String":"ROLE_NAME"},{"String":"testrolle1"}]}]}
+function um_show_user_role_list(resp) {
+  $("#nutzerrollen").empty();
+  var rollen = resp.List[0];
+  for(var i = 1; i < rollen.List.length; i++) {
+    var rolle = rollen.List[i];
+    $("#nutzerrollen").append('<option value=' + rolle.String + '>' + rolle.String + '</option>');
+  }
+  $('#nutzerRolleEntziehen').prop( "disabled", true );
 }
 
 /* ---- api calls ----- */
@@ -183,6 +191,52 @@
   });      
 }
 
+// public UserRole grantRole(String userId, String roleName) 
+function um_apicall_grant_role(userId, roleName) {
+  var m = 'grantRole';
+  var u = '../svc/' + m;
+  $.ajax({
+    url: u,
+    data: {
+      p1: userId,
+      p2: roleName
+    },
+    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);
+    },
+    error: function( xhr, status, errorThrown ) {
+      $('#fehler').html("Error: " + errorThrown + " Status: " + status);
+    },
+    complete: function( xhr, status ) {
+      //alert( "The request is complete!" );
+    }
+  });
+}
+
+//public List getUserRoleNames(String userId)
+function um_apicall_get_user_roles(userId) {
+  var m = 'getUserRoleNames';
+  var u = '../svc/' + m + '?p=' + userId;
+  $.ajax({
+    url: u,
+    type: "GET",
+    dataType : "json",
+    success: function( resp ) {
+      // Antwort in Liste anzeigen
+      um_show_user_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) {
diff --git a/web/ui/user.jsp b/web/ui/user.jsp
index 61a918d..f8425d9 100644
--- a/web/ui/user.jsp
+++ b/web/ui/user.jsp
@@ -5,33 +5,37 @@
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>Benutzer</title>
-    <!-- <link rel="stylesheet" href="/jslib/skeleton-2.0.4/css/normalize.css"> -->
-    <!-- <link rel="stylesheet" href="/jslib/skeleton-2.0.4/css/skeleton.css"> -->
     <link rel="stylesheet" type="text/css" href="stile.css">
   </head>
   <body>
     <div id="inhalt">
       <h1>Benutzer</h1>
       <div id="user-list-form">
-        <select size="8" name="nutzerliste" id="nutzerliste"></select>
+        <select size="5" name="nutzerliste" id="nutzerliste"></select>
       </div>
       <div>
         <input type="button" name="nutzerLoeschen" id="nutzerLoeschen" value="L&ouml;schen">
-        &nbsp;
         <input type="button" name="nutzerNeu" id="nutzerNeu" value="Neu">            
       </div>
       <div id="user-form">
         <input type="text" size="20" maxlength="20" placeholder="Anmeldename" name="anmeldename" id="anmeldename">
         <input type="password" size="20" maxlength="20" placeholder="Kennwort" name="kennwort" id="kennwort">
         <input type="password" size="20" maxlength="20" placeholder="Wiederholung" name="kennwortw" id="kennwortw">
+        <button class="user-cancel-btn">Abbrechen</button>
         <button class="user-save-btn">OK</button>
       </div>
       <div id="user-role-form">
-        <select size="8" name="nutzerrollen" id="nutzerrollen"></select>
+        <h5>Rollen des Benutzers</h5>
+        <select size="5" name="nutzerrollen" id="nutzerrollen"></select>
+      </div>
+      <div>
         <input type="button" name="nutzerRolleEntziehen" id="nutzerRolleEntziehen" value="Entziehen">
       </div>
       <div id="role-form">
-        <select size="8" name="rollen" id="rollen"></select>
+        <h5>Rollen</h5>
+        <select size="5" name="rollen" id="rollen"></select>
+      </div>
+      <div>
         <input type="button" name="neueRolle" id="neueRolle" value="Neu">
         <input type="button" name="rolleErteilen" id="rolleErteilen" value="Erteilen">
       </div>

--
Gitblit v1.9.3