summaryrefslogtreecommitdiffstats
path: root/public/javascripts
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-23 09:16:14 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-23 09:16:14 +0000
commitef45304817e9eeca5bc80b26a06594a4165f38cd (patch)
tree77434a1893c7a8dce9c34f8a12a22922f9d91c50 /public/javascripts
parentc91a4391d34b9bd97270d20f04aeb40ee64166a1 (diff)
downloadredmine-ef45304817e9eeca5bc80b26a06594a4165f38cd.tar.gz
redmine-ef45304817e9eeca5bc80b26a06594a4165f38cd.zip
Adds file custom field format (#6719).
git-svn-id: http://svn.redmine.org/redmine/trunk@15917 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/attachments.js41
1 files changed, 28 insertions, 13 deletions
diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js
index c5e6b962a..dbba6543c 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -2,23 +2,32 @@
Copyright (C) 2006-2016 Jean-Philippe Lang */
function addFile(inputEl, file, eagerUpload) {
+ var attachmentsFields = $(inputEl).closest('.attachments_form').find('.attachments_fields');
+ var addAttachment = $(inputEl).closest('.attachments_form').find('.add_attachment');
+ var maxFiles = ($(inputEl).prop('multiple') == true ? 10 : 1);
- if ($('#attachments_fields').children().length < 10) {
-
+ if (attachmentsFields.children().length < maxFiles) {
var attachmentId = addFile.nextAttachmentId++;
-
var fileSpan = $('<span>', { id: 'attachments_' + attachmentId });
+ var param = $(inputEl).data('param');
+ if (!param) {param = 'attachments'};
fileSpan.append(
- $('<input>', { type: 'text', 'class': 'filename readonly', name: 'attachments[' + attachmentId + '][filename]', readonly: 'readonly'} ).val(file.name),
- $('<input>', { type: 'text', 'class': 'description', name: 'attachments[' + attachmentId + '][description]', maxlength: 255, placeholder: $(inputEl).data('description-placeholder') } ).toggle(!eagerUpload),
+ $('<input>', { type: 'text', 'class': 'filename readonly', name: param +'[' + attachmentId + '][filename]', readonly: 'readonly'} ).val(file.name),
+ $('<input>', { type: 'text', 'class': 'description', name: param + '[' + attachmentId + '][description]', maxlength: 255, placeholder: $(inputEl).data('description-placeholder') } ).toggle(!eagerUpload),
+ $('<input>', { type: 'hidden', 'class': 'token', name: param + '[' + attachmentId + '][token]'} ),
$('<a>&nbsp</a>').attr({ href: "#", 'class': 'remove-upload' }).click(removeFile).toggle(!eagerUpload)
- ).appendTo('#attachments_fields');
+ ).appendTo(attachmentsFields);
+
+ if ($(inputEl).data('description') == 0) {
+ fileSpan.find('input.description').remove();
+ }
if(eagerUpload) {
ajaxUpload(file, attachmentId, fileSpan, inputEl);
}
-
+
+ addAttachment.toggle(attachmentsFields.children().length < maxFiles);
return attachmentId;
}
return null;
@@ -118,11 +127,16 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
}
function addInputFiles(inputEl) {
+ var attachmentsFields = $(inputEl).closest('.attachments_form').find('.attachments_fields');
+ var addAttachment = $(inputEl).closest('.attachments_form').find('.add_attachment');
var clearedFileInput = $(inputEl).clone().val('');
+ var sizeExceeded = false;
+ var param = $(inputEl).data('param');
+ if (!param) {param = 'attachments'};
if ($.ajaxSettings.xhr().upload && inputEl.files) {
// upload files using ajax
- uploadAndAttachFiles(inputEl.files, inputEl);
+ sizeExceeded = uploadAndAttachFiles(inputEl.files, inputEl);
$(inputEl).remove();
} else {
// browser not supporting the file API, upload on form submission
@@ -130,11 +144,11 @@ function addInputFiles(inputEl) {
var aFilename = inputEl.value.split(/\/|\\/);
attachmentId = addFile(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false);
if (attachmentId) {
- $(inputEl).attr({ name: 'attachments[' + attachmentId + '][file]', style: 'display:none;' }).appendTo('#attachments_' + attachmentId);
+ $(inputEl).attr({ name: param + '[' + attachmentId + '][file]', style: 'display:none;' }).appendTo('#attachments_' + attachmentId);
}
}
- clearedFileInput.insertAfter('#attachments_fields');
+ clearedFileInput.prependTo(addAttachment);
}
function uploadAndAttachFiles(files, inputEl) {
@@ -151,6 +165,7 @@ function uploadAndAttachFiles(files, inputEl) {
} else {
$.each(files, function() {addFile(inputEl, this, true);});
}
+ return sizeExceeded;
}
function handleFileDropEvent(e) {
@@ -159,7 +174,7 @@ function handleFileDropEvent(e) {
blockEventPropagation(e);
if ($.inArray('Files', e.dataTransfer.types) > -1) {
- uploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector'));
+ uploadAndAttachFiles(e.dataTransfer.files, $('input:file.filedrop').first());
}
}
@@ -178,12 +193,12 @@ function setupFileDrop() {
$.event.fixHooks.drop = { props: [ 'dataTransfer' ] };
- $('form div.box').has('input:file').each(function() {
+ $('form div.box:not(.filedroplistner)').has('input:file.filedrop').each(function() {
$(this).on({
dragover: dragOverHandler,
dragleave: dragOutHandler,
drop: handleFileDropEvent
- });
+ }).addClass('filedroplistner');
});
}
}