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 += '<span class="changePasswordDone infos" style="display:none">✔ Password updated</span>'; |
---|
115 | userDetails += '<span class="changePassword" style="display:none">{/literal}{'New password'|translate}{literal} <input type="text"> <a href="#" class="buttonLike updatePassword"><img src="themes/default/images/ajax-loader-small.gif" style="margin-bottom:-1px;margin-left:1px;display:none;"><span class="text">{/literal}{'Submit'|translate}{literal}</span></a> <a href="#" class="cancel">Cancel</a></span>'; |
---|
116 | userDetails += '<a class="icon-key changePasswordOpen" href="#">Change password</a>'; |
---|
117 | userDetails += '<br><a target="_blank" href="admin.php?page=user_perm&user_id='+userId+'" class="icon-lock">Permissions</a>'; |
---|
118 | 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>'; |
---|
119 | userDetails += '</div>'; |
---|
120 | |
---|
121 | userDetails += '<span class="changeUsernameOpen"><strong class="username">'+user.username+'</strong> <a href="#" class="icon-pencil">Change username</a></span>'; |
---|
122 | userDetails += '<span class="changeUsername" style="display:none">'; |
---|
123 | userDetails += '<input type="text"> <a href="#" class="buttonLike updateUsername"><img src="themes/default/images/ajax-loader-small.gif" style="margin-bottom:-1px;margin-left:1px;display:none;"><span class="text">{/literal}{'Submit'|translate}{literal}</span></a> <a href="#" class="cancel">Cancel</a>'; |
---|
124 | userDetails += '</span>'; |
---|
125 | |
---|
126 | userDetails += '<div class="userStats">'; |
---|
127 | userDetails += sprintf(registeredOn_pattern, user.registration_date_string, user.registration_date_since); |
---|
128 | |
---|
129 | if (typeof user.last_visit != 'undefined') { |
---|
130 | userDetails += '<br>'+sprintf(lastVisit_pattern, user.last_visit_string, user.last_visit_since); |
---|
131 | } |
---|
132 | |
---|
133 | userDetails += '</div>'; |
---|
134 | userDetails += '<div class="userPropertiesContainer">'; |
---|
135 | userDetails += '<input type="hidden" name="user_id" value="'+user.id+'">'; |
---|
136 | userDetails += '<div class="userPropertiesSet">'; |
---|
137 | userDetails += '<div class="userPropertiesSetTitle">{/literal}{'Properties'|translate}{literal}</div>'; |
---|
138 | |
---|
139 | userDetails += '<div class="userProperty"><strong>{/literal}{'Email address'|translate}{literal}</strong>'; |
---|
140 | userDetails += '<br><input name="email" type="text" value="'+user.email+'"></div>'; |
---|
141 | |
---|
142 | userDetails += '<div class="userProperty"><strong>{/literal}{'Status'|translate}{literal}</strong>'; |
---|
143 | userDetails += '<br><select name="status">'; |
---|
144 | jQuery("#action select[name=status] option").each(function() { |
---|
145 | var selected = ''; |
---|
146 | if (user.status == jQuery(this).val()) { |
---|
147 | selected = ' selected="selected"'; |
---|
148 | } |
---|
149 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
150 | }); |
---|
151 | userDetails += '</select></div>'; |
---|
152 | |
---|
153 | userDetails += '<div class="userProperty"><strong>{/literal}{'Privacy level'|translate}{literal}</strong>'; |
---|
154 | userDetails += '<br><select name="level">'; |
---|
155 | jQuery("#action select[name=level] option").each(function() { |
---|
156 | var selected = ''; |
---|
157 | if (user.level == jQuery(this).val()) { |
---|
158 | selected = ' selected="selected"'; |
---|
159 | } |
---|
160 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
161 | }); |
---|
162 | userDetails += '</select></div>'; |
---|
163 | |
---|
164 | var checked = ''; |
---|
165 | if (user.enabled_high == 'true') { |
---|
166 | checked = ' checked="checked"'; |
---|
167 | } |
---|
168 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="enabled_high"'+checked+'> <strong>{/literal}{'High definition enabled'|translate}{literal}</strong></label>'; |
---|
169 | userDetails += '</div>'; |
---|
170 | |
---|
171 | userDetails += '<div class="userProperty"><strong>{/literal}{'Groups'|translate}{literal}</strong>'; |
---|
172 | userDetails += '<br><select multiple class="chzn-select" style="width:340px;" name="group_id[]">'; |
---|
173 | jQuery("#action select[name=associate] option").each(function() { |
---|
174 | var selected = ''; |
---|
175 | if (user.groups.indexOf(jQuery(this).val()) != -1) { |
---|
176 | selected = ' selected="selected"'; |
---|
177 | } |
---|
178 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
179 | }); |
---|
180 | userDetails += '</select></div>'; |
---|
181 | // userDetails += '<br>'+user.groups.join(",")+'</div>'; |
---|
182 | |
---|
183 | userDetails += '</div><div class="userPropertiesSet userPrefs">'; |
---|
184 | userDetails += '<div class="userPropertiesSetTitle">{/literal}{'Preferences'|translate}{literal}</div>'; |
---|
185 | |
---|
186 | userDetails += '<div class="userProperty"><strong>{/literal}{'Number of photos per page'|translate}{literal}</strong>'; |
---|
187 | userDetails += '<br>'+user.nb_image_page+'</div>'; |
---|
188 | |
---|
189 | userDetails += '<div class="userProperty"><strong>{/literal}{'Theme'|translate}{literal}</strong>'; |
---|
190 | userDetails += '<br><select name="theme">'; |
---|
191 | jQuery("#action select[name=theme] option").each(function() { |
---|
192 | var selected = ''; |
---|
193 | if (user.theme == jQuery(this).val()) { |
---|
194 | selected = ' selected="selected"'; |
---|
195 | } |
---|
196 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
197 | }); |
---|
198 | userDetails += '</select></div>'; |
---|
199 | |
---|
200 | userDetails += '<div class="userProperty"><strong>{/literal}{'Language'|translate}{literal}</strong>'; |
---|
201 | userDetails += '<br><select name="language">'; |
---|
202 | jQuery("#action select[name=language] option").each(function() { |
---|
203 | var selected = ''; |
---|
204 | if (user.language == jQuery(this).val()) { |
---|
205 | selected = ' selected="selected"'; |
---|
206 | } |
---|
207 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
208 | }); |
---|
209 | userDetails += '</select></div>'; |
---|
210 | |
---|
211 | userDetails += '<div class="userProperty"><strong>{/literal}{'Recent period'|translate}{literal}</strong>'; |
---|
212 | userDetails += '<br>'+user.recent_period+'</div>'; |
---|
213 | |
---|
214 | var checked = ''; |
---|
215 | if (user.expand == 'true') { |
---|
216 | checked = ' checked="checked"'; |
---|
217 | } |
---|
218 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="expand"'+checked+'> <strong>{/literal}{'Expand all albums'|translate}{literal}</strong></label>'; |
---|
219 | userDetails += '</div>'; |
---|
220 | |
---|
221 | var checked = ''; |
---|
222 | if (user.show_nb_comments == 'true') { |
---|
223 | checked = ' checked="checked"'; |
---|
224 | } |
---|
225 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="show_nb_comments"'+checked+'> <strong>{/literal}{'Show number of comments'|translate}{literal}</strong></label>'; |
---|
226 | userDetails += '</div>'; |
---|
227 | |
---|
228 | var checked = ''; |
---|
229 | if (user.show_nb_hits == 'true') { |
---|
230 | checked = ' checked="checked"'; |
---|
231 | } |
---|
232 | userDetails += '<div class="userProperty"><label><input type="checkbox" name="show_nb_hits"'+checked+'> <strong>{/literal}{'Show number of hits'|translate}{literal}</strong></label>'; |
---|
233 | userDetails += '</div>'; |
---|
234 | userDetails += '</div>'; |
---|
235 | userDetails += '<div style="clear:both"></div></div>'; |
---|
236 | |
---|
237 | userDetails += '<span class="infos propertiesUpdateDone" style="display:none">✔ User '+user.username+' updated</span>'; |
---|
238 | userDetails += '<input type="submit" value="{/literal}{'Update user'|translate}{literal}" style="display:none;" data-user_id="'+userId+'">'; |
---|
239 | userDetails += '<img class="submitWait" src="themes/default/images/ajax-loader-small.gif" style="display:none">' |
---|
240 | userDetails += '</form>'; |
---|
241 | |
---|
242 | jQuery("#user"+userId).append(userDetails); |
---|
243 | jQuery(".chzn-select").chosen(); |
---|
244 | } |
---|
245 | else { |
---|
246 | console.log('error loading user details'); |
---|
247 | } |
---|
248 | }, |
---|
249 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
250 | console.log('technical error loading user details'); |
---|
251 | } |
---|
252 | }); |
---|
253 | |
---|
254 | return '<div id="user'+userId+'" class="userProperties"><img class="loading" src="themes/default/images/ajax-loader-small.gif"></div>'; |
---|
255 | } |
---|
256 | |
---|
257 | /* change password */ |
---|
258 | jQuery(document).on('click', '.changePasswordOpen', function() { |
---|
259 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
260 | |
---|
261 | jQuery(this).hide(); |
---|
262 | jQuery('#user'+userId+' .changePasswordDone').hide(); |
---|
263 | jQuery('#user'+userId+' .changePassword').show(); |
---|
264 | jQuery('#user'+userId+' .changePassword input[type=text]').focus(); |
---|
265 | |
---|
266 | return false; |
---|
267 | }); |
---|
268 | |
---|
269 | jQuery(document).on('click', '.changePassword a.updatePassword', function() { |
---|
270 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
271 | |
---|
272 | jQuery('#user'+userId+' .changePassword a .text').hide(); |
---|
273 | jQuery('#user'+userId+' .changePassword a img').show(); |
---|
274 | |
---|
275 | jQuery.ajax({ |
---|
276 | url: "ws.php?format=json&method=pwg.users.setInfo", |
---|
277 | type:"POST", |
---|
278 | data: { |
---|
279 | user_id:userId, |
---|
280 | password: jQuery('#user'+userId+' .changePassword input[type=text]').val() |
---|
281 | }, |
---|
282 | beforeSend: function() { |
---|
283 | jQuery('#user'+userId+' .changePassword input[type=text]').val(""); |
---|
284 | }, |
---|
285 | success:function(data) { |
---|
286 | jQuery('#user'+userId+' .changePassword a .text').show(); |
---|
287 | jQuery('#user'+userId+' .changePassword a img').hide(); |
---|
288 | jQuery('#user'+userId+' .changePassword').hide(); |
---|
289 | jQuery('#user'+userId+' .changePasswordOpen').show(); |
---|
290 | jQuery('#user'+userId+' .changePasswordDone').show(); |
---|
291 | }, |
---|
292 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
293 | } |
---|
294 | }); |
---|
295 | |
---|
296 | return false; |
---|
297 | }); |
---|
298 | |
---|
299 | jQuery(document).on('click', '.changePassword a.cancel', function() { |
---|
300 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
301 | |
---|
302 | jQuery('#user'+userId+' .changePassword').hide(); |
---|
303 | jQuery('#user'+userId+' .changePasswordOpen').show(); |
---|
304 | |
---|
305 | return false; |
---|
306 | }); |
---|
307 | |
---|
308 | /* change username */ |
---|
309 | jQuery(document).on('click', '.changeUsernameOpen a', function() { |
---|
310 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
311 | var username = jQuery('#user'+userId+' .username').html(); |
---|
312 | |
---|
313 | jQuery('#user'+userId+' .changeUsernameOpen').hide(); |
---|
314 | jQuery('#user'+userId+' .changeUsername').show(); |
---|
315 | jQuery('#user'+userId+' .changeUsername input[type=text]').val(username).focus(); |
---|
316 | |
---|
317 | return false; |
---|
318 | }); |
---|
319 | |
---|
320 | jQuery(document).on('click', 'a.updateUsername', function() { |
---|
321 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
322 | |
---|
323 | jQuery('#user'+userId+' .changeUsername a .text').hide(); |
---|
324 | jQuery('#user'+userId+' .changeUsername a img').show(); |
---|
325 | |
---|
326 | jQuery.ajax({ |
---|
327 | url: "ws.php?format=json&method=pwg.users.setInfo", |
---|
328 | type:"POST", |
---|
329 | data: { |
---|
330 | user_id:userId, |
---|
331 | username: jQuery('#user'+userId+' .changeUsername input[type=text]').val() |
---|
332 | }, |
---|
333 | success:function(data) { |
---|
334 | jQuery('#user'+userId+' .changeUsername a .text').show(); |
---|
335 | jQuery('#user'+userId+' .changeUsername a img').hide(); |
---|
336 | jQuery('#user'+userId+' .changeUsername').hide(); |
---|
337 | jQuery('#user'+userId+' .changeUsernameOpen').show(); |
---|
338 | |
---|
339 | var data = jQuery.parseJSON(data); |
---|
340 | jQuery('#user'+userId+' .username').html(data.result.users[0].username); |
---|
341 | }, |
---|
342 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
343 | } |
---|
344 | }); |
---|
345 | |
---|
346 | return false; |
---|
347 | }); |
---|
348 | |
---|
349 | jQuery(document).on('click', '.changeUsername a.cancel', function() { |
---|
350 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
351 | |
---|
352 | jQuery('#user'+userId+' .changeUsername').hide(); |
---|
353 | jQuery('#user'+userId+' .changeUsernameOpen').show(); |
---|
354 | |
---|
355 | return false; |
---|
356 | }); |
---|
357 | |
---|
358 | /* display the "save" button when a field changes */ |
---|
359 | jQuery(document).on('change', '.userProperties input, .userProperties select', function() { |
---|
360 | var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); |
---|
361 | |
---|
362 | jQuery('#user'+userId+' input[type=submit]').show(); |
---|
363 | jQuery('#user'+userId+' .propertiesUpdateDone').hide(); |
---|
364 | }); |
---|
365 | |
---|
366 | /* delete user */ |
---|
367 | jQuery(document).on('click', '.userDelete a', function() { |
---|
368 | if (!confirm("{/literal}{'Are you sure?'|translate|escape:javascript}{literal}")) { |
---|
369 | return false; |
---|
370 | } |
---|
371 | |
---|
372 | var userId = jQuery(this).data('user_id'); |
---|
373 | var username = jQuery('#user'+userId+' .username').html(); |
---|
374 | |
---|
375 | jQuery.ajax({ |
---|
376 | url: "ws.php?format=json&method=pwg.users.delete", |
---|
377 | type:"POST", |
---|
378 | data: { |
---|
379 | user_id:userId, |
---|
380 | pwg_token:pwg_token |
---|
381 | }, |
---|
382 | beforeSend: function() { |
---|
383 | jQuery('#user'+userId+' .userDelete .loading').show(); |
---|
384 | }, |
---|
385 | success:function(data) { |
---|
386 | oTable.fnDraw(); |
---|
387 | jQuery('#showAddUser .infos').html('✔ User '+username+' deleted').show(); |
---|
388 | }, |
---|
389 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
390 | jQuery('#user'+userId+' .userDelete .loading').hide(); |
---|
391 | } |
---|
392 | }); |
---|
393 | |
---|
394 | return false; |
---|
395 | }); |
---|
396 | |
---|
397 | jQuery(document).on('click', '.userProperties input[type=submit]', function() { |
---|
398 | var userId = jQuery(this).data('user_id'); |
---|
399 | |
---|
400 | var formData = jQuery('#user'+userId+' form').serialize(); |
---|
401 | |
---|
402 | if (jQuery('#user'+userId+' form select[name="group_id[]"] option:selected').length == 0) { |
---|
403 | formData += '&group_id=-1'; |
---|
404 | } |
---|
405 | |
---|
406 | if (!jQuery('#user'+userId+' form input[name=enabled_high]').is(':checked')) { |
---|
407 | formData += '&enabled_high=false'; |
---|
408 | } |
---|
409 | |
---|
410 | if (!jQuery('#user'+userId+' form input[name=expand]').is(':checked')) { |
---|
411 | formData += '&expand=false'; |
---|
412 | } |
---|
413 | |
---|
414 | if (!jQuery('#user'+userId+' form input[name=show_nb_hits]').is(':checked')) { |
---|
415 | formData += '&show_nb_hits=false'; |
---|
416 | } |
---|
417 | |
---|
418 | if (!jQuery('#user'+userId+' form input[name=show_nb_comments]').is(':checked')) { |
---|
419 | formData += '&show_nb_comments=false'; |
---|
420 | } |
---|
421 | |
---|
422 | jQuery.ajax({ |
---|
423 | url: "ws.php?format=json&method=pwg.users.setInfo", |
---|
424 | type:"POST", |
---|
425 | data: formData, |
---|
426 | beforeSend: function() { |
---|
427 | jQuery('#user'+userId+' .submitWait').show(); |
---|
428 | }, |
---|
429 | success:function(data) { |
---|
430 | jQuery('#user'+userId+' .submitWait').hide(); |
---|
431 | jQuery('#user'+userId+' input[type=submit]').hide(); |
---|
432 | jQuery('#user'+userId+' .propertiesUpdateDone').show(); |
---|
433 | }, |
---|
434 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
435 | jQuery('#user'+userId+' .submitWait').hide(); |
---|
436 | } |
---|
437 | }); |
---|
438 | |
---|
439 | return false; |
---|
440 | }); |
---|
441 | |
---|
442 | /* Add event listener for opening and closing details |
---|
443 | * Note that the indicator for showing which row is open is not controlled by DataTables, |
---|
444 | * rather it is done here |
---|
445 | */ |
---|
446 | jQuery(document).on('click', '#userList tbody td .openUserDetails', function() { |
---|
447 | var nTr = this.parentNode.parentNode; |
---|
448 | if (jQuery(this).hasClass('icon-angle-circled-up')) { |
---|
449 | /* This row is already open - close it */ |
---|
450 | jQuery(this).removeClass('icon-angle-circled-up').addClass('icon-angle-circled-down').attr('title', 'Open user details'); |
---|
451 | oTable.fnClose( nTr ); |
---|
452 | } |
---|
453 | else { |
---|
454 | /* Open this row */ |
---|
455 | jQuery(this).removeClass('icon-angle-circled-down').addClass('icon-angle-circled-up').attr('title', 'Close user details'); |
---|
456 | oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' ); |
---|
457 | } |
---|
458 | }); |
---|
459 | |
---|
460 | |
---|
461 | /* first column must be prefixed with the open/close icon */ |
---|
462 | var aoColumns = [ |
---|
463 | { |
---|
464 | 'bVisible':false |
---|
465 | }, |
---|
466 | { |
---|
467 | "mRender": function(data, type, full) { |
---|
468 | return '<span title="Open user details" class="icon-angle-circled-down openUserDetails"></span> <label><input type="checkbox" data-user_id="'+full[0]+'"> '+data+'</label>'; |
---|
469 | } |
---|
470 | } |
---|
471 | ]; |
---|
472 | |
---|
473 | for (i=2; i<jQuery("#userList thead tr th").length; i++) { |
---|
474 | aoColumns.push(null); |
---|
475 | } |
---|
476 | |
---|
477 | var oTable = jQuery('#userList').dataTable({ |
---|
478 | "iDisplayLength": 10, |
---|
479 | "bDeferRender": true, |
---|
480 | "bProcessing": true, |
---|
481 | "bServerSide": true, |
---|
482 | "sAjaxSource": "admin/user_list_backend.php", |
---|
483 | "oLanguage": { |
---|
484 | "sProcessing": "Traitement en cours...", |
---|
485 | "sLengthMenu": "Afficher _MENU_ éléments", |
---|
486 | "sZeroRecords": "Aucun élément à afficher", |
---|
487 | "sInfo": "Affichage des élements _START_ à _END_ sur _TOTAL_", |
---|
488 | "sInfoEmpty": "Affichage de l'élement 0 à 0 sur 0 éléments", |
---|
489 | "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})", |
---|
490 | "sInfoPostFix": "", |
---|
491 | "sSearch": "Rechercher", |
---|
492 | "sLoadingRecords": "Téléchargement...", |
---|
493 | "sUrl": "", |
---|
494 | "oPaginate": { |
---|
495 | "sFirst": "Premier", |
---|
496 | "sPrevious": "← Précédent", |
---|
497 | "sNext": "Suivant →", |
---|
498 | "sLast": "Dernier" |
---|
499 | } |
---|
500 | }, |
---|
501 | "fnDrawCallback": function( oSettings ) { |
---|
502 | jQuery("#userList input[type=checkbox]").each(function() { |
---|
503 | var user_id = jQuery(this).data("user_id"); |
---|
504 | jQuery(this).prop('checked', (selection.indexOf(user_id) != -1)); |
---|
505 | }); |
---|
506 | }, |
---|
507 | "aoColumns": aoColumns |
---|
508 | }); |
---|
509 | |
---|
510 | /** |
---|
511 | * Selection management |
---|
512 | */ |
---|
513 | function checkSelection() { |
---|
514 | if (selection.length > 0) { |
---|
515 | jQuery("#forbidAction").hide(); |
---|
516 | jQuery("#permitAction").show(); |
---|
517 | |
---|
518 | jQuery("#applyOnDetails").text( |
---|
519 | sprintf( |
---|
520 | applyOnDetails_pattern, |
---|
521 | selection.length |
---|
522 | ) |
---|
523 | ); |
---|
524 | |
---|
525 | if (selection.length == allUsers.length) { |
---|
526 | jQuery("#selectedMessage").text( |
---|
527 | sprintf( |
---|
528 | selectedMessage_all, |
---|
529 | allUsers.length |
---|
530 | ) |
---|
531 | ); |
---|
532 | } |
---|
533 | else { |
---|
534 | jQuery("#selectedMessage").text( |
---|
535 | sprintf( |
---|
536 | selectedMessage_pattern, |
---|
537 | selection.length, |
---|
538 | allUsers.length |
---|
539 | ) |
---|
540 | ); |
---|
541 | } |
---|
542 | } |
---|
543 | else { |
---|
544 | jQuery("#forbidAction").show(); |
---|
545 | jQuery("#permitAction").hide(); |
---|
546 | |
---|
547 | jQuery("#selectedMessage").text( |
---|
548 | sprintf( |
---|
549 | selectedMessage_none, |
---|
550 | allUsers.length |
---|
551 | ) |
---|
552 | ); |
---|
553 | } |
---|
554 | |
---|
555 | jQuery("#applyActionBlock .infos").hide(); |
---|
556 | } |
---|
557 | |
---|
558 | jQuery(document).on('change', '#userList input[type=checkbox]', function() { |
---|
559 | var user_id = jQuery(this).data("user_id"); |
---|
560 | |
---|
561 | array_delete(selection, user_id); |
---|
562 | |
---|
563 | if (jQuery(this).is(":checked")) { |
---|
564 | selection.push(user_id); |
---|
565 | } |
---|
566 | |
---|
567 | checkSelection(); |
---|
568 | }); |
---|
569 | |
---|
570 | jQuery("#selectAll").click(function () { |
---|
571 | selection = allUsers; |
---|
572 | jQuery("#userList input[type=checkbox]").prop('checked', true); |
---|
573 | checkSelection(); |
---|
574 | return false; |
---|
575 | }); |
---|
576 | |
---|
577 | jQuery("#selectNone").click(function () { |
---|
578 | selection = []; |
---|
579 | jQuery("#userList input[type=checkbox]").prop('checked', false); |
---|
580 | checkSelection(); |
---|
581 | return false; |
---|
582 | }); |
---|
583 | |
---|
584 | jQuery("#selectInvert").click(function () { |
---|
585 | var newSelection = []; |
---|
586 | for(var i in allUsers) |
---|
587 | { |
---|
588 | if (selection.indexOf(allUsers[i]) == -1) { |
---|
589 | newSelection.push(allUsers[i]); |
---|
590 | } |
---|
591 | } |
---|
592 | selection = newSelection; |
---|
593 | |
---|
594 | jQuery("#userList input[type=checkbox]").each(function() { |
---|
595 | var user_id = jQuery(this).data("user_id"); |
---|
596 | jQuery(this).prop('checked', (selection.indexOf(user_id) != -1)); |
---|
597 | }); |
---|
598 | |
---|
599 | checkSelection(); |
---|
600 | return false; |
---|
601 | }); |
---|
602 | |
---|
603 | /** |
---|
604 | * Action management |
---|
605 | */ |
---|
606 | jQuery("[id^=action_]").hide(); |
---|
607 | |
---|
608 | jQuery("select[name=selectAction]").change(function () { |
---|
609 | jQuery("#applyActionBlock .infos").hide(); |
---|
610 | |
---|
611 | jQuery("[id^=action_]").hide(); |
---|
612 | |
---|
613 | jQuery("#action_"+$(this).prop("value")).show(); |
---|
614 | |
---|
615 | if (jQuery(this).val() != -1) { |
---|
616 | jQuery("#applyActionBlock").show(); |
---|
617 | } |
---|
618 | else { |
---|
619 | jQuery("#applyActionBlock").hide(); |
---|
620 | } |
---|
621 | }); |
---|
622 | |
---|
623 | jQuery("#permitAction input, #permitAction select").click(function() { |
---|
624 | jQuery("#applyActionBlock .infos").hide(); |
---|
625 | }); |
---|
626 | |
---|
627 | jQuery("#applyAction").click(function() { |
---|
628 | var action = jQuery("select[name=selectAction]").prop("value"); |
---|
629 | var method = 'pwg.users.setInfo'; |
---|
630 | var data = { |
---|
631 | user_id: selection |
---|
632 | }; |
---|
633 | |
---|
634 | switch (action) { |
---|
635 | case 'delete': |
---|
636 | if (!jQuery("input[name=confirm_deletion]").is(':checked')) { |
---|
637 | alert(missingConfirm); |
---|
638 | return false; |
---|
639 | } |
---|
640 | method = 'pwg.users.delete'; |
---|
641 | data.pwg_token = pwg_token; |
---|
642 | break; |
---|
643 | case 'group_associate': |
---|
644 | method = 'pwg.groups.addUser'; |
---|
645 | data.group_id = jQuery("select[name=associate]").prop("value"); |
---|
646 | break; |
---|
647 | case 'group_dissociate': |
---|
648 | method = 'pwg.groups.deleteUser'; |
---|
649 | data.group_id = jQuery("select[name=dissociate]").prop("value"); |
---|
650 | break; |
---|
651 | case 'status': |
---|
652 | data.status = jQuery("select[name=status]").prop("value"); |
---|
653 | break; |
---|
654 | case 'enabled_high': |
---|
655 | data.enabled_high = jQuery("input[name=enabled_high]:checked").val(); |
---|
656 | break; |
---|
657 | case 'level': |
---|
658 | data.level = jQuery("select[name=level]").val(); |
---|
659 | break; |
---|
660 | case 'nb_image_page': |
---|
661 | data.nb_image_page = jQuery("input[name=nb_image_page]").val(); |
---|
662 | break; |
---|
663 | case 'theme': |
---|
664 | data.theme = jQuery("select[name=theme]").val(); |
---|
665 | break; |
---|
666 | case 'language': |
---|
667 | data.language = jQuery("select[name=language]").val(); |
---|
668 | break; |
---|
669 | case 'recent_period': |
---|
670 | data.recent_period = jQuery("input[name=recent_period]").val(); |
---|
671 | break; |
---|
672 | case 'expand': |
---|
673 | data.expand = jQuery("input[name=expand]:checked").val(); |
---|
674 | break; |
---|
675 | case 'show_nb_comments': |
---|
676 | data.show_nb_comments = jQuery("input[name=show_nb_comments]:checked").val(); |
---|
677 | break; |
---|
678 | case 'show_nb_hits': |
---|
679 | data.show_nb_hits = jQuery("input[name=show_nb_hits]:checked").val(); |
---|
680 | break; |
---|
681 | default: |
---|
682 | alert("Unexpected action"); |
---|
683 | return false; |
---|
684 | } |
---|
685 | |
---|
686 | jQuery.ajax({ |
---|
687 | url: "ws.php?format=json&method="+method, |
---|
688 | type:"POST", |
---|
689 | data: data, |
---|
690 | beforeSend: function() { |
---|
691 | jQuery("#applyActionLoading").show(); |
---|
692 | }, |
---|
693 | success:function(data) { |
---|
694 | oTable.fnDraw(); |
---|
695 | jQuery("#applyActionLoading").hide(); |
---|
696 | jQuery("#applyActionBlock .infos").show(); |
---|
697 | |
---|
698 | if (action == 'delete') { |
---|
699 | var allUsers_new = []; |
---|
700 | for(var i in allUsers) |
---|
701 | { |
---|
702 | if (selection.indexOf(allUsers[i]) == -1) { |
---|
703 | allUsers_new.push(allUsers[i]); |
---|
704 | } |
---|
705 | } |
---|
706 | allUsers = allUsers_new; |
---|
707 | console.log('allUsers_new.length = '+allUsers_new.length); |
---|
708 | selection = []; |
---|
709 | checkSelection(); |
---|
710 | } |
---|
711 | }, |
---|
712 | error:function(XMLHttpRequest, textStatus, errorThrows) { |
---|
713 | jQuery("#applyActionLoading").hide(); |
---|
714 | } |
---|
715 | }); |
---|
716 | |
---|
717 | return false; |
---|
718 | }); |
---|
719 | |
---|
720 | }); |
---|
721 | {/literal}{/footer_script} |
---|
722 | |
---|
723 | {literal} |
---|
724 | <style> |
---|
725 | .dataTables_wrapper, .dataTables_info {clear:none;} |
---|
726 | table.dataTable {clear:right;padding-top:10px;} |
---|
727 | .dataTable td img {margin-bottom: -6px;margin-left: -6px;} |
---|
728 | .paginate_enabled_previous, .paginate_enabled_previous:hover, .paginate_disabled_previous, .paginate_enabled_next, .paginate_enabled_next:hover, .paginate_disabled_next {background:none;} |
---|
729 | .paginate_enabled_previous, .paginate_enabled_next {color:#005E89 !important;} |
---|
730 | .paginate_enabled_previous:hover, .paginate_enabled_next:hover {color:#D54E21 !important; text-decoration:underline !important;} |
---|
731 | |
---|
732 | .paginate_disabled_next, .paginate_enabled_next {padding-right:3px;} |
---|
733 | .bulkAction {margin-top:10px;} |
---|
734 | #addUserForm p {margin-left:0;} |
---|
735 | #applyActionBlock .actionButtons {margin-left:0;} |
---|
736 | span.infos, span.errors {background-image:none; padding:2px 5px; margin:0;border-radius:5px;} |
---|
737 | |
---|
738 | .userStats {margin-top:10px;} |
---|
739 | </style> |
---|
740 | {/literal} |
---|
741 | |
---|
742 | <div class="titrePage"> |
---|
743 | <h2>{'User list'|@translate}</h2> |
---|
744 | </div> |
---|
745 | |
---|
746 | <p class="showCreateAlbum" id="showAddUser"> |
---|
747 | <a href="#" id="addUser" class="icon-plus-circled">{'Add a user'|translate}</a> |
---|
748 | <span class="infos" style="display:none"></span> |
---|
749 | </p> |
---|
750 | |
---|
751 | <form id="addUserForm" style="display:none" method="post" name="add_user" action="{$F_ADD_ACTION}"> |
---|
752 | <fieldset> |
---|
753 | <legend>{'Add a user'|@translate}</legend> |
---|
754 | |
---|
755 | <p> |
---|
756 | <strong>{'Username'|translate}</strong><br> |
---|
757 | <input type="text" name="username" maxlength="50" size="20"> |
---|
758 | </p> |
---|
759 | |
---|
760 | <p> |
---|
761 | <strong>{'Password'|translate}</strong><br> |
---|
762 | <input type="{if $Double_Password}password{else}text{/if}" name="password"> |
---|
763 | </p> |
---|
764 | |
---|
765 | {if $Double_Password} |
---|
766 | <p> |
---|
767 | <strong>{'Confirm Password'|@translate}</strong><br> |
---|
768 | <input type="password" name="password_confirm"> |
---|
769 | </p> |
---|
770 | {/if} |
---|
771 | |
---|
772 | <p> |
---|
773 | <strong>{'Email address'|@translate}</strong><br> |
---|
774 | <input type="text" name="email"> |
---|
775 | </p> |
---|
776 | |
---|
777 | <p> |
---|
778 | <label><input type="checkbox" name="send_password_by_mail"> <strong>{'Send connection settings by email'|@translate}</strong></label> |
---|
779 | </p> |
---|
780 | |
---|
781 | <p class="actionButtons"> |
---|
782 | <input class="submit" name="submit_add" type="submit" value="{'Submit'|@translate}"> |
---|
783 | <a href="#" id="addUserClose">{'Cancel'|@translate}</a> |
---|
784 | <span class="loading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span> |
---|
785 | <span class="errors" style="display:none"></span> |
---|
786 | </p> |
---|
787 | </fieldset> |
---|
788 | </form> |
---|
789 | |
---|
790 | <form method="post" name="preferences" action=""> |
---|
791 | |
---|
792 | <table id="userList"> |
---|
793 | <thead> |
---|
794 | <tr> |
---|
795 | <th>id</th> |
---|
796 | <th>{'Username'|@translate}</th> |
---|
797 | <th>{'Status'|@translate}</th> |
---|
798 | <th>{'Email address'|@translate}</th> |
---|
799 | <th>{'registration date'|@translate}</th> |
---|
800 | </tr> |
---|
801 | </thead> |
---|
802 | </table> |
---|
803 | |
---|
804 | <div style="clear:right"></div> |
---|
805 | |
---|
806 | <p class="checkActions"> |
---|
807 | {'Select:'|@translate} |
---|
808 | <a href="#" id="selectAll">{'All'|@translate}</a>, |
---|
809 | <a href="#" id="selectNone">{'None'|@translate}</a>, |
---|
810 | <a href="#" id="selectInvert">{'Invert'|@translate}</a> |
---|
811 | |
---|
812 | <span id="selectedMessage"></span> |
---|
813 | </p> |
---|
814 | |
---|
815 | <fieldset id="action"> |
---|
816 | <legend>{'Action'|@translate}</legend> |
---|
817 | |
---|
818 | <div id="forbidAction"{if count($selection) != 0} style="display:none"{/if}>{'No user selected, no action possible.'|@translate}</div> |
---|
819 | <div id="permitAction"{if count($selection) == 0} style="display:none"{/if}> |
---|
820 | |
---|
821 | <select name="selectAction"> |
---|
822 | <option value="-1">{'Choose an action'|@translate}</option> |
---|
823 | <option disabled="disabled">------------------</option> |
---|
824 | <option value="delete" class="icon-trash">{'Delete selected users'|@translate}</option> |
---|
825 | <option value="status">{'Status'|@translate}</option> |
---|
826 | <option value="group_associate">{'associate to group'|translate}</option> |
---|
827 | <option value="group_dissociate">{'dissociate from group'|@translate}</option> |
---|
828 | <option value="enabled_high">{'High definition enabled'|@translate}</option> |
---|
829 | <option value="level">{'Privacy level'|@translate}</option> |
---|
830 | <option value="nb_image_page">{'Number of photos per page'|@translate}</option> |
---|
831 | <option value="theme">{'Interface theme'|@translate}</option> |
---|
832 | <option value="language">{'Language'|@translate}</option> |
---|
833 | <option value="recent_period">{'Recent period'|@translate}</option> |
---|
834 | <option value="expand">{'Expand all albums'|@translate}</option> |
---|
835 | {if $ACTIVATE_COMMENTS} |
---|
836 | <option value="show_nb_comments">{'Show number of comments'|@translate}</option> |
---|
837 | {/if} |
---|
838 | <option value="show_nb_hits">{'Show number of hits'|@translate}</option> |
---|
839 | </select> |
---|
840 | |
---|
841 | {* delete *} |
---|
842 | <div id="action_delete" class="bulkAction"> |
---|
843 | <p><label><input type="checkbox" name="confirm_deletion" value="1"> {'Are you sure?'|@translate}</label></p> |
---|
844 | </div> |
---|
845 | |
---|
846 | {* status *} |
---|
847 | <div id="action_status" class="bulkAction"> |
---|
848 | <select name="status"> |
---|
849 | {html_options options=$pref_status_options selected=$pref_status_selected} |
---|
850 | </select> |
---|
851 | </div> |
---|
852 | |
---|
853 | {* group_associate *} |
---|
854 | <div id="action_group_associate" class="bulkAction"> |
---|
855 | {html_options name=associate options=$association_options selected=$associate_selected} |
---|
856 | </div> |
---|
857 | |
---|
858 | {* group_dissociate *} |
---|
859 | <div id="action_group_dissociate" class="bulkAction"> |
---|
860 | {html_options name=dissociate options=$association_options selected=$dissociate_selected} |
---|
861 | </div> |
---|
862 | |
---|
863 | {* enabled_high *} |
---|
864 | <div id="action_enabled_high" class="bulkAction"> |
---|
865 | <label><input type="radio" name="enabled_high" value="true">{'Yes'|@translate}</label> |
---|
866 | <label><input type="radio" name="enabled_high" value="false" checked="checked">{'No'|@translate}</label> |
---|
867 | </div> |
---|
868 | |
---|
869 | {* level *} |
---|
870 | <div id="action_level" class="bulkAction"> |
---|
871 | <select name="level" size="1"> |
---|
872 | {html_options options=$level_options selected=$level_selected} |
---|
873 | </select> |
---|
874 | </div> |
---|
875 | |
---|
876 | {* nb_image_page *} |
---|
877 | <div id="action_nb_image_page" class="bulkAction"> |
---|
878 | <input size="4" maxlength="3" type="text" name="nb_image_page" value="{$NB_IMAGE_PAGE}"> |
---|
879 | </div> |
---|
880 | |
---|
881 | {* theme *} |
---|
882 | <div id="action_theme" class="bulkAction"> |
---|
883 | <select name="theme" size="1"> |
---|
884 | {html_options options=$theme_options selected=$theme_selected} |
---|
885 | </select> |
---|
886 | </div> |
---|
887 | |
---|
888 | {* language *} |
---|
889 | <div id="action_language" class="bulkAction"> |
---|
890 | <select name="language" size="1"> |
---|
891 | {html_options options=$language_options selected=$language_selected} |
---|
892 | </select> |
---|
893 | </div> |
---|
894 | |
---|
895 | {* recent_period *} |
---|
896 | <div id="action_recent_period" class="bulkAction"> |
---|
897 | <input type="text" size="3" maxlength="2" name="recent_period" value="{$RECENT_PERIOD}"> |
---|
898 | </div> |
---|
899 | |
---|
900 | {* expand *} |
---|
901 | <div id="action_expand" class="bulkAction"> |
---|
902 | <label><input type="radio" name="expand" value="true">{'Yes'|@translate}</label> |
---|
903 | <label><input type="radio" name="expand" value="false" checked="checked">{'No'|@translate}</label> |
---|
904 | </div> |
---|
905 | |
---|
906 | {* show_nb_comments *} |
---|
907 | <div id="action_show_nb_comments" class="bulkAction"> |
---|
908 | <label><input type="radio" name="show_nb_comments" value="true">{'Yes'|@translate}</label> |
---|
909 | <label><input type="radio" name="show_nb_comments" value="false" checked="checked">{'No'|@translate}</label> |
---|
910 | </div> |
---|
911 | |
---|
912 | {* show_nb_hits *} |
---|
913 | <div id="action_show_nb_hits" class="bulkAction"> |
---|
914 | <label><input type="radio" name="show_nb_hits" value="true">{'Yes'|@translate}</label> |
---|
915 | <label><input type="radio" name="show_nb_hits" value="false" checked="checked">{'No'|@translate}</label> |
---|
916 | </div> |
---|
917 | |
---|
918 | <p id="applyActionBlock" style="display:none" class="actionButtons"> |
---|
919 | <input id="applyAction" class="submit" type="submit" value="{'Apply action'|@translate}" name="submit"> <span id="applyOnDetails"></span> |
---|
920 | <span id="applyActionLoading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span> |
---|
921 | <span class="infos" style="display:none">✔ Users modified</span> |
---|
922 | </p> |
---|
923 | |
---|
924 | </div> {* #permitAction *} |
---|
925 | </fieldset> |
---|
926 | |
---|
927 | </form> |
---|