{include file='include/colorbox.inc.tpl'} {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.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'} {combine_css id='jquery.selectize' path="themes/default/js/plugins/selectize.{$themeconf.colorscheme}.css"} {combine_script id='jquery.underscore' load='footer' path='themes/default/js/plugins/underscore.js'} {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 passwordProtectedUsers = [{$password_protected_users}]; var guestUser = {$guest_user}; var truefalse = { 'true':"{'Yes'|translate}", 'false':"{'No'|translate}", }; var statusLabels = { {foreach from=$label_of_status key=status item=label} '{$status}' : '{$label|escape:javascript}', {/foreach} }; {/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()+"&pwg_token="+pwg_token, 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.draw(); 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.api().row(nTr).data()[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]; /* Prepare data for template */ user.statusOptions = []; jQuery("#action select[name=status] option").each(function() { var option = {value:jQuery(this).val(), label:jQuery(this).html(), isSelected:false}; if (user.status == jQuery(this).val()) { option.isSelected = true; } user.statusOptions.push(option); }); user.levelOptions = []; jQuery("#action select[name=level] option").each(function() { var option = {value:jQuery(this).val(), label:jQuery(this).html(), isSelected:false}; if (user.level == jQuery(this).val()) { option.isSelected = true; } user.levelOptions.push(option); }); user.groupOptions = []; jQuery("#action select[name=associate] option").each(function() { var option = {value:jQuery(this).val(), label:jQuery(this).html(), isSelected:false}; if (user.groups.indexOf( parseInt(jQuery(this).val()) ) != -1) { option.isSelected = true; } user.groupOptions.push(option); }); user.themeOptions = []; jQuery("#action select[name=theme] option").each(function() { var option = {value:jQuery(this).val(), label:jQuery(this).html(), isSelected:false}; if (user.theme == jQuery(this).val()) { option.isSelected = true; } user.themeOptions.push(option); }); user.languageOptions = []; jQuery("#action select[name=language] option").each(function() { var option = {value:jQuery(this).val(), label:jQuery(this).html(), isSelected:false}; if (user.language == jQuery(this).val()) { option.isSelected = true; } user.languageOptions.push(option); }); user.isGuest = (parseInt(userId) == guestUser); user.isProtected = (protectedUsers.indexOf(parseInt(userId)) != -1); user.isPasswordProtected = (passwordProtectedUsers.indexOf(parseInt(userId)) != -1); user.registeredOn_string = sprintf( registeredOn_pattern, user.registration_date_string, user.registration_date_since ); user.lastVisit_string = ""; if (typeof user.last_visit != 'undefined') { user.lastVisit_string = sprintf(lastVisit_pattern, user.last_visit_string, user.last_visit_since); } user.email = user.email || ''; user.statusLabel = statusLabels[user.status]; /* Render the underscore template */ _.templateSettings.variable = "user"; var template = _.template( jQuery("script.userDetails").html() ); jQuery("#user"+userId).html(template(user)); /* groups select */ jQuery('[data-selectize=groups]').selectize({ valueField: 'value', labelField: 'label', searchField: ['label'], plugins: ['remove_button'] }); var groupSelectize = jQuery('[data-selectize=groups]')[0].selectize; groupSelectize.load(function(callback) { callback(user.groupOptions); }); jQuery.each(jQuery.grep(user.groupOptions, function(group) { return group.isSelected; }), function(i, group) { groupSelectize.addItem(group.value); }); /* 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'); } }); jQuery(".user_form_popin") .attr("id", "user"+userId) .html('