aboutsummaryrefslogtreecommitdiffstats
path: root/admin/themes/default/js/LocalStorageCache.js
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2014-05-28 19:04:40 +0000
committermistic100 <mistic@piwigo.org>2014-05-28 19:04:40 +0000
commit9a842dd86af254aa5d2212d0e3e4a10961aef492 (patch)
tree5271edfc6826b58b160d59c8d210af4d38247444 /admin/themes/default/js/LocalStorageCache.js
parent7b3783c9814173d05d5efb216d5b383a4aa2a8fe (diff)
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
Diffstat (limited to 'admin/themes/default/js/LocalStorageCache.js')
-rw-r--r--admin/themes/default/js/LocalStorageCache.js27
1 files changed, 21 insertions, 6 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() == '') {