aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/themes/default/js/LocalStorageCache.js2
-rw-r--r--admin/themes/default/js/addAlbum.js139
-rw-r--r--admin/themes/default/js/batchManagerGlobal.js2
-rw-r--r--admin/themes/default/template/include/add_album.inc.tpl3
-rw-r--r--admin/themes/default/template/photos_add_direct.tpl6
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('<option/>')
- .attr('value', newAlbum)
- .attr('selected', 'selected')
- .text(newAlbum_name);
-
- $albumSelect.find('option').removeAttr('selected');
-
- if (parent_id==0) {
- $albumSelect.prepend(new_option);
- }
- else {
- $albumSelect.find('option[value='+ parent_id +']').after(new_option);
- }
- }
- // target is selectize
- else {
- var selectize = $albumSelect[0].selectize;
-
- 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);
- }
+ var parent = parentSelectize.options[parent_id];
+ newAlbum.fullname = parent.fullname + ' / ' + newAlbum.fullname;
+ newAlbum.global_rank = parent.global_rank + '.1';
+ newAlbum.pos = parent.pos + 1;
}
- albumParent.val('');
- jQuery('#albumSelection, .selectFiles, .showFieldset').show();
+ var targetSelectize = $target[0].selectize;
+ targetSelectize.addOption(newAlbum);
+ targetSelectize.setValue(newAlbum.id);
+
+ parentSelectize.addOption(newAlbum);
+
+ if (options.afterSelect) {
+ options.afterSelect();
+ }
},
error: function(XMLHttpRequest, textStatus, errorThrows) {
jQuery('#albumCreationLoading').hide();
- jQuery('#categoryNameError').text(errorThrows).css('color', 'red');
+ alert(errorThrows);
}
});
});
}
-
+
this.colorbox({
inline: true,
href: '#addAlbumForm',
width: 650, height: 300,
onComplete: function() {
- init();
- $popup.data('target', jQuery(this).data('addAlbum'));
- $popup.find('[name=category_name]').focus();
+ if (!$popup.data('init')) {
+ init();
+ }
+
+ jQuery('#categoryNameError').hide();
+ $popup.find('[name=category_name]').val('').focus();
+ $albumParent[0].selectize.setValue($target.val() || 0);
}
});
-
+
return this;
}; \ No newline at end of file
diff --git a/admin/themes/default/js/batchManagerGlobal.js b/admin/themes/default/js/batchManagerGlobal.js
index e3d4a3455..50fadb1f1 100644
--- a/admin/themes/default/js/batchManagerGlobal.js
+++ b/admin/themes/default/js/batchManagerGlobal.js
@@ -111,7 +111,7 @@ jQuery('[data-datepicker]').pwgDatepicker({
cancelButton: lang.Cancel
});
-jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
+jQuery('[data-add-album]').pwgAddAlbum();
$("input[name=remove_author]").click(function () {
if ($(this).is(':checked')) {
diff --git a/admin/themes/default/template/include/add_album.inc.tpl b/admin/themes/default/template/include/add_album.inc.tpl
index 988dc1907..ebda5d2cc 100644
--- a/admin/themes/default/template/include/add_album.inc.tpl
+++ b/admin/themes/default/template/include/add_album.inc.tpl
@@ -14,7 +14,8 @@
<br><br>
{'Album name'|@translate}<br>
- <input name="category_name" type="text" maxlength="255"> <span id="categoryNameError"></span>
+ <input name="category_name" type="text" maxlength="255">
+ <span id="categoryNameError" style="color:red;">{'The name of an album must not be empty'|translate}</span>
<br><br><br>
<input type="submit" value="{'Create'|@translate}">
diff --git a/admin/themes/default/template/photos_add_direct.tpl b/admin/themes/default/template/photos_add_direct.tpl
index 705f07265..07a2c4495 100644
--- a/admin/themes/default/template/photos_add_direct.tpl
+++ b/admin/themes/default/template/photos_add_direct.tpl
@@ -38,7 +38,11 @@ categoriesCache.selectize(jQuery('[data-selectize=categories]'), {
}
});
-jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
+jQuery('[data-add-album]').pwgAddAlbum({
+ afterSelect: function() {
+ jQuery("#albumSelection, .selectFiles, .showFieldset").show();
+ }
+});
var pwg_token = '{$pwg_token}';
var photosUploaded_label = "{'%d photos uploaded'|translate}";