From 9a842dd86af254aa5d2212d0e3e4a10961aef492 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Wed, 28 May 2014 19:04:40 +0000 Subject: feature 3077 : fix addAlbum process when creating the first ever album, improve data API git-svn-id: http://piwigo.org/svn/trunk@28555 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/themes/default/js/LocalStorageCache.js | 27 ++++++-- admin/themes/default/js/addAlbum.js | 74 +++++++++++----------- .../default/template/batch_manager_global.tpl | 17 +++-- .../themes/default/template/batch_manager_unit.tpl | 3 +- admin/themes/default/template/cat_perm.tpl | 6 +- .../themes/default/template/photos_add_direct.tpl | 3 +- admin/themes/default/template/picture_modify.tpl | 14 ++-- admin/themes/default/template/user_list.tpl | 3 +- 8 files changed, 84 insertions(+), 63 deletions(-) diff --git a/admin/themes/default/js/LocalStorageCache.js b/admin/themes/default/js/LocalStorageCache.js index b2712dadf..67e804062 100644 --- a/admin/themes/default/js/LocalStorageCache.js +++ b/admin/themes/default/js/LocalStorageCache.js @@ -84,17 +84,20 @@ /* * Load Selectize with cache content - * @param $target {jQuery} + * @param $target {jQuery} may have some data attributes (create, default, value) * @param options {object} + * - value (optional) list of preselected items (ids, or objects with "id" attribute") * - default (optional) default value which will be forced if the select is emptyed + * - create (optional) allow item user creation * - filter (optional) function called for each select before applying the data * takes two parameters: cache data, options * must return new data */ - AbstractSelectizer.prototype._selectize = function($target, options) { + AbstractSelectizer.prototype._selectize = function($target, globalOptions) { this.get(function(data) { $target.each(function() { - var filtered, value; + var filtered, value, defaultValue, + options = $.extend({}, globalOptions); // apply filter function if (options.filter != undefined) { @@ -105,10 +108,11 @@ } // active creation mode - if (this.hasAttribute('data-selectize-create')) { - this.selectize.settings.create = true; + if (this.hasAttribute('data-create')) { + options.create = true; } - + this.selectize.settings.create = !!options.create; + // load options this.selectize.load(function(callback) { if ($.isEmptyObject(this.options)) { @@ -118,6 +122,9 @@ // load items if ((value = $(this).data('value'))) { + options.value = value; + } + if (options.value != undefined) { $.each(value, $.proxy(function(i, cat) { if ($.isNumeric(cat)) this.selectize.addItem(cat); @@ -126,6 +133,14 @@ }, this)); } + // set default + if ((defaultValue = $(this).data('default'))) { + options.default = defaultValue; + } + if (options.default == 'first') { + options.default = filtered[0] ? filtered[0].id : undefined; + } + if (options.default != undefined) { // add default item if (this.selectize.getValue() == '') { diff --git a/admin/themes/default/js/addAlbum.js b/admin/themes/default/js/addAlbum.js index 0efdd8c95..02fb25f0d 100644 --- a/admin/themes/default/js/addAlbum.js +++ b/admin/themes/default/js/addAlbum.js @@ -4,19 +4,23 @@ jQuery.fn.pwgAddAlbum = function(options) { } var $popup = jQuery('#addAlbumForm'); - if (!$popup.data('init')) { - $popup.find('[name="category_parent"]').selectize({ - valueField: 'id', - labelField: 'fullname', - sortField: 'global_rank', - searchField: ['fullname'], - plugins: ['remove_button'], - onInitialize: function() { - this.on('dropdown_close', function() { - if (this.getValue() == '') { - this.setValue(0); - } + + function init() { + if ($popup.data('init')) { + return; + } + $popup.data('init', true); + + options.cache.selectize($popup.find('[name="category_parent"]'), { + 'default': 0, + 'filter': function(categories) { + categories.push({ + id: 0, + fullname: '------------', + global_rank: 0 }); + + return categories; } }); @@ -47,10 +51,12 @@ jQuery.fn.pwgAddAlbum = function(options) { jQuery('[data-add-album="'+ target +'"]').colorbox.close(); var newAlbum = data.result.id, - newAlbum_name = ''; + newAlbum_name = '', + newAlbum_rank = '0'; if (parent_id != 0) { newAlbum_name = albumParent[0].selectize.options[parent_id].fullname +' / '; + newAlbum_rank = albumParent[0].selectize.options[parent_id].global_rank +'.1'; } newAlbum_name+= name; @@ -74,12 +80,24 @@ jQuery.fn.pwgAddAlbum = function(options) { } // target is selectize else { - $albumSelect[0].selectize.addOption({ - id: newAlbum, - fullname: newAlbum_name - }); + var selectize = $albumSelect[0].selectize; - $albumSelect[0].selectize.setValue(newAlbum); + if (jQuery.isEmptyObject(selectize.options)) { + options.cache.clear(); + options.cache.selectize($albumSelect, { + 'default': newAlbum, + 'value': newAlbum + }); + } + else { + $albumSelect[0].selectize.addOption({ + id: newAlbum, + fullname: newAlbum_name, + global_rank: newAlbum_rank + }); + + $albumSelect[0].selectize.setValue(newAlbum); + } } albumParent.val(''); @@ -98,25 +116,9 @@ jQuery.fn.pwgAddAlbum = function(options) { href: '#addAlbumForm', width: 350, height: 300, onComplete: function() { - var albumParent = $popup.find('[name="category_parent"]')[0]; - + init(); $popup.data('target', jQuery(this).data('addAlbum')); - - albumParent.selectize.clearOptions(); - - options.cache.get(function(categories) { - categories.push({ - id: 0, - fullname: '------------', - global_rank: 0 - }); - - albumParent.selectize.load(function(callback) { - callback(categories); - }); - - albumParent.selectize.setValue(0); - }); + $popup.find('[name=category_name]').focus(); } }); diff --git a/admin/themes/default/template/batch_manager_global.tpl b/admin/themes/default/template/batch_manager_global.tpl index 00cdc50f3..971fb90fb 100644 --- a/admin/themes/default/template/batch_manager_global.tpl +++ b/admin/themes/default/template/batch_manager_global.tpl @@ -98,7 +98,6 @@ jQuery(document).ready(function() {ldelim} return filtered; } else { - options.default = categories[0].id; return categories; } } @@ -603,7 +602,7 @@ $(document).ready(function() { {'Album'|@translate} + data-default="first" name="filter_category" style="width:400px"> @@ -612,6 +611,7 @@ $(document).ready(function() { {'Tags'|@translate} @@ -811,14 +811,14 @@ UL.thumbnails SPAN.wrap2 {ldelim}
- +
{'... or '|@translate} {'create a new album'|@translate}
- +
{'... or '|@translate} {'create a new album'|@translate}
@@ -826,19 +826,22 @@ UL.thumbnails SPAN.wrap2 {ldelim}
- +
{if !empty($associated_tags)} - {foreach from=$associated_tags item=tag} {/foreach} diff --git a/admin/themes/default/template/batch_manager_unit.tpl b/admin/themes/default/template/batch_manager_unit.tpl index 27f8cd721..dd7b5aa64 100644 --- a/admin/themes/default/template/batch_manager_unit.tpl +++ b/admin/themes/default/template/batch_manager_unit.tpl @@ -98,7 +98,8 @@ $(".elementEdit img") {'Tags'|@translate} + placeholder="{'Type in a search term'|translate}" + data-create="true" name="tags-{$element.id}[]" multiple style="width:500px;"> diff --git a/admin/themes/default/template/cat_perm.tpl b/admin/themes/default/template/cat_perm.tpl index edaab262a..52272e06b 100644 --- a/admin/themes/default/template/cat_perm.tpl +++ b/admin/themes/default/template/cat_perm.tpl @@ -72,7 +72,8 @@ jQuery("#selectStatus").change(function() { {'Permission granted for groups'|@translate}
+ placeholder="{'Type in a search term'|translate}" + name="groups[]" multiple style="width:600px;"> {else} {'There is no group in this gallery.'|@translate} {'Group management'|@translate} {/if} @@ -82,7 +83,8 @@ jQuery("#selectStatus").change(function() { {'Permission granted for users'|@translate}
+ placeholder="{'Type in a search term'|translate}" + name="users[]" multiple style="width:600px;">

{if isset($nb_users_granted_indirect) && $nb_users_granted_indirect>0} diff --git a/admin/themes/default/template/photos_add_direct.tpl b/admin/themes/default/template/photos_add_direct.tpl index 0a23ca8f0..39eb856cc 100644 --- a/admin/themes/default/template/photos_add_direct.tpl +++ b/admin/themes/default/template/photos_add_direct.tpl @@ -27,7 +27,6 @@ categoriesCache.selectize(jQuery('[data-selectize=categories]'), { filter: function(categories, options) { if (categories.length > 0) { jQuery("#albumSelection, .selectFiles, .showFieldset").show(); - options.default = categories[0].id; } return categories; @@ -201,7 +200,7 @@ jQuery(document).ready(function(){ {'create a new album'|@translate} diff --git a/admin/themes/default/template/picture_modify.tpl b/admin/themes/default/template/picture_modify.tpl index 60c98140d..21033be92 100644 --- a/admin/themes/default/template/picture_modify.tpl +++ b/admin/themes/default/template/picture_modify.tpl @@ -16,12 +16,7 @@ var categoriesCache = new CategoriesCache({ rootUrl: '{$ROOT_URL}' }); -categoriesCache.selectize(jQuery('[data-selectize=categories]'), { {if $STORAGE_ALBUM} - filter: function(categories, options) { - options.default = (this.name == 'associate[]') ? {$STORAGE_ALBUM} : undefined; - return categories; - } -{/if} }); +categoriesCache.selectize(jQuery('[data-selectize=categories]')); {* *} var tagsCache = new TagsCache({ @@ -109,13 +104,15 @@ jQuery(function(){ {* *} {'Linked albums'|@translate}
+ placeholder="{'Type in a search term'|translate}" + data-default="{$STORAGE_ALBUM}" name="associate[]" multiple style="width:600px;">

{'Representation of albums'|@translate}

@@ -123,7 +120,8 @@ jQuery(function(){ {* *} {'Tags'|@translate}
+ placeholder="{'Type in a search term'|translate}" + data-create="true" name="tags[]" multiple style="width:600px;"

diff --git a/admin/themes/default/template/user_list.tpl b/admin/themes/default/template/user_list.tpl index fbbaf873d..e55f2f9e0 100644 --- a/admin/themes/default/template/user_list.tpl +++ b/admin/themes/default/template/user_list.tpl @@ -1104,7 +1104,8 @@ span.infos, span.errors {background-image:none; padding:2px 5px; margin:0;border

{'Groups'|translate}
- +
-- cgit v1.2.3