From a5b2cf82007ac1b2461ba86b79c48e43c2640053 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Mon, 26 May 2014 22:03:57 +0000 Subject: feature 3077 : factorize code for categories cache (TODO for other collections) + fix incorrect categories list for dissociation git-svn-id: http://piwigo.org/svn/trunk@28542 68402e56-0260-453c-a942-63ccdbb3a9ee --- .../default/template/batch_manager_global.tpl | 59 ++++++++-------------- admin/themes/default/template/cat_modify.tpl | 59 ++++++---------------- .../themes/default/template/photos_add_direct.tpl | 47 ++++------------- admin/themes/default/template/picture_modify.tpl | 39 ++++---------- 4 files changed, 55 insertions(+), 149 deletions(-) (limited to 'admin/themes/default/template') diff --git a/admin/themes/default/template/batch_manager_global.tpl b/admin/themes/default/template/batch_manager_global.tpl index 4a45cab41..a5a48e8de 100644 --- a/admin/themes/default/template/batch_manager_global.tpl +++ b/admin/themes/default/template/batch_manager_global.tpl @@ -119,46 +119,31 @@ jQuery(document).ready(function() {ldelim} }); {* *} - var categoriesCache = new LocalStorageCache({ - key: 'categoriesAdminList', + var categoriesCache = new CategoriesCache({ serverKey: '{$CACHE_KEYS.categories}', serverId: '{$CACHE_KEYS._hash}', - - loader: function(callback) { - jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { - callback(data.result.categories); - }); - } + rootUrl: '{$ROOT_URL}' }); - jQuery('[data-selectize=categories]').selectize({ - valueField: 'id', - labelField: 'fullname', - sortField: 'global_rank', - searchField: ['fullname'], - plugins: ['remove_button'] - }); - - categoriesCache.get(function(categories) { - jQuery('[data-selectize=categories]').each(function() { - this.selectize.load(function(callback) { - callback(categories); - }); - - if (jQuery(this).data('value')) { - this.selectize.setValue(jQuery(this).data('value')[0]); + categoriesCache.selectize(jQuery('[data-selectize=categories]'), { + filter: function(categories, options) { + if (this.name == 'dissociate') { + var filtered = jQuery.grep(categories, function(cat) { + return !cat.dir; + }); + + if (filtered.length > 0) { + jQuery('.albumDissociate').show(); + options.default = filtered[0].id; + } + + return filtered; } - - // prevent empty value - if (this.selectize.getValue() == '') { - this.selectize.setValue(categories[0].id); + else { + options.default = categories[0].id; + return categories; } - this.selectize.on('dropdown_close', function() { - if (this.getValue() == '') { - this.setValue(categories[0].id); - } - }); - }); + } }); jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache }); @@ -837,9 +822,7 @@ UL.thumbnails SPAN.wrap2 {ldelim} - {if !empty($dissociate_options)} - - {/if} + {if !empty($associated_tags)} @@ -884,7 +867,7 @@ UL.thumbnails SPAN.wrap2 {ldelim} -
+ diff --git a/admin/themes/default/template/cat_modify.tpl b/admin/themes/default/template/cat_modify.tpl index 4bb06c03b..b1b9a5e06 100644 --- a/admin/themes/default/template/cat_modify.tpl +++ b/admin/themes/default/template/cat_modify.tpl @@ -5,57 +5,28 @@ {footer_script} {* *} -var categoriesCache = new LocalStorageCache({ - key: 'categoriesAdminList', +var categoriesCache = new CategoriesCache({ serverKey: '{$CACHE_KEYS.categories}', serverId: '{$CACHE_KEYS._hash}', - - loader: function(callback) { - jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { - callback(data.result.categories); - }); - } -}); - -jQuery('[data-selectize=categories]').selectize({ - valueField: 'id', - labelField: 'fullname', - sortField: 'global_rank', - searchField: ['fullname'], - plugins: ['remove_button'] + rootUrl: '{$ROOT_URL}' }); -categoriesCache.get(function(categories) { - categories.push({ - id: 0, - fullname: '------------', - global_rank: 0 - }); - - // remove itself and children - categories = jQuery.grep(categories, function(cat) { - return !(/\b{$CAT_ID}\b/.test(cat.uppercats)); - }); - - jQuery('[data-selectize=categories]').each(function() { - this.selectize.load(function(callback) { - callback(categories); +categoriesCache.selectize(jQuery('[data-selectize=categories]'), { + default: 0, + filter: function(categories, options) { + // remove itself and children + var filtered = jQuery.grep(categories, function(cat) { + return !(/\b{$CAT_ID}\b/.test(cat.uppercats)); }); - - if (jQuery(this).data('value')) { - this.selectize.setValue(jQuery(this).data('value')[0]); - } - // prevent empty value - if (this.selectize.getValue() == '') { - this.selectize.setValue(0); - } - this.selectize.on('dropdown_close', function() { - if (this.getValue() == '') { - this.setValue(0); - } + filtered.push({ + id: 0, + fullname: '------------', + global_rank: 0 }); - }); + + return filtered; + } }); {/footer_script} diff --git a/admin/themes/default/template/photos_add_direct.tpl b/admin/themes/default/template/photos_add_direct.tpl index fdf80c481..df87e4d87 100644 --- a/admin/themes/default/template/photos_add_direct.tpl +++ b/admin/themes/default/template/photos_add_direct.tpl @@ -16,50 +16,21 @@ {footer_script} {* *} -var categoriesCache = new LocalStorageCache({ - key: 'categoriesAdminList', +var categoriesCache = new CategoriesCache({ serverKey: '{$CACHE_KEYS.categories}', serverId: '{$CACHE_KEYS._hash}', - - loader: function(callback) { - jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { - callback(data.result.categories); - }); - } + rootUrl: '{$ROOT_URL}' }); -jQuery('[data-selectize=categories]').selectize({ - valueField: 'id', - labelField: 'fullname', - sortField: 'global_rank', - searchField: ['fullname'], - plugins: ['remove_button'] -}); - -categoriesCache.get(function(categories) { - if (categories.length > 0) { - jQuery("#albumSelection").show(); - } - - jQuery('[data-selectize=categories]').each(function() { - this.selectize.load(function(callback) { - callback(categories); - }); - - if (jQuery(this).data('value')) { - this.selectize.setValue(jQuery(this).data('value')[0]); +categoriesCache.selectize(jQuery('[data-selectize=categories]'), { + filter: function(categories, options) { + if (categories.length > 0) { + jQuery("#albumSelection").show(); + options.default = categories[0].id; } - // prevent empty value - if (this.selectize.getValue() == '') { - this.selectize.setValue(categories[0].id); - } - this.selectize.on('dropdown_close', function() { - if (this.getValue() == '') { - this.setValue(categories[0].id); - } - }); - }); + return categories; + } }); jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache }); diff --git a/admin/themes/default/template/picture_modify.tpl b/admin/themes/default/template/picture_modify.tpl index 3688d92ff..454a06428 100644 --- a/admin/themes/default/template/picture_modify.tpl +++ b/admin/themes/default/template/picture_modify.tpl @@ -10,37 +10,18 @@ {footer_script} (function(){ {* *} -var categoriesCache = new LocalStorageCache({ - key: 'categoriesAdminList', +var categoriesCache = new CategoriesCache({ serverKey: '{$CACHE_KEYS.categories}', serverId: '{$CACHE_KEYS._hash}', - - loader: function(callback) { - jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { - callback(data.result.categories); - }); - } -}); - -jQuery('[data-selectize=categories]').selectize({ - valueField: 'id', - labelField: 'fullname', - sortField: 'global_rank', - searchField: ['fullname'], - plugins: ['remove_button'] + rootUrl: '{$ROOT_URL}' }); -categoriesCache.get(function(categories) { - jQuery('[data-selectize=categories]').each(function() { - this.selectize.load(function(callback) { - callback(categories); - }); - - jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) { - this.selectize.addItem(id); - }, this)); - }); -}); +categoriesCache.selectize(jQuery('[data-selectize=categories]'), { {if $STORAGE_ALBUM} + filter: function(categories, options) { + options.default = (this.name == 'associate[]') ? {$STORAGE_ALBUM} : undefined; + return categories; + } +{/if} }); {* *} var tagsCache = new LocalStorageCache({ @@ -157,14 +138,14 @@ jQuery(function(){ {* *}

{'Linked albums'|@translate}
-

{'Representation of albums'|@translate}
-

-- cgit v1.2.3