app/assets/javascripts/adminpanel/images_form.js in adminpanel-1.2.11 vs app/assets/javascripts/adminpanel/images_form.js in adminpanel-1.2.12

- old
+ new

@@ -1,14 +1,20 @@ $(document).ready(function(){ $('form').on('click', '.add_fields', function(e) { - time = new Date().getTime(); - regexp = new RegExp($(this).data('id'), 'g'); - $(this).before($(this).data('fields').replace(regexp, time)); e.preventDefault(); + var $collectionContainer = $(this).closest('.file-collection-container'); + var maxFiles = $collectionContainer.data('max'); + var numberOfFiles = $collectionContainer.find('.product-image:not(.hidden)').length + 1; + + if (maxFiles == '0' || numberOfFiles <= maxFiles) { + time = new Date().getTime(); + regexp = new RegExp($(this).data('id'), 'g'); + $(this).before($(this).data('fields').replace(regexp, time)); + } }); $('form').on('click', '.remove_fields', function(e){ $(this).prev('input[type=hidden]').val('1'); - $(this).parent().parent().parent().hide(); + $(this).parent().parent().parent().addClass('hidden'); e.preventDefault(); }); -}); \ No newline at end of file +});