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
This commit is contained in:
mistic100
2014-05-26 22:03:57 +00:00
parent b97c45b941
commit a5b2cf8200
8 changed files with 187 additions and 181 deletions
@@ -119,46 +119,31 @@ jQuery(document).ready(function() {ldelim}
});
{* <!-- CATEGORIES --> *}
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]);
}
// 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);
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;
}
else {
options.default = categories[0].id;
return categories;
}
}
});
jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
@@ -837,9 +822,7 @@ UL.thumbnails SPAN.wrap2 {ldelim}
<option value="delete" class="icon-trash">{'Delete selected photos'|@translate}</option>
<option value="associate">{'Associate to album'|@translate}</option>
<option value="move">{'Move to album'|@translate}</option>
{if !empty($dissociate_options)}
<option value="dissociate">{'Dissociate from album'|@translate}</option>
{/if}
<option value="dissociate" class="albumDissociate" style="display:none">{'Dissociate from album'|@translate}</option>
<option value="add_tags">{'Add tags'|@translate}</option>
{if !empty($associated_tags)}
<option value="del_tags">{'remove tags'|@translate}</option>
@@ -884,7 +867,7 @@ UL.thumbnails SPAN.wrap2 {ldelim}
<!-- dissociate -->
<div id="action_dissociate" class="bulkAction">
<div id="action_dissociate" class="bulkAction albumDissociate" style="display:none">
<select data-selectize="categories" name="dissociate" style="width:400px"></select>
</div>
+15 -44
View File
@@ -5,57 +5,28 @@
{footer_script}
{* <!-- CATEGORIES --> *}
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) {
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}
@@ -16,50 +16,21 @@
{footer_script}
{* <!-- CATEGORIES --> *}
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 });
@@ -10,37 +10,18 @@
{footer_script}
(function(){
{* <!-- CATEGORIES --> *}
var categoriesCache = new LocalStorageCache({
key: 'categoriesAdminList',
var categoriesCache = new CategoriesCache({
serverKey: '{$CACHE_KEYS.categories}',
serverId: '{$CACHE_KEYS._hash}',
rootUrl: '{$ROOT_URL}'
});
loader: function(callback) {
jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) {
callback(data.result.categories);
});
categoriesCache.selectize(jQuery('[data-selectize=categories]'), { {if $STORAGE_ALBUM}
filter: function(categories, options) {
options.default = (this.name == 'associate[]') ? {$STORAGE_ALBUM} : undefined;
return categories;
}
});
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);
});
jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) {
this.selectize.addItem(id);
}, this));
});
});
{/if} });
{* <!-- TAGS --> *}
var tagsCache = new LocalStorageCache({
@@ -157,14 +138,14 @@ jQuery(function(){ {* <!-- onLoad needed to wait localization loads --> *}
<p>
<strong>{'Linked albums'|@translate}</strong>
<br>
<select data-selectize="categories" data-value="{$associate_options_selected|@json_encode|escape:html}"
<select data-selectize="categories" data-value="{$associated_albums|@json_encode|escape:html}"
name="associate[]" multiple style="width:600px;" ></select>
</p>
<p>
<strong>{'Representation of albums'|@translate}</strong>
<br>
<select data-selectize="categories" data-value="{$represent_options_selected|@json_encode|escape:html}"
<select data-selectize="categories" data-value="{$represented_albums|@json_encode|escape:html}"
name="represent[]" multiple style="width:600px;" ></select>
</p>