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/photos_add_direct.tpl

    r28540 r28542  
    1717{footer_script}
    1818{* <!-- CATEGORIES --> *}
    19 var categoriesCache = new LocalStorageCache({
    20   key: 'categoriesAdminList',
     19var categoriesCache = new CategoriesCache({
    2120  serverKey: '{$CACHE_KEYS.categories}',
    2221  serverId: '{$CACHE_KEYS._hash}',
    23 
    24   loader: function(callback) {
    25     jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) {
    26       callback(data.result.categories);
    27     });
     22  rootUrl: '{$ROOT_URL}'
     23});
     24
     25categoriesCache.selectize(jQuery('[data-selectize=categories]'), {
     26  filter: function(categories, options) {
     27    if (categories.length > 0) {
     28      jQuery("#albumSelection").show();
     29      options.default = categories[0].id;
     30    }
     31   
     32    return categories;
    2833  }
    29 });
    30 
    31 jQuery('[data-selectize=categories]').selectize({
    32   valueField: 'id',
    33   labelField: 'fullname',
    34   sortField: 'global_rank',
    35   searchField: ['fullname'],
    36   plugins: ['remove_button']
    37 });
    38 
    39 categoriesCache.get(function(categories) {
    40   if (categories.length > 0) {
    41     jQuery("#albumSelection").show();
    42   }
    43  
    44   jQuery('[data-selectize=categories]').each(function() {
    45     this.selectize.load(function(callback) {
    46       callback(categories);
    47     });
    48 
    49     if (jQuery(this).data('value')) {
    50       this.selectize.setValue(jQuery(this).data('value')[0]);
    51     }
    52    
    53     // prevent empty value
    54     if (this.selectize.getValue() == '') {
    55       this.selectize.setValue(categories[0].id);
    56     }
    57     this.selectize.on('dropdown_close', function() {
    58       if (this.getValue() == '') {
    59         this.setValue(categories[0].id);
    60       }
    61     });
    62   });
    6334});
    6435
Note: See TracChangeset for help on using the changeset viewer.