From 87e382c61272e351b04715c960d485f863b7e594 Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Sat, 24 Dec 2016 15:30:33 +0000
Subject: [PATCH] Rollen in Arbeit

---
 web/ui/ui.js |  135 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 122 insertions(+), 13 deletions(-)

diff --git a/web/ui/ui.js b/web/ui/ui.js
index cb2f979..7782450 100644
--- a/web/ui/ui.js
+++ b/web/ui/ui.js
@@ -1,7 +1,15 @@
 
 function um_init() {
   $('.user-save-btn').click(um_user_save);
+  $('#nutzerliste').click(um_user_list_click);
+  $('#nutzerLoeschen').click(um_del_user);
+  $('#nutzerNeu').click(um_new_user);
+  $('#nutzerLoeschen').prop( "disabled", true );
+  um_clear_user_form();
+  um_apicall_get_user_list();
 }
+
+/* ----- user functions ------ */
 
 function um_user_save() {
   var user = um_user_form_lesen();
@@ -9,25 +17,88 @@
   if(user.pw != kww) {
     alert('Kennworte stimmen nicht ueberein.');
   } else {
-    alert('user-save ' + user.id);
-    um_apicall(self.serialisieren(user));
+    //alert('user-save ' + user.id);
+    um_apicall_create_user(self.serialisieren(user));
   }
 }
 
-function um_apicall(obj) {
-  var c = 'de.uhilger.um.api.UserMgr';
+function um_del_user() {
+  var users = [];
+  $('#nutzerliste :selected').each(function(i, selected){
+    users[i] = $(selected).text();
+  });
+
+  //alert('delete user ' + users[0]);
+  var antwort = confirm("Wollen Sie den Nutzer " + users[0] + " loeschen?"); 
+  if (antwort == true) {
+    var user = new User(users[0], '-', '-', '-', '-');
+    um_apicall_del_user(self.serialisieren(user));
+  }  
+}
+
+function um_new_user() {
+  alert('show form to enter new user');
+}
+
+/* ----------- ui interaction ------------ */
+
+function um_user_list_click() {
+  $('#nutzerLoeschen').prop( "disabled", false );
+  /*
+   var users = [];
+   $('#nutzerliste :selected').each(function(i, selected){
+     users[i] = $(selected).text();
+   });
+  */
+   //alert(users[0]);
+}
+
+
+/* ------- ui i/o ------ */
+
+function um_user_form_lesen() {
+  var userId = $('#anmeldename').val();
+  var kw = $('#kennwort').val();
+  var user = new User(userId, kw, '-', '-', '-');
+  return user;
+}
+
+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 user1 = users.List[1];
+  //var username = user1.String;
+  //alert(username);
+}
+
+function um_clear_user_form() {
+  $('#anmeldename').val('');
+  $('#kennwort').val('');
+  $('#kennwortw').val('');
+}
+
+/* ---- api calls ----- */
+
+function um_apicall_create_user(user) {
   var m = 'createUser';
-  var u = '../api?c=' + c + '&m=' + m;
+  var u = '../svc/' + m;
   $.ajax({
     url: u,
     data: {
-      p: obj
+      p: user
     },
     type: "POST",
     dataType : "html",
-    //success: function( resp ) {
+    success: function( resp ) {
       //$('#fehler').html('Antwort: ' + resp);
-    //},
+      um_apicall_get_user_list();
+      um_clear_user_form();
+    },
     error: function( xhr, status, errorThrown ) {
       $('#fehler').html("Error: " + errorThrown + " Status: " + status);
     },
@@ -37,17 +108,55 @@
   });      
 }
 
-function um_user_form_lesen() {
-  var userId = $('#anmeldename').val();
-  var kw = $('#kennwort').val();
-  var user = new User(userId, kw, '-', '-', '-');
-  return user;
+function um_apicall_del_user(user) {
+  var m = 'deleteUser';
+  var u = '../svc/' + m;
+  $.ajax({
+    url: u,
+    data: {
+      p: user
+    },
+    type: "POST",
+    dataType : "html",
+    success: function( resp ) {
+      um_apicall_get_user_list();
+    },
+    error: function( xhr, status, errorThrown ) {
+      $('#fehler').html("Error: " + errorThrown + " Status: " + status);
+    },
+    complete: function( xhr, status ) {
+      //alert( "The request is complete!" );
+    }
+  });      
 }
+
+function um_apicall_get_user_list() {
+  var m = 'getUserNameList';
+  var u = '../svc/' + m;
+  $.ajax({
+    url: u,
+    type: "GET",
+    dataType : "json",
+    success: function( resp ) {
+      um_show_user_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) {
   return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}';
 };
 
+/* ----- Objekte ----- */
+
 function User(i, p, fn, ln, em) {
   this.id = i;
   this.pw = p;

--
Gitblit v1.9.3