- Timestamp:
- Nov 30, 2014, 6:42:18 PM (10 years ago)
- Location:
- branches/2.7/admin/themes/default
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.7/admin/themes/default/js/LocalStorageCache.js
r29613 r30633 95 95 */ 96 96 AbstractSelectizer.prototype._selectize = function($target, globalOptions) { 97 $target.data('cache', this); 98 97 99 this.get(function(data) { 98 100 $target.each(function() { -
branches/2.7/admin/themes/default/js/addAlbum.js
r29619 r30633 1 1 jQuery.fn.pwgAddAlbum = function(options) { 2 if (!options.cache) { 2 options = options || {}; 3 4 var $popup = jQuery('#addAlbumForm'), 5 $albumParent = $popup.find('[name="category_parent"]') 6 $button = jQuery(this), 7 $target = jQuery('[name="'+ $button.data('addAlbum') +'"]'), 8 cache = $target.data('cache'); 9 10 if (!$target[0].selectize) { 11 jQuery.error('pwgAddAlbum: target must use selectize'); 12 } 13 if (!cache) { 3 14 jQuery.error('pwgAddAlbum: missing categories cache'); 4 15 } 5 6 var $popup = jQuery('#addAlbumForm'); 7 16 8 17 function init() { 9 if ($popup.data('init')) {10 return;11 }12 18 $popup.data('init', true); 13 14 options.cache.selectize($popup.find('[name="category_parent"]'), {19 20 cache.selectize($albumParent, { 15 21 'default': 0, 16 22 'filter': function(categories) { … … 20 26 global_rank: 0 21 27 }); 22 28 29 if (options.filter) { 30 categories = options.filter.call(this, categories); 31 } 32 23 33 return categories; 24 34 } 25 35 }); 26 36 27 37 $popup.find('form').on('submit', function(e) { 28 38 e.preventDefault(); 29 30 jQuery('#categoryNameError').text(''); 31 32 var albumParent = $popup.find('[name="category_parent"]'), 33 parent_id = albumParent.val(), 34 name = $popup.find('[name=category_name]').val(), 35 target = $popup.data('target'); 39 40 var parent_id = $albumParent.val(), 41 name = $popup.find('[name=category_name]').val(); 42 43 jQuery('#categoryNameError').toggle(!name); 44 if (!name) { 45 return; 46 } 36 47 37 48 jQuery.ajax({ … … 49 60 success: function(data) { 50 61 jQuery('#albumCreationLoading').hide(); 51 jQuery('[data-add-album="'+ target +'"]').colorbox.close();62 $button.colorbox.close(); 52 63 53 var newAlbum = data.result.id, 54 newAlbum_name = '', 55 newAlbum_rank = '0'; 56 64 var newAlbum = { 65 id: data.result.id, 66 name: name, 67 fullname: name, 68 global_rank: '0', 69 dir: null, 70 nb_images: 0, 71 pos: 0 72 }; 73 74 var parentSelectize = $albumParent[0].selectize; 75 57 76 if (parent_id != 0) { 58 newAlbum_name = albumParent[0].selectize.options[parent_id].fullname +' / '; 59 newAlbum_rank = albumParent[0].selectize.options[parent_id].global_rank +'.1'; 60 } 61 newAlbum_name+= name; 62 63 var $albumSelect = jQuery('[name="'+ target +'"]'); 64 65 // target is a normal select 66 if (!$albumSelect[0].selectize) { 67 var new_option = jQuery('<option/>') 68 .attr('value', newAlbum) 69 .attr('selected', 'selected') 70 .text(newAlbum_name); 71 72 $albumSelect.find('option').removeAttr('selected'); 73 74 if (parent_id==0) { 75 $albumSelect.prepend(new_option); 76 } 77 else { 78 $albumSelect.find('option[value='+ parent_id +']').after(new_option); 79 } 80 } 81 // target is selectize 82 else { 83 var selectize = $albumSelect[0].selectize; 84 85 if (jQuery.isEmptyObject(selectize.options)) { 86 options.cache.clear(); 87 options.cache.selectize($albumSelect, { 88 'default': newAlbum, 89 'value': newAlbum 90 }); 91 } 92 else { 93 $albumSelect[0].selectize.addOption({ 94 id: newAlbum, 95 fullname: newAlbum_name, 96 global_rank: newAlbum_rank 97 }); 98 99 $albumSelect[0].selectize.setValue(newAlbum); 100 } 77 var parent = parentSelectize.options[parent_id]; 78 newAlbum.fullname = parent.fullname + ' / ' + newAlbum.fullname; 79 newAlbum.global_rank = parent.global_rank + '.1'; 80 newAlbum.pos = parent.pos + 1; 101 81 } 102 82 103 albumParent.val(''); 104 jQuery('#albumSelection, .selectFiles, .showFieldset').show(); 83 var targetSelectize = $target[0].selectize; 84 targetSelectize.addOption(newAlbum); 85 targetSelectize.setValue(newAlbum.id); 86 87 parentSelectize.addOption(newAlbum); 88 89 if (options.afterSelect) { 90 options.afterSelect(); 91 } 105 92 }, 106 93 error: function(XMLHttpRequest, textStatus, errorThrows) { 107 94 jQuery('#albumCreationLoading').hide(); 108 jQuery('#categoryNameError').text(errorThrows).css('color', 'red');95 alert(errorThrows); 109 96 } 110 97 }); 111 98 }); 112 99 } 113 100 114 101 this.colorbox({ 115 102 inline: true, … … 117 104 width: 650, height: 300, 118 105 onComplete: function() { 119 init(); 120 $popup.data('target', jQuery(this).data('addAlbum')); 121 $popup.find('[name=category_name]').focus(); 106 if (!$popup.data('init')) { 107 init(); 108 } 109 110 jQuery('#categoryNameError').hide(); 111 $popup.find('[name=category_name]').val('').focus(); 112 $albumParent[0].selectize.setValue($target.val() || 0); 122 113 } 123 114 }); 124 115 125 116 return this; 126 117 }; -
branches/2.7/admin/themes/default/js/batchManagerGlobal.js
r29249 r30633 112 112 }); 113 113 114 jQuery('[data-add-album]').pwgAddAlbum( { cache: categoriesCache });114 jQuery('[data-add-album]').pwgAddAlbum(); 115 115 116 116 $("input[name=remove_author]").click(function () { -
branches/2.7/admin/themes/default/template/include/add_album.inc.tpl
r29389 r30633 15 15 16 16 {'Album name'|@translate}<br> 17 <input name="category_name" type="text" maxlength="255"> <span id="categoryNameError"></span> 17 <input name="category_name" type="text" maxlength="255"> 18 <span id="categoryNameError" style="color:red;">{'The name of an album must not be empty'|translate}</span> 18 19 <br><br><br> 19 20 -
branches/2.7/admin/themes/default/template/photos_add_direct.tpl
r29903 r30633 39 39 }); 40 40 41 jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache }); 41 jQuery('[data-add-album]').pwgAddAlbum({ 42 afterSelect: function() { 43 jQuery("#albumSelection, .selectFiles, .showFieldset").show(); 44 } 45 }); 42 46 43 47 var pwg_token = '{$pwg_token}';
Note: See TracChangeset
for help on using the changeset viewer.