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/trunk@30630 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
5f80cb589c
commit
f1a7d6b66e
5 changed files with 75 additions and 77 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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')) {
|
||||
|
|
|
|||
|
|
@ -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}">
|
||||
|
|
|
|||
|
|
@ -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}";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue