From 3cd7fefd7afb5a8a2f70290b9bbeb453c5f9382b Mon Sep 17 00:00:00 2001
From: ulrich
Date: Thu, 02 Feb 2017 05:31:34 +0000
Subject: [PATCH] Doku ergaenzt

---
 web/ui/ui.js |   59 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/web/ui/ui.js b/web/ui/ui.js
index 1de6543..b2efd06 100644
--- a/web/ui/ui.js
+++ b/web/ui/ui.js
@@ -134,14 +134,26 @@
   return user;
 }
 
+/*
+ * BaseLink liefert fuer einfache selects wie die der Nutzerverwaltung 
+ * eine simple Listenfunktion, die auf der JSON-Seite wie folgt 
+ * herauskommt.
+ * 
+ * {"List":[{"List":[{"String":"USER_NAME"},{"String":"admin"},{"String":"test"}]}]}
+ * 
+ * Fuer Mustache sieht ein Template dann z.B so aus:
+ * 
+ *    {{#List}}
+ *    {{#List}}
+ *      <option value="{{ String }}">{{ String }}</option>'
+ *    {{/List}}
+ *    {{/List}}
+ */
 function um_show_user_list(resp) {
   $("#nutzerliste").empty();
-  var users = resp.List[0];
-  for(var i = 1; i < users.List.length; i++) {
-    var user = users.List[i];
-    $("#nutzerliste").append('<option value=' + user.String + '>' + user.String + '</option>');
-  }
-  $('#nutzerLoeschen').prop( "disabled", true );
+  var template = $('#tpl-list').html();
+  Mustache.parse(template);   // optional, speeds up future uses
+  $("#nutzerliste").append( Mustache.render(template, resp) );
 }
 
 function um_clear_user_form() {
@@ -188,21 +200,22 @@
 
 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>');
-  }
+  
+  var template = $('#tpl-list').html();
+  Mustache.parse(template);   // optional, speeds up future uses
+  $("#nutzerrollen").append( Mustache.render(template, resp) );
+  
   $('#nutzerRolleEntziehen').prop( "disabled", true );
+  $('#rolleErteilen').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>');
-  }
+  
+  var template = $('#tpl-list').html();
+  Mustache.parse(template);   // optional, speeds up future uses
+  $("#rollen").append( Mustache.render(template, resp) );
+  
   $('#rolleErteilen').prop( "disabled", true );
 }
 
@@ -272,14 +285,15 @@
   });      
 }
 
+// http]://example.com/um/api?c=de.uhilger.um.api.UserMgr&m=testmethode
 function um_apicall_grant_role(userId, roleName, isNewRole) {
+  var ur = new UserRole(userId, roleName);
   var m = 'grantRole';
   var u = '../svc/' + m;
   $.ajax({
     url: u,
     data: {
-      p1: userId,
-      p2: roleName
+      p: self.serialisieren(ur)
     },
     type: "POST",
     dataType : "html",
@@ -299,13 +313,13 @@
 }
 
 function um_apicall_revoke_role(userId, roleName) {
+  var ur = new UserRole(userId, roleName);
   var m = 'revokeRole';
   var u = '../svc/' + m;
   $.ajax({
     url: u,
     data: {
-      p1: userId,
-      p2: roleName
+      p: self.serialisieren(ur)
     },
     type: "POST",
     dataType : "html",
@@ -373,4 +387,9 @@
   this.firstName = fn;
   this.lastName = ln;
   this.email = em;
+}
+
+function UserRole(u, r) {
+  this.userId = u;
+  this.role = r;
 }
\ No newline at end of file

--
Gitblit v1.9.3