diff options
author | mistic100 <mistic@piwigo.org> | 2014-05-24 16:24:52 +0000 |
---|---|---|
committer | mistic100 <mistic@piwigo.org> | 2014-05-24 16:24:52 +0000 |
commit | ad10a97f4ac3ffad5508b90da45b5c5a63db95ff (patch) | |
tree | 5d31569cbd3784fee3ed7662dd838d281d3910cc /admin/themes/default/js/addAlbum.js | |
parent | fea2a4efd1ad085def7cf84cc444325d0815b62e (diff) |
feature 3077 : use selectize on batch_manager_global, cat_modify and photos_add_direct
+ rewrite "add album" popup (more flexible and working with selectize)
git-svn-id: http://piwigo.org/svn/trunk@28533 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/themes/default/js/addAlbum.js | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/admin/themes/default/js/addAlbum.js b/admin/themes/default/js/addAlbum.js new file mode 100644 index 000000000..60942d8a7 --- /dev/null +++ b/admin/themes/default/js/addAlbum.js @@ -0,0 +1,123 @@ +jQuery.fn.pwgAddAlbum = function(options) { + if (!options.cache) { + jQuery.error('pwgAddAlbum: missing categories cache'); + } + + var $popup = jQuery('#addAlbumForm'); + if (!$popup.data('init')) { + $popup.find('[name="category_parent"]').selectize({ + valueField: 'id', + labelField: 'fullname', + sortField: 'fullname', + searchField: ['fullname'], + plugins: ['remove_button'], + onInitialize: function() { + this.on('dropdown_close', function() { + if (this.getValue() == '') { + this.setValue(0); + } + }); + } + }); + + $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'); + + jQuery.ajax({ + url: 'ws.php?format=json', + type: 'POST', + dataType: 'json', + data: { + method: 'pwg.categories.add', + parent: parent_id, + name: name + }, + beforeSend: function() { + jQuery('#albumCreationLoading').show(); + }, + success: function(data) { + jQuery('#albumCreationLoading').hide(); + jQuery('[data-add-album="'+ target +'"]').colorbox.close(); + + var newAlbum = data.result.id, + newAlbum_name = ''; + + if (parent_id != 0) { + newAlbum_name = albumParent[0].selectize.options[parent_id].fullname +' / '; + } + 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 { + $albumSelect[0].selectize.addOption({ + id: newAlbum, + fullname: newAlbum_name + }); + + $albumSelect[0].selectize.setValue(newAlbum); + } + + albumParent.val(''); + jQuery('#albumSelection').show(); + }, + error: function(XMLHttpRequest, textStatus, errorThrows) { + jQuery('#albumCreationLoading').hide(); + jQuery('#categoryNameError').text(errorThrows).css('color', 'red'); + } + }); + }); + } + + this.colorbox({ + inline: true, + href: '#addAlbumForm', + width: 350, height: 300, + onComplete: function() { + var albumParent = $popup.find('[name="category_parent"]')[0]; + + $popup.data('target', jQuery(this).data('addAlbum')); + + albumParent.selectize.clearOptions(); + + options.cache.get(function(categories) { + categories.push({ + id: 0, + fullname: '------------' + }); + + albumParent.selectize.load(function(callback) { + callback(categories); + }); + + albumParent.selectize.setValue(0); + }); + } + }); + + return this; +};
\ No newline at end of file |