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); |
1345f0
|
20 |
$('#userMenu').text('?'); |
b4b5eb
|
21 |
$('#logout').click(um_apicall_logout); |
72c5c3
|
22 |
um_clear_user_form(); |
U |
23 |
um_apicall_get_user_list(); |
51edf4
|
24 |
um_apicall_get_granted_roles(); |
1345f0
|
25 |
um_apicall_get_login(); |
5bf001
|
26 |
} |
4df887
|
27 |
|
U |
28 |
/* ----- user functions ------ */ |
5bf001
|
29 |
|
U |
30 |
function um_user_save() { |
f8b605
|
31 |
var user = um_user_form_lesen(); |
U |
32 |
var kww = $('#kennwortw').val(); |
|
33 |
if(user.pw != kww) { |
|
34 |
alert('Kennworte stimmen nicht ueberein.'); |
|
35 |
} else { |
72c5c3
|
36 |
um_apicall_create_user(self.serialisieren(user)); |
f8b605
|
37 |
} |
U |
38 |
} |
4df887
|
39 |
|
72c5c3
|
40 |
function um_del_user() { |
95f415
|
41 |
var userId = um_get_first_selected_user_id(); |
U |
42 |
if(userId !== 'none') { |
c79c12
|
43 |
var antwort = confirm("Wollen Sie den Nutzer " + userId + " loeschen?"); |
95f415
|
44 |
if (antwort === true) { |
U |
45 |
var user = new User(userId, '-', '-', '-', '-'); |
|
46 |
um_apicall_del_user(self.serialisieren(user)); |
|
47 |
} |
|
48 |
} |
4df887
|
49 |
} |
U |
50 |
|
95f415
|
51 |
/* ----------- role functions ------------ */ |
U |
52 |
|
|
53 |
function um_new_role() { |
51edf4
|
54 |
var roleIsNew = true; |
95f415
|
55 |
var userId = um_get_first_selected_user_id(); |
U |
56 |
if(userId === 'none') { |
|
57 |
alert('Es wurde kein Benutzer ausgewaehlt.'); |
|
58 |
} else { |
|
59 |
var answer = prompt("Name der Rolle", ""); |
|
60 |
if (answer === null) { |
|
61 |
alert("Es wurde Cancel betaetigt."); |
|
62 |
} else if(answer !== "") { |
51edf4
|
63 |
um_apicall_grant_role(userId, answer, roleIsNew); |
95f415
|
64 |
} else { |
U |
65 |
alert("OK betaetigt, aber Keine Rolle angegeben."); |
|
66 |
} |
|
67 |
} |
4df887
|
68 |
} |
U |
69 |
|
5e4151
|
70 |
function um_grant_role() { |
U |
71 |
var roleIsNew = false; |
|
72 |
var userId = um_get_first_selected_user_id(); |
|
73 |
var roleId = um_get_first_selected_role_id(); |
|
74 |
if(roleId !== 'none' && userId !== 'none') { |
|
75 |
um_apicall_grant_role(userId, roleId, roleIsNew); |
|
76 |
} |
|
77 |
} |
|
78 |
|
e03a3e
|
79 |
function um_revoke_role() { |
U |
80 |
var userId = um_get_first_selected_user_id(); |
|
81 |
var roleId = um_get_first_selected_userrole_id(); |
|
82 |
if(roleId !== 'none' && userId !== 'none') { |
|
83 |
um_apicall_revoke_role(userId, roleId); |
|
84 |
} |
|
85 |
} |
|
86 |
|
4df887
|
87 |
/* ----------- ui interaction ------------ */ |
U |
88 |
|
|
89 |
function um_user_list_click() { |
7f8a03
|
90 |
$('#nav-back-btn').click(um_back_from_roles); |
72c5c3
|
91 |
$('#nutzerLoeschen').prop( "disabled", false ); |
5e4151
|
92 |
$('#rollen :selected').prop("selected", false); |
c79c12
|
93 |
var userId = um_get_first_selected_user_id(); |
7f8a03
|
94 |
$('#userid').html(userId); |
c79c12
|
95 |
um_apicall_get_user_roles(userId); |
7f8a03
|
96 |
$('#user-list-form').hide(); |
U |
97 |
$('#nav').show(); |
|
98 |
$('#role-form').show(); |
|
99 |
$('#user-role-form').show(); |
51edf4
|
100 |
} |
U |
101 |
|
4f4b29
|
102 |
function um_new_user() { |
U |
103 |
$('#nav-back-btn').click(um_back_from_new_user); |
|
104 |
$('#user-list-form').hide(); |
|
105 |
$('#user-form').show(); |
|
106 |
$('#nav').show(); |
|
107 |
} |
|
108 |
|
51edf4
|
109 |
function um_role_list_click() { |
U |
110 |
$('#rolleErteilen').prop( "disabled", false ); |
|
111 |
} |
|
112 |
|
|
113 |
function um_user_role_list_click() { |
|
114 |
$('#nutzerRolleEntziehen').prop( "disabled", false ); |
4df887
|
115 |
} |
U |
116 |
|
7f8a03
|
117 |
function um_back_from_roles() { |
U |
118 |
$('#user-list-form').show(); |
|
119 |
$('#nav').hide(); |
|
120 |
$('#role-form').hide(); |
|
121 |
$('#user-role-form').hide(); |
4f4b29
|
122 |
} |
U |
123 |
|
|
124 |
function um_back_from_new_user() { |
|
125 |
$('#user-list-form').show(); |
|
126 |
$('#nav').hide(); |
|
127 |
$('#user-form').hide(); |
|
128 |
um_clear_user_form(); |
7f8a03
|
129 |
} |
4df887
|
130 |
|
U |
131 |
/* ------- ui i/o ------ */ |
|
132 |
|
|
133 |
function um_user_form_lesen() { |
|
134 |
var userId = $('#anmeldename').val(); |
|
135 |
var kw = $('#kennwort').val(); |
1345f0
|
136 |
var firstName = $('#vorname').val(); |
6fda23
|
137 |
var lastName = $('#nachname').val(); |
1345f0
|
138 |
var user = new User(userId, kw, firstName, lastName, '-'); |
4df887
|
139 |
return user; |
U |
140 |
} |
|
141 |
|
61cf48
|
142 |
/* |
ff2dff
|
143 |
* BaseLink liefert fuer einfache selects wie die der Nutzerverwaltung |
U |
144 |
* eine simple Listenfunktion, die auf der JSON-Seite wie folgt |
|
145 |
* herauskommt. |
|
146 |
* |
|
147 |
* {"List":[{"List":[{"String":"USER_NAME"},{"String":"admin"},{"String":"test"}]}]} |
|
148 |
* |
|
149 |
* Fuer Mustache sieht ein Template dann z.B so aus: |
|
150 |
* |
|
151 |
* {{#List}} |
|
152 |
* {{#List}} |
|
153 |
* <option value="{{ String }}">{{ String }}</option>' |
|
154 |
* {{/List}} |
|
155 |
* {{/List}} |
61cf48
|
156 |
*/ |
546fbc
|
157 |
function um_show_user_list(resp) { |
72c5c3
|
158 |
$("#nutzerliste").empty(); |
ff2dff
|
159 |
var template = $('#tpl-list').html(); |
61cf48
|
160 |
Mustache.parse(template); // optional, speeds up future uses |
U |
161 |
$("#nutzerliste").append( Mustache.render(template, resp) ); |
72c5c3
|
162 |
} |
U |
163 |
|
|
164 |
function um_clear_user_form() { |
|
165 |
$('#anmeldename').val(''); |
|
166 |
$('#kennwort').val(''); |
|
167 |
$('#kennwortw').val(''); |
546fbc
|
168 |
} |
4df887
|
169 |
|
95f415
|
170 |
function um_get_first_selected_user_id() { |
U |
171 |
var userId = 'none'; |
|
172 |
var userIds = []; |
|
173 |
$('#nutzerliste :selected').each(function(i, selected){ |
|
174 |
userIds[i] = $(selected).text(); |
|
175 |
}); |
|
176 |
if(userIds.length > 0) { |
|
177 |
userId = userIds[0]; |
|
178 |
} |
|
179 |
return userId; |
c79c12
|
180 |
} |
U |
181 |
|
5e4151
|
182 |
function um_get_first_selected_role_id() { |
U |
183 |
var roleId = 'none'; |
|
184 |
var roleIds = []; |
|
185 |
$('#rollen :selected').each(function(i, selected){ |
e03a3e
|
186 |
roleIds[i] = $(selected).text(); |
U |
187 |
}); |
|
188 |
if(roleIds.length > 0) { |
|
189 |
roleId = roleIds[0]; |
|
190 |
} |
|
191 |
return roleId; |
|
192 |
} |
|
193 |
|
|
194 |
function um_get_first_selected_userrole_id() { |
|
195 |
var roleId = 'none'; |
|
196 |
var roleIds = []; |
|
197 |
$('#nutzerrollen :selected').each(function(i, selected){ |
5e4151
|
198 |
roleIds[i] = $(selected).text(); |
U |
199 |
}); |
|
200 |
if(roleIds.length > 0) { |
|
201 |
roleId = roleIds[0]; |
|
202 |
} |
|
203 |
return roleId; |
|
204 |
} |
|
205 |
|
c79c12
|
206 |
function um_show_user_role_list(resp) { |
U |
207 |
$("#nutzerrollen").empty(); |
ff2dff
|
208 |
|
U |
209 |
var template = $('#tpl-list').html(); |
|
210 |
Mustache.parse(template); // optional, speeds up future uses |
|
211 |
$("#nutzerrollen").append( Mustache.render(template, resp) ); |
|
212 |
|
c79c12
|
213 |
$('#nutzerRolleEntziehen').prop( "disabled", true ); |
118fec
|
214 |
$('#rolleErteilen').prop( "disabled", true ); |
95f415
|
215 |
} |
U |
216 |
|
51edf4
|
217 |
function um_show_role_list(resp) { |
U |
218 |
$("#rollen").empty(); |
ff2dff
|
219 |
|
U |
220 |
var template = $('#tpl-list').html(); |
|
221 |
Mustache.parse(template); // optional, speeds up future uses |
|
222 |
$("#rollen").append( Mustache.render(template, resp) ); |
|
223 |
|
51edf4
|
224 |
$('#rolleErteilen').prop( "disabled", true ); |
U |
225 |
} |
5e4151
|
226 |
|
4df887
|
227 |
/* ---- api calls ----- */ |
f8b605
|
228 |
|
72c5c3
|
229 |
function um_apicall_create_user(user) { |
f8b605
|
230 |
var m = 'createUser'; |
72c5c3
|
231 |
var u = '../svc/' + m; |
f8b605
|
232 |
$.ajax({ |
U |
233 |
url: u, |
|
234 |
data: { |
72c5c3
|
235 |
p: user |
f8b605
|
236 |
}, |
U |
237 |
type: "POST", |
|
238 |
dataType : "html", |
72c5c3
|
239 |
success: function( resp ) { |
U |
240 |
um_apicall_get_user_list(); |
4f4b29
|
241 |
um_back_from_new_user(); |
72c5c3
|
242 |
}, |
f8b605
|
243 |
error: function( xhr, status, errorThrown ) { |
U |
244 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
245 |
}, |
|
246 |
complete: function( xhr, status ) { |
|
247 |
//alert( "The request is complete!" ); |
|
248 |
} |
|
249 |
}); |
|
250 |
} |
|
251 |
|
72c5c3
|
252 |
function um_apicall_del_user(user) { |
U |
253 |
var m = 'deleteUser'; |
|
254 |
var u = '../svc/' + m; |
|
255 |
$.ajax({ |
|
256 |
url: u, |
|
257 |
data: { |
|
258 |
p: user |
|
259 |
}, |
|
260 |
type: "POST", |
|
261 |
dataType : "html", |
|
262 |
success: function( resp ) { |
|
263 |
um_apicall_get_user_list(); |
|
264 |
}, |
|
265 |
error: function( xhr, status, errorThrown ) { |
|
266 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
267 |
}, |
|
268 |
complete: function( xhr, status ) { |
|
269 |
//alert( "The request is complete!" ); |
|
270 |
} |
|
271 |
}); |
|
272 |
} |
|
273 |
|
|
274 |
function um_apicall_get_user_list() { |
546fbc
|
275 |
var m = 'getUserNameList'; |
U |
276 |
var u = '../svc/' + m; |
|
277 |
$.ajax({ |
|
278 |
url: u, |
|
279 |
type: "GET", |
|
280 |
dataType : "json", |
|
281 |
success: function( resp ) { |
|
282 |
um_show_user_list(resp); |
|
283 |
}, |
|
284 |
error: function( xhr, status, errorThrown ) { |
|
285 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
286 |
}, |
|
287 |
complete: function( xhr, status ) { |
|
288 |
//alert( "The request is complete!" ); |
|
289 |
} |
|
290 |
}); |
|
291 |
} |
|
292 |
|
ccefc8
|
293 |
// http]://example.com/um/api?c=de.uhilger.um.api.UserMgr&m=testmethode |
51edf4
|
294 |
function um_apicall_grant_role(userId, roleName, isNewRole) { |
ccefc8
|
295 |
var ur = new UserRole(userId, roleName); |
c79c12
|
296 |
var m = 'grantRole'; |
U |
297 |
var u = '../svc/' + m; |
|
298 |
$.ajax({ |
|
299 |
url: u, |
|
300 |
data: { |
ccefc8
|
301 |
p: self.serialisieren(ur) |
c79c12
|
302 |
}, |
U |
303 |
type: "POST", |
|
304 |
dataType : "html", |
|
305 |
success: function( resp ) { |
|
306 |
um_apicall_get_user_roles(userId); |
51edf4
|
307 |
if(isNewRole) { |
U |
308 |
um_apicall_get_granted_roles(); |
|
309 |
} |
c79c12
|
310 |
}, |
U |
311 |
error: function( xhr, status, errorThrown ) { |
|
312 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
313 |
}, |
|
314 |
complete: function( xhr, status ) { |
|
315 |
//alert( "The request is complete!" ); |
|
316 |
} |
|
317 |
}); |
|
318 |
} |
|
319 |
|
e03a3e
|
320 |
function um_apicall_revoke_role(userId, roleName) { |
ccefc8
|
321 |
var ur = new UserRole(userId, roleName); |
e03a3e
|
322 |
var m = 'revokeRole'; |
U |
323 |
var u = '../svc/' + m; |
|
324 |
$.ajax({ |
|
325 |
url: u, |
|
326 |
data: { |
ccefc8
|
327 |
p: self.serialisieren(ur) |
e03a3e
|
328 |
}, |
U |
329 |
type: "POST", |
|
330 |
dataType : "html", |
|
331 |
success: function( resp ) { |
|
332 |
um_apicall_get_user_roles(userId); |
|
333 |
}, |
|
334 |
error: function( xhr, status, errorThrown ) { |
|
335 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
336 |
}, |
|
337 |
complete: function( xhr, status ) { |
|
338 |
//alert( "The request is complete!" ); |
|
339 |
} |
|
340 |
}); |
|
341 |
} |
|
342 |
|
c79c12
|
343 |
function um_apicall_get_user_roles(userId) { |
U |
344 |
var m = 'getUserRoleNames'; |
|
345 |
var u = '../svc/' + m + '?p=' + userId; |
|
346 |
$.ajax({ |
|
347 |
url: u, |
|
348 |
type: "GET", |
|
349 |
dataType : "json", |
|
350 |
success: function( resp ) { |
|
351 |
um_show_user_role_list(resp); |
|
352 |
}, |
|
353 |
error: function( xhr, status, errorThrown ) { |
|
354 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
355 |
}, |
|
356 |
complete: function( xhr, status ) { |
|
357 |
//alert( "The request is complete!" ); |
|
358 |
} |
|
359 |
}); |
|
360 |
} |
|
361 |
|
51edf4
|
362 |
function um_apicall_get_granted_roles() { |
U |
363 |
var m = 'getRoleNamesGranted'; |
|
364 |
var u = '../svc/' + m; |
|
365 |
$.ajax({ |
|
366 |
url: u, |
|
367 |
type: "GET", |
|
368 |
dataType : "json", |
|
369 |
success: function( resp ) { |
|
370 |
um_show_role_list(resp); |
|
371 |
}, |
|
372 |
error: function( xhr, status, errorThrown ) { |
|
373 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
374 |
}, |
|
375 |
complete: function( xhr, status ) { |
|
376 |
//alert( "The request is complete!" ); |
|
377 |
} |
|
378 |
}); |
|
379 |
} |
|
380 |
|
1345f0
|
381 |
function um_apicall_get_login() { |
U |
382 |
var m = '?c=de.uhilger.um.pub.SessionManager&m=getSessionUser'; |
|
383 |
var u = '../pub' + m; |
|
384 |
$.ajax({ |
|
385 |
url: u, |
|
386 |
type: "GET", |
|
387 |
dataType : "json", |
|
388 |
success: function( resp ) { |
|
389 |
$('#userMenu').text(resp.UserData.firstName); |
|
390 |
}, |
|
391 |
error: function( xhr, status, errorThrown ) { |
|
392 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
393 |
}, |
|
394 |
complete: function( xhr, status ) { |
|
395 |
//alert( "The request is complete!" ); |
|
396 |
} |
|
397 |
}); |
|
398 |
|
|
399 |
} |
|
400 |
|
|
401 |
function um_apicall_logout() { |
|
402 |
var m = '?c=de.uhilger.um.pub.SessionManager&m=expireSession'; |
|
403 |
var u = '../pub' + m; |
|
404 |
$.ajax({ |
|
405 |
url: u, |
|
406 |
type: "GET", |
|
407 |
dataType : "text", |
|
408 |
success: function( resp ) { |
|
409 |
$('#userMenu').text('nicht angemeldet'); |
|
410 |
window.location.href = '../logout.html'; |
|
411 |
}, |
|
412 |
error: function( xhr, status, errorThrown ) { |
|
413 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
414 |
}, |
|
415 |
complete: function( xhr, status ) { |
|
416 |
//alert( "The request is complete!" ); |
|
417 |
} |
|
418 |
}); |
|
419 |
} |
|
420 |
|
4df887
|
421 |
/* ----- Hilfsfunktionen ----- */ |
f8b605
|
422 |
|
U |
423 |
function serialisieren(obj) { |
|
424 |
return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; |
|
425 |
}; |
|
426 |
|
4df887
|
427 |
/* ----- Objekte ----- */ |
U |
428 |
|
f8b605
|
429 |
function User(i, p, fn, ln, em) { |
U |
430 |
this.id = i; |
|
431 |
this.pw = p; |
|
432 |
this.firstName = fn; |
|
433 |
this.lastName = ln; |
|
434 |
this.email = em; |
ccefc8
|
435 |
} |
U |
436 |
|
|
437 |
function UserRole(u, r) { |
|
438 |
this.userId = u; |
|
439 |
this.role = r; |
5bf001
|
440 |
} |