"Add new attachment" button works.

This commit is contained in:
Sybren A. Stüvel 2016-11-02 12:11:46 +01:00
parent 90c6fdc377
commit 6ea7386bd3
2 changed files with 21 additions and 8 deletions

View File

@ -39,4 +39,24 @@
}, scroll_duration_msec);
}
/**
* Marks the queried buttons as "Add New Attachment" buttons.
*/
$.fn.addNewAttachmentButton = function() {
var $button = this;
$button.click(function() {
console.log('Cloning last repeating group');
var lastRepeatingGroup = $button
.parent()
.next('.attachments')
.children('ul.fieldlist')
.children('li')
.last();
console.log(lastRepeatingGroup.toArray());
var cloned = lastRepeatingGroup.clone(false);
cloned.insertAfter(lastRepeatingGroup);
resetAttributeNames(cloned);
cloned.find('.fileupload').each(setup_file_uploader)
})
}
}(jQuery));

View File

@ -252,14 +252,7 @@ script(type="text/javascript").
section.find('div.form-upload-progress-bar').hide();
}
if (document.getElementById("attachments") !== null) {
$("#attachments-action-add").on('click', function(){
var lastRepeatingGroup = $('#attachments > li').last();
var cloned = lastRepeatingGroup.clone(true);
cloned.insertAfter(lastRepeatingGroup);
resetAttributeNames(cloned);
});
}
$("#attachments-action-add").addNewAttachmentButton();
if (document.getElementById("files") !== null) {
$("#files-action-add").on('click', function () {