{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"} {footer_script} var selectedMessage_pattern = "{'%d of %d photos selected'|@translate}"; var selectedMessage_none = "{'No photo selected, %d photos in current set'|@translate}"; var selectedMessage_all = "{'All %d photos are selected'|@translate}"; var applyOnDetails_pattern = "{'on the %d selected users'|@translate}"; var newUser_pattern = "✔ {'User %s added'|translate}"; var missingConfirm = "{'You need to confirm deletion'|translate}"; var missingUsername = "{'Please, enter a login'|translate}"; var allUsers = [{$all_users}]; var selection = [{$selection}]; var pwg_token = "{$PWG_TOKEN}"; 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 */ /* 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 += ''; userDetails += '
{/literal}{'Properties'|translate}{literal}'; userDetails += '
{/literal}{'Username'|translate}{literal}'; userDetails += '
'+user.username+'
'; userDetails += '
{/literal}{'Email address'|translate}{literal}'; userDetails += '
'; userDetails += '
{/literal}{'Status'|translate}{literal}'; userDetails += '
'; /* userDetails += '
{/literal}{'Groups'|translate}{literal}'; userDetails += '
'; // userDetails += '
'+user.groups.join(",")+''; */ userDetails += '
{/literal}{'Privacy level'|translate}{literal}'; userDetails += '
'; userDetails += '
{/literal}{'High definition enabled'|translate}{literal}'; userDetails += '
'; jQuery.each(truefalse, function(value, label) { var checked = ''; if (user.enabled_high == value) { checked = ' checked="checked"'; } userDetails += ''; }); userDetails += '
'; userDetails += '
{/literal}{'Preferences'|translate}{literal}'; userDetails += '
{/literal}{'Number of photos per page'|translate}{literal}'; userDetails += '
'+user.nb_image_page+'
'; userDetails += '
{/literal}{'Theme'|translate}{literal}'; userDetails += '
'; userDetails += '
{/literal}{'Language'|translate}{literal}'; userDetails += '
'; userDetails += '
{/literal}{'Recent period'|translate}{literal}'; userDetails += '
'+user.recent_period+'
'; userDetails += '
{/literal}{'Expand all albums'|translate}{literal}'; userDetails += '
'; jQuery.each(truefalse, function(value, label) { var checked = ''; if (user.expand == value) { checked = ' checked="checked"'; } userDetails += ''; }); userDetails += '
'; userDetails += '
{/literal}{'Show number of comments'|translate}{literal}'; userDetails += '
'; jQuery.each(truefalse, function(value, label) { var checked = ''; if (user.show_nb_comments == value) { checked = ' checked="checked"'; } userDetails += ''; }); userDetails += '
'; userDetails += '
{/literal}{'Show number of hits'|translate}{literal}'; userDetails += '
'; jQuery.each(truefalse, function(value, label) { var checked = ''; if (user.show_nb_hits == value) { checked = ' checked="checked"'; } userDetails += ''; }); userDetails += '
'; userDetails += '
'; userDetails += ''; userDetails += '' userDetails += '
'; jQuery("#user"+userId).append(userDetails); } else { console.log('error loading user details'); } }, error:function(XMLHttpRequest, textStatus, errorThrows) { console.log('technical error loading user details'); } }); return '
'; } jQuery(document).on('click', '.userProperties input[type=submit]', function() { var userId = jQuery(this).data('user_id'); jQuery.ajax({ url: "ws.php?format=json&method=pwg.users.setInfo", type:"POST", data: jQuery('#user'+userId+' form').serialize(), beforeSend: function() { jQuery('#user'+userId+' .submitWait').show(); }, success:function(data) { jQuery('#user'+userId+' .submitWait').hide(); }, 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 img', function() { var nTr = this.parentNode.parentNode; if ( this.src.match('details_close') ) { /* This row is already open - close it */ this.src = "admin/themes/default/icon/details_open.png"; oTable.fnClose( nTr ); } else { /* Open this row */ this.src = "admin/themes/default/icon/details_close.png"; 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 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} {literal} {/literal}

{'User list'|@translate}

{'Add a user'|translate}

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

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

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