From bd4ff9fe713ed0b9ee122cf7812939f794c601d8 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 30 Nov 2014 17:42:18 +0000 Subject: Merged revision(s) 30630 from trunk: bug 3183: Improve album creation update popup selectize with new album init popup selectize with main selectize value git-svn-id: http://piwigo.org/svn/branches/2.7@30633 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/themes/default/js/LocalStorageCache.js | 2 + admin/themes/default/js/addAlbum.js | 139 ++++++++++----------- admin/themes/default/js/batchManagerGlobal.js | 2 +- .../default/template/include/add_album.inc.tpl | 3 +- .../themes/default/template/photos_add_direct.tpl | 6 +- 5 files changed, 75 insertions(+), 77 deletions(-) diff --git a/admin/themes/default/js/LocalStorageCache.js b/admin/themes/default/js/LocalStorageCache.js index e585e2acd..55e4b36fb 100644 --- a/admin/themes/default/js/LocalStorageCache.js +++ b/admin/themes/default/js/LocalStorageCache.js @@ -94,6 +94,8 @@ * must return new data */ AbstractSelectizer.prototype._selectize = function($target, globalOptions) { + $target.data('cache', this); + this.get(function(data) { $target.each(function() { var filtered, value, defaultValue, diff --git a/admin/themes/default/js/addAlbum.js b/admin/themes/default/js/addAlbum.js index 8ada8bb30..b30c2bc50 100644 --- a/admin/themes/default/js/addAlbum.js +++ b/admin/themes/default/js/addAlbum.js @@ -1,17 +1,23 @@ jQuery.fn.pwgAddAlbum = function(options) { - if (!options.cache) { + options = options || {}; + + var $popup = jQuery('#addAlbumForm'), + $albumParent = $popup.find('[name="category_parent"]') + $button = jQuery(this), + $target = jQuery('[name="'+ $button.data('addAlbum') +'"]'), + cache = $target.data('cache'); + + if (!$target[0].selectize) { + jQuery.error('pwgAddAlbum: target must use selectize'); + } + if (!cache) { jQuery.error('pwgAddAlbum: missing categories cache'); } - - var $popup = jQuery('#addAlbumForm'); - + function init() { - if ($popup.data('init')) { - return; - } $popup.data('init', true); - - options.cache.selectize($popup.find('[name="category_parent"]'), { + + cache.selectize($albumParent, { 'default': 0, 'filter': function(categories) { categories.push({ @@ -19,20 +25,25 @@ jQuery.fn.pwgAddAlbum = function(options) { fullname: '------------', global_rank: 0 }); - + + if (options.filter) { + categories = options.filter.call(this, categories); + } + return categories; } }); - + $popup.find('form').on('submit', function(e) { e.preventDefault(); - - jQuery('#categoryNameError').text(''); - - var albumParent = $popup.find('[name="category_parent"]'), - parent_id = albumParent.val(), - name = $popup.find('[name=category_name]').val(), - target = $popup.data('target'); + + var parent_id = $albumParent.val(), + name = $popup.find('[name=category_name]').val(); + + jQuery('#categoryNameError').toggle(!name); + if (!name) { + return; + } jQuery.ajax({ url: 'ws.php?format=json', @@ -48,79 +59,59 @@ jQuery.fn.pwgAddAlbum = function(options) { }, success: function(data) { jQuery('#albumCreationLoading').hide(); - jQuery('[data-add-album="'+ target +'"]').colorbox.close(); + $button.colorbox.close(); + + var newAlbum = { + id: data.result.id, + name: name, + fullname: name, + global_rank: '0', + dir: null, + nb_images: 0, + pos: 0 + }; + + var parentSelectize = $albumParent[0].selectize; - var newAlbum = data.result.id, - 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; - - var $albumSelect = jQuery('[name="'+ target +'"]'); - - // target is a normal select - if (!$albumSelect[0].selectize) { - var new_option = jQuery('