1 | {combine_script id='common' load='footer' path='admin/themes/default/js/common.js'} |
---|
2 | |
---|
3 | {combine_script id='jquery.dataTables' load='footer' path='themes/default/js/plugins/jquery.dataTables.js'} |
---|
4 | {combine_css path="themes/default/js/plugins/datatables/css/jquery.dataTables.css"} |
---|
5 | |
---|
6 | {combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'} |
---|
7 | {combine_css path="themes/default/js/plugins/chosen.css"} |
---|
8 | |
---|
9 | {footer_script} |
---|
10 | var selectedMessage_pattern = "{'%d of %d photos selected'|@translate}"; |
---|
11 | var selectedMessage_none = "{'No photo selected, %d photos in current set'|@translate}"; |
---|
12 | var selectedMessage_all = "{'All %d photos are selected'|@translate}"; |
---|
13 | var applyOnDetails_pattern = "{'on the %d selected users'|@translate}"; |
---|
14 | var newUser_pattern = "✔ {'User %s added'|translate}"; |
---|
15 | var registeredOn_pattern = "{'Registered on %s, %s.'|translate}"; |
---|
16 | var lastVisit_pattern = "{'Last visit on %s, %s.'|translate}"; |
---|
17 | var missingConfirm = "{'You need to confirm deletion'|translate}"; |
---|
18 | var missingUsername = "{'Please, enter a login'|translate}"; |
---|
19 | |
---|
20 | var allUsers = [{$all_users}]; |
---|
21 | var selection = [{$selection}]; |
---|
22 | var pwg_token = "{$PWG_TOKEN}"; |
---|
23 | |
---|
24 | var truefalse = { |
---|
25 | true:"{'Yes'|translate}", |
---|
26 | false:"{'No'|translate}", |
---|
27 | }; |
---|
28 | {/footer_script} |
---|
29 | |
---|
30 | {footer_script}{literal} |
---|
31 | jQuery(document).ready(function() { |
---|
32 | /** |
---|
33 | * Add user |
---|
34 | */ |
---|
35 | jQuery("#addUser").click(function() { |
---|
36 | jQuery("#addUserForm").toggle(); |
---|
37 | jQuery("#showAddUser .infos").hide(); |
---|
38 | jQuery("input[name=username]").focus(); |
---|
39 | return false; |
---|
40 | }); |
---|
41 | |
---|
42 | jQuery("#addUserClose").click(function() { |
---|
43 | jQuery("#addUserForm").hide(); |
---|
44 | return false; |
---|
45 | }); |
---|
46 | |
---|
47 | jQuery("#addUserForm").submit(function() { |
---|
48 | jQuery.ajax({ |
---|
49 | url: "ws.php?format=json&method=pwg.users.add", |
---|
50 | type:"POST", |
---|
51 | data: jQuery(this).serialize(), |
---|
52 | beforeSend: function() { |
---|
53 | jQuery("#addUserForm .errors").hide(); |
---|
54 | |
---|
55 | if (jQuery("input[name=username]").val() == "") { |
---|
56 | jQuery("#addUserForm .errors").html('✘ '+missingUsername).show(); |
---|
57 | return false; |
---|
58 | } |
---|
59 | |
---|
60 | jQuery("#addUserForm .loading").show(); |
---|
61 | }, |
---|
62 | success:function(data) { |
---|
63 | oTable.fnDraw(); |
---|
64 | jQuery("#addUserForm .loading").hide(); |
---|
65 | |
---|
66 | var data = jQuery.parseJSON(data); |
---|
67 | if (data.stat == 'ok') { |
---|
68 | jQuery("#addUserForm input[type=text], #addUserForm input[type=password]").val(""); |
---|
69 | |
---|
70 | var new_user = data.result.users[0]; |
---|
71 | allUsers.push(parseInt(new_user.id)); |
---|
72 | jQuery("#showAddUser .infos").html(sprintf(newUser_pattern, new_user.username)).show(); |
---|
73 | checkSelection(); |
---|
74 | |
---|
75 | jQuery("#addUserForm").hide(); |
---|
76 | } |
---|
77 | else { |
---|
78 | jQuery("#addUserForm .errors").html('✘ '+data.message).show(); |
---|
79 | } |
---|
80 | }, |
---|
81 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
82 | jQuery("#addUserForm .loading").hide(); |
---|
83 | } |
---|
84 | }); |
---|
85 | |
---|
86 | return false; |
---|
87 | }); |
---|
88 | |
---|
89 | /** |
---|
90 | * Table with users |
---|
91 | */ |
---|
92 | /* Formating function for row details */ |
---|
93 | function fnFormatDetails(oTable, nTr) { |
---|
94 | var userId = oTable.fnGetData(nTr)[0]; |
---|
95 | console.log("userId = "+userId); |
---|
96 | var sOut = null; |
---|
97 | |
---|
98 | jQuery.ajax({ |
---|
99 | url: "ws.php?format=json&method=pwg.users.getList", |
---|
100 | type:"POST", |
---|
101 | data: { |
---|
102 | user_id: userId, |
---|
103 | display: "all", |
---|
104 | }, |
---|
105 | success:function(data) { |
---|
106 | jQuery("#user"+userId+" .loading").hide(); |
---|
107 | |
---|
108 | var data = jQuery.parseJSON(data); |
---|
109 | if (data.stat == 'ok') { |
---|
110 | var user = data.result.users[0]; |
---|
111 | |
---|
112 | var userDetails = '<form>'; |
---|
113 | userDetails += '<div class="userActions">'; |
---|
114 | userDetails += '<a class="icon-key" href="#">Change password</a>'; |
---|
115 | userDetails += '<br><a target="_blank" href="admin.php?page=user_perm&user_id='+userId+'" class="icon-lock">Permissions</a>'; |
---|
116 | userDetails += '<br><span class="userDelete"><img class="loading" src="themes/default/images/ajax-loader-small.gif" style="display:none;"><a href="#" class="icon-trash" data-user_id="'+userId+'">Delete</a></span>'; |
---|
117 | userDetails += '</div>'; |
---|
118 | userDetails += '<strong class="username">'+user.username+'</strong> <span class="icon-pencil"></span>'; |
---|
119 | userDetails += '<br><br>'; |
---|
120 | userDetails += sprintf(registeredOn_pattern, user.registration_date_string, user.registration_date_since); |
---|
121 | |
---|
122 | if (typeof user.last_visit != 'undefined') { |
---|
123 | userDetails += '<br>'+sprintf(lastVisit_pattern, user.last_visit_string, user.last_visit_since); |
---|
124 | } |
---|
125 | |
---|
126 | userDetails += '<div class="userPropertiesContainer">'; |
---|
127 | userDetails += '<input type="hidden" name="user_id" value="'+user.id+'">'; |
---|
128 | userDetails += '<div class="userPropertiesSet">'; |
---|
129 | userDetails += '<div class="userPropertiesSetTitle">{/literal}{'Properties'|translate}{literal}</div>'; |
---|
130 | |
---|
131 | userDetails += '<div class="userProperty"><strong>{/literal}{'Email address'|translate}{literal}</strong>'; |
---|
132 | userDetails += '<br><input name="email" type="text" value="'+user.email+'"></div>'; |
---|
133 | |
---|
134 | userDetails += '<div class="userProperty"><strong>{/literal}{'Status'|translate}{literal}</strong>'; |
---|
135 | userDetails += '<br><select name="status">'; |
---|
136 | jQuery("#action select[name=status] option").each(function() { |
---|
137 | var selected = ''; |
---|
138 | if (user.status == jQuery(this).val()) { |
---|
139 | selected = ' selected="selected"'; |
---|
140 | } |
---|
141 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
142 | }); |
---|
143 | userDetails += '</select></div>'; |
---|
144 | |
---|
145 | userDetails += '<div class="userProperty"><strong>{/literal}{'Privacy level'|translate}{literal}</strong>'; |
---|
146 | userDetails += '<br><select name="level">'; |
---|
147 | jQuery("#action select[name=level] option").each(function() { |
---|
148 | var selected = ''; |
---|
149 | if (user.level == jQuery(this).val()) { |
---|
150 | selected = ' selected="selected"'; |
---|
151 | } |
---|
152 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
153 | }); |
---|
154 | userDetails += '</select></div>'; |
---|
155 | |
---|
156 | var checked = ''; |
---|
157 | if (user.enabled_high == 'true') { |
---|
158 | checked = ' checked="checked"'; |
---|
159 | } |
---|
160 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="enabled_high"'+checked+'> <strong>{/literal}{'High definition enabled'|translate}{literal}</strong></label>'; |
---|
161 | userDetails += '</div>'; |
---|
162 | |
---|
163 | userDetails += '<div class="userProperty"><strong>{/literal}{'Groups'|translate}{literal}</strong>'; |
---|
164 | userDetails += '<br><select multiple class="chzn-select" style="width:340px;" name="group_id[]">'; |
---|
165 | jQuery("#action select[name=associate] option").each(function() { |
---|
166 | var selected = ''; |
---|
167 | if (user.groups.indexOf(jQuery(this).val()) != -1) { |
---|
168 | selected = ' selected="selected"'; |
---|
169 | } |
---|
170 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
171 | }); |
---|
172 | userDetails += '</select></div>'; |
---|
173 | // userDetails += '<br>'+user.groups.join(",")+'</div>'; |
---|
174 | |
---|
175 | userDetails += '</div><div class="userPropertiesSet userPrefs">'; |
---|
176 | userDetails += '<div class="userPropertiesSetTitle">{/literal}{'Preferences'|translate}{literal}</div>'; |
---|
177 | |
---|
178 | userDetails += '<div class="userProperty"><strong>{/literal}{'Number of photos per page'|translate}{literal}</strong>'; |
---|
179 | userDetails += '<br>'+user.nb_image_page+'</div>'; |
---|
180 | |
---|
181 | userDetails += '<div class="userProperty"><strong>{/literal}{'Theme'|translate}{literal}</strong>'; |
---|
182 | userDetails += '<br><select name="theme">'; |
---|
183 | jQuery("#action select[name=theme] option").each(function() { |
---|
184 | var selected = ''; |
---|
185 | if (user.theme == jQuery(this).val()) { |
---|
186 | selected = ' selected="selected"'; |
---|
187 | } |
---|
188 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
189 | }); |
---|
190 | userDetails += '</select></div>'; |
---|
191 | |
---|
192 | userDetails += '<div class="userProperty"><strong>{/literal}{'Language'|translate}{literal}</strong>'; |
---|
193 | userDetails += '<br><select name="language">'; |
---|
194 | jQuery("#action select[name=language] option").each(function() { |
---|
195 | var selected = ''; |
---|
196 | if (user.language == jQuery(this).val()) { |
---|
197 | selected = ' selected="selected"'; |
---|
198 | } |
---|
199 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
200 | }); |
---|
201 | userDetails += '</select></div>'; |
---|
202 | |
---|
203 | userDetails += '<div class="userProperty"><strong>{/literal}{'Recent period'|translate}{literal}</strong>'; |
---|
204 | userDetails += '<br>'+user.recent_period+'</div>'; |
---|
205 | |
---|
206 | var checked = ''; |
---|
207 | if (user.expand == 'true') { |
---|
208 | checked = ' checked="checked"'; |
---|
209 | } |
---|
210 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="expand"'+checked+'> <strong>{/literal}{'Expand all albums'|translate}{literal}</strong></label>'; |
---|
211 | userDetails += '</div>'; |
---|
212 | |
---|
213 | var checked = ''; |
---|
214 | if (user.show_nb_comments == 'true') { |
---|
215 | checked = ' checked="checked"'; |
---|
216 | } |
---|
217 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="show_nb_comments"'+checked+'> <strong>{/literal}{'Show number of comments'|translate}{literal}</strong></label>'; |
---|
218 | userDetails += '</div>'; |
---|
219 | |
---|
220 | var checked = ''; |
---|
221 | if (user.show_nb_hits == 'true') { |
---|
222 | checked = ' checked="checked"'; |
---|
223 | } |
---|
224 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="show_nb_hits"'+checked+'> <strong>{/literal}{'Show number of hits'|translate}{literal}</strong></label>'; |
---|
225 | userDetails += '</div>'; |
---|
226 | userDetails += '</div>'; |
---|
227 | userDetails += '<div style="clear:both"></div></div>'; |
---|
228 | |
---|
229 | userDetails += '<span class="infos" style="display:none">✔ User '+user.username+' updated</span>'; |
---|
230 | userDetails += '<input type="submit" value="{/literal}{'Update user'|translate}{literal}" style="display:none;" data-user_id="'+userId+'">'; |
---|
231 | userDetails += '<img class="submitWait" src="themes/default/images/ajax-loader-small.gif" style="display:none">' |
---|
232 | userDetails += '</form>'; |
---|
233 | |
---|
234 | jQuery("#user"+userId).append(userDetails); |
---|
235 | jQuery(".chzn-select").chosen(); |
---|
236 | } |
---|
237 | else { |
---|
238 | console.log('error loading user details'); |
---|
239 | } |
---|
240 | }, |
---|
241 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
242 | console.log('technical error loading user details'); |
---|
243 | } |
---|
244 | }); |
---|
245 | |
---|
246 | return '<div id="user'+userId+'" class="userProperties"><img class="loading" src="themes/default/images/ajax-loader-small.gif"></div>'; |
---|
247 | } |
---|
248 | |
---|
249 | jQuery(document).on('change', '.userProperties input, .userProperties select', function() { |
---|
250 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
251 | |
---|
252 | jQuery('#user'+userId+' input[type=submit]').show(); |
---|
253 | jQuery('#user'+userId+' .infos').hide(); |
---|
254 | }); |
---|
255 | |
---|
256 | jQuery(document).on('click', '.userDelete a', function() { |
---|
257 | if (!confirm("{/literal}{'Are you sure?'|translate|escape:javascript}{literal}")) { |
---|
258 | return false; |
---|
259 | } |
---|
260 | |
---|
261 | var userId = jQuery(this).data('user_id'); |
---|
262 | var username = jQuery('#user'+userId+' .username').html(); |
---|
263 | |
---|
264 | jQuery.ajax({ |
---|
265 | url: "ws.php?format=json&method=pwg.users.delete", |
---|
266 | type:"POST", |
---|
267 | data: { |
---|
268 | user_id:userId, |
---|
269 | pwg_token:pwg_token |
---|
270 | }, |
---|
271 | beforeSend: function() { |
---|
272 | jQuery('#user'+userId+' .userDelete .loading').show(); |
---|
273 | }, |
---|
274 | success:function(data) { |
---|
275 | oTable.fnDraw(); |
---|
276 | jQuery('#showAddUser .infos').html('✔ User '+username+' deleted').show(); |
---|
277 | }, |
---|
278 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
279 | jQuery('#user'+userId+' .userDelete .loading').hide(); |
---|
280 | } |
---|
281 | }); |
---|
282 | |
---|
283 | return false; |
---|
284 | }); |
---|
285 | |
---|
286 | jQuery(document).on('click', '.userProperties input[type=submit]', function() { |
---|
287 | var userId = jQuery(this).data('user_id'); |
---|
288 | |
---|
289 | var formData = jQuery('#user'+userId+' form').serialize(); |
---|
290 | |
---|
291 | if (jQuery('#user'+userId+' form select[name="group_id[]"] option:selected').length == 0) { |
---|
292 | formData += '&group_id=-1'; |
---|
293 | } |
---|
294 | |
---|
295 | if (!jQuery('#user'+userId+' form input[name=enabled_high]').is(':checked')) { |
---|
296 | formData += '&enabled_high=false'; |
---|
297 | } |
---|
298 | |
---|
299 | if (!jQuery('#user'+userId+' form input[name=expand]').is(':checked')) { |
---|
300 | formData += '&expand=false'; |
---|
301 | } |
---|
302 | |
---|
303 | if (!jQuery('#user'+userId+' form input[name=show_nb_hits]').is(':checked')) { |
---|
304 | formData += '&show_nb_hits=false'; |
---|
305 | } |
---|
306 | |
---|
307 | if (!jQuery('#user'+userId+' form input[name=show_nb_comments]').is(':checked')) { |
---|
308 | formData += '&show_nb_comments=false'; |
---|
309 | } |
---|
310 | |
---|
311 | jQuery.ajax({ |
---|
312 | url: "ws.php?format=json&method=pwg.users.setInfo", |
---|
313 | type:"POST", |
---|
314 | data: formData, |
---|
315 | beforeSend: function() { |
---|
316 | jQuery('#user'+userId+' .submitWait').show(); |
---|
317 | }, |
---|
318 | success:function(data) { |
---|
319 | jQuery('#user'+userId+' .submitWait').hide(); |
---|
320 | jQuery('#user'+userId+' input[type=submit]').hide(); |
---|
321 | jQuery('#user'+userId+' .infos').show(); |
---|
322 | }, |
---|
323 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
324 | jQuery('#user'+userId+' .submitWait').hide(); |
---|
325 | } |
---|
326 | }); |
---|
327 | |
---|
328 | return false; |
---|
329 | }); |
---|
330 | |
---|
331 | /* Add event listener for opening and closing details |
---|
332 | * Note that the indicator for showing which row is open is not controlled by DataTables, |
---|
333 | * rather it is done here |
---|
334 | */ |
---|
335 | jQuery(document).on('click', '#userList tbody td .openUserDetails', function() { |
---|
336 | var nTr = this.parentNode.parentNode; |
---|
337 | if (jQuery(this).hasClass('icon-angle-circled-up')) { |
---|
338 | /* This row is already open - close it */ |
---|
339 | jQuery(this).removeClass('icon-angle-circled-up').addClass('icon-angle-circled-down').attr('title', 'Open user details'); |
---|
340 | oTable.fnClose( nTr ); |
---|
341 | } |
---|
342 | else { |
---|
343 | /* Open this row */ |
---|
344 | jQuery(this).removeClass('icon-angle-circled-down').addClass('icon-angle-circled-up').attr('title', 'Close user details'); |
---|
345 | oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' ); |
---|
346 | } |
---|
347 | }); |
---|
348 | |
---|
349 | |
---|
350 | /* first column must be prefixed with the open/close icon */ |
---|
351 | var aoColumns = [ |
---|
352 | { |
---|
353 | 'bVisible':false |
---|
354 | }, |
---|
355 | { |
---|
356 | "mRender": function(data, type, full) { |
---|
357 | return '<span title="Open user details" class="icon-angle-circled-down openUserDetails"></span> <label><input type="checkbox" data-user_id="'+full[0]+'"> '+data+'</label>'; |
---|
358 | } |
---|
359 | } |
---|
360 | ]; |
---|
361 | |
---|
362 | for (i=2; i<jQuery("#userList thead tr th").length; i++) { |
---|
363 | aoColumns.push(null); |
---|
364 | } |
---|
365 | |
---|
366 | var oTable = jQuery('#userList').dataTable({ |
---|
367 | "iDisplayLength": 10, |
---|
368 | "bDeferRender": true, |
---|
369 | "bProcessing": true, |
---|
370 | "bServerSide": true, |
---|
371 | "sAjaxSource": "admin/user_list_backend.php", |
---|
372 | "oLanguage": { |
---|
373 | "sProcessing": "Traitement en cours...", |
---|
374 | "sLengthMenu": "Afficher _MENU_ éléments", |
---|
375 | "sZeroRecords": "Aucun élément à afficher", |
---|
376 | "sInfo": "Affichage des élements _START_ à _END_ sur _TOTAL_", |
---|
377 | "sInfoEmpty": "Affichage de l'élement 0 à 0 sur 0 éléments", |
---|
378 | "sInfoFiltered": "<br>(filtré de _MAX_ éléments au total{/literal}{if $is_a_guest} <span class='limitedVersionWarning'>dans la version complète</span>{/if}{literal})", |
---|
379 | "sInfoPostFix": "", |
---|
380 | "sSearch": "Rechercher", |
---|
381 | "sLoadingRecords": "Téléchargement...", |
---|
382 | "sUrl": "", |
---|
383 | "oPaginate": { |
---|
384 | "sFirst": "Premier", |
---|
385 | "sPrevious": "← Précédent", |
---|
386 | "sNext": "Suivant →", |
---|
387 | "sLast": "Dernier" |
---|
388 | } |
---|
389 | }, |
---|
390 | "fnDrawCallback": function( oSettings ) { |
---|
391 | jQuery("#userList input[type=checkbox]").each(function() { |
---|
392 | var user_id = jQuery(this).data("user_id"); |
---|
393 | jQuery(this).prop('checked', (selection.indexOf(user_id) != -1)); |
---|
394 | }); |
---|
395 | }, |
---|
396 | "aoColumns": aoColumns |
---|
397 | }); |
---|
398 | |
---|
399 | /** |
---|
400 | * Selection management |
---|
401 | */ |
---|
402 | function checkSelection() { |
---|
403 | if (selection.length > 0) { |
---|
404 | jQuery("#forbidAction").hide(); |
---|
405 | jQuery("#permitAction").show(); |
---|
406 | |
---|
407 | jQuery("#applyOnDetails").text( |
---|
408 | sprintf( |
---|
409 | applyOnDetails_pattern, |
---|
410 | selection.length |
---|
411 | ) |
---|
412 | ); |
---|
413 | |
---|
414 | if (selection.length == allUsers.length) { |
---|
415 | jQuery("#selectedMessage").text( |
---|
416 | sprintf( |
---|
417 | selectedMessage_all, |
---|
418 | allUsers.length |
---|
419 | ) |
---|
420 | ); |
---|
421 | } |
---|
422 | else { |
---|
423 | jQuery("#selectedMessage").text( |
---|
424 | sprintf( |
---|
425 | selectedMessage_pattern, |
---|
426 | selection.length, |
---|
427 | allUsers.length |
---|
428 | ) |
---|
429 | ); |
---|
430 | } |
---|
431 | } |
---|
432 | else { |
---|
433 | jQuery("#forbidAction").show(); |
---|
434 | jQuery("#permitAction").hide(); |
---|
435 | |
---|
436 | jQuery("#selectedMessage").text( |
---|
437 | sprintf( |
---|
438 | selectedMessage_none, |
---|
439 | allUsers.length |
---|
440 | ) |
---|
441 | ); |
---|
442 | } |
---|
443 | |
---|
444 | jQuery("#applyActionBlock .infos").hide(); |
---|
445 | } |
---|
446 | |
---|
447 | jQuery(document).on('change', '#userList input[type=checkbox]', function() { |
---|
448 | var user_id = jQuery(this).data("user_id"); |
---|
449 | |
---|
450 | array_delete(selection, user_id); |
---|
451 | |
---|
452 | if (jQuery(this).is(":checked")) { |
---|
453 | selection.push(user_id); |
---|
454 | } |
---|
455 | |
---|
456 | checkSelection(); |
---|
457 | }); |
---|
458 | |
---|
459 | jQuery("#selectAll").click(function () { |
---|
460 | selection = allUsers; |
---|
461 | jQuery("#userList input[type=checkbox]").prop('checked', true); |
---|
462 | checkSelection(); |
---|
463 | return false; |
---|
464 | }); |
---|
465 | |
---|
466 | jQuery("#selectNone").click(function () { |
---|
467 | selection = []; |
---|
468 | jQuery("#userList input[type=checkbox]").prop('checked', false); |
---|
469 | checkSelection(); |
---|
470 | return false; |
---|
471 | }); |
---|
472 | |
---|
473 | jQuery("#selectInvert").click(function () { |
---|
474 | var newSelection = []; |
---|
475 | for(var i in allUsers) |
---|
476 | { |
---|
477 | if (selection.indexOf(allUsers[i]) == -1) { |
---|
478 | newSelection.push(allUsers[i]); |
---|
479 | } |
---|
480 | } |
---|
481 | selection = newSelection; |
---|
482 | |
---|
483 | jQuery("#userList input[type=checkbox]").each(function() { |
---|
484 | var user_id = jQuery(this).data("user_id"); |
---|
485 | jQuery(this).prop('checked', (selection.indexOf(user_id) != -1)); |
---|
486 | }); |
---|
487 | |
---|
488 | checkSelection(); |
---|
489 | return false; |
---|
490 | }); |
---|
491 | |
---|
492 | /** |
---|
493 | * Action management |
---|
494 | */ |
---|
495 | jQuery("[id^=action_]").hide(); |
---|
496 | |
---|
497 | jQuery("select[name=selectAction]").change(function () { |
---|
498 | jQuery("#applyActionBlock .infos").hide(); |
---|
499 | |
---|
500 | jQuery("[id^=action_]").hide(); |
---|
501 | |
---|
502 | jQuery("#action_"+$(this).prop("value")).show(); |
---|
503 | |
---|
504 | if (jQuery(this).val() != -1) { |
---|
505 | jQuery("#applyActionBlock").show(); |
---|
506 | } |
---|
507 | else { |
---|
508 | jQuery("#applyActionBlock").hide(); |
---|
509 | } |
---|
510 | }); |
---|
511 | |
---|
512 | jQuery("#permitAction input, #permitAction select").click(function() { |
---|
513 | jQuery("#applyActionBlock .infos").hide(); |
---|
514 | }); |
---|
515 | |
---|
516 | jQuery("#applyAction").click(function() { |
---|
517 | var action = jQuery("select[name=selectAction]").prop("value"); |
---|
518 | var method = 'pwg.users.setInfo'; |
---|
519 | var data = { |
---|
520 | user_id: selection |
---|
521 | }; |
---|
522 | |
---|
523 | switch (action) { |
---|
524 | case 'delete': |
---|
525 | if (!jQuery("input[name=confirm_deletion]").is(':checked')) { |
---|
526 | alert(missingConfirm); |
---|
527 | return false; |
---|
528 | } |
---|
529 | method = 'pwg.users.delete'; |
---|
530 | data.pwg_token = pwg_token; |
---|
531 | break; |
---|
532 | case 'group_associate': |
---|
533 | method = 'pwg.groups.addUser'; |
---|
534 | data.group_id = jQuery("select[name=associate]").prop("value"); |
---|
535 | break; |
---|
536 | case 'group_dissociate': |
---|
537 | method = 'pwg.groups.deleteUser'; |
---|
538 | data.group_id = jQuery("select[name=dissociate]").prop("value"); |
---|
539 | break; |
---|
540 | case 'status': |
---|
541 | data.status = jQuery("select[name=status]").prop("value"); |
---|
542 | break; |
---|
543 | case 'enabled_high': |
---|
544 | data.enabled_high = jQuery("input[name=enabled_high]:checked").val(); |
---|
545 | break; |
---|
546 | case 'level': |
---|
547 | data.level = jQuery("select[name=level]").val(); |
---|
548 | break; |
---|
549 | case 'nb_image_page': |
---|
550 | data.nb_image_page = jQuery("input[name=nb_image_page]").val(); |
---|
551 | break; |
---|
552 | case 'theme': |
---|
553 | data.theme = jQuery("select[name=theme]").val(); |
---|
554 | break; |
---|
555 | case 'language': |
---|
556 | data.language = jQuery("select[name=language]").val(); |
---|
557 | break; |
---|
558 | case 'recent_period': |
---|
559 | data.recent_period = jQuery("input[name=recent_period]").val(); |
---|
560 | break; |
---|
561 | case 'expand': |
---|
562 | data.expand = jQuery("input[name=expand]:checked").val(); |
---|
563 | break; |
---|
564 | case 'show_nb_comments': |
---|
565 | data.show_nb_comments = jQuery("input[name=show_nb_comments]:checked").val(); |
---|
566 | break; |
---|
567 | case 'show_nb_hits': |
---|
568 | data.show_nb_hits = jQuery("input[name=show_nb_hits]:checked").val(); |
---|
569 | break; |
---|
570 | default: |
---|
571 | alert("Unexpected action"); |
---|
572 | return false; |
---|
573 | } |
---|
574 | |
---|
575 | jQuery.ajax({ |
---|
576 | url: "ws.php?format=json&method="+method, |
---|
577 | type:"POST", |
---|
578 | data: data, |
---|
579 | beforeSend: function() { |
---|
580 | jQuery("#applyActionLoading").show(); |
---|
581 | }, |
---|
582 | success:function(data) { |
---|
583 | oTable.fnDraw(); |
---|
584 | jQuery("#applyActionLoading").hide(); |
---|
585 | jQuery("#applyActionBlock .infos").show(); |
---|
586 | |
---|
587 | if (action == 'delete') { |
---|
588 | var allUsers_new = []; |
---|
589 | for(var i in allUsers) |
---|
590 | { |
---|
591 | if (selection.indexOf(allUsers[i]) == -1) { |
---|
592 | allUsers_new.push(allUsers[i]); |
---|
593 | } |
---|
594 | } |
---|
595 | allUsers = allUsers_new; |
---|
596 | console.log('allUsers_new.length = '+allUsers_new.length); |
---|
597 | selection = []; |
---|
598 | checkSelection(); |
---|
599 | } |
---|
600 | }, |
---|
601 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
602 | jQuery("#applyActionLoading").hide(); |
---|
603 | } |
---|
604 | }); |
---|
605 | |
---|
606 | return false; |
---|
607 | }); |
---|
608 | |
---|
609 | }); |
---|
610 | {/literal}{/footer_script} |
---|
611 | |
---|
612 | {literal} |
---|
613 | <style> |
---|
614 | .dataTables_wrapper, .dataTables_info {clear:none;} |
---|
615 | table.dataTable {clear:right;padding-top:10px;} |
---|
616 | .dataTable td img {margin-bottom: -6px;margin-left: -6px;} |
---|
617 | .paginate_enabled_previous, .paginate_enabled_previous:hover, .paginate_disabled_previous, .paginate_enabled_next, .paginate_enabled_next:hover, .paginate_disabled_next {background:none;} |
---|
618 | .paginate_enabled_previous, .paginate_enabled_next {color:#005E89 !important;} |
---|
619 | .paginate_enabled_previous:hover, .paginate_enabled_next:hover {color:#D54E21 !important; text-decoration:underline !important;} |
---|
620 | |
---|
621 | .paginate_disabled_next, .paginate_enabled_next {padding-right:3px;} |
---|
622 | .bulkAction {margin-top:10px;} |
---|
623 | #addUserForm p {margin-left:0;} |
---|
624 | #applyActionBlock .actionButtons {margin-left:0;} |
---|
625 | span.infos, span.errors {background-image:none; padding:2px 5px; margin:0;border-radius:5px;} |
---|
626 | </style> |
---|
627 | {/literal} |
---|
628 | |
---|
629 | <div class="titrePage"> |
---|
630 | <h2>{'User list'|@translate}</h2> |
---|
631 | </div> |
---|
632 | |
---|
633 | <p class="showCreateAlbum" id="showAddUser"> |
---|
634 | <a href="#" id="addUser" class="icon-plus-circled">{'Add a user'|translate}</a> |
---|
635 | <span class="infos" style="display:none"></span> |
---|
636 | </p> |
---|
637 | |
---|
638 | <form id="addUserForm" style="display:none" method="post" name="add_user" action="{$F_ADD_ACTION}"> |
---|
639 | <fieldset> |
---|
640 | <legend>{'Add a user'|@translate}</legend> |
---|
641 | |
---|
642 | <p> |
---|
643 | <strong>{'Username'|translate}</strong><br> |
---|
644 | <input type="text" name="username" maxlength="50" size="20"> |
---|
645 | </p> |
---|
646 | |
---|
647 | <p> |
---|
648 | <strong>{'Password'|translate}</strong><br> |
---|
649 | <input type="{if $Double_Password}password{else}text{/if}" name="password"> |
---|
650 | </p> |
---|
651 | |
---|
652 | {if $Double_Password} |
---|
653 | <p> |
---|
654 | <strong>{'Confirm Password'|@translate}</strong><br> |
---|
655 | <input type="password" name="password_confirm"> |
---|
656 | </p> |
---|
657 | {/if} |
---|
658 | |
---|
659 | <p> |
---|
660 | <strong>{'Email address'|@translate}</strong><br> |
---|
661 | <input type="text" name="email"> |
---|
662 | </p> |
---|
663 | |
---|
664 | <p> |
---|
665 | <label><input type="checkbox" name="send_password_by_mail"> <strong>{'Send connection settings by email'|@translate}</strong></label> |
---|
666 | </p> |
---|
667 | |
---|
668 | <p class="actionButtons"> |
---|
669 | <input class="submit" name="submit_add" type="submit" value="{'Submit'|@translate}"> |
---|
670 | <a href="#" id="addUserClose">{'Cancel'|@translate}</a> |
---|
671 | <span class="loading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span> |
---|
672 | <span class="errors" style="display:none"></span> |
---|
673 | </p> |
---|
674 | </fieldset> |
---|
675 | </form> |
---|
676 | |
---|
677 | <form method="post" name="preferences" action=""> |
---|
678 | |
---|
679 | <table id="userList"> |
---|
680 | <thead> |
---|
681 | <tr> |
---|
682 | <th>id</th> |
---|
683 | <th>{'Username'|@translate}</th> |
---|
684 | <th>{'Status'|@translate}</th> |
---|
685 | <th>{'Email address'|@translate}</th> |
---|
686 | <th>{'registration date'|@translate}</th> |
---|
687 | </tr> |
---|
688 | </thead> |
---|
689 | </table> |
---|
690 | |
---|
691 | <div style="clear:right"></div> |
---|
692 | |
---|
693 | <p class="checkActions"> |
---|
694 | {'Select:'|@translate} |
---|
695 | <a href="#" id="selectAll">{'All'|@translate}</a>, |
---|
696 | <a href="#" id="selectNone">{'None'|@translate}</a>, |
---|
697 | <a href="#" id="selectInvert">{'Invert'|@translate}</a> |
---|
698 | |
---|
699 | <span id="selectedMessage"></span> |
---|
700 | </p> |
---|
701 | |
---|
702 | <fieldset id="action"> |
---|
703 | <legend>{'Action'|@translate}</legend> |
---|
704 | |
---|
705 | <div id="forbidAction"{if count($selection) != 0} style="display:none"{/if}>{'No user selected, no action possible.'|@translate}</div> |
---|
706 | <div id="permitAction"{if count($selection) == 0} style="display:none"{/if}> |
---|
707 | |
---|
708 | <select name="selectAction"> |
---|
709 | <option value="-1">{'Choose an action'|@translate}</option> |
---|
710 | <option disabled="disabled">------------------</option> |
---|
711 | <option value="delete" class="icon-trash">{'Delete selected users'|@translate}</option> |
---|
712 | <option value="status">{'Status'|@translate}</option> |
---|
713 | <option value="group_associate">{'associate to group'|translate}</option> |
---|
714 | <option value="group_dissociate">{'dissociate from group'|@translate}</option> |
---|
715 | <option value="enabled_high">{'High definition enabled'|@translate}</option> |
---|
716 | <option value="level">{'Privacy level'|@translate}</option> |
---|
717 | <option value="nb_image_page">{'Number of photos per page'|@translate}</option> |
---|
718 | <option value="theme">{'Interface theme'|@translate}</option> |
---|
719 | <option value="language">{'Language'|@translate}</option> |
---|
720 | <option value="recent_period">{'Recent period'|@translate}</option> |
---|
721 | <option value="expand">{'Expand all albums'|@translate}</option> |
---|
722 | {if $ACTIVATE_COMMENTS} |
---|
723 | <option value="show_nb_comments">{'Show number of comments'|@translate}</option> |
---|
724 | {/if} |
---|
725 | <option value="show_nb_hits">{'Show number of hits'|@translate}</option> |
---|
726 | </select> |
---|
727 | |
---|
728 | {* delete *} |
---|
729 | <div id="action_delete" class="bulkAction"> |
---|
730 | <p><label><input type="checkbox" name="confirm_deletion" value="1"> {'Are you sure?'|@translate}</label></p> |
---|
731 | </div> |
---|
732 | |
---|
733 | {* status *} |
---|
734 | <div id="action_status" class="bulkAction"> |
---|
735 | <select name="status"> |
---|
736 | {html_options options=$pref_status_options selected=$pref_status_selected} |
---|
737 | </select> |
---|
738 | </div> |
---|
739 | |
---|
740 | {* group_associate *} |
---|
741 | <div id="action_group_associate" class="bulkAction"> |
---|
742 | {html_options name=associate options=$association_options selected=$associate_selected} |
---|
743 | </div> |
---|
744 | |
---|
745 | {* group_dissociate *} |
---|
746 | <div id="action_group_dissociate" class="bulkAction"> |
---|
747 | {html_options name=dissociate options=$association_options selected=$dissociate_selected} |
---|
748 | </div> |
---|
749 | |
---|
750 | {* enabled_high *} |
---|
751 | <div id="action_enabled_high" class="bulkAction"> |
---|
752 | <label><input type="radio" name="enabled_high" value="true">{'Yes'|@translate}</label> |
---|
753 | <label><input type="radio" name="enabled_high" value="false" checked="checked">{'No'|@translate}</label> |
---|
754 | </div> |
---|
755 | |
---|
756 | {* level *} |
---|
757 | <div id="action_level" class="bulkAction"> |
---|
758 | <select name="level" size="1"> |
---|
759 | {html_options options=$level_options selected=$level_selected} |
---|
760 | </select> |
---|
761 | </div> |
---|
762 | |
---|
763 | {* nb_image_page *} |
---|
764 | <div id="action_nb_image_page" class="bulkAction"> |
---|
765 | <input size="4" maxlength="3" type="text" name="nb_image_page" value="{$NB_IMAGE_PAGE}"> |
---|
766 | </div> |
---|
767 | |
---|
768 | {* theme *} |
---|
769 | <div id="action_theme" class="bulkAction"> |
---|
770 | <select name="theme" size="1"> |
---|
771 | {html_options options=$theme_options selected=$theme_selected} |
---|
772 | </select> |
---|
773 | </div> |
---|
774 | |
---|
775 | {* language *} |
---|
776 | <div id="action_language" class="bulkAction"> |
---|
777 | <select name="language" size="1"> |
---|
778 | {html_options options=$language_options selected=$language_selected} |
---|
779 | </select> |
---|
780 | </div> |
---|
781 | |
---|
782 | {* recent_period *} |
---|
783 | <div id="action_recent_period" class="bulkAction"> |
---|
784 | <input type="text" size="3" maxlength="2" name="recent_period" value="{$RECENT_PERIOD}"> |
---|
785 | </div> |
---|
786 | |
---|
787 | {* expand *} |
---|
788 | <div id="action_expand" class="bulkAction"> |
---|
789 | <label><input type="radio" name="expand" value="true">{'Yes'|@translate}</label> |
---|
790 | <label><input type="radio" name="expand" value="false" checked="checked">{'No'|@translate}</label> |
---|
791 | </div> |
---|
792 | |
---|
793 | {* show_nb_comments *} |
---|
794 | <div id="action_show_nb_comments" class="bulkAction"> |
---|
795 | <label><input type="radio" name="show_nb_comments" value="true">{'Yes'|@translate}</label> |
---|
796 | <label><input type="radio" name="show_nb_comments" value="false" checked="checked">{'No'|@translate}</label> |
---|
797 | </div> |
---|
798 | |
---|
799 | {* show_nb_hits *} |
---|
800 | <div id="action_show_nb_hits" class="bulkAction"> |
---|
801 | <label><input type="radio" name="show_nb_hits" value="true">{'Yes'|@translate}</label> |
---|
802 | <label><input type="radio" name="show_nb_hits" value="false" checked="checked">{'No'|@translate}</label> |
---|
803 | </div> |
---|
804 | |
---|
805 | <p id="applyActionBlock" style="display:none" class="actionButtons"> |
---|
806 | <input id="applyAction" class="submit" type="submit" value="{'Apply action'|@translate}" name="submit"> <span id="applyOnDetails"></span> |
---|
807 | <span id="applyActionLoading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span> |
---|
808 | <span class="infos" style="display:none">✔ Users modified</span> |
---|
809 | </p> |
---|
810 | |
---|
811 | </div> {* #permitAction *} |
---|
812 | </fieldset> |
---|
813 | |
---|
814 | </form> |
---|