|
|
@ -1,8 +1,7 @@
|
|
|
|
/* Redmine - project management software
|
|
|
|
/* Redmine - project management software
|
|
|
|
Copyright (C) 2006-2013 Jean-Philippe Lang */
|
|
|
|
Copyright (C) 2006-2013 Jean-Philippe Lang */
|
|
|
|
|
|
|
|
|
|
|
|
function postUpMsg(attachmentId)
|
|
|
|
function postUpMsg(attachmentId) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
$.ajax({
|
|
|
|
url: '/attachments/renderTag',
|
|
|
|
url: '/attachments/renderTag',
|
|
|
|
type: "GET",
|
|
|
|
type: "GET",
|
|
|
@ -30,14 +29,40 @@ function addFile_board(inputEl, file, eagerUpload, id) {
|
|
|
|
deleteallfiles = $(inputEl).data('deleteAllFiles');
|
|
|
|
deleteallfiles = $(inputEl).data('deleteAllFiles');
|
|
|
|
var attachmentId = addFile.nextAttachmentId++;
|
|
|
|
var attachmentId = addFile.nextAttachmentId++;
|
|
|
|
|
|
|
|
|
|
|
|
var fileSpan = $('<span>', { 'id': 'attachments_' + attachmentId, 'class':'attachment' });
|
|
|
|
var fileSpan = $('<span>', {
|
|
|
|
|
|
|
|
'id': 'attachments_' + attachmentId,
|
|
|
|
|
|
|
|
'class': 'attachment'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fileSpan.append(
|
|
|
|
fileSpan.append(
|
|
|
|
$('<input>', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name),
|
|
|
|
$('<input>', {
|
|
|
|
$('<input>', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('descriptionPlaceholder') } ).toggle(!eagerUpload),
|
|
|
|
'type': 'text',
|
|
|
|
$('<span >'+$(inputEl).data('fieldIsPublic')+':</span>').attr({ 'class': 'ispublic-label' }) ,
|
|
|
|
'class': 'filename readonly',
|
|
|
|
$('<input>', { 'type': 'checkbox', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload),
|
|
|
|
'name': 'attachments[' + attachmentId + '][filename]',
|
|
|
|
$('<a> </a>').attr({ 'href': "#", 'class': 'remove-upload', 'data-containerid':id }).click(function(){
|
|
|
|
'readonly': 'readonly'
|
|
|
|
|
|
|
|
}).val(file.name),
|
|
|
|
|
|
|
|
$('<input>', {
|
|
|
|
|
|
|
|
'type': 'text',
|
|
|
|
|
|
|
|
'class': 'description',
|
|
|
|
|
|
|
|
'name': 'attachments[' + attachmentId + '][description]',
|
|
|
|
|
|
|
|
'maxlength': 254,
|
|
|
|
|
|
|
|
'placeholder': $(inputEl).data('descriptionPlaceholder')
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
|
|
|
|
$('<span >' + $(inputEl).data('fieldIsPublic') + ':</span>').attr({
|
|
|
|
|
|
|
|
'class': 'ispublic-label'
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
$('<input>', {
|
|
|
|
|
|
|
|
'type': 'checkbox',
|
|
|
|
|
|
|
|
'class': 'is_public_checkbox',
|
|
|
|
|
|
|
|
'value': 1,
|
|
|
|
|
|
|
|
'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
|
|
|
|
|
|
|
|
checked: 'checked'
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
|
|
|
|
$('<a> </a>').attr({
|
|
|
|
|
|
|
|
'href': "#",
|
|
|
|
|
|
|
|
'class': 'remove-upload',
|
|
|
|
|
|
|
|
'data-containerid': id
|
|
|
|
|
|
|
|
}).click(function() {
|
|
|
|
if (confirm($(inputEl).data('areYouSure'))) {
|
|
|
|
if (confirm($(inputEl).data('areYouSure'))) {
|
|
|
|
removeFile();
|
|
|
|
removeFile();
|
|
|
|
if (!eagerUpload) {
|
|
|
|
if (!eagerUpload) {
|
|
|
@ -48,7 +73,10 @@ function addFile_board(inputEl, file, eagerUpload, id) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
$('<div>', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} )
|
|
|
|
$('<div>', {
|
|
|
|
|
|
|
|
'class': 'div_attachments',
|
|
|
|
|
|
|
|
'name': 'div_' + 'attachments_' + attachmentId
|
|
|
|
|
|
|
|
})
|
|
|
|
).appendTo(attachments_frame);
|
|
|
|
).appendTo(attachments_frame);
|
|
|
|
|
|
|
|
|
|
|
|
if (eagerUpload) {
|
|
|
|
if (eagerUpload) {
|
|
|
@ -59,6 +87,7 @@ function addFile_board(inputEl, file, eagerUpload, id) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addFile(inputEl, file, eagerUpload) {
|
|
|
|
function addFile(inputEl, file, eagerUpload) {
|
|
|
|
|
|
|
|
|
|
|
|
var attachments_frame = '#attachments_fields';
|
|
|
|
var attachments_frame = '#attachments_fields';
|
|
|
@ -66,14 +95,39 @@ function addFile(inputEl, file, eagerUpload) {
|
|
|
|
deleteallfiles = $(inputEl).data('deleteAllFiles');
|
|
|
|
deleteallfiles = $(inputEl).data('deleteAllFiles');
|
|
|
|
var attachmentId = addFile.nextAttachmentId++;
|
|
|
|
var attachmentId = addFile.nextAttachmentId++;
|
|
|
|
|
|
|
|
|
|
|
|
var fileSpan = $('<span>', { 'id': 'attachments_' + attachmentId, 'class':'attachment' });
|
|
|
|
var fileSpan = $('<span>', {
|
|
|
|
|
|
|
|
'id': 'attachments_' + attachmentId,
|
|
|
|
|
|
|
|
'class': 'attachment'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fileSpan.append(
|
|
|
|
fileSpan.append(
|
|
|
|
$('<input>', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name),
|
|
|
|
$('<input>', {
|
|
|
|
$('<input>', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('descriptionPlaceholder') } ).toggle(!eagerUpload),
|
|
|
|
'type': 'text',
|
|
|
|
$('<span >'+$(inputEl).data('fieldIsPublic')+':</span>').attr({ 'class': 'ispublic-label' }) ,
|
|
|
|
'class': 'filename readonly',
|
|
|
|
$('<input>', { 'type': 'checkbox', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload),
|
|
|
|
'name': 'attachments[' + attachmentId + '][filename]',
|
|
|
|
$('<a> </a>').attr({ 'href': "#", 'class': 'remove-upload' }).click(function(){
|
|
|
|
'readonly': 'readonly'
|
|
|
|
|
|
|
|
}).val(file.name),
|
|
|
|
|
|
|
|
$('<input>', {
|
|
|
|
|
|
|
|
'type': 'text',
|
|
|
|
|
|
|
|
'class': 'description',
|
|
|
|
|
|
|
|
'name': 'attachments[' + attachmentId + '][description]',
|
|
|
|
|
|
|
|
'maxlength': 254,
|
|
|
|
|
|
|
|
'placeholder': $(inputEl).data('descriptionPlaceholder')
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
|
|
|
|
$('<span >' + $(inputEl).data('fieldIsPublic') + ':</span>').attr({
|
|
|
|
|
|
|
|
'class': 'ispublic-label'
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
$('<input>', {
|
|
|
|
|
|
|
|
'type': 'checkbox',
|
|
|
|
|
|
|
|
'class': 'is_public_checkbox',
|
|
|
|
|
|
|
|
'value': 1,
|
|
|
|
|
|
|
|
'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
|
|
|
|
|
|
|
|
checked: 'checked'
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
|
|
|
|
$('<a> </a>').attr({
|
|
|
|
|
|
|
|
'href': "#",
|
|
|
|
|
|
|
|
'class': 'remove-upload'
|
|
|
|
|
|
|
|
}).click(function() {
|
|
|
|
if (confirm($(inputEl).data('areYouSure'))) {
|
|
|
|
if (confirm($(inputEl).data('areYouSure'))) {
|
|
|
|
removeFile();
|
|
|
|
removeFile();
|
|
|
|
if (!eagerUpload) {
|
|
|
|
if (!eagerUpload) {
|
|
|
@ -84,7 +138,10 @@ function addFile(inputEl, file, eagerUpload) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
$('<div>', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} )
|
|
|
|
$('<div>', {
|
|
|
|
|
|
|
|
'class': 'div_attachments',
|
|
|
|
|
|
|
|
'name': 'div_' + 'attachments_' + attachmentId
|
|
|
|
|
|
|
|
})
|
|
|
|
).appendTo('#attachments_fields');
|
|
|
|
).appendTo('#attachments_fields');
|
|
|
|
|
|
|
|
|
|
|
|
if (eagerUpload) {
|
|
|
|
if (eagerUpload) {
|
|
|
@ -126,8 +183,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.fail(function(result) {
|
|
|
|
.fail(function(result) {
|
|
|
|
progressSpan.text(result.statusText);
|
|
|
|
progressSpan.text(result.statusText);
|
|
|
|
if($("#network_issue"))
|
|
|
|
if ($("#network_issue")) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$("#network_issue").show();
|
|
|
|
$("#network_issue").show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).always(function() {
|
|
|
|
}).always(function() {
|
|
|
@ -151,7 +207,11 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
|
|
|
|
var add_attachs = $('.add_attachment');
|
|
|
|
var add_attachs = $('.add_attachment');
|
|
|
|
var delete_all = $('.remove_all');
|
|
|
|
var delete_all = $('.remove_all');
|
|
|
|
if (delete_all.length < 1) {
|
|
|
|
if (delete_all.length < 1) {
|
|
|
|
add_attachs.append($("<a> </a>").attr({"href":"javascript:void(0)", 'class': 'remove_all',"onclick": "removeAll()"}));
|
|
|
|
add_attachs.append($("<a> </a>").attr({
|
|
|
|
|
|
|
|
"href": "javascript:void(0)",
|
|
|
|
|
|
|
|
'class': 'remove_all',
|
|
|
|
|
|
|
|
"onclick": "removeAll()"
|
|
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -254,7 +314,6 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
|
|
|
|
|
|
|
|
|
|
|
|
function addInputFiles(inputEl) {
|
|
|
|
function addInputFiles(inputEl) {
|
|
|
|
// var clearedFileInput = $(inputEl).clone().val('');
|
|
|
|
// var clearedFileInput = $(inputEl).clone().val('');
|
|
|
|
|
|
|
|
|
|
|
|
if (inputEl.files) {
|
|
|
|
if (inputEl.files) {
|
|
|
|
// upload files using ajax
|
|
|
|
// upload files using ajax
|
|
|
|
uploadAndAttachFiles(inputEl.files, inputEl);
|
|
|
|
uploadAndAttachFiles(inputEl.files, inputEl);
|
|
|
@ -263,15 +322,22 @@ function addInputFiles(inputEl) {
|
|
|
|
// browser not supporting the file API, upload on form submission
|
|
|
|
// browser not supporting the file API, upload on form submission
|
|
|
|
var attachmentId;
|
|
|
|
var attachmentId;
|
|
|
|
var aFilename = inputEl.value.split(/\/|\\/);
|
|
|
|
var aFilename = inputEl.value.split(/\/|\\/);
|
|
|
|
attachmentId = addFile(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false);
|
|
|
|
var count = $('#attachments_fields>span').length;
|
|
|
|
|
|
|
|
attachmentId = addFile(inputEl, {
|
|
|
|
|
|
|
|
name: aFilename[aFilename.length - 1]
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
if (attachmentId) {
|
|
|
|
if (attachmentId) {
|
|
|
|
$(inputEl).attr({ name: 'attachments[' + attachmentId + '][file]'}).hide();
|
|
|
|
$(inputEl).attr({
|
|
|
|
|
|
|
|
name: 'attachments[' + attachmentId + '][file]'
|
|
|
|
|
|
|
|
}).hide();
|
|
|
|
|
|
|
|
if (count <= 0) count = 1;
|
|
|
|
$('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
|
|
|
|
$('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//clearedFileInput.insertAfter('#attachments_fields');
|
|
|
|
//clearedFileInput.insertAfter('#attachments_fields');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addInputFiles_board(inputEl, id) {
|
|
|
|
function addInputFiles_board(inputEl, id) {
|
|
|
|
// var clearedFileInput = $(inputEl).clone().val('');
|
|
|
|
// var clearedFileInput = $(inputEl).clone().val('');
|
|
|
|
|
|
|
|
|
|
|
@ -283,15 +349,20 @@ function addInputFiles_board(inputEl, id) {
|
|
|
|
// browser not supporting the file API, upload on form submission
|
|
|
|
// browser not supporting the file API, upload on form submission
|
|
|
|
var attachmentId;
|
|
|
|
var attachmentId;
|
|
|
|
var aFilename = inputEl.value.split(/\/|\\/);
|
|
|
|
var aFilename = inputEl.value.split(/\/|\\/);
|
|
|
|
attachmentId = addFile_board(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false, id);
|
|
|
|
attachmentId = addFile_board(inputEl, {
|
|
|
|
|
|
|
|
name: aFilename[aFilename.length - 1]
|
|
|
|
|
|
|
|
}, false, id);
|
|
|
|
if (attachmentId) {
|
|
|
|
if (attachmentId) {
|
|
|
|
$(inputEl).attr({ name: 'attachments[' + attachmentId + '][file]'}).hide();
|
|
|
|
$(inputEl).attr({
|
|
|
|
|
|
|
|
name: 'attachments[' + attachmentId + '][file]'
|
|
|
|
|
|
|
|
}).hide();
|
|
|
|
$('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
|
|
|
|
$('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//clearedFileInput.insertAfter('#attachments_fields');
|
|
|
|
//clearedFileInput.insertAfter('#attachments_fields');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uploadAndAttachFiles(files, inputEl) {
|
|
|
|
function uploadAndAttachFiles(files, inputEl) {
|
|
|
|
|
|
|
|
|
|
|
|
var maxFileSize = $(inputEl).data('max-file-size');
|
|
|
|
var maxFileSize = $(inputEl).data('max-file-size');
|
|
|
@ -299,14 +370,19 @@ function uploadAndAttachFiles(files, inputEl) {
|
|
|
|
|
|
|
|
|
|
|
|
var sizeExceeded = false;
|
|
|
|
var sizeExceeded = false;
|
|
|
|
$.each(files, function() {
|
|
|
|
$.each(files, function() {
|
|
|
|
if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {sizeExceeded=true;}
|
|
|
|
if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {
|
|
|
|
|
|
|
|
sizeExceeded = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (sizeExceeded) {
|
|
|
|
if (sizeExceeded) {
|
|
|
|
window.alert(maxFileSizeExceeded);
|
|
|
|
window.alert(maxFileSizeExceeded);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$.each(files, function() {addFile(inputEl, this, true);});
|
|
|
|
$.each(files, function() {
|
|
|
|
|
|
|
|
addFile(inputEl, this, true);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uploadAndAttachFiles_board(files, inputEl, id) {
|
|
|
|
function uploadAndAttachFiles_board(files, inputEl, id) {
|
|
|
|
|
|
|
|
|
|
|
|
var maxFileSize = $(inputEl).data('max-file-size');
|
|
|
|
var maxFileSize = $(inputEl).data('max-file-size');
|
|
|
@ -314,14 +390,19 @@ function uploadAndAttachFiles_board(files, inputEl, id) {
|
|
|
|
|
|
|
|
|
|
|
|
var sizeExceeded = false;
|
|
|
|
var sizeExceeded = false;
|
|
|
|
$.each(files, function() {
|
|
|
|
$.each(files, function() {
|
|
|
|
if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {sizeExceeded=true;}
|
|
|
|
if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {
|
|
|
|
|
|
|
|
sizeExceeded = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (sizeExceeded) {
|
|
|
|
if (sizeExceeded) {
|
|
|
|
window.alert(maxFileSizeExceeded);
|
|
|
|
window.alert(maxFileSizeExceeded);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$.each(files, function() {addFile_board(inputEl, this, true, id);});
|
|
|
|
$.each(files, function() {
|
|
|
|
|
|
|
|
addFile_board(inputEl, this, true, id);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleFileDropEvent(e) {
|
|
|
|
function handleFileDropEvent(e) {
|
|
|
|
|
|
|
|
|
|
|
|
$(this).removeClass('fileover');
|
|
|
|
$(this).removeClass('fileover');
|
|
|
@ -345,7 +426,9 @@ function dragOutHandler(e) {
|
|
|
|
function setupFileDrop() {
|
|
|
|
function setupFileDrop() {
|
|
|
|
if (window.File && window.FileList && window.ProgressEvent && window.FormData) {
|
|
|
|
if (window.File && window.FileList && window.ProgressEvent && window.FormData) {
|
|
|
|
|
|
|
|
|
|
|
|
$.event.fixHooks.drop = { props: [ 'dataTransfer' ] };
|
|
|
|
$.event.fixHooks.drop = {
|
|
|
|
|
|
|
|
props: ['dataTransfer']
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$('form div.box').has('input:file').each(function() {
|
|
|
|
$('form div.box').has('input:file').each(function() {
|
|
|
|
$(this).on({
|
|
|
|
$(this).on({
|
|
|
|