[25194] | 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 | |
---|
[25475] | 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 | |
---|
[25194] | 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}"; |
---|
[25237] | 14 | var newUser_pattern = "✔ {'User %s added'|translate}"; |
---|
[25475] | 15 | var registeredOn_pattern = "{'Registered on %s, %s.'|translate}"; |
---|
| 16 | var lastVisit_pattern = "{'Last visit on %s, %s.'|translate}"; |
---|
[25194] | 17 | var missingConfirm = "{'You need to confirm deletion'|translate}"; |
---|
[25237] | 18 | var missingUsername = "{'Please, enter a login'|translate}"; |
---|
[25194] | 19 | |
---|
| 20 | var allUsers = [{$all_users}]; |
---|
| 21 | var selection = [{$selection}]; |
---|
[25282] | 22 | var pwg_token = "{$PWG_TOKEN}"; |
---|
[25405] | 23 | |
---|
| 24 | var truefalse = { |
---|
| 25 | true:"{'Yes'|translate}", |
---|
| 26 | false:"{'No'|translate}", |
---|
| 27 | }; |
---|
[25194] | 28 | {/footer_script} |
---|
| 29 | |
---|
| 30 | {footer_script}{literal} |
---|
| 31 | jQuery(document).ready(function() { |
---|
[25237] | 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 | */ |
---|
[25405] | 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; |
---|
[25237] | 97 | |
---|
[25405] | 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 | |
---|
[25445] | 112 | var userDetails = '<form>'; |
---|
[25475] | 113 | userDetails += '<div class="userActions">'; |
---|
| 114 | userDetails += '<a class="icon-key" href="#">Change password</a>'; |
---|
[25479] | 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>'; |
---|
[25475] | 117 | userDetails += '</div>'; |
---|
[25479] | 118 | userDetails += '<strong class="username">'+user.username+'</strong> <span class="icon-pencil"></span>'; |
---|
[25475] | 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">'; |
---|
[25445] | 127 | userDetails += '<input type="hidden" name="user_id" value="'+user.id+'">'; |
---|
[25475] | 128 | userDetails += '<div class="userPropertiesSet">'; |
---|
| 129 | userDetails += '<div class="userPropertiesSetTitle">{/literal}{'Properties'|translate}{literal}</div>'; |
---|
[25405] | 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 | |
---|
[25475] | 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() { |
---|
[25405] | 148 | var selected = ''; |
---|
[25475] | 149 | if (user.level == jQuery(this).val()) { |
---|
[25405] | 150 | selected = ' selected="selected"'; |
---|
| 151 | } |
---|
| 152 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
| 153 | }); |
---|
| 154 | userDetails += '</select></div>'; |
---|
| 155 | |
---|
[25475] | 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() { |
---|
[25405] | 166 | var selected = ''; |
---|
[25475] | 167 | if (user.groups.indexOf(jQuery(this).val()) != -1) { |
---|
[25405] | 168 | selected = ' selected="selected"'; |
---|
| 169 | } |
---|
| 170 | userDetails += '<option value="'+jQuery(this).val()+'"'+selected+'>'+jQuery(this).html()+'</option>'; |
---|
| 171 | }); |
---|
| 172 | userDetails += '</select></div>'; |
---|
[25475] | 173 | // userDetails += '<br>'+user.groups.join(",")+'</div>'; |
---|
[25405] | 174 | |
---|
[25475] | 175 | userDetails += '</div><div class="userPropertiesSet userPrefs">'; |
---|
| 176 | userDetails += '<div class="userPropertiesSetTitle">{/literal}{'Preferences'|translate}{literal}</div>'; |
---|
[25405] | 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 | |
---|
[25475] | 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>'; |
---|
[25405] | 211 | userDetails += '</div>'; |
---|
| 212 | |
---|
[25475] | 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>'; |
---|
[25405] | 218 | userDetails += '</div>'; |
---|
| 219 | |
---|
[25475] | 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>'; |
---|
[25405] | 225 | userDetails += '</div>'; |
---|
[25475] | 226 | userDetails += '</div>'; |
---|
| 227 | userDetails += '<div style="clear:both"></div></div>'; |
---|
[25405] | 228 | |
---|
[25479] | 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+'">'; |
---|
[25405] | 231 | userDetails += '<img class="submitWait" src="themes/default/images/ajax-loader-small.gif" style="display:none">' |
---|
[25445] | 232 | userDetails += '</form>'; |
---|
[25405] | 233 | |
---|
| 234 | jQuery("#user"+userId).append(userDetails); |
---|
[25475] | 235 | jQuery(".chzn-select").chosen(); |
---|
[25405] | 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 | |
---|
[25475] | 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 | |
---|
[25479] | 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 | |
---|
[25405] | 286 | jQuery(document).on('click', '.userProperties input[type=submit]', function() { |
---|
| 287 | var userId = jQuery(this).data('user_id'); |
---|
| 288 | |
---|
[25475] | 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 | |
---|
[25405] | 311 | jQuery.ajax({ |
---|
| 312 | url: "ws.php?format=json&method=pwg.users.setInfo", |
---|
| 313 | type:"POST", |
---|
[25475] | 314 | data: formData, |
---|
[25405] | 315 | beforeSend: function() { |
---|
| 316 | jQuery('#user'+userId+' .submitWait').show(); |
---|
| 317 | }, |
---|
| 318 | success:function(data) { |
---|
| 319 | jQuery('#user'+userId+' .submitWait').hide(); |
---|
[25475] | 320 | jQuery('#user'+userId+' input[type=submit]').hide(); |
---|
| 321 | jQuery('#user'+userId+' .infos').show(); |
---|
[25405] | 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 | */ |
---|
[25457] | 335 | jQuery(document).on('click', '#userList tbody td .openUserDetails', function() { |
---|
[25405] | 336 | var nTr = this.parentNode.parentNode; |
---|
[25457] | 337 | if (jQuery(this).hasClass('icon-angle-circled-up')) { |
---|
[25405] | 338 | /* This row is already open - close it */ |
---|
[25457] | 339 | jQuery(this).removeClass('icon-angle-circled-up').addClass('icon-angle-circled-down').attr('title', 'Open user details'); |
---|
[25405] | 340 | oTable.fnClose( nTr ); |
---|
| 341 | } |
---|
| 342 | else { |
---|
| 343 | /* Open this row */ |
---|
[25457] | 344 | jQuery(this).removeClass('icon-angle-circled-down').addClass('icon-angle-circled-up').attr('title', 'Close user details'); |
---|
[25405] | 345 | oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' ); |
---|
| 346 | } |
---|
| 347 | }); |
---|
| 348 | |
---|
| 349 | |
---|
[25194] | 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) { |
---|
[25457] | 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>'; |
---|
[25194] | 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", |
---|
[25475] | 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 | }, |
---|
[25194] | 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"); |
---|
[25198] | 518 | var method = 'pwg.users.setInfo'; |
---|
[25194] | 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'; |
---|
[25282] | 530 | data.pwg_token = pwg_token; |
---|
[25194] | 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; |
---|
[25198] | 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; |
---|
[25194] | 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;} |
---|
[25405] | 616 | .dataTable td img {margin-bottom: -6px;margin-left: -6px;} |
---|
[25475] | 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;} |
---|
[25194] | 622 | .bulkAction {margin-top:10px;} |
---|
[25237] | 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;} |
---|
[25194] | 626 | </style> |
---|
| 627 | {/literal} |
---|
| 628 | |
---|
[2531] | 629 | <div class="titrePage"> |
---|
[5021] | 630 | <h2>{'User list'|@translate}</h2> |
---|
[2531] | 631 | </div> |
---|
| 632 | |
---|
[25237] | 633 | <p class="showCreateAlbum" id="showAddUser"> |
---|
[25457] | 634 | <a href="#" id="addUser" class="icon-plus-circled">{'Add a user'|translate}</a> |
---|
[25237] | 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}"> |
---|
[2531] | 639 | <fieldset> |
---|
| 640 | <legend>{'Add a user'|@translate}</legend> |
---|
[25237] | 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> |
---|
[2531] | 674 | </fieldset> |
---|
| 675 | </form> |
---|
| 676 | |
---|
| 677 | <form method="post" name="preferences" action=""> |
---|
| 678 | |
---|
[25194] | 679 | <table id="userList"> |
---|
[2531] | 680 | <thead> |
---|
[25194] | 681 | <tr> |
---|
| 682 | <th>id</th> |
---|
| 683 | <th>{'Username'|@translate}</th> |
---|
| 684 | <th>{'Status'|@translate}</th> |
---|
| 685 | <th>{'Email address'|@translate}</th> |
---|
[25475] | 686 | <th>{'registration date'|@translate}</th> |
---|
[2531] | 687 | </tr> |
---|
| 688 | </thead> |
---|
| 689 | </table> |
---|
| 690 | |
---|
[25194] | 691 | <div style="clear:right"></div> |
---|
[2531] | 692 | |
---|
[25194] | 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> |
---|
[2531] | 698 | |
---|
[25194] | 699 | <span id="selectedMessage"></span> |
---|
| 700 | </p> |
---|
[2531] | 701 | |
---|
[25194] | 702 | <fieldset id="action"> |
---|
| 703 | <legend>{'Action'|@translate}</legend> |
---|
[2531] | 704 | |
---|
[25194] | 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}> |
---|
[2531] | 707 | |
---|
[25194] | 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> |
---|
[2531] | 727 | |
---|
[25194] | 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"> |
---|
[2531] | 742 | {html_options name=associate options=$association_options selected=$associate_selected} |
---|
[25194] | 743 | </div> |
---|
[2531] | 744 | |
---|
[25194] | 745 | {* group_dissociate *} |
---|
| 746 | <div id="action_group_dissociate" class="bulkAction"> |
---|
[2531] | 747 | {html_options name=dissociate options=$association_options selected=$dissociate_selected} |
---|
[25194] | 748 | </div> |
---|
[2531] | 749 | |
---|
[25194] | 750 | {* enabled_high *} |
---|
| 751 | <div id="action_enabled_high" class="bulkAction"> |
---|
| 752 | <label><input type="radio" name="enabled_high" value="true">{'Yes'|@translate}</label> |
---|
[25198] | 753 | <label><input type="radio" name="enabled_high" value="false" checked="checked">{'No'|@translate}</label> |
---|
[25194] | 754 | </div> |
---|
[2531] | 755 | |
---|
[25194] | 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> |
---|
[2531] | 762 | |
---|
[25194] | 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> |
---|
[2531] | 767 | |
---|
[25194] | 768 | {* theme *} |
---|
| 769 | <div id="action_theme" class="bulkAction"> |
---|
| 770 | <select name="theme" size="1"> |
---|
[5974] | 771 | {html_options options=$theme_options selected=$theme_selected} |
---|
[2531] | 772 | </select> |
---|
[25194] | 773 | </div> |
---|
[2531] | 774 | |
---|
[25194] | 775 | {* language *} |
---|
| 776 | <div id="action_language" class="bulkAction"> |
---|
| 777 | <select name="language" size="1"> |
---|
[2531] | 778 | {html_options options=$language_options selected=$language_selected} |
---|
| 779 | </select> |
---|
[25194] | 780 | </div> |
---|
[2531] | 781 | |
---|
[25194] | 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> |
---|
[2531] | 786 | |
---|
[25194] | 787 | {* expand *} |
---|
| 788 | <div id="action_expand" class="bulkAction"> |
---|
[3752] | 789 | <label><input type="radio" name="expand" value="true">{'Yes'|@translate}</label> |
---|
[25198] | 790 | <label><input type="radio" name="expand" value="false" checked="checked">{'No'|@translate}</label> |
---|
[25194] | 791 | </div> |
---|
[2531] | 792 | |
---|
[25194] | 793 | {* show_nb_comments *} |
---|
| 794 | <div id="action_show_nb_comments" class="bulkAction"> |
---|
[3752] | 795 | <label><input type="radio" name="show_nb_comments" value="true">{'Yes'|@translate}</label> |
---|
[25198] | 796 | <label><input type="radio" name="show_nb_comments" value="false" checked="checked">{'No'|@translate}</label> |
---|
[25194] | 797 | </div> |
---|
[2531] | 798 | |
---|
[25194] | 799 | {* show_nb_hits *} |
---|
| 800 | <div id="action_show_nb_hits" class="bulkAction"> |
---|
[3752] | 801 | <label><input type="radio" name="show_nb_hits" value="true">{'Yes'|@translate}</label> |
---|
[25198] | 802 | <label><input type="radio" name="show_nb_hits" value="false" checked="checked">{'No'|@translate}</label> |
---|
[25194] | 803 | </div> |
---|
[2531] | 804 | |
---|
[25194] | 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> |
---|
[2531] | 810 | |
---|
[25194] | 811 | </div> {* #permitAction *} |
---|
[2531] | 812 | </fieldset> |
---|
| 813 | |
---|
[25194] | 814 | </form> |
---|