Changeset 28555


Ignore:
Timestamp:
05/28/14 21:04:40 (5 years ago)
Author:
mistic100
Message:

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

Location:
trunk/admin/themes/default
Files:
8 edited

Legend:

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

    r28550 r28555  
    8585  /* 
    8686   * Load Selectize with cache content 
    87    * @param $target {jQuery} 
    88    * @param options {object} 
     87   * @param $target {jQuery} may have some data attributes (create, default, value) 
     88   * @param options {object} 
     89   *    - value (optional) list of preselected items (ids, or objects with "id" attribute") 
    8990   *    - default (optional) default value which will be forced if the select is emptyed 
     91   *    - create (optional) allow item user creation 
    9092   *    - filter (optional) function called for each select before applying the data 
    9193   *      takes two parameters: cache data, options 
    9294   *      must return new data 
    9395   */ 
    94   AbstractSelectizer.prototype._selectize = function($target, options) { 
     96  AbstractSelectizer.prototype._selectize = function($target, globalOptions) { 
    9597    this.get(function(data) { 
    9698      $target.each(function() { 
    97         var filtered, value; 
     99        var filtered, value, defaultValue, 
     100            options = $.extend({}, globalOptions); 
    98101         
    99102        // apply filter function 
     
    106109         
    107110        // active creation mode 
    108         if (this.hasAttribute('data-selectize-create')) { 
    109           this.selectize.settings.create = true; 
    110         } 
    111          
     111        if (this.hasAttribute('data-create')) { 
     112          options.create = true; 
     113        } 
     114        this.selectize.settings.create = !!options.create; 
     115 
    112116        // load options 
    113117        this.selectize.load(function(callback) { 
     
    119123        // load items 
    120124        if ((value = $(this).data('value'))) { 
     125          options.value = value; 
     126        } 
     127        if (options.value != undefined) { 
    121128          $.each(value, $.proxy(function(i, cat) { 
    122129            if ($.isNumeric(cat)) 
     
    125132              this.selectize.addItem(cat.id); 
    126133          }, this)); 
     134        } 
     135         
     136        // set default 
     137        if ((defaultValue = $(this).data('default'))) { 
     138          options.default = defaultValue; 
     139        } 
     140        if (options.default == 'first') { 
     141          options.default = filtered[0] ? filtered[0].id : undefined; 
    127142        } 
    128143         
  • 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  }); 
  • trunk/admin/themes/default/template/batch_manager_global.tpl

    r28550 r28555  
    9999      } 
    100100      else { 
    101         options.default = categories[0].id; 
    102101        return categories; 
    103102      } 
     
    604603        {'Album'|@translate} 
    605604        <select data-selectize="categories" data-value="{$filter_category_selected|@json_encode|escape:html}" 
    606           name="filter_category" style="width:400px"></select> 
     605          data-default="first" name="filter_category" style="width:400px"></select> 
    607606        <label><input type="checkbox" name="filter_category_recursive" {if isset($filter.category_recursive)}checked="checked"{/if}> {'include child albums'|@translate}</label> 
    608607      </li> 
     
    613612        {'Tags'|@translate} 
    614613        <select data-selectize="tags" data-value="{$filter_tags|@json_encode|escape:html}" 
     614          placeholder="{'Type in a search term'|translate}" 
    615615          name="filter_tags[]" multiple style="width:400px;"></select> 
    616616        <label><span><input type="radio" name="tag_mode" value="AND" {if !isset($filter.tag_mode) or $filter.tag_mode eq 'AND'}checked="checked"{/if}> {'All tags'|@translate}</span></label> 
     
    812812    <!-- associate --> 
    813813    <div id="action_associate" class="bulkAction"> 
    814       <select data-selectize="categories" name="associate" style="width:400px"></select> 
     814      <select data-selectize="categories" data-default="first" name="associate" style="width:400px"></select> 
    815815      <br>{'... or '|@translate} 
    816816      <a href="#" data-add-album="associate" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a> 
     
    819819    <!-- move --> 
    820820    <div id="action_move" class="bulkAction"> 
    821       <select data-selectize="categories" name="move" style="width:400px"></select> 
     821      <select data-selectize="categories" data-default="first" name="move" style="width:400px"></select> 
    822822      <br>{'... or '|@translate} 
    823823      <a href="#" data-add-album="move" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a> 
     
    827827    <!-- dissociate --> 
    828828    <div id="action_dissociate" class="bulkAction albumDissociate" style="display:none"> 
    829       <select data-selectize="categories" name="dissociate" style="width:400px"></select> 
     829      <select data-selectize="categories" placeholder="{'Type in a search term'|translate}" 
     830        name="dissociate" style="width:400px"></select> 
    830831    </div> 
    831832 
     
    833834    <!-- add_tags --> 
    834835    <div id="action_add_tags" class="bulkAction"> 
    835       <select data-selectize="tags" data-selectize-create name="add_tags[]" multiple style="width:400px;"></select> 
     836      <select data-selectize="tags" data-create="true" placeholder="{'Type in a search term'|translate}" 
     837        name="add_tags[]" multiple style="width:400px;"></select> 
    836838    </div> 
    837839 
     
    839841    <div id="action_del_tags" class="bulkAction"> 
    840842{if !empty($associated_tags)} 
    841       <select data-selectize="tags" name="del_tags[]" multiple style="width:400px;"> 
     843      <select data-selectize="tags" name="del_tags[]" multiple style="width:400px;" 
     844        placeholder="{'Type in a search term'|translate}"> 
    842845      {foreach from=$associated_tags item=tag} 
    843846        <option value="{$tag.id}">{$tag.name}</option> 
  • trunk/admin/themes/default/template/batch_manager_unit.tpl

    r28550 r28555  
    9999      <td> 
    100100        <select data-selectize="tags" data-value="{$element.TAGS|@json_encode|escape:html}" 
    101           name="tags-{$element.id}[]" multiple style="width:500px;" data-selectize-create></select> 
     101          placeholder="{'Type in a search term'|translate}" 
     102          data-create="true" name="tags-{$element.id}[]" multiple style="width:500px;"></select> 
    102103      </td> 
    103104    </tr> 
  • trunk/admin/themes/default/template/cat_perm.tpl

    r28550 r28555  
    7373    <br> 
    7474    <select data-selectize="groups" data-value="{$groups_selected|@json_encode|escape:html}" 
    75         name="groups[]" multiple style="width:600px;"></select> 
     75      placeholder="{'Type in a search term'|translate}" 
     76      name="groups[]" multiple style="width:600px;"></select> 
    7677{else} 
    7778    {'There is no group in this gallery.'|@translate} <a href="admin.php?page=group_list" class="externalLink">{'Group management'|@translate}</a> 
     
    8384    <br> 
    8485    <select data-selectize="users" data-value="{$users_selected|@json_encode|escape:html}" 
    85         name="users[]" multiple style="width:600px;"></select> 
     86      placeholder="{'Type in a search term'|translate}" 
     87      name="users[]" multiple style="width:600px;"></select> 
    8688  </p> 
    8789 
  • trunk/admin/themes/default/template/photos_add_direct.tpl

    r28554 r28555  
    2828    if (categories.length > 0) { 
    2929      jQuery("#albumSelection, .selectFiles, .showFieldset").show(); 
    30       options.default = categories[0].id; 
    3130    } 
    3231     
     
    202201      <span id="albumSelection" style="display:none"> 
    203202      <select data-selectize="categories" data-value="{$selected_category|@json_encode|escape:html}" 
    204         name="category" style="width:400px"></select> 
     203        data-default="first" name="category" style="width:400px"></select> 
    205204      <br>{'... or '|@translate}</span> 
    206205      <a href="#" data-add-album="category" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a> 
  • trunk/admin/themes/default/template/picture_modify.tpl

    r28550 r28555  
    1717}); 
    1818 
    19 categoriesCache.selectize(jQuery('[data-selectize=categories]'), { {if $STORAGE_ALBUM} 
    20   filter: function(categories, options) { 
    21     options.default = (this.name == 'associate[]') ? {$STORAGE_ALBUM} : undefined; 
    22     return categories; 
    23   } 
    24 {/if} }); 
     19categoriesCache.selectize(jQuery('[data-selectize=categories]')); 
    2520 
    2621{* <!-- TAGS --> *} 
     
    110105      <br> 
    111106      <select data-selectize="categories" data-value="{$associated_albums|@json_encode|escape:html}" 
    112         name="associate[]" multiple style="width:600px;"></select> 
     107        placeholder="{'Type in a search term'|translate}" 
     108        data-default="{$STORAGE_ALBUM}" name="associate[]" multiple style="width:600px;"></select> 
    113109    </p> 
    114110 
     
    117113      <br> 
    118114      <select data-selectize="categories" data-value="{$represented_albums|@json_encode|escape:html}" 
     115        placeholder="{'Type in a search term'|translate}" 
    119116        name="represent[]" multiple style="width:600px;"></select> 
    120117    </p> 
     
    124121      <br> 
    125122      <select data-selectize="tags" data-value="{$tag_selection|@json_encode|escape:html}" 
    126         name="tags[]" multiple style="width:600px;" data-selectize-create></select> 
     123        placeholder="{'Type in a search term'|translate}" 
     124        data-create="true" name="tags[]" multiple style="width:600px;"</select> 
    127125    </p> 
    128126 
  • trunk/admin/themes/default/template/user_list.tpl

    r28501 r28555  
    11051105 
    11061106      <div class="userProperty"><strong>{'Groups'|translate}</strong><br> 
    1107         <select data-selectize="groups" name="group_id[]" multiple style="width:340px;"></select> 
     1107        <select data-selectize="groups" placeholder="{'Type in a search term'|translate}"  
     1108          name="group_id[]" multiple style="width:340px;"></select> 
    11081109      </div> 
    11091110    </div> 
Note: See TracChangeset for help on using the changeset viewer.