Unified "Add New File" and ".. Attachment" buttons.
This commit is contained in:
@@ -39,24 +39,58 @@
|
|||||||
}, scroll_duration_msec);
|
}, scroll_duration_msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***** Attachment handling ******/
|
||||||
|
var attrs = ['for', 'id', 'name', 'data-field-name'];
|
||||||
|
function resetAttributeNames(section) {
|
||||||
|
var tags = section.find('input, select, label, div, a');
|
||||||
|
var idx = section.index();
|
||||||
|
tags.each(function () {
|
||||||
|
var $this = $(this);
|
||||||
|
|
||||||
|
// Renumber certain attributes.
|
||||||
|
$.each(attrs, function (i, attr) {
|
||||||
|
var attr_val = $this.attr(attr);
|
||||||
|
if (attr_val) {
|
||||||
|
$this.attr(attr, attr_val.replace(/-\d+/, '-' + idx))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear input field values
|
||||||
|
var tagname = $this.prop('tagName');
|
||||||
|
if (tagname == 'INPUT') {
|
||||||
|
if ($this.attr('type') == 'checkbox') {
|
||||||
|
$this.prop('checked', false);
|
||||||
|
} else {
|
||||||
|
$this.val('');
|
||||||
|
}
|
||||||
|
} else if (tagname == 'SELECT') {
|
||||||
|
$this.find(':nth-child(1)').prop('selected', true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Click on all file delete buttons to clear all file widgets.
|
||||||
|
section.find('a.file_delete').click();
|
||||||
|
section.find('div.form-upload-progress-bar').hide();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the queried buttons as "Add New Attachment" buttons.
|
* Marks the queried buttons as "Add New Attachment" or
|
||||||
|
* "Add New File" button.
|
||||||
*/
|
*/
|
||||||
$.fn.addNewAttachmentButton = function() {
|
$.fn.addNewFileButton = function() {
|
||||||
var $button = this;
|
var $button = this;
|
||||||
$button.click(function() {
|
$button.click(function() {
|
||||||
console.log('Cloning last repeating group');
|
|
||||||
var lastRepeatingGroup = $button
|
var lastRepeatingGroup = $button
|
||||||
.parent()
|
.parent()
|
||||||
.next('.attachments')
|
.next('.form-group')
|
||||||
.children('ul.fieldlist')
|
.children('ul.fieldlist')
|
||||||
.children('li')
|
.children('li')
|
||||||
.last();
|
.last();
|
||||||
console.log(lastRepeatingGroup.toArray());
|
|
||||||
var cloned = lastRepeatingGroup.clone(false);
|
var cloned = lastRepeatingGroup.clone(false);
|
||||||
cloned.insertAfter(lastRepeatingGroup);
|
cloned.insertAfter(lastRepeatingGroup);
|
||||||
resetAttributeNames(cloned);
|
resetAttributeNames(cloned);
|
||||||
cloned.find('.fileupload').each(setup_file_uploader)
|
cloned.find('.fileupload').each(setup_file_uploader)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}(jQuery));
|
}(jQuery));
|
||||||
|
@@ -48,7 +48,6 @@
|
|||||||
| {{ render_field(field, field.name) }}
|
| {{ render_field(field, field.name) }}
|
||||||
|
|
||||||
| {% elif field.name == 'files' %}
|
| {% elif field.name == 'files' %}
|
||||||
.files-header
|
|
||||||
#files-actions
|
#files-actions
|
||||||
#files-action-add
|
#files-action-add
|
||||||
i.pi-plus
|
i.pi-plus
|
||||||
@@ -219,50 +218,7 @@ script(type="text/javascript").
|
|||||||
displayNode('{{node._id}}');
|
displayNode('{{node._id}}');
|
||||||
});
|
});
|
||||||
|
|
||||||
var attrs = ['for', 'id', 'name', 'data-field-name'];
|
$("#attachments-action-add").addNewFileButton();
|
||||||
function resetAttributeNames(section) {
|
$("#files-action-add").addNewFileButton();
|
||||||
var tags = section.find('input, select, label, div, a');
|
|
||||||
var idx = section.index();
|
|
||||||
tags.each(function () {
|
|
||||||
var $this = $(this);
|
|
||||||
|
|
||||||
// Renumber certain attributes.
|
|
||||||
$.each(attrs, function (i, attr) {
|
|
||||||
var attr_val = $this.attr(attr);
|
|
||||||
if (attr_val) {
|
|
||||||
$this.attr(attr, attr_val.replace(/-\d+/, '-' + idx))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clear input field values
|
|
||||||
var tagname = $this.prop('tagName');
|
|
||||||
if (tagname == 'INPUT') {
|
|
||||||
if ($this.attr('type') == 'checkbox') {
|
|
||||||
$this.prop('checked', false);
|
|
||||||
} else {
|
|
||||||
$this.val('');
|
|
||||||
}
|
|
||||||
} else if (tagname == 'SELECT') {
|
|
||||||
$this.find(':nth-child(1)').prop('selected', true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Click on all file delete buttons to clear all file widgets.
|
|
||||||
section.find('a.file_delete').click();
|
|
||||||
section.find('div.form-upload-progress-bar').hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#attachments-action-add").addNewAttachmentButton();
|
|
||||||
|
|
||||||
if (document.getElementById("files") !== null) {
|
|
||||||
$("#files-action-add").on('click', function () {
|
|
||||||
var lastRepeatingGroup = $('#files > li').last();
|
|
||||||
var cloned = lastRepeatingGroup.clone(false);
|
|
||||||
cloned.insertAfter(lastRepeatingGroup);
|
|
||||||
resetAttributeNames(cloned);
|
|
||||||
cloned.find('.fileupload').each(setup_file_uploader)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//- console.log($._data($(elementSelector)[0], "events"));
|
|
||||||
|
|
||||||
| {% endblock %}
|
| {% endblock %}
|
||||||
|
Reference in New Issue
Block a user