Changeset 30633


Ignore:
Timestamp:
Nov 30, 2014, 6:42:18 PM (9 years ago)
Author:
mistic100
Message:

Merged revision(s) 30630 from trunk:
bug 3183: Improve album creation
update popup selectize with new album
init popup selectize with main selectize value

Location:
branches/2.7/admin/themes/default
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.7/admin/themes/default/js/LocalStorageCache.js

    r29613 r30633  
    9595   */
    9696  AbstractSelectizer.prototype._selectize = function($target, globalOptions) {
     97    $target.data('cache', this);
     98
    9799    this.get(function(data) {
    98100      $target.each(function() {
  • branches/2.7/admin/themes/default/js/addAlbum.js

    r29619 r30633  
    11jQuery.fn.pwgAddAlbum = function(options) {
    2   if (!options.cache) {
     2  options = options || {};
     3
     4  var $popup = jQuery('#addAlbumForm'),
     5      $albumParent = $popup.find('[name="category_parent"]')
     6      $button = jQuery(this),
     7      $target = jQuery('[name="'+ $button.data('addAlbum') +'"]'),
     8      cache = $target.data('cache');
     9
     10  if (!$target[0].selectize) {
     11    jQuery.error('pwgAddAlbum: target must use selectize');
     12  }
     13  if (!cache) {
    314    jQuery.error('pwgAddAlbum: missing categories cache');
    415  }
    5  
    6   var $popup = jQuery('#addAlbumForm');
    7  
     16
    817  function init() {
    9     if ($popup.data('init')) {
    10       return;
    11     }
    1218    $popup.data('init', true);
    13    
    14     options.cache.selectize($popup.find('[name="category_parent"]'), {
     19
     20    cache.selectize($albumParent, {
    1521      'default': 0,
    1622      'filter': function(categories) {
     
    2026          global_rank: 0
    2127        });
    22        
     28
     29        if (options.filter) {
     30          categories = options.filter.call(this, categories);
     31        }
     32
    2333        return categories;
    2434      }
    2535    });
    26    
     36
    2737    $popup.find('form').on('submit', function(e) {
    2838      e.preventDefault();
    29      
    30       jQuery('#categoryNameError').text('');
    31      
    32       var albumParent = $popup.find('[name="category_parent"]'),
    33           parent_id = albumParent.val(),
    34           name = $popup.find('[name=category_name]').val(),
    35           target = $popup.data('target');
     39
     40      var parent_id = $albumParent.val(),
     41          name = $popup.find('[name=category_name]').val();
     42         
     43      jQuery('#categoryNameError').toggle(!name);
     44      if (!name) {
     45        return;
     46      }
    3647
    3748      jQuery.ajax({
     
    4960        success: function(data) {
    5061          jQuery('#albumCreationLoading').hide();
    51           jQuery('[data-add-album="'+ target +'"]').colorbox.close();
     62          $button.colorbox.close();
    5263
    53           var newAlbum = data.result.id,
    54               newAlbum_name = '',
    55               newAlbum_rank = '0';
    56              
     64          var newAlbum = {
     65            id: data.result.id,
     66            name: name,
     67            fullname: name,
     68            global_rank: '0',
     69            dir: null,
     70            nb_images: 0,
     71            pos: 0
     72          };
     73
     74          var parentSelectize = $albumParent[0].selectize;
     75
    5776          if (parent_id != 0) {
    58             newAlbum_name = albumParent[0].selectize.options[parent_id].fullname +' / ';
    59             newAlbum_rank = albumParent[0].selectize.options[parent_id].global_rank +'.1';
    60           }
    61           newAlbum_name+= name;
    62          
    63           var $albumSelect = jQuery('[name="'+ target +'"]');
    64          
    65           // target is a normal select
    66           if (!$albumSelect[0].selectize) {
    67             var new_option = jQuery('<option/>')
    68                 .attr('value', newAlbum)
    69                 .attr('selected', 'selected')
    70                 .text(newAlbum_name);
    71 
    72             $albumSelect.find('option').removeAttr('selected');
    73            
    74             if (parent_id==0) {
    75               $albumSelect.prepend(new_option);
    76             }
    77             else {
    78               $albumSelect.find('option[value='+ parent_id +']').after(new_option);
    79             }
    80           }
    81           // target is selectize
    82           else {
    83             var selectize = $albumSelect[0].selectize;
    84            
    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             }
     77            var parent = parentSelectize.options[parent_id];
     78            newAlbum.fullname = parent.fullname + ' / ' + newAlbum.fullname;
     79            newAlbum.global_rank = parent.global_rank + '.1';
     80            newAlbum.pos = parent.pos + 1;
    10181          }
    10282
    103           albumParent.val('');
    104           jQuery('#albumSelection, .selectFiles, .showFieldset').show();
     83          var targetSelectize = $target[0].selectize;
     84          targetSelectize.addOption(newAlbum);
     85          targetSelectize.setValue(newAlbum.id);
     86
     87          parentSelectize.addOption(newAlbum);
     88
     89          if (options.afterSelect) {
     90            options.afterSelect();
     91          }
    10592        },
    10693        error: function(XMLHttpRequest, textStatus, errorThrows) {
    10794            jQuery('#albumCreationLoading').hide();
    108             jQuery('#categoryNameError').text(errorThrows).css('color', 'red');
     95            alert(errorThrows);
    10996        }
    11097      });
    11198    });
    11299  }
    113  
     100
    114101  this.colorbox({
    115102    inline: true,
     
    117104    width: 650, height: 300,
    118105    onComplete: function() {
    119       init();
    120       $popup.data('target', jQuery(this).data('addAlbum'));
    121       $popup.find('[name=category_name]').focus();
     106      if (!$popup.data('init')) {
     107        init();
     108      }
     109
     110      jQuery('#categoryNameError').hide();
     111      $popup.find('[name=category_name]').val('').focus();
     112      $albumParent[0].selectize.setValue($target.val() || 0);
    122113    }
    123114  });
    124  
     115
    125116  return this;
    126117};
  • branches/2.7/admin/themes/default/js/batchManagerGlobal.js

    r29249 r30633  
    112112});
    113113
    114 jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
     114jQuery('[data-add-album]').pwgAddAlbum();
    115115
    116116$("input[name=remove_author]").click(function () {
  • branches/2.7/admin/themes/default/template/include/add_album.inc.tpl

    r29389 r30633  
    1515     
    1616      {'Album name'|@translate}<br>
    17       <input name="category_name" type="text" maxlength="255"> <span id="categoryNameError"></span>
     17      <input name="category_name" type="text" maxlength="255">
     18      <span id="categoryNameError" style="color:red;">{'The name of an album must not be empty'|translate}</span>
    1819      <br><br><br>
    1920     
  • branches/2.7/admin/themes/default/template/photos_add_direct.tpl

    r29903 r30633  
    3939});
    4040
    41 jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
     41jQuery('[data-add-album]').pwgAddAlbum({
     42  afterSelect: function() {
     43    jQuery("#albumSelection, .selectFiles, .showFieldset").show();
     44  }
     45});
    4246
    4347var pwg_token = '{$pwg_token}';
Note: See TracChangeset for help on using the changeset viewer.