{combine_script id='common' load='footer' path='admin/themes/default/js/common.js'} {combine_script id='jquery.dataTables' load='footer' path='themes/default/js/plugins/jquery.dataTables.js'} {combine_css path="themes/default/js/plugins/datatables/css/jquery.dataTables.css"} {combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'} {combine_css path="themes/default/js/plugins/chosen.css"} {combine_script id='jquery.ui.slider' require='jquery.ui' load='footer' path='themes/default/js/ui/minified/jquery.ui.slider.min.js'} {combine_css path="themes/default/js/ui/theme/jquery.ui.slider.css"} {footer_script} var selectedMessage_pattern = "{'%d of %d users selected'|translate|escape:javascript}"; var selectedMessage_none = "{'No user selected of %d users'|translate|escape:javascript}"; var selectedMessage_all = "{'All %d users are selected'|translate|escape:javascript}"; var applyOnDetails_pattern = "{'on the %d selected users'|translate|escape:javascript}"; var newUser_pattern = "✔ {'User %s added'|translate|escape:javascript}"; var registeredOn_pattern = "{'Registered on %s, %s.'|translate|escape:javascript}"; var lastVisit_pattern = "{'Last visit on %s, %s.'|translate|escape:javascript}"; var missingConfirm = "{'You need to confirm deletion'|translate|escape:javascript}"; var missingUsername = "{'Please, enter a login'|translate|escape:javascript}"; var allUsers = [{$all_users}]; var selection = [{$selection}]; var pwg_token = "{$PWG_TOKEN}"; var protectedUsers = [{$protected_users}]; var guestUser = {$guest_user}; var truefalse = { true:"{'Yes'|translate}", false:"{'No'|translate}", }; {/footer_script} {footer_script}{literal} jQuery(document).ready(function() { /** * Add user */ jQuery("#addUser").click(function() { jQuery("#addUserForm").toggle(); jQuery("#showAddUser .infos").hide(); jQuery("input[name=username]").focus(); return false; }); jQuery("#addUserClose").click(function() { jQuery("#addUserForm").hide(); return false; }); jQuery("#addUserForm").submit(function() { jQuery.ajax({ url: "ws.php?format=json&method=pwg.users.add", type:"POST", data: jQuery(this).serialize(), beforeSend: function() { jQuery("#addUserForm .errors").hide(); if (jQuery("input[name=username]").val() == "") { jQuery("#addUserForm .errors").html('✘ '+missingUsername).show(); return false; } jQuery("#addUserForm .loading").show(); }, success:function(data) { oTable.fnDraw(); jQuery("#addUserForm .loading").hide(); var data = jQuery.parseJSON(data); if (data.stat == 'ok') { jQuery("#addUserForm input[type=text], #addUserForm input[type=password]").val(""); var new_user = data.result.users[0]; allUsers.push(parseInt(new_user.id)); jQuery("#showAddUser .infos").html(sprintf(newUser_pattern, new_user.username)).show(); checkSelection(); jQuery("#addUserForm").hide(); } else { jQuery("#addUserForm .errors").html('✘ '+data.message).show(); } }, error:function(XMLHttpRequest, textStatus, errorThrows) { jQuery("#addUserForm .loading").hide(); } }); return false; }); /** * Table with users */ /** * find the key from a value in the startStopValues array */ function getSliderKeyFromValue(value, values) { for (var key in values) { if (values[key] >= value) { return key; } } return 0; } var recent_period_values = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,25,30,40,50,60,80,99]; function getRecentPeriodInfoFromIdx(idx) { return sprintf( "{/literal}{'%d days'|@translate}{literal}", recent_period_values[idx] ); } var nb_image_page_values = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,35,40,45,50,60,70,80,90,100,200,300,500,999]; function getNbImagePageInfoFromIdx(idx) { return sprintf( "{/literal}{'%d photos per page'|@translate}{literal}", nb_image_page_values[idx] ); } /* nb_image_page slider */ var nb_image_page_init = getSliderKeyFromValue(jQuery('#action_nb_image_page input[name=nb_image_page]').val(), nb_image_page_values); jQuery('#action_nb_image_page .nb_image_page_infos').html(getNbImagePageInfoFromIdx(nb_image_page_init)); jQuery('#action_nb_image_page .nb_image_page').slider({ range: "min", min: 0, max: nb_image_page_values.length - 1, value: nb_image_page_init, slide: function( event, ui ) { jQuery('#action_nb_image_page .nb_image_page_infos').html(getNbImagePageInfoFromIdx(ui.value)); }, stop: function( event, ui ) { jQuery('#action_nb_image_page input[name=nb_image_page]').val(nb_image_page_values[ui.value]).trigger('change'); } }); /* recent_period slider */ var recent_period_init = getSliderKeyFromValue(jQuery('#action_recent_period input[name=recent_period]').val(), recent_period_values); jQuery('#action_recent_period .recent_period_infos').html(getRecentPeriodInfoFromIdx(recent_period_init)); jQuery('#action_recent_period .recent_period').slider({ range: "min", min: 0, max: recent_period_values.length - 1, value: recent_period_init, slide: function( event, ui ) { jQuery('#action_recent_period .recent_period_infos').html(getRecentPeriodInfoFromIdx(ui.value)); }, stop: function( event, ui ) { jQuery('#action_recent_period input[name=recent_period]').val(recent_period_values[ui.value]).trigger('change'); } }); /* Formating function for row details */ function fnFormatDetails(oTable, nTr) { var userId = oTable.fnGetData(nTr)[0]; console.log("userId = "+userId); var sOut = null; jQuery.ajax({ url: "ws.php?format=json&method=pwg.users.getList", type:"POST", data: { user_id: userId, display: "all", }, success:function(data) { jQuery("#user"+userId+" .loading").hide(); var data = jQuery.parseJSON(data); if (data.stat == 'ok') { var user = data.result.users[0]; var userDetails = '
'; userDetails += '
'; if (parseInt(userId) != guestUser) { userDetails += ''; userDetails += ''; userDetails += '{/literal}{'Change password'|translate|escape:javascript}{literal}'; userDetails += '
'; } userDetails += '{/literal}{'Permissions'|translate|escape:javascript}{literal}'; if (protectedUsers.indexOf(parseInt(userId)) == -1) { userDetails += '
{/literal}{'Delete'|translate|escape:javascript}{literal}'; } userDetails += '
'; userDetails += ''+user.username+''; if (parseInt(userId) != guestUser) { userDetails += ' {/literal}{'Change username'|translate|escape:javascript}{literal}'; userDetails += ''; userDetails += '
'; userDetails += sprintf(registeredOn_pattern, user.registration_date_string, user.registration_date_since); if (typeof user.last_visit != 'undefined') { userDetails += '
'+sprintf(lastVisit_pattern, user.last_visit_string, user.last_visit_since); } userDetails += '
'; userDetails += '
'; userDetails += ''; userDetails += '
'; userDetails += '
{/literal}{'Properties'|translate}{literal}
'; userDetails += '
{/literal}{'Email address'|translate}{literal}'; userDetails += '
'; if (parseInt(userId) != guestUser) { userDetails += ''; } else { userDetails += '{/literal}{'N/A'|translate}{literal}'; } userDetails += '
'; userDetails += '
{/literal}{'Status'|translate}{literal}'; userDetails += '
'; userDetails += '
{/literal}{'Privacy level'|translate}{literal}'; userDetails += '
'; var checked = ''; if (user.enabled_high == 'true') { checked = ' checked="checked"'; } userDetails += '
'; userDetails += '
'; userDetails += '
{/literal}{'Groups'|translate}{literal}'; userDetails += '
'; // userDetails += '
'+user.groups.join(",")+'
'; userDetails += '
'; userDetails += '
{/literal}{'Preferences'|translate}{literal}
'; userDetails += '
'; userDetails += '
'; userDetails += ''; userDetails += '
'; userDetails += '
{/literal}{'Theme'|translate|escape:javascript}{literal}'; userDetails += '
'; userDetails += '
{/literal}{'Language'|translate}{literal}'; userDetails += '
'; userDetails += '
{/literal}{'Recent period'|translate}{literal} '; userDetails += '
'; userDetails += ''; userDetails += '
'; var checked = ''; if (user.expand == 'true') { checked = ' checked="checked"'; } userDetails += '
'; userDetails += '
'; var checked = ''; if (user.show_nb_comments == 'true') { checked = ' checked="checked"'; } userDetails += '
'; userDetails += '
'; var checked = ''; if (user.show_nb_hits == 'true') { checked = ' checked="checked"'; } userDetails += '
'; userDetails += '
'; userDetails += '
'; userDetails += '
'; userDetails += ''; userDetails += ''; userDetails += '' userDetails += '
'; jQuery("#user"+userId).append(userDetails); jQuery(".chzn-select").chosen(); /* nb_image_page slider */ var nb_image_page_init = getSliderKeyFromValue(jQuery('#user'+userId+' input[name=nb_image_page]').val(), nb_image_page_values); jQuery('#user'+userId+' .nb_image_page_infos').html(getNbImagePageInfoFromIdx(nb_image_page_init)); jQuery('#user'+userId+' .nb_image_page').slider({ range: "min", min: 0, max: nb_image_page_values.length - 1, value: nb_image_page_init, slide: function( event, ui ) { jQuery('#user'+userId+' .nb_image_page_infos').html(getNbImagePageInfoFromIdx(ui.value)); }, stop: function( event, ui ) { jQuery('#user'+userId+' input[name=nb_image_page]').val(nb_image_page_values[ui.value]).trigger('change'); } }); /* recent_period slider */ var recent_period_init = getSliderKeyFromValue(jQuery('#user'+userId+' input[name=recent_period]').val(), recent_period_values); jQuery('#user'+userId+' .recent_period_infos').html(getRecentPeriodInfoFromIdx(recent_period_init)); jQuery('#user'+userId+' .recent_period').slider({ range: "min", min: 0, max: recent_period_values.length - 1, value: recent_period_init, slide: function( event, ui ) { jQuery('#user'+userId+' .recent_period_infos').html(getRecentPeriodInfoFromIdx(ui.value)); }, stop: function( event, ui ) { jQuery('#user'+userId+' input[name=recent_period]').val(recent_period_values[ui.value]).trigger('change'); } }); } else { console.log('error loading user details'); } }, error:function(XMLHttpRequest, textStatus, errorThrows) { console.log('technical error loading user details'); } }); return '
'; } /* change password */ jQuery(document).on('click', '.changePasswordOpen', function() { var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); jQuery(this).hide(); jQuery('#user'+userId+' .changePasswordDone').hide(); jQuery('#user'+userId+' .changePassword').show(); jQuery('#user'+userId+' .changePassword input[type=text]').focus(); return false; }); jQuery(document).on('click', '.changePassword a.updatePassword', function() { var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); jQuery('#user'+userId+' .changePassword a .text').hide(); jQuery('#user'+userId+' .changePassword a img').show(); jQuery.ajax({ url: "ws.php?format=json&method=pwg.users.setInfo", type:"POST", data: { user_id:userId, password: jQuery('#user'+userId+' .changePassword input[type=text]').val() }, beforeSend: function() { jQuery('#user'+userId+' .changePassword input[type=text]').val(""); }, success:function(data) { jQuery('#user'+userId+' .changePassword a .text').show(); jQuery('#user'+userId+' .changePassword a img').hide(); jQuery('#user'+userId+' .changePassword').hide(); jQuery('#user'+userId+' .changePasswordOpen').show(); jQuery('#user'+userId+' .changePasswordDone').show(); }, error:function(XMLHttpRequest, textStatus, errorThrows) { } }); return false; }); jQuery(document).on('click', '.changePassword a.cancel', function() { var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); jQuery('#user'+userId+' .changePassword').hide(); jQuery('#user'+userId+' .changePasswordOpen').show(); return false; }); /* change username */ jQuery(document).on('click', '.changeUsernameOpen a', function() { var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); var username = jQuery('#user'+userId+' .username').html(); jQuery('#user'+userId+' .changeUsernameOpen').hide(); jQuery('#user'+userId+' .changeUsername').show(); jQuery('#user'+userId+' .changeUsername input[type=text]').val(username).focus(); return false; }); jQuery(document).on('click', 'a.updateUsername', function() { var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); jQuery('#user'+userId+' .changeUsername a .text').hide(); jQuery('#user'+userId+' .changeUsername a img').show(); jQuery.ajax({ url: "ws.php?format=json&method=pwg.users.setInfo", type:"POST", data: { user_id:userId, username: jQuery('#user'+userId+' .changeUsername input[type=text]').val() }, success:function(data) { jQuery('#user'+userId+' .changeUsername a .text').show(); jQuery('#user'+userId+' .changeUsername a img').hide(); jQuery('#user'+userId+' .changeUsername').hide(); jQuery('#user'+userId+' .changeUsernameOpen').show(); var data = jQuery.parseJSON(data); jQuery('#user'+userId+' .username').html(data.result.users[0].username); }, error:function(XMLHttpRequest, textStatus, errorThrows) { } }); return false; }); jQuery(document).on('click', '.changeUsername a.cancel', function() { var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); jQuery('#user'+userId+' .changeUsername').hide(); jQuery('#user'+userId+' .changeUsernameOpen').show(); return false; }); /* display the "save" button when a field changes */ jQuery(document).on('change', '.userProperties input, .userProperties select', function() { var userId = jQuery(this).parentsUntil('form').parent().find('input[name=user_id]').val(); jQuery('#user'+userId+' input[type=submit]').show(); jQuery('#user'+userId+' .propertiesUpdateDone').hide(); }); /* delete user */ jQuery(document).on('click', '.userDelete a', function() { if (!confirm("{/literal}{'Are you sure?'|translate|escape:javascript}{literal}")) { return false; } var userId = jQuery(this).data('user_id'); var username = jQuery('#user'+userId+' .username').html(); jQuery.ajax({ url: "ws.php?format=json&method=pwg.users.delete", type:"POST", data: { user_id:userId, pwg_token:pwg_token }, beforeSend: function() { jQuery('#user'+userId+' .userDelete .loading').show(); }, success:function(data) { oTable.fnDraw(); jQuery('#showAddUser .infos').html('✔ User '+username+' deleted').show(); }, error:function(XMLHttpRequest, textStatus, errorThrows) { jQuery('#user'+userId+' .userDelete .loading').hide(); } }); return false; }); jQuery(document).on('click', '.userProperties input[type=submit]', function() { var userId = jQuery(this).data('user_id'); var formData = jQuery('#user'+userId+' form').serialize(); if (jQuery('#user'+userId+' form select[name="group_id[]"] option:selected').length == 0) { formData += '&group_id=-1'; } if (!jQuery('#user'+userId+' form input[name=enabled_high]').is(':checked')) { formData += '&enabled_high=false'; } if (!jQuery('#user'+userId+' form input[name=expand]').is(':checked')) { formData += '&expand=false'; } if (!jQuery('#user'+userId+' form input[name=show_nb_hits]').is(':checked')) { formData += '&show_nb_hits=false'; } if (!jQuery('#user'+userId+' form input[name=show_nb_comments]').is(':checked')) { formData += '&show_nb_comments=false'; } jQuery.ajax({ url: "ws.php?format=json&method=pwg.users.setInfo", type:"POST", data: formData, beforeSend: function() { jQuery('#user'+userId+' .submitWait').show(); }, success:function(data) { jQuery('#user'+userId+' .submitWait').hide(); jQuery('#user'+userId+' input[type=submit]').hide(); jQuery('#user'+userId+' .propertiesUpdateDone').show(); }, error:function(XMLHttpRequest, textStatus, errorThrows) { jQuery('#user'+userId+' .submitWait').hide(); } }); return false; }); /* Add event listener for opening and closing details * Note that the indicator for showing which row is open is not controlled by DataTables, * rather it is done here */ jQuery(document).on('click', '#userList tbody td .openUserDetails', function() { var nTr = this.parentNode.parentNode; if (jQuery(this).hasClass('icon-angle-circled-up')) { /* This row is already open - close it */ jQuery(this).removeClass('icon-angle-circled-up').addClass('icon-angle-circled-down').attr('title', 'Open user details'); oTable.fnClose( nTr ); } else { /* Open this row */ jQuery(this).removeClass('icon-angle-circled-down').addClass('icon-angle-circled-up').attr('title', 'Close user details'); oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' ); } }); /* first column must be prefixed with the open/close icon */ var aoColumns = [ { 'bVisible':false }, { "mRender": function(data, type, full) { return ' '; } } ]; for (i=2; i'+"{/literal}{'Search'|translate|escape:'javascript'}{literal}", "sLoadingRecords": "{/literal}{'Loading...'|translate|escape:'javascript'}{literal}", "oPaginate": { "sFirst": "{/literal}{'First'|translate|escape:'javascript'}{literal}", "sPrevious": '← '+"{/literal}{'Previous'|translate|escape:'javascript'}{literal}", "sNext": "{/literal}{'Next'|translate|escape:'javascript'}{literal}"+' →', "sLast": "{/literal}{'Last'|translate|escape:'javascript'}{literal}", } }, "fnDrawCallback": function( oSettings ) { jQuery("#userList input[type=checkbox]").each(function() { var user_id = jQuery(this).data("user_id"); jQuery(this).prop('checked', (selection.indexOf(user_id) != -1)); }); }, "aoColumns": aoColumns }); /** * Selection management */ function checkSelection() { if (selection.length > 0) { jQuery("#forbidAction").hide(); jQuery("#permitAction").show(); jQuery("#applyOnDetails").text( sprintf( applyOnDetails_pattern, selection.length ) ); if (selection.length == allUsers.length) { jQuery("#selectedMessage").text( sprintf( selectedMessage_all, allUsers.length ) ); } else { jQuery("#selectedMessage").text( sprintf( selectedMessage_pattern, selection.length, allUsers.length ) ); } } else { jQuery("#forbidAction").show(); jQuery("#permitAction").hide(); jQuery("#selectedMessage").text( sprintf( selectedMessage_none, allUsers.length ) ); } jQuery("#applyActionBlock .infos").hide(); } jQuery(document).on('change', '#userList input[type=checkbox]', function() { var user_id = jQuery(this).data("user_id"); array_delete(selection, user_id); if (jQuery(this).is(":checked")) { selection.push(user_id); } checkSelection(); }); jQuery("#selectAll").click(function () { selection = allUsers; jQuery("#userList input[type=checkbox]").prop('checked', true); checkSelection(); return false; }); jQuery("#selectNone").click(function () { selection = []; jQuery("#userList input[type=checkbox]").prop('checked', false); checkSelection(); return false; }); jQuery("#selectInvert").click(function () { var newSelection = []; for(var i in allUsers) { if (selection.indexOf(allUsers[i]) == -1) { newSelection.push(allUsers[i]); } } selection = newSelection; jQuery("#userList input[type=checkbox]").each(function() { var user_id = jQuery(this).data("user_id"); jQuery(this).prop('checked', (selection.indexOf(user_id) != -1)); }); checkSelection(); return false; }); /** * Action management */ jQuery("[id^=action_]").hide(); jQuery("select[name=selectAction]").change(function () { jQuery("#applyActionBlock .infos").hide(); jQuery("[id^=action_]").hide(); jQuery("#action_"+$(this).prop("value")).show(); if (jQuery(this).val() != -1) { jQuery("#applyActionBlock").show(); } else { jQuery("#applyActionBlock").hide(); } }); jQuery("#permitAction input, #permitAction select").click(function() { jQuery("#applyActionBlock .infos").hide(); }); jQuery("#applyAction").click(function() { var action = jQuery("select[name=selectAction]").prop("value"); var method = 'pwg.users.setInfo'; var data = { user_id: selection }; switch (action) { case 'delete': if (!jQuery("input[name=confirm_deletion]").is(':checked')) { alert(missingConfirm); return false; } method = 'pwg.users.delete'; data.pwg_token = pwg_token; break; case 'group_associate': method = 'pwg.groups.addUser'; data.group_id = jQuery("select[name=associate]").prop("value"); break; case 'group_dissociate': method = 'pwg.groups.deleteUser'; data.group_id = jQuery("select[name=dissociate]").prop("value"); break; case 'status': data.status = jQuery("select[name=status]").prop("value"); break; case 'enabled_high': data.enabled_high = jQuery("input[name=enabled_high]:checked").val(); break; case 'level': data.level = jQuery("select[name=level]").val(); break; case 'nb_image_page': data.nb_image_page = jQuery("input[name=nb_image_page]").val(); break; case 'theme': data.theme = jQuery("select[name=theme]").val(); break; case 'language': data.language = jQuery("select[name=language]").val(); break; case 'recent_period': data.recent_period = jQuery("input[name=recent_period]").val(); break; case 'expand': data.expand = jQuery("input[name=expand]:checked").val(); break; case 'show_nb_comments': data.show_nb_comments = jQuery("input[name=show_nb_comments]:checked").val(); break; case 'show_nb_hits': data.show_nb_hits = jQuery("input[name=show_nb_hits]:checked").val(); break; default: alert("Unexpected action"); return false; } jQuery.ajax({ url: "ws.php?format=json&method="+method, type:"POST", data: data, beforeSend: function() { jQuery("#applyActionLoading").show(); }, success:function(data) { oTable.fnDraw(); jQuery("#applyActionLoading").hide(); jQuery("#applyActionBlock .infos").show(); if (action == 'delete') { var allUsers_new = []; for(var i in allUsers) { if (selection.indexOf(allUsers[i]) == -1) { allUsers_new.push(allUsers[i]); } } allUsers = allUsers_new; console.log('allUsers_new.length = '+allUsers_new.length); selection = []; checkSelection(); } }, error:function(XMLHttpRequest, textStatus, errorThrows) { jQuery("#applyActionLoading").hide(); } }); return false; }); }); {/literal}{/footer_script} {html_style}{literal} .dataTables_wrapper, .dataTables_info {clear:none;} table.dataTable {clear:right;padding-top:10px;} .dataTable td img {margin-bottom: -6px;margin-left: -6px;} .paginate_enabled_previous, .paginate_enabled_previous:hover, .paginate_disabled_previous, .paginate_enabled_next, .paginate_enabled_next:hover, .paginate_disabled_next {background:none;} .paginate_enabled_previous, .paginate_enabled_next {color:#005E89 !important;} .paginate_enabled_previous:hover, .paginate_enabled_next:hover {color:#D54E21 !important; text-decoration:underline !important;} .paginate_disabled_next, .paginate_enabled_next {padding-right:3px;} .bulkAction {margin-top:10px;} #addUserForm p {margin-left:0;} #applyActionBlock .actionButtons {margin-left:0;} span.infos, span.errors {background-image:none; padding:2px 5px; margin:0;border-radius:5px;} .userStats {margin-top:10px;} .recent_period_infos {margin-left:10px;} .nb_image_page, .recent_period {width:340px;margin-top:5px;} #action_recent_period .recent_period {display:inline-block;} {/literal}{/html_style}

{'User list'|@translate}

{'Add a user'|translate}

id {'Username'|@translate} {'Status'|@translate} {'Email address'|@translate} {'registration date'|@translate}

{'Select:'|@translate} {'All'|@translate}, {'None'|@translate}, {'Invert'|@translate}

{'Action'|@translate} {* #permitAction *}