Ignore:
Timestamp:
May 27, 2014, 11:47:57 PM (10 years ago)
Author:
mistic100
Message:

feature 3077 : factorize code for cache/selectize

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/template/cat_perm.tpl

    r28532 r28550  
    77(function(){
    88{* <!-- GROUPS --> *}
    9 var groupsCache = new LocalStorageCache({
    10   key: 'groupsAdminList',
     9var groupsCache = new GroupsCache({
    1110  serverKey: '{$CACHE_KEYS.groups}',
    1211  serverId: '{$CACHE_KEYS._hash}',
    13 
    14   loader: function(callback) {
    15     jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.groups.getList&per_page=99999', function(data) {
    16       callback(data.result.groups);
    17     });
    18   }
     12  rootUrl: '{$ROOT_URL}'
    1913});
    2014
    21 jQuery('[data-selectize=groups]').selectize({
    22   valueField: 'id',
    23   labelField: 'name',
    24   searchField: ['name'],
    25   plugins: ['remove_button']
     15groupsCache.selectize(jQuery('[data-selectize=groups]'));
     16
     17{* <!-- USERS --> *}
     18var usersCache = new UsersCache({
     19  serverKey: '{$CACHE_KEYS.users}',
     20  serverId: '{$CACHE_KEYS._hash}',
     21  rootUrl: '{$ROOT_URL}'
    2622});
    2723
    28 groupsCache.get(function(groups) {
    29   jQuery('[data-selectize=groups]').each(function() {
    30     this.selectize.load(function(callback) {
    31       callback(groups);
    32     });
    33 
    34     jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) {
    35       this.selectize.addItem(id);
    36     }, this));
    37   });
    38 });
    39 
    40 {* <!-- USERS --> *}
    41 var usersCache = new LocalStorageCache({
    42   key: 'usersAdminList',
    43   serverKey: '{$CACHE_KEYS.users}',
    44   serverId: '{$CACHE_KEYS._hash}',
    45 
    46   loader: function(callback) {
    47     var users = [];
    48    
    49     // recursive loader
    50     (function load(page){
    51       jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.users.getList&display=username&per_page=99999&page='+ page, function(data) {
    52         users = users.concat(data.result.users);
    53        
    54         if (data.result.paging.count == data.result.paging.per_page) {
    55           load(++page);
    56         }
    57         else {
    58           callback(users);
    59         }
    60       });
    61     }(0));
    62   }
    63 });
    64 
    65 jQuery('[data-selectize=users]').selectize({
    66   valueField: 'id',
    67   labelField: 'username',
    68   searchField: ['username'],
    69   plugins: ['remove_button']
    70 });
    71 
    72 usersCache.get(function(users) {
    73   jQuery('[data-selectize=users]').each(function() {
    74     this.selectize.load(function(callback) {
    75       callback(users);
    76     });
    77 
    78     jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) {
    79       this.selectize.addItem(id);
    80     }, this));
    81   });
    82 });
     24usersCache.selectize(jQuery('[data-selectize=users]'));
    8325
    8426{* <!-- TOGGLES --> *}
     
    13173    <br>
    13274    <select data-selectize="groups" data-value="{$groups_selected|@json_encode|escape:html}"
    133         name="groups[]" multiple style="width:600px;" ></select>
     75        name="groups[]" multiple style="width:600px;"></select>
    13476{else}
    13577    {'There is no group in this gallery.'|@translate} <a href="admin.php?page=group_list" class="externalLink">{'Group management'|@translate}</a>
     
    14183    <br>
    14284    <select data-selectize="users" data-value="{$users_selected|@json_encode|escape:html}"
    143         name="users[]" multiple style="width:600px;" ></select>
     85        name="users[]" multiple style="width:600px;"></select>
    14486  </p>
    14587
Note: See TracChangeset for help on using the changeset viewer.