Changeset 25237 for trunk/admin


Ignore:
Timestamp:
Oct 30, 2013, 1:54:46 PM (11 years ago)
Author:
plg
Message:

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).

Location:
trunk/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/add_core_tabs.inc.php

    r25084 r25237  
    6161    case 'comments':
    6262      $sheets[''] = array('caption' => l10n('User comments'), 'url' => '');
     63      break;
     64
     65    case 'users':
     66      $sheets[''] = array('caption' => '<span class="icon-users"> </span>'.l10n('User list'), 'url' => '');
    6367      break;
    6468     
  • trunk/admin/themes/default/template/user_list.tpl

    r25198 r25237  
    99var selectedMessage_all = "{'All %d photos are selected'|@translate}";
    1010var applyOnDetails_pattern = "{'on the %d selected users'|@translate}";
     11var newUser_pattern = "&#x2714; {'User %s added'|translate}";
    1112var missingConfirm = "{'You need to confirm deletion'|translate}";
     13var missingUsername = "{'Please, enter a login'|translate}";
    1214
    1315var allUsers = [{$all_users}];
     
    1719{footer_script}{literal}
    1820jQuery(document).ready(function() {
     21  /**
     22   * Add user
     23   */
     24  jQuery("#addUser").click(function() {
     25    jQuery("#addUserForm").toggle();
     26    jQuery("#showAddUser .infos").hide();
     27    jQuery("input[name=username]").focus();
     28    return false;
     29  });
     30
     31  jQuery("#addUserClose").click(function() {
     32    jQuery("#addUserForm").hide();
     33    return false;
     34  });
     35
     36  jQuery("#addUserForm").submit(function() {
     37    jQuery.ajax({
     38      url: "ws.php?format=json&method=pwg.users.add",
     39      type:"POST",
     40      data: jQuery(this).serialize(),
     41      beforeSend: function() {
     42        jQuery("#addUserForm .errors").hide();
     43
     44        if (jQuery("input[name=username]").val() == "") {
     45          jQuery("#addUserForm .errors").html('&#x2718; '+missingUsername).show();
     46          return false;
     47        }
     48
     49        jQuery("#addUserForm .loading").show();
     50      },
     51      success:function(data) {
     52        oTable.fnDraw();
     53        jQuery("#addUserForm .loading").hide();
     54
     55        var data = jQuery.parseJSON(data);
     56        if (data.stat == 'ok') {
     57          jQuery("#addUserForm input[type=text], #addUserForm input[type=password]").val("");
     58
     59          var new_user = data.result.users[0];
     60          allUsers.push(parseInt(new_user.id));
     61          jQuery("#showAddUser .infos").html(sprintf(newUser_pattern, new_user.username)).show();
     62          checkSelection();
     63
     64          jQuery("#addUserForm").hide();
     65        }
     66        else {
     67          jQuery("#addUserForm .errors").html('&#x2718; '+data.message).show();
     68        }
     69      },
     70      error:function(XMLHttpRequest, textStatus, errorThrows) {
     71        jQuery("#addUserForm .loading").hide();
     72      }
     73    });
     74
     75    return false;
     76  });
     77
     78  /**
     79   * Table with users
     80   */
     81
    1982  /* first column must be prefixed with the open/close icon */
    2083  var aoColumns = [
     
    265328table.dataTable {clear:right;padding-top:10px;}
    266329.bulkAction {margin-top:10px;}
    267 .actionButtons {margin-left:0;}
    268 #applyActionBlock .infos {background-image:none; padding:2px 5px; margin:0;border-radius:5px;}
     330#addUserForm p {margin-left:0;}
     331#applyActionBlock .actionButtons {margin-left:0;}
     332span.infos, span.errors {background-image:none; padding:2px 5px; margin:0;border-radius:5px;}
    269333</style>
    270334{/literal}
     
    274338</div>
    275339
    276 <form style="display:none" class="filter" method="post" name="add_user" action="{$F_ADD_ACTION}">
     340<p class="showCreateAlbum" id="showAddUser">
     341  <a href="#" id="addUser">{'Add a user'|translate}</a>
     342  <span class="infos" style="display:none"></span>
     343</p>
     344
     345<form id="addUserForm" style="display:none" method="post" name="add_user" action="{$F_ADD_ACTION}">
    277346  <fieldset>
    278347    <legend>{'Add a user'|@translate}</legend>
    279     <label>{'Username'|@translate} <input type="text" name="login" maxlength="50" size="20"></label>
    280     {if $Double_Password}
    281                 <label>{'Password'|@translate} <input type="password" name="password"></label>
    282                 <label>{'Confirm Password'|@translate} <input type="password" name="password_conf" id="password_conf"></label>
    283                 {else}
    284                 <label>{'Password'|@translate} <input type="text" name="password"></label>
    285                 {/if}
    286                 <label>{'Email address'|@translate} <input type="text" name="email"></label>
    287     <label>{'Send connection settings by email'|@translate} <input type="checkbox" name="send_password_by_mail" value="1" checked="checked"></label>
    288     <label>&nbsp; <input class="submit" type="submit" name="submit_add" value="{'Submit'|@translate}"></label>
     348
     349    <p>
     350      <strong>{'Username'|translate}</strong><br>
     351      <input type="text" name="username" maxlength="50" size="20">
     352    </p>
     353
     354    <p>
     355      <strong>{'Password'|translate}</strong><br>
     356      <input type="{if $Double_Password}password{else}text{/if}" name="password">
     357    </p>
     358   
     359{if $Double_Password}
     360    <p>
     361      <strong>{'Confirm Password'|@translate}</strong><br>
     362      <input type="password" name="password_confirm">
     363    </p>
     364{/if}
     365
     366    <p>
     367      <strong>{'Email address'|@translate}</strong><br>
     368      <input type="text" name="email">
     369    </p>
     370
     371    <p>
     372      <label><input type="checkbox" name="send_password_by_mail"> <strong>{'Send connection settings by email'|@translate}</strong></label>
     373    </p>
     374
     375    <p class="actionButtons">
     376      <input class="submit" name="submit_add" type="submit" value="{'Submit'|@translate}">
     377      <a href="#" id="addUserClose">{'Cancel'|@translate}</a>
     378      <span class="loading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span>
     379      <span class="errors" style="display:none"></span>
     380    </p>
    289381  </fieldset>
    290382</form>
  • trunk/admin/user_list.php

    r25194 r25237  
    2525 * Add users and manage users list
    2626 */
     27
     28// +-----------------------------------------------------------------------+
     29// | tabs                                                                  |
     30// +-----------------------------------------------------------------------+
     31
     32include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     33
     34$my_base_url = get_root_url().'admin.php?page=';
     35
     36$tabsheet = new tabsheet();
     37$tabsheet->set_id('users');
     38$tabsheet->select('user_list');
     39$tabsheet->assign();
    2740
    2841// +-----------------------------------------------------------------------+
     
    7487    'users' => $users,
    7588    'all_users' => join(',', $user_ids),
     89    'Double_Password' => $conf['double_password_type_in_admin']
    7690    )
    7791  );
Note: See TracChangeset for help on using the changeset viewer.