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 | 211 +++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 164 insertions(+), 47 deletions(-) diff --git a/web/ui/ui.js b/web/ui/ui.js index e567e34..7782450 100644 --- a/web/ui/ui.js +++ b/web/ui/ui.js @@ -1,49 +1,166 @@ -/* - Beispiel aus Spot fuer den Post eines Coordinates-Objektes - - var coord = new Coordinates( - c.latitude, - c.longitude, - self.nummer(c.altitude), - self.nummer(c.accuracy), - self.nummer(c.altitudeAccuracy), - self.nummer(c.heading), - self.nummer(c.speed)); - var cObj = self.serialisieren(coord); - - - $.ajax({ - url: '../rpc?c=de.uhilger.spot.api.NutzerApi&m=ortSpeichern', - data: { - p: cObj - }, - type: "POST", - dataType : "html", - //success: function( resp ) { - //$('#fehler').html('Antwort: ' + resp); - //}, - error: function( xhr, status, errorThrown ) { - $('#fehler').html("Error: " + errorThrown + " Status: " + status); - }, - complete: function( xhr, status ) { - //alert( "The request is complete!" ); - } - }); - usw. - - - function Coordinates(la, lo, al, ac, aa, hd, sp) { - this.latitude = la; - this.longitude = lo; - this.altitude = al; - this.accuracy = ac; - this.altitudeAccuracy = aa; - this.heading = hd; - this.speed = sp; +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(); } - - - - - */ \ No newline at end of file + +/* ----- user functions ------ */ + +function um_user_save() { + var user = um_user_form_lesen(); + var kww = $('#kennwortw').val(); + 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 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 = '../svc/' + m; + $.ajax({ + url: u, + data: { + p: user + }, + type: "POST", + dataType : "html", + 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); + }, + complete: function( xhr, status ) { + //alert( "The request is complete!" ); + } + }); +} + +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; + this.firstName = fn; + this.lastName = ln; + this.email = em; +} \ No newline at end of file -- Gitblit v1.9.3