commit | author | age
|
5bf001
|
1 |
|
U |
2 |
function um_init() { |
5e4151
|
3 |
$('#user-form').hide(); |
7f8a03
|
4 |
$('#nav').hide(); |
U |
5 |
$('#role-form').hide(); |
|
6 |
$('#user-role-form').hide(); |
5bf001
|
7 |
$('.user-save-btn').click(um_user_save); |
50ed23
|
8 |
$('.user-cancel-btn').click(um_back_from_new_user); |
4df887
|
9 |
$('#nutzerliste').click(um_user_list_click); |
U |
10 |
$('#nutzerLoeschen').click(um_del_user); |
|
11 |
$('#nutzerNeu').click(um_new_user); |
|
12 |
$('#nutzerLoeschen').prop( "disabled", true ); |
c79c12
|
13 |
$('#nutzerRolleEntziehen').prop( "disabled", true ); |
51edf4
|
14 |
$('#rolleErteilen').prop( "disabled", true ); |
5e4151
|
15 |
$('#rolleErteilen').click(um_grant_role); |
e03a3e
|
16 |
$('#nutzerRolleEntziehen').click(um_revoke_role); |
95f415
|
17 |
$('#neueRolle').click(um_new_role); |
51edf4
|
18 |
$('#rollen').click(um_role_list_click); |
U |
19 |
$('#nutzerrollen').click(um_user_role_list_click); |
72c5c3
|
20 |
um_clear_user_form(); |
U |
21 |
um_apicall_get_user_list(); |
51edf4
|
22 |
um_apicall_get_granted_roles(); |
5bf001
|
23 |
} |
4df887
|
24 |
|
U |
25 |
/* ----- user functions ------ */ |
5bf001
|
26 |
|
U |
27 |
function um_user_save() { |
f8b605
|
28 |
var user = um_user_form_lesen(); |
U |
29 |
var kww = $('#kennwortw').val(); |
|
30 |
if(user.pw != kww) { |
|
31 |
alert('Kennworte stimmen nicht ueberein.'); |
|
32 |
} else { |
72c5c3
|
33 |
um_apicall_create_user(self.serialisieren(user)); |
f8b605
|
34 |
} |
U |
35 |
} |
4df887
|
36 |
|
72c5c3
|
37 |
function um_del_user() { |
95f415
|
38 |
var userId = um_get_first_selected_user_id(); |
U |
39 |
if(userId !== 'none') { |
c79c12
|
40 |
var antwort = confirm("Wollen Sie den Nutzer " + userId + " loeschen?"); |
95f415
|
41 |
if (antwort === true) { |
U |
42 |
var user = new User(userId, '-', '-', '-', '-'); |
|
43 |
um_apicall_del_user(self.serialisieren(user)); |
|
44 |
} |
|
45 |
} |
4df887
|
46 |
} |
U |
47 |
|
95f415
|
48 |
/* ----------- role functions ------------ */ |
U |
49 |
|
|
50 |
function um_new_role() { |
51edf4
|
51 |
var roleIsNew = true; |
95f415
|
52 |
var userId = um_get_first_selected_user_id(); |
U |
53 |
if(userId === 'none') { |
|
54 |
alert('Es wurde kein Benutzer ausgewaehlt.'); |
|
55 |
} else { |
|
56 |
var answer = prompt("Name der Rolle", ""); |
|
57 |
if (answer === null) { |
|
58 |
alert("Es wurde Cancel betaetigt."); |
|
59 |
} else if(answer !== "") { |
51edf4
|
60 |
um_apicall_grant_role(userId, answer, roleIsNew); |
95f415
|
61 |
} else { |
U |
62 |
alert("OK betaetigt, aber Keine Rolle angegeben."); |
|
63 |
} |
|
64 |
} |
4df887
|
65 |
} |
U |
66 |
|
5e4151
|
67 |
function um_grant_role() { |
U |
68 |
var roleIsNew = false; |
|
69 |
var userId = um_get_first_selected_user_id(); |
|
70 |
var roleId = um_get_first_selected_role_id(); |
|
71 |
if(roleId !== 'none' && userId !== 'none') { |
|
72 |
um_apicall_grant_role(userId, roleId, roleIsNew); |
|
73 |
} |
|
74 |
} |
|
75 |
|
e03a3e
|
76 |
function um_revoke_role() { |
U |
77 |
var userId = um_get_first_selected_user_id(); |
|
78 |
var roleId = um_get_first_selected_userrole_id(); |
|
79 |
if(roleId !== 'none' && userId !== 'none') { |
|
80 |
um_apicall_revoke_role(userId, roleId); |
|
81 |
} |
|
82 |
} |
|
83 |
|
4df887
|
84 |
/* ----------- ui interaction ------------ */ |
U |
85 |
|
|
86 |
function um_user_list_click() { |
7f8a03
|
87 |
$('#nav-back-btn').click(um_back_from_roles); |
72c5c3
|
88 |
$('#nutzerLoeschen').prop( "disabled", false ); |
5e4151
|
89 |
$('#rollen :selected').prop("selected", false); |
c79c12
|
90 |
var userId = um_get_first_selected_user_id(); |
7f8a03
|
91 |
$('#userid').html(userId); |
c79c12
|
92 |
um_apicall_get_user_roles(userId); |
7f8a03
|
93 |
$('#user-list-form').hide(); |
U |
94 |
$('#nav').show(); |
|
95 |
$('#role-form').show(); |
|
96 |
$('#user-role-form').show(); |
51edf4
|
97 |
} |
U |
98 |
|
4f4b29
|
99 |
function um_new_user() { |
U |
100 |
$('#nav-back-btn').click(um_back_from_new_user); |
|
101 |
$('#user-list-form').hide(); |
|
102 |
$('#user-form').show(); |
|
103 |
$('#nav').show(); |
|
104 |
} |
|
105 |
|
51edf4
|
106 |
function um_role_list_click() { |
U |
107 |
$('#rolleErteilen').prop( "disabled", false ); |
|
108 |
} |
|
109 |
|
|
110 |
function um_user_role_list_click() { |
|
111 |
$('#nutzerRolleEntziehen').prop( "disabled", false ); |
4df887
|
112 |
} |
U |
113 |
|
7f8a03
|
114 |
function um_back_from_roles() { |
U |
115 |
$('#user-list-form').show(); |
|
116 |
$('#nav').hide(); |
|
117 |
$('#role-form').hide(); |
|
118 |
$('#user-role-form').hide(); |
4f4b29
|
119 |
} |
U |
120 |
|
|
121 |
function um_back_from_new_user() { |
|
122 |
$('#user-list-form').show(); |
|
123 |
$('#nav').hide(); |
|
124 |
$('#user-form').hide(); |
|
125 |
um_clear_user_form(); |
7f8a03
|
126 |
} |
4df887
|
127 |
|
U |
128 |
/* ------- ui i/o ------ */ |
|
129 |
|
|
130 |
function um_user_form_lesen() { |
|
131 |
var userId = $('#anmeldename').val(); |
|
132 |
var kw = $('#kennwort').val(); |
|
133 |
var user = new User(userId, kw, '-', '-', '-'); |
|
134 |
return user; |
|
135 |
} |
|
136 |
|
546fbc
|
137 |
function um_show_user_list(resp) { |
72c5c3
|
138 |
$("#nutzerliste").empty(); |
546fbc
|
139 |
var users = resp.List[0]; |
72c5c3
|
140 |
for(var i = 1; i < users.List.length; i++) { |
546fbc
|
141 |
var user = users.List[i]; |
U |
142 |
$("#nutzerliste").append('<option value=' + user.String + '>' + user.String + '</option>'); |
|
143 |
} |
72c5c3
|
144 |
$('#nutzerLoeschen').prop( "disabled", true ); |
U |
145 |
} |
|
146 |
|
|
147 |
function um_clear_user_form() { |
|
148 |
$('#anmeldename').val(''); |
|
149 |
$('#kennwort').val(''); |
|
150 |
$('#kennwortw').val(''); |
546fbc
|
151 |
} |
4df887
|
152 |
|
95f415
|
153 |
function um_get_first_selected_user_id() { |
U |
154 |
var userId = 'none'; |
|
155 |
var userIds = []; |
|
156 |
$('#nutzerliste :selected').each(function(i, selected){ |
|
157 |
userIds[i] = $(selected).text(); |
|
158 |
}); |
|
159 |
if(userIds.length > 0) { |
|
160 |
userId = userIds[0]; |
|
161 |
} |
|
162 |
return userId; |
c79c12
|
163 |
} |
U |
164 |
|
5e4151
|
165 |
function um_get_first_selected_role_id() { |
U |
166 |
var roleId = 'none'; |
|
167 |
var roleIds = []; |
|
168 |
$('#rollen :selected').each(function(i, selected){ |
e03a3e
|
169 |
roleIds[i] = $(selected).text(); |
U |
170 |
}); |
|
171 |
if(roleIds.length > 0) { |
|
172 |
roleId = roleIds[0]; |
|
173 |
} |
|
174 |
return roleId; |
|
175 |
} |
|
176 |
|
|
177 |
function um_get_first_selected_userrole_id() { |
|
178 |
var roleId = 'none'; |
|
179 |
var roleIds = []; |
|
180 |
$('#nutzerrollen :selected').each(function(i, selected){ |
5e4151
|
181 |
roleIds[i] = $(selected).text(); |
U |
182 |
}); |
|
183 |
if(roleIds.length > 0) { |
|
184 |
roleId = roleIds[0]; |
|
185 |
} |
|
186 |
return roleId; |
|
187 |
} |
|
188 |
|
c79c12
|
189 |
function um_show_user_role_list(resp) { |
U |
190 |
$("#nutzerrollen").empty(); |
|
191 |
var rollen = resp.List[0]; |
|
192 |
for(var i = 1; i < rollen.List.length; i++) { |
|
193 |
var rolle = rollen.List[i]; |
|
194 |
$("#nutzerrollen").append('<option value=' + rolle.String + '>' + rolle.String + '</option>'); |
|
195 |
} |
|
196 |
$('#nutzerRolleEntziehen').prop( "disabled", true ); |
95f415
|
197 |
} |
U |
198 |
|
51edf4
|
199 |
function um_show_role_list(resp) { |
U |
200 |
$("#rollen").empty(); |
|
201 |
var rollen = resp.List[0]; |
|
202 |
for(var i = 1; i < rollen.List.length; i++) { |
|
203 |
var rolle = rollen.List[i]; |
|
204 |
$("#rollen").append('<option value=' + rolle.String + '>' + rolle.String + '</option>'); |
|
205 |
} |
|
206 |
$('#rolleErteilen').prop( "disabled", true ); |
|
207 |
} |
5e4151
|
208 |
|
4df887
|
209 |
/* ---- api calls ----- */ |
f8b605
|
210 |
|
72c5c3
|
211 |
function um_apicall_create_user(user) { |
f8b605
|
212 |
var m = 'createUser'; |
72c5c3
|
213 |
var u = '../svc/' + m; |
f8b605
|
214 |
$.ajax({ |
U |
215 |
url: u, |
|
216 |
data: { |
72c5c3
|
217 |
p: user |
f8b605
|
218 |
}, |
U |
219 |
type: "POST", |
|
220 |
dataType : "html", |
72c5c3
|
221 |
success: function( resp ) { |
U |
222 |
um_apicall_get_user_list(); |
4f4b29
|
223 |
um_back_from_new_user(); |
72c5c3
|
224 |
}, |
f8b605
|
225 |
error: function( xhr, status, errorThrown ) { |
U |
226 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
227 |
}, |
|
228 |
complete: function( xhr, status ) { |
|
229 |
//alert( "The request is complete!" ); |
|
230 |
} |
|
231 |
}); |
|
232 |
} |
|
233 |
|
72c5c3
|
234 |
function um_apicall_del_user(user) { |
U |
235 |
var m = 'deleteUser'; |
|
236 |
var u = '../svc/' + m; |
|
237 |
$.ajax({ |
|
238 |
url: u, |
|
239 |
data: { |
|
240 |
p: user |
|
241 |
}, |
|
242 |
type: "POST", |
|
243 |
dataType : "html", |
|
244 |
success: function( resp ) { |
|
245 |
um_apicall_get_user_list(); |
|
246 |
}, |
|
247 |
error: function( xhr, status, errorThrown ) { |
|
248 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
249 |
}, |
|
250 |
complete: function( xhr, status ) { |
|
251 |
//alert( "The request is complete!" ); |
|
252 |
} |
|
253 |
}); |
|
254 |
} |
|
255 |
|
|
256 |
function um_apicall_get_user_list() { |
546fbc
|
257 |
var m = 'getUserNameList'; |
U |
258 |
var u = '../svc/' + m; |
|
259 |
$.ajax({ |
|
260 |
url: u, |
|
261 |
type: "GET", |
|
262 |
dataType : "json", |
|
263 |
success: function( resp ) { |
|
264 |
um_show_user_list(resp); |
|
265 |
}, |
|
266 |
error: function( xhr, status, errorThrown ) { |
|
267 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
268 |
}, |
|
269 |
complete: function( xhr, status ) { |
|
270 |
//alert( "The request is complete!" ); |
|
271 |
} |
|
272 |
}); |
|
273 |
} |
|
274 |
|
ccefc8
|
275 |
// http]://example.com/um/api?c=de.uhilger.um.api.UserMgr&m=testmethode |
51edf4
|
276 |
function um_apicall_grant_role(userId, roleName, isNewRole) { |
ccefc8
|
277 |
var ur = new UserRole(userId, roleName); |
c79c12
|
278 |
var m = 'grantRole'; |
U |
279 |
var u = '../svc/' + m; |
|
280 |
$.ajax({ |
|
281 |
url: u, |
|
282 |
data: { |
ccefc8
|
283 |
p: self.serialisieren(ur) |
c79c12
|
284 |
}, |
U |
285 |
type: "POST", |
|
286 |
dataType : "html", |
|
287 |
success: function( resp ) { |
|
288 |
um_apicall_get_user_roles(userId); |
51edf4
|
289 |
if(isNewRole) { |
U |
290 |
um_apicall_get_granted_roles(); |
|
291 |
} |
c79c12
|
292 |
}, |
U |
293 |
error: function( xhr, status, errorThrown ) { |
|
294 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
295 |
}, |
|
296 |
complete: function( xhr, status ) { |
|
297 |
//alert( "The request is complete!" ); |
|
298 |
} |
|
299 |
}); |
|
300 |
} |
|
301 |
|
e03a3e
|
302 |
function um_apicall_revoke_role(userId, roleName) { |
ccefc8
|
303 |
var ur = new UserRole(userId, roleName); |
e03a3e
|
304 |
var m = 'revokeRole'; |
U |
305 |
var u = '../svc/' + m; |
|
306 |
$.ajax({ |
|
307 |
url: u, |
|
308 |
data: { |
ccefc8
|
309 |
p: self.serialisieren(ur) |
e03a3e
|
310 |
}, |
U |
311 |
type: "POST", |
|
312 |
dataType : "html", |
|
313 |
success: function( resp ) { |
|
314 |
um_apicall_get_user_roles(userId); |
|
315 |
}, |
|
316 |
error: function( xhr, status, errorThrown ) { |
|
317 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
318 |
}, |
|
319 |
complete: function( xhr, status ) { |
|
320 |
//alert( "The request is complete!" ); |
|
321 |
} |
|
322 |
}); |
|
323 |
} |
|
324 |
|
c79c12
|
325 |
function um_apicall_get_user_roles(userId) { |
U |
326 |
var m = 'getUserRoleNames'; |
|
327 |
var u = '../svc/' + m + '?p=' + userId; |
|
328 |
$.ajax({ |
|
329 |
url: u, |
|
330 |
type: "GET", |
|
331 |
dataType : "json", |
|
332 |
success: function( resp ) { |
|
333 |
um_show_user_role_list(resp); |
|
334 |
}, |
|
335 |
error: function( xhr, status, errorThrown ) { |
|
336 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
337 |
}, |
|
338 |
complete: function( xhr, status ) { |
|
339 |
//alert( "The request is complete!" ); |
|
340 |
} |
|
341 |
}); |
|
342 |
} |
|
343 |
|
51edf4
|
344 |
function um_apicall_get_granted_roles() { |
U |
345 |
var m = 'getRoleNamesGranted'; |
|
346 |
var u = '../svc/' + m; |
|
347 |
$.ajax({ |
|
348 |
url: u, |
|
349 |
type: "GET", |
|
350 |
dataType : "json", |
|
351 |
success: function( resp ) { |
|
352 |
um_show_role_list(resp); |
|
353 |
}, |
|
354 |
error: function( xhr, status, errorThrown ) { |
|
355 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
356 |
}, |
|
357 |
complete: function( xhr, status ) { |
|
358 |
//alert( "The request is complete!" ); |
|
359 |
} |
|
360 |
}); |
|
361 |
} |
|
362 |
|
4df887
|
363 |
/* ----- Hilfsfunktionen ----- */ |
f8b605
|
364 |
|
U |
365 |
function serialisieren(obj) { |
|
366 |
return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; |
|
367 |
}; |
|
368 |
|
4df887
|
369 |
/* ----- Objekte ----- */ |
U |
370 |
|
f8b605
|
371 |
function User(i, p, fn, ln, em) { |
U |
372 |
this.id = i; |
|
373 |
this.pw = p; |
|
374 |
this.firstName = fn; |
|
375 |
this.lastName = ln; |
|
376 |
this.email = em; |
ccefc8
|
377 |
} |
U |
378 |
|
|
379 |
function UserRole(u, r) { |
|
380 |
this.userId = u; |
|
381 |
this.role = r; |
5bf001
|
382 |
} |