commit | author | age
|
5bf001
|
1 |
|
U |
2 |
function um_init() { |
|
3 |
$('.user-save-btn').click(um_user_save); |
4df887
|
4 |
$('#nutzerliste').click(um_user_list_click); |
U |
5 |
$('#nutzerLoeschen').click(um_del_user); |
|
6 |
$('#nutzerNeu').click(um_new_user); |
|
7 |
$('#nutzerLoeschen').prop( "disabled", true ); |
72c5c3
|
8 |
um_clear_user_form(); |
U |
9 |
um_apicall_get_user_list(); |
5bf001
|
10 |
} |
4df887
|
11 |
|
U |
12 |
/* ----- user functions ------ */ |
5bf001
|
13 |
|
U |
14 |
function um_user_save() { |
f8b605
|
15 |
var user = um_user_form_lesen(); |
U |
16 |
var kww = $('#kennwortw').val(); |
|
17 |
if(user.pw != kww) { |
|
18 |
alert('Kennworte stimmen nicht ueberein.'); |
|
19 |
} else { |
72c5c3
|
20 |
//alert('user-save ' + user.id); |
U |
21 |
um_apicall_create_user(self.serialisieren(user)); |
f8b605
|
22 |
} |
U |
23 |
} |
4df887
|
24 |
|
72c5c3
|
25 |
function um_del_user() { |
U |
26 |
var users = []; |
|
27 |
$('#nutzerliste :selected').each(function(i, selected){ |
|
28 |
users[i] = $(selected).text(); |
|
29 |
}); |
|
30 |
|
|
31 |
//alert('delete user ' + users[0]); |
|
32 |
var antwort = confirm("Wollen Sie den Nutzer " + users[0] + " loeschen?"); |
|
33 |
if (antwort == true) { |
|
34 |
var user = new User(users[0], '-', '-', '-', '-'); |
|
35 |
um_apicall_del_user(self.serialisieren(user)); |
|
36 |
} |
4df887
|
37 |
} |
U |
38 |
|
|
39 |
function um_new_user() { |
|
40 |
alert('show form to enter new user'); |
|
41 |
} |
|
42 |
|
|
43 |
/* ----------- ui interaction ------------ */ |
|
44 |
|
|
45 |
function um_user_list_click() { |
72c5c3
|
46 |
$('#nutzerLoeschen').prop( "disabled", false ); |
U |
47 |
/* |
|
48 |
var users = []; |
|
49 |
$('#nutzerliste :selected').each(function(i, selected){ |
|
50 |
users[i] = $(selected).text(); |
|
51 |
}); |
|
52 |
*/ |
|
53 |
//alert(users[0]); |
4df887
|
54 |
} |
U |
55 |
|
|
56 |
|
|
57 |
/* ------- ui i/o ------ */ |
|
58 |
|
|
59 |
function um_user_form_lesen() { |
|
60 |
var userId = $('#anmeldename').val(); |
|
61 |
var kw = $('#kennwort').val(); |
|
62 |
var user = new User(userId, kw, '-', '-', '-'); |
|
63 |
return user; |
|
64 |
} |
|
65 |
|
546fbc
|
66 |
function um_show_user_list(resp) { |
72c5c3
|
67 |
$("#nutzerliste").empty(); |
546fbc
|
68 |
var users = resp.List[0]; |
72c5c3
|
69 |
for(var i = 1; i < users.List.length; i++) { |
546fbc
|
70 |
var user = users.List[i]; |
U |
71 |
$("#nutzerliste").append('<option value=' + user.String + '>' + user.String + '</option>'); |
|
72 |
} |
72c5c3
|
73 |
$('#nutzerLoeschen').prop( "disabled", true ); |
546fbc
|
74 |
//var user1 = users.List[1]; |
U |
75 |
//var username = user1.String; |
|
76 |
//alert(username); |
72c5c3
|
77 |
} |
U |
78 |
|
|
79 |
function um_clear_user_form() { |
|
80 |
$('#anmeldename').val(''); |
|
81 |
$('#kennwort').val(''); |
|
82 |
$('#kennwortw').val(''); |
546fbc
|
83 |
} |
4df887
|
84 |
|
U |
85 |
/* ---- api calls ----- */ |
f8b605
|
86 |
|
72c5c3
|
87 |
function um_apicall_create_user(user) { |
f8b605
|
88 |
var m = 'createUser'; |
72c5c3
|
89 |
var u = '../svc/' + m; |
f8b605
|
90 |
$.ajax({ |
U |
91 |
url: u, |
|
92 |
data: { |
72c5c3
|
93 |
p: user |
f8b605
|
94 |
}, |
U |
95 |
type: "POST", |
|
96 |
dataType : "html", |
72c5c3
|
97 |
success: function( resp ) { |
f8b605
|
98 |
//$('#fehler').html('Antwort: ' + resp); |
72c5c3
|
99 |
um_apicall_get_user_list(); |
U |
100 |
um_clear_user_form(); |
|
101 |
}, |
f8b605
|
102 |
error: function( xhr, status, errorThrown ) { |
U |
103 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
104 |
}, |
|
105 |
complete: function( xhr, status ) { |
|
106 |
//alert( "The request is complete!" ); |
|
107 |
} |
|
108 |
}); |
|
109 |
} |
|
110 |
|
72c5c3
|
111 |
function um_apicall_del_user(user) { |
U |
112 |
var m = 'deleteUser'; |
|
113 |
var u = '../svc/' + m; |
|
114 |
$.ajax({ |
|
115 |
url: u, |
|
116 |
data: { |
|
117 |
p: user |
|
118 |
}, |
|
119 |
type: "POST", |
|
120 |
dataType : "html", |
|
121 |
success: function( resp ) { |
|
122 |
um_apicall_get_user_list(); |
|
123 |
}, |
|
124 |
error: function( xhr, status, errorThrown ) { |
|
125 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
126 |
}, |
|
127 |
complete: function( xhr, status ) { |
|
128 |
//alert( "The request is complete!" ); |
|
129 |
} |
|
130 |
}); |
|
131 |
} |
|
132 |
|
|
133 |
function um_apicall_get_user_list() { |
546fbc
|
134 |
var m = 'getUserNameList'; |
U |
135 |
var u = '../svc/' + m; |
|
136 |
$.ajax({ |
|
137 |
url: u, |
|
138 |
type: "GET", |
|
139 |
dataType : "json", |
|
140 |
success: function( resp ) { |
|
141 |
um_show_user_list(resp); |
|
142 |
}, |
|
143 |
error: function( xhr, status, errorThrown ) { |
|
144 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
145 |
}, |
|
146 |
complete: function( xhr, status ) { |
|
147 |
//alert( "The request is complete!" ); |
|
148 |
} |
|
149 |
}); |
|
150 |
} |
|
151 |
|
4df887
|
152 |
/* ----- Hilfsfunktionen ----- */ |
f8b605
|
153 |
|
U |
154 |
function serialisieren(obj) { |
|
155 |
return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; |
|
156 |
}; |
|
157 |
|
4df887
|
158 |
/* ----- Objekte ----- */ |
U |
159 |
|
f8b605
|
160 |
function User(i, p, fn, ln, em) { |
U |
161 |
this.id = i; |
|
162 |
this.pw = p; |
|
163 |
this.firstName = fn; |
|
164 |
this.lastName = ln; |
|
165 |
this.email = em; |
5bf001
|
166 |
} |