mirror of
https://github.com/redmine/redmine.git
synced 2026-06-17 22:20:58 +02:00
Adds file custom field format (#6719).
git-svn-id: http://svn.redmine.org/redmine/trunk@15917 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -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> </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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user