From df6718f3f868b226328ff292f2b5d13f054850ea Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 30 Oct 2013 12:54:46 +0000 Subject: feature 1668, user manager redesign: ability to add a new user (call to pwg.users.add through AJAX) Move the "send connection settings" code to function register_user (avoid code duplication). git-svn-id: http://piwigo.org/svn/trunk@25237 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/add_core_tabs.inc.php | 4 + admin/themes/default/template/user_list.tpl | 118 +++++++++++++++++++++++++--- admin/user_list.php | 14 ++++ 3 files changed, 123 insertions(+), 13 deletions(-) (limited to 'admin') diff --git a/admin/include/add_core_tabs.inc.php b/admin/include/add_core_tabs.inc.php index 443775d38..9769cb32c 100644 --- a/admin/include/add_core_tabs.inc.php +++ b/admin/include/add_core_tabs.inc.php @@ -61,6 +61,10 @@ function add_core_tabs($sheets, $tab_id) case 'comments': $sheets[''] = array('caption' => l10n('User comments'), 'url' => ''); break; + + case 'users': + $sheets[''] = array('caption' => ' '.l10n('User list'), 'url' => ''); + break; case 'configuration': global $conf_link; diff --git a/admin/themes/default/template/user_list.tpl b/admin/themes/default/template/user_list.tpl index 11a97c29d..6cd7de900 100644 --- a/admin/themes/default/template/user_list.tpl +++ b/admin/themes/default/template/user_list.tpl @@ -8,7 +8,9 @@ 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}]; @@ -16,6 +18,67 @@ var selection = [{$selection}]; {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 + */ + /* first column must be prefixed with the open/close icon */ var aoColumns = [ { @@ -264,8 +327,9 @@ jQuery(document).ready(function() { .dataTables_wrapper, .dataTables_info {clear:none;} table.dataTable {clear:right;padding-top:10px;} .bulkAction {margin-top:10px;} -.actionButtons {margin-left:0;} -#applyActionBlock .infos {background-image:none; padding:2px 5px; margin:0;border-radius:5px;} +#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;} {/literal} @@ -273,19 +337,47 @@ table.dataTable {clear:right;padding-top:10px;}

{'User list'|@translate}

- diff --git a/admin/user_list.php b/admin/user_list.php index a9744a0d2..3c0b6488d 100644 --- a/admin/user_list.php +++ b/admin/user_list.php @@ -25,6 +25,19 @@ * Add users and manage users list */ +// +-----------------------------------------------------------------------+ +// | tabs | +// +-----------------------------------------------------------------------+ + +include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); + +$my_base_url = get_root_url().'admin.php?page='; + +$tabsheet = new tabsheet(); +$tabsheet->set_id('users'); +$tabsheet->select('user_list'); +$tabsheet->assign(); + // +-----------------------------------------------------------------------+ // | groups list | // +-----------------------------------------------------------------------+ @@ -73,6 +86,7 @@ $template->assign( array( 'users' => $users, 'all_users' => join(',', $user_ids), + 'Double_Password' => $conf['double_password_type_in_admin'] ) ); -- cgit v1.2.3