Ignore:
Timestamp:
May 28, 2014, 9:04:40 PM (10 years ago)
Author:
mistic100
Message:

feature 3077 : fix addAlbum process when creating the first ever album, improve data API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/js/addAlbum.js

    r28552 r28555  
    55 
    66  var $popup = jQuery('#addAlbumForm');
    7   if (!$popup.data('init')) {
    8     $popup.find('[name="category_parent"]').selectize({
    9       valueField: 'id',
    10       labelField: 'fullname',
    11       sortField: 'global_rank',
    12       searchField: ['fullname'],
    13       plugins: ['remove_button'],
    14       onInitialize: function() {
    15         this.on('dropdown_close', function() {
    16           if (this.getValue() == '') {
    17             this.setValue(0);
    18           }
     7 
     8  function init() {
     9    if ($popup.data('init')) {
     10      return;
     11    }
     12    $popup.data('init', true);
     13   
     14    options.cache.selectize($popup.find('[name="category_parent"]'), {
     15      'default': 0,
     16      'filter': function(categories) {
     17        categories.push({
     18          id: 0,
     19          fullname: '------------',
     20          global_rank: 0
    1921        });
     22       
     23        return categories;
    2024      }
    2125    });
     
    4852
    4953          var newAlbum = data.result.id,
    50               newAlbum_name = '';
     54              newAlbum_name = '',
     55              newAlbum_rank = '0';
    5156             
    5257          if (parent_id != 0) {
    5358            newAlbum_name = albumParent[0].selectize.options[parent_id].fullname +' / ';
     59            newAlbum_rank = albumParent[0].selectize.options[parent_id].global_rank +'.1';
    5460          }
    5561          newAlbum_name+= name;
     
    7581          // target is selectize
    7682          else {
    77             $albumSelect[0].selectize.addOption({
    78               id: newAlbum,
    79               fullname: newAlbum_name
    80             });
     83            var selectize = $albumSelect[0].selectize;
    8184           
    82             $albumSelect[0].selectize.setValue(newAlbum);
     85            if (jQuery.isEmptyObject(selectize.options)) {
     86              options.cache.clear();
     87              options.cache.selectize($albumSelect, {
     88                'default': newAlbum,
     89                'value': newAlbum
     90              });
     91            }
     92            else {
     93              $albumSelect[0].selectize.addOption({
     94                id: newAlbum,
     95                fullname: newAlbum_name,
     96                global_rank: newAlbum_rank
     97              });
     98             
     99              $albumSelect[0].selectize.setValue(newAlbum);
     100            }
    83101          }
    84102
     
    99117    width: 350, height: 300,
    100118    onComplete: function() {
    101       var albumParent = $popup.find('[name="category_parent"]')[0];
    102      
     119      init();
    103120      $popup.data('target', jQuery(this).data('addAlbum'));
    104 
    105       albumParent.selectize.clearOptions();
    106      
    107       options.cache.get(function(categories) {
    108         categories.push({
    109           id: 0,
    110           fullname: '------------',
    111           global_rank: 0
    112         });
    113        
    114         albumParent.selectize.load(function(callback) {
    115           callback(categories);
    116         });
    117        
    118         albumParent.selectize.setValue(0);
    119       });
     121      $popup.find('[name=category_name]').focus();
    120122    }
    121123  });
Note: See TracChangeset for help on using the changeset viewer.