Ignore:
Timestamp:
May 27, 2014, 12:03:57 AM (10 years ago)
Author:
mistic100
Message:

feature 3077 : factorize code for categories cache (TODO for other collections) + fix incorrect categories list for dissociation

File:
1 edited

Legend:

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

    r28540 r28542  
    66{footer_script}
    77{* <!-- CATEGORIES --> *}
    8 var categoriesCache = new LocalStorageCache({
    9   key: 'categoriesAdminList',
     8var categoriesCache = new CategoriesCache({
    109  serverKey: '{$CACHE_KEYS.categories}',
    1110  serverId: '{$CACHE_KEYS._hash}',
    12 
    13   loader: function(callback) {
    14     jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) {
    15       callback(data.result.categories);
    16     });
    17   }
     11  rootUrl: '{$ROOT_URL}'
    1812});
    1913
    20 jQuery('[data-selectize=categories]').selectize({
    21   valueField: 'id',
    22   labelField: 'fullname',
    23   sortField: 'global_rank',
    24   searchField: ['fullname'],
    25   plugins: ['remove_button']
    26 });
    27 
    28 categoriesCache.get(function(categories) {
    29   categories.push({
    30     id: 0,
    31     fullname: '------------',
    32     global_rank: 0
    33   });
    34  
    35   // remove itself and children
    36   categories = jQuery.grep(categories, function(cat) {
    37     return !(/\b{$CAT_ID}\b/.test(cat.uppercats));
    38   });
    39  
    40   jQuery('[data-selectize=categories]').each(function() {
    41     this.selectize.load(function(callback) {
    42       callback(categories);
     14categoriesCache.selectize(jQuery('[data-selectize=categories]'), {
     15  default: 0,
     16  filter: function(categories, options) {
     17    // remove itself and children
     18    var filtered = jQuery.grep(categories, function(cat) {
     19      return !(/\b{$CAT_ID}\b/.test(cat.uppercats));
    4320    });
    44 
    45     if (jQuery(this).data('value')) {
    46       this.selectize.setValue(jQuery(this).data('value')[0]);
    47     }
    4821   
    49     // prevent empty value
    50     if (this.selectize.getValue() == '') {
    51       this.selectize.setValue(0);
    52     }
    53     this.selectize.on('dropdown_close', function() {
    54       if (this.getValue() == '') {
    55         this.setValue(0);
    56       }
     22    filtered.push({
     23      id: 0,
     24      fullname: '------------',
     25      global_rank: 0
    5726    });
    58   });
     27   
     28    return filtered;
     29  }
    5930});
    6031{/footer_script}
Note: See TracChangeset for help on using the changeset viewer.