{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"} {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 registeredOn_pattern = "{'Registered on %s, %s.'|translate}"; var lastVisit_pattern = "{'Last visit on %s, %s.'|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 = '
'; jQuery("#user"+userId).append(userDetails); jQuery(".chzn-select").chosen(); } else { console.log('error loading user details'); } }, error:function(XMLHttpRequest, textStatus, errorThrows) { console.log('technical error loading user details'); } }); return ''; } 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+' .infos').hide(); }); 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+' .infos').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