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

    r28540 r28542  
    120120 
    121121  {* <!-- CATEGORIES --> *}
    122   var categoriesCache = new LocalStorageCache({
    123     key: 'categoriesAdminList',
     122  var categoriesCache = new CategoriesCache({
    124123    serverKey: '{$CACHE_KEYS.categories}',
    125124    serverId: '{$CACHE_KEYS._hash}',
    126 
    127     loader: function(callback) {
    128       jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) {
    129         callback(data.result.categories);
    130       });
    131     }
     125    rootUrl: '{$ROOT_URL}'
    132126  });
    133127 
    134   jQuery('[data-selectize=categories]').selectize({
    135     valueField: 'id',
    136     labelField: 'fullname',
    137     sortField: 'global_rank',
    138     searchField: ['fullname'],
    139     plugins: ['remove_button']
    140   });
    141  
    142   categoriesCache.get(function(categories) {
    143     jQuery('[data-selectize=categories]').each(function() {
    144       this.selectize.load(function(callback) {
    145         callback(categories);
    146       });
    147 
    148       if (jQuery(this).data('value')) {
    149         this.selectize.setValue(jQuery(this).data('value')[0]);
     128  categoriesCache.selectize(jQuery('[data-selectize=categories]'), {
     129    filter: function(categories, options) {
     130      if (this.name == 'dissociate') {
     131        var filtered = jQuery.grep(categories, function(cat) {
     132          return !cat.dir;
     133        });
     134       
     135        if (filtered.length > 0) {
     136          jQuery('.albumDissociate').show();
     137          options.default = filtered[0].id;
     138        }
     139       
     140        return filtered;
    150141      }
    151      
    152       // prevent empty value
    153       if (this.selectize.getValue() == '') {
    154         this.selectize.setValue(categories[0].id);
     142      else {
     143        options.default = categories[0].id;
     144        return categories;
    155145      }
    156       this.selectize.on('dropdown_close', function() {
    157         if (this.getValue() == '') {
    158           this.setValue(categories[0].id);
    159         }
    160       });
    161     });
     146    }
    162147  });
    163148 
     
    838823      <option value="associate">{'Associate to album'|@translate}</option>
    839824      <option value="move">{'Move to album'|@translate}</option>
    840   {if !empty($dissociate_options)}
    841       <option value="dissociate">{'Dissociate from album'|@translate}</option>
    842   {/if}
     825      <option value="dissociate" class="albumDissociate" style="display:none">{'Dissociate from album'|@translate}</option>
    843826      <option value="add_tags">{'Add tags'|@translate}</option>
    844827  {if !empty($associated_tags)}
     
    885868
    886869    <!-- dissociate -->
    887     <div id="action_dissociate" class="bulkAction">
     870    <div id="action_dissociate" class="bulkAction albumDissociate" style="display:none">
    888871      <select data-selectize="categories" name="dissociate" style="width:400px"></select>
    889872    </div>
Note: See TracChangeset for help on using the changeset viewer.