Add a waring about max number of uploaded files exceeded #1561
This commit is contained in:
parent
40f1d18f52
commit
cc69212b74
@ -91,6 +91,8 @@
|
|||||||
multiple: multiple,
|
multiple: multiple,
|
||||||
onchange: 'dmsfAddInputFiles(this);',
|
onchange: 'dmsfAddInputFiles(this);',
|
||||||
data: {
|
data: {
|
||||||
|
max_number_of_files_message: l(:error_attachments_too_many,
|
||||||
|
max_number_of_files: (multiple ? 10 : 1)),
|
||||||
max_file_size: Setting.attachment_max_size.to_i.kilobytes,
|
max_file_size: Setting.attachment_max_size.to_i.kilobytes,
|
||||||
max_file_size_message: l(:error_attachment_too_big,
|
max_file_size_message: l(:error_attachment_too_big,
|
||||||
max_size: number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
|
max_size: number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
|
||||||
|
|||||||
@ -18,29 +18,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function dmsfAddLink(linksSpan, linkId, linkName, title, project, awf) {
|
function dmsfAddLink(linksSpan, linkId, linkName, title, project, awf) {
|
||||||
|
let nextLinkId = dmsfAddLink.nextLinkId++;
|
||||||
if (linksSpan.children().length < 10) {
|
let linkSpan = $('<span>', { id: 'dmsf_links_attachments_' + nextLinkId, 'class': 'attachment' });
|
||||||
|
let iconDel = $('<a>').attr({href: '#', 'class': 'remove-upload icon-only icon-del'});
|
||||||
let nextLinkId = dmsfAddLink.nextLinkId++;
|
let inputId = $('<input>', {type: 'hidden', name: 'dmsf_links[' + nextLinkId + ']'}).val(linkId);
|
||||||
let linkSpan = $('<span>', { id: 'dmsf_links_attachments_' + nextLinkId, 'class': 'attachment' });
|
let inputName = $('<input>', {type: 'text', class: 'filename readonly'}).val(linkName);
|
||||||
let iconDel = $('<a>').attr({href: '#', 'class': 'remove-upload icon-only icon-del'});
|
linkSpan.append(inputId);
|
||||||
let inputId = $('<input>', {type: 'hidden', name: 'dmsf_links[' + nextLinkId + ']'}).val(linkId);
|
linkSpan.append(inputName);
|
||||||
let inputName = $('<input>', {type: 'text', class: 'filename readonly'}).val(linkName);
|
linkSpan.append(iconDel.click(dmsfRemoveFileLbl));
|
||||||
|
if(awf) {
|
||||||
linkSpan.append(inputId);
|
let iconWf = $('<a>').attr({href: "/dmsf-workflows/" + project + "/assign?dmsf_link_id=" + linkId,
|
||||||
linkSpan.append(inputName);
|
'class': 'modify-upload icon-only icon-ok', 'data-remote': 'true', 'title': title});
|
||||||
linkSpan.append(iconDel.click(dmsfRemoveFileLbl));
|
linkSpan.append(iconWf);
|
||||||
|
|
||||||
if(awf) {
|
|
||||||
|
|
||||||
let iconWf = $('<a>').attr({href: "/dmsf-workflows/" + project + "/assign?dmsf_link_id=" + linkId,
|
|
||||||
'class': 'modify-upload icon-only icon-ok', 'data-remote': 'true', 'title': title});
|
|
||||||
|
|
||||||
linkSpan.append(iconWf);
|
|
||||||
}
|
|
||||||
|
|
||||||
linksSpan.append(linkSpan);
|
|
||||||
}
|
}
|
||||||
|
linksSpan.append(linkSpan);
|
||||||
}
|
}
|
||||||
|
|
||||||
dmsfAddLink.nextLinkId = 1000;
|
dmsfAddLink.nextLinkId = 1000;
|
||||||
@ -148,40 +139,29 @@ function replaceVersion(detailsForm, attachmentId, name, version) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dmsfAddFile(inputEl, file, eagerUpload) {
|
function dmsfAddFile(inputEl, file, eagerUpload) {
|
||||||
|
|
||||||
let attachments = $('#dmsf_attachments_fields');
|
let attachments = $('#dmsf_attachments_fields');
|
||||||
let max = ($(inputEl).attr('multiple') == 'multiple') ? 10 : 1
|
let max = ($(inputEl).attr('multiple') == 'multiple') ? 10 : 1
|
||||||
|
|
||||||
if (attachments.children('.attachment').length < max) {
|
if (attachments.children('.attachment').length < max) {
|
||||||
|
|
||||||
let attachmentId = dmsfAddFile.nextAttachmentId++;
|
let attachmentId = dmsfAddFile.nextAttachmentId++;
|
||||||
let fileSpan = $('<span>', { id: 'dmsf_attachments_' + attachmentId, 'class': 'attachment' });
|
let fileSpan = $('<span>', { id: 'dmsf_attachments_' + attachmentId, 'class': 'attachment' });
|
||||||
let iconDel = $('<a>').attr({href: '#', 'class': 'remove-upload icon-only icon-del'}).toggle(!eagerUpload);
|
let iconDel = $('<a>').attr({href: '#', 'class': 'remove-upload icon-only icon-del'}).toggle(!eagerUpload);
|
||||||
let fileName = $('<input>', {type: 'text', 'class': 'filename readonly',
|
let fileName = $('<input>', {type: 'text', 'class': 'filename readonly',
|
||||||
name: 'dmsf_attachments[' + attachmentId + '][filename]', readonly: 'readonly'}).val(file.name);
|
name: 'dmsf_attachments[' + attachmentId + '][filename]', readonly: 'readonly'}).val(file.name);
|
||||||
|
|
||||||
fileSpan.append(fileName);
|
fileSpan.append(fileName);
|
||||||
|
|
||||||
if($(inputEl).attr('multiple') == 'multiple') {
|
if($(inputEl).attr('multiple') == 'multiple') {
|
||||||
|
|
||||||
fileSpan.append(iconDel.click(dmsfRemoveFileLbl));
|
fileSpan.append(iconDel.click(dmsfRemoveFileLbl));
|
||||||
|
|
||||||
if ($(inputEl).data('awf')) {
|
if ($(inputEl).data('awf')) {
|
||||||
|
|
||||||
let iconWf = $('<a>').attr({
|
let iconWf = $('<a>').attr({
|
||||||
href: '/dmsf-workflows/' + $(inputEl).attr(
|
href: '/dmsf-workflows/' + $(inputEl).attr(
|
||||||
'data-project') + "/assign?attachment_id=" + attachmentId,
|
'data-project') + "/assign?attachment_id=" + attachmentId,
|
||||||
'class': 'modify-upload icon-only icon-ok',
|
'class': 'modify-upload icon-only icon-ok',
|
||||||
'data-remote': 'true'
|
'data-remote': 'true'
|
||||||
});
|
});
|
||||||
|
|
||||||
fileSpan.append(iconWf);
|
fileSpan.append(iconWf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Details
|
// Details
|
||||||
let detailsDiv = $('<div>').attr({id: 'dmsf_attachments_details_' + attachmentId});
|
let detailsDiv = $('<div>').attr({id: 'dmsf_attachments_details_' + attachmentId});
|
||||||
let detailsArrow = $('<a>');
|
let detailsArrow = $('<a>');
|
||||||
|
|
||||||
detailsArrow.text('[+]');
|
detailsArrow.text('[+]');
|
||||||
detailsArrow.attr({href: "#", 'data-cy': 'toggle__new_revision_from_content--dmsf', title: 'Details'});
|
detailsArrow.attr({href: "#", 'data-cy': 'toggle__new_revision_from_content--dmsf', title: 'Details'});
|
||||||
detailsArrow.attr(
|
detailsArrow.attr(
|
||||||
@ -196,7 +176,6 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
|
|||||||
let files = $(inputEl).data('files');
|
let files = $(inputEl).data('files');
|
||||||
let locked = isFileLocked(file.name, files);
|
let locked = isFileLocked(file.name, files);
|
||||||
let detailsForm = $(inputEl).data(locked ? 'dmsf-file-details-form-locked' : 'dmsf-file-details-form');
|
let detailsForm = $(inputEl).data(locked ? 'dmsf-file-details-form-locked' : 'dmsf-file-details-form');
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
detailsForm = detailsForm.replace(/\[0\]/g, '[' + attachmentId + ']');
|
detailsForm = detailsForm.replace(/\[0\]/g, '[' + attachmentId + ']');
|
||||||
detailsForm = detailsForm.replace(/_0/g, '_' + attachmentId);
|
detailsForm = detailsForm.replace(/_0/g, '_' + attachmentId);
|
||||||
@ -226,10 +205,8 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
|
|||||||
detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]);
|
detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]);
|
||||||
detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]);
|
detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
detailsDiv.append(detailsForm);
|
detailsDiv.append(detailsForm);
|
||||||
detailsDiv.hide();
|
detailsDiv.hide();
|
||||||
|
|
||||||
fileSpan.append(detailsArrow)
|
fileSpan.append(detailsArrow)
|
||||||
attachments.append(fileSpan);
|
attachments.append(fileSpan);
|
||||||
attachments.append(detailsDiv);
|
attachments.append(detailsDiv);
|
||||||
@ -239,11 +216,9 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
|
|||||||
$('#dmsf_file_revision_name').val(file.name);
|
$('#dmsf_file_revision_name').val(file.name);
|
||||||
}
|
}
|
||||||
attachments.append('<br>');
|
attachments.append('<br>');
|
||||||
|
|
||||||
if(eagerUpload) {
|
if(eagerUpload) {
|
||||||
dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl);
|
dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachmentId;
|
return attachmentId;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -252,29 +227,24 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
|
|||||||
dmsfAddFile.nextAttachmentId = 1;
|
dmsfAddFile.nextAttachmentId = 1;
|
||||||
|
|
||||||
function dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl) {
|
function dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl) {
|
||||||
|
|
||||||
function onLoadstart(e) {
|
function onLoadstart(e) {
|
||||||
fileSpan.removeClass('ajax-waiting');
|
fileSpan.removeClass('ajax-waiting');
|
||||||
fileSpan.addClass('ajax-loading');
|
fileSpan.addClass('ajax-loading');
|
||||||
$('input:submit', $(this).parents('form')).attr('disabled', 'disabled');
|
$('input:submit', $(this).parents('form')).attr('disabled', 'disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
function onProgress(e) {
|
function onProgress(e) {
|
||||||
if(e.lengthComputable) {
|
if(e.lengthComputable) {
|
||||||
this.progressbar('value', e.loaded * 100 / e.total);
|
this.progressbar('value', e.loaded * 100 / e.total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function actualUpload(file, attachmentId, fileSpan, inputEl) {
|
function actualUpload(file, attachmentId, fileSpan, inputEl) {
|
||||||
|
|
||||||
dmsfAjaxUpload.uploading++;
|
dmsfAjaxUpload.uploading++;
|
||||||
|
|
||||||
dmsfUploadBlob(file, $(inputEl).data('upload-path'), attachmentId, {
|
dmsfUploadBlob(file, $(inputEl).data('upload-path'), attachmentId, {
|
||||||
loadstartEventHandler: onLoadstart.bind(progressSpan),
|
loadstartEventHandler: onLoadstart.bind(progressSpan),
|
||||||
progressEventHandler: onProgress.bind(progressSpan)
|
progressEventHandler: onProgress.bind(progressSpan)
|
||||||
})
|
})
|
||||||
.done(function(result) {
|
.done(function(result) {
|
||||||
progressSpan.progressbar( 'value', 100 ).remove();
|
progressSpan.progressbar('value', 100).remove();
|
||||||
fileSpan.find('input.description, a').css('display', 'inline-block');
|
fileSpan.find('input.description, a').css('display', 'inline-block');
|
||||||
})
|
})
|
||||||
.fail(function(result) {
|
.fail(function(result) {
|
||||||
@ -289,13 +259,10 @@ function dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl) {
|
|||||||
form.dequeue('upload');
|
form.dequeue('upload');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let progressSpan = $('<div>').insertAfter(fileSpan.find('input.filename'));
|
let progressSpan = $('<div>').insertAfter(fileSpan.find('input.filename'));
|
||||||
progressSpan.progressbar();
|
progressSpan.progressbar();
|
||||||
fileSpan.addClass('ajax-waiting');
|
fileSpan.addClass('ajax-waiting');
|
||||||
|
|
||||||
let maxSyncUpload = $(inputEl).data('max-concurrent-uploads');
|
let maxSyncUpload = $(inputEl).data('max-concurrent-uploads');
|
||||||
|
|
||||||
if(maxSyncUpload == null || maxSyncUpload <= 0 || dmsfAjaxUpload.uploading < maxSyncUpload)
|
if(maxSyncUpload == null || maxSyncUpload <= 0 || dmsfAjaxUpload.uploading < maxSyncUpload)
|
||||||
actualUpload(file, attachmentId, fileSpan, inputEl);
|
actualUpload(file, attachmentId, fileSpan, inputEl);
|
||||||
else
|
else
|
||||||
@ -305,29 +272,23 @@ function dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl) {
|
|||||||
dmsfAjaxUpload.uploading = 0;
|
dmsfAjaxUpload.uploading = 0;
|
||||||
|
|
||||||
function dmsfRemoveFileLbl() {
|
function dmsfRemoveFileLbl() {
|
||||||
|
|
||||||
let span = $(this).parent('span');
|
let span = $(this).parent('span');
|
||||||
|
|
||||||
span.next('div').remove();
|
span.next('div').remove();
|
||||||
span.next('br').remove();
|
span.next('br').remove();
|
||||||
span.remove();
|
span.remove();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function dmsfUploadBlob(blob, uploadUrl, attachmentId, options) {
|
function dmsfUploadBlob(blob, uploadUrl, attachmentId, options) {
|
||||||
|
|
||||||
let actualOptions = $.extend({
|
let actualOptions = $.extend({
|
||||||
loadstartEventHandler: $.noop,
|
loadstartEventHandler: $.noop,
|
||||||
progressEventHandler: $.noop
|
progressEventHandler: $.noop
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
uploadUrl = uploadUrl + '?attachment_id=' + attachmentId;
|
uploadUrl = uploadUrl + '?attachment_id=' + attachmentId;
|
||||||
if (blob instanceof window.File) {
|
if (blob instanceof window.File) {
|
||||||
uploadUrl += '&filename=' + encodeURIComponent(blob.name);
|
uploadUrl += '&filename=' + encodeURIComponent(blob.name);
|
||||||
uploadUrl += '&content_type=' + encodeURIComponent(blob.type);
|
uploadUrl += '&content_type=' + encodeURIComponent(blob.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $.ajax(uploadUrl, {
|
return $.ajax(uploadUrl, {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
contentType: 'application/octet-stream',
|
contentType: 'application/octet-stream',
|
||||||
@ -349,10 +310,8 @@ function dmsfUploadBlob(blob, uploadUrl, attachmentId, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dmsfAddInputFiles(inputEl) {
|
function dmsfAddInputFiles(inputEl) {
|
||||||
|
|
||||||
let clearedFileInput = $(inputEl).clone().val('');
|
let clearedFileInput = $(inputEl).clone().val('');
|
||||||
let addFileSpan = $('.dmsf_add_attachment');
|
let addFileSpan = $('.dmsf_add_attachment');
|
||||||
|
|
||||||
if ($.ajaxSettings.xhr().upload && inputEl.files) {
|
if ($.ajaxSettings.xhr().upload && inputEl.files) {
|
||||||
// upload files using ajax
|
// upload files using ajax
|
||||||
dmsfUploadAndAttachFiles(inputEl.files, inputEl);
|
dmsfUploadAndAttachFiles(inputEl.files, inputEl);
|
||||||
@ -367,19 +326,19 @@ function dmsfAddInputFiles(inputEl) {
|
|||||||
'#dmsf_attachments_' + attachmentId);
|
'#dmsf_attachments_' + attachmentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearedFileInput.val('');
|
clearedFileInput.val('');
|
||||||
addFileSpan.prepend(clearedFileInput);
|
addFileSpan.prepend(clearedFileInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dmsfUploadAndAttachFiles(files, inputEl) {
|
function dmsfUploadAndAttachFiles(files, inputEl) {
|
||||||
|
|
||||||
let maxFileSize = $(inputEl).data('max-file-size');
|
let maxFileSize = $(inputEl).data('max-file-size');
|
||||||
let maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
|
let maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
|
||||||
let sizeExceeded = false;
|
let sizeExceeded = false;
|
||||||
|
let filesLength = $('#dmsf_attachments_fields').children().length + files.length
|
||||||
$.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);
|
||||||
@ -388,13 +347,14 @@ function dmsfUploadAndAttachFiles(files, inputEl) {
|
|||||||
dmsfAddFile(inputEl, this, true);
|
dmsfAddFile(inputEl, this, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (filesLength > ($(inputEl).attr('multiple') == 'multiple' ? 10 : 1)) {
|
||||||
|
window.alert($(inputEl).data('max-number-of-files-message'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dmsfHandleFileDropEvent(e) {
|
function dmsfHandleFileDropEvent(e) {
|
||||||
|
|
||||||
$(this).removeClass('fileover');
|
$(this).removeClass('fileover');
|
||||||
blockEventPropagation(e);
|
blockEventPropagation(e);
|
||||||
|
|
||||||
if ($.inArray('Files', e.dataTransfer.types) > -1) {
|
if ($.inArray('Files', e.dataTransfer.types) > -1) {
|
||||||
dmsfUploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector'));
|
dmsfUploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector'));
|
||||||
}
|
}
|
||||||
@ -411,16 +371,13 @@ function dmsfDragOutHandler(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dmsfSetupFileDrop() {
|
function dmsfSetupFileDrop() {
|
||||||
|
|
||||||
if (window.File && window.FileList && window.ProgressEvent && window.FormData) {
|
if (window.File && window.FileList && window.ProgressEvent && window.FormData) {
|
||||||
|
|
||||||
if($().jquery < '3.0.0') {
|
if($().jquery < '3.0.0') {
|
||||||
$.event.fixHooks.drop = {props: ['dataTransfer']};
|
$.event.fixHooks.drop = {props: ['dataTransfer']};
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$.event.addProp('dataTransfer');
|
$.event.addProp('dataTransfer');
|
||||||
}
|
}
|
||||||
|
|
||||||
$('form span.dmsf-uploader:not(.dmsffiledroplistner)').has('input:file').each(function () {
|
$('form span.dmsf-uploader:not(.dmsffiledroplistner)').has('input:file').each(function () {
|
||||||
|
|
||||||
$(this).on({
|
$(this).on({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user