mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
Fix uploaded file max size validation in JS [SCI-2590]
This commit is contained in:
parent
339fe1cc81
commit
a169639b3c
6 changed files with 25 additions and 16 deletions
|
@ -469,8 +469,8 @@ function initImport() {
|
|||
alert(I18n.t("my_modules.protocols.load_from_file_error_locked"));
|
||||
} else {
|
||||
if (data.status === 'size_too_large') {
|
||||
alert('<%= I18n.t('my_modules.protocols.load_from_file_size_error',
|
||||
size: Rails.configuration.x.file_max_size_mb ) %>');
|
||||
alert(I18n.t('my_modules.protocols.load_from_file_size_error',
|
||||
{ size: $(document.body).data('file-max-size-mb') } ));
|
||||
} else {
|
||||
alert(I18n.t("my_modules.protocols.load_from_file_error"));
|
||||
}
|
||||
|
|
|
@ -557,7 +557,7 @@ function importProtocolFromFile(
|
|||
$.extend(data_json, params);
|
||||
|
||||
var rough_size = roughSizeOfObject(data_json);
|
||||
if (rough_size > <%= Rails.configuration.x.file_max_size_mb.megabytes %>) {
|
||||
if (rough_size > ($(document.body).data('file-max-size-mb') * 1024 * 1024)) {
|
||||
// Call the callback function
|
||||
resultCallback({ name: protocolJson["name"], new_name: null, status: "size_too_large" });
|
||||
return;
|
||||
|
|
|
@ -161,8 +161,12 @@
|
|||
var droppedFiles = [];
|
||||
var filesValid = true;
|
||||
var totalSize = 0;
|
||||
var fileMaxSizeMb;
|
||||
var fileMaxSize;
|
||||
|
||||
function init(files) {
|
||||
fileMaxSizeMb = $(document.body).data('file-max-size-mb');
|
||||
fileMaxSize = fileMaxSizeMb * 1024 * 1024;
|
||||
for(var i = 0; i < files.length; i++) {
|
||||
droppedFiles.push(files[i]);
|
||||
}
|
||||
|
@ -235,23 +239,23 @@
|
|||
function _validateFilesSize(file) {
|
||||
var fileSize = file.size;
|
||||
totalSize += parseInt(fileSize);
|
||||
if(fileSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||
if(fileSize > fileMaxSize) {
|
||||
file.isValid = false;
|
||||
_disableSubmitButton();
|
||||
return "<p class='dnd-error'><%= I18n.t 'general.file.size_exceeded', file_size: Rails.configuration.x.file_max_size_mb %></p>";
|
||||
return "<p class='dnd-error'>" + I18n.t('general.file.size_exceeded', { file_size: fileMaxSizeMb }) + '</p>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function _validateTotalSize() {
|
||||
if(totalSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||
if(totalSize > fileMaxSize) {
|
||||
filesValid = false;
|
||||
_disableSubmitButton();
|
||||
$.each($('.panel-step-attachment-new'), function() {
|
||||
if(!$(this).find('p').hasClass('dnd-total-error')) {
|
||||
$(this)
|
||||
.find('.panel-body')
|
||||
.append("<p class='dnd-total-error'><%= I18n.t('general.file.total_size', size: Rails.configuration.x.file_max_size_mb) %></p>");
|
||||
.append("<p class='dnd-total-error'>" + I18n.t('general.file.total_size', { size: fileMaxSizeMb }) + '</p>');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -315,8 +319,12 @@
|
|||
var droppedFiles = [];
|
||||
var isValid = true;
|
||||
var totalSize = 0;
|
||||
var fileMaxSizeMb;
|
||||
var fileMaxSize;
|
||||
|
||||
function init(files) {
|
||||
fileMaxSizeMb = $(document.body).data('file-max-size-mb');
|
||||
fileMaxSize = fileMaxSizeMb * 1024 * 1024;
|
||||
for(var i = 0; i < files.length; i++) {
|
||||
droppedFiles.push(files[i]);
|
||||
}
|
||||
|
@ -392,23 +400,23 @@
|
|||
function _validateFilesSize(file) {
|
||||
var fileSize = file.size;
|
||||
totalSize += parseInt(fileSize);
|
||||
if(fileSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||
if(fileSize > fileMaxSize) {
|
||||
file.isValid = false;
|
||||
_disableSubmitButton();
|
||||
return "<p class='dnd-error'><%= I18n.t 'general.file.size_exceeded', file_size: Rails.configuration.x.file_max_size_mb %></p>";
|
||||
return "<p class='dnd-error'>" + I18n.t('general.file.size_exceeded', { file_size: fileMaxSizeMb }) + '</p>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function _validateTotalSize() {
|
||||
if(totalSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||
if(totalSize > fileMaxSize) {
|
||||
isValid = false;
|
||||
_disableSubmitButton();
|
||||
$.each($('.panel-result-attachment-new'), function() {
|
||||
if(!$(this).find('p').hasClass('dnd-total-error')) {
|
||||
$(this)
|
||||
.find('.panel-body')
|
||||
.append("<p class='dnd-total-error'><%= I18n.t('general.file.total_size', size: Rails.configuration.x.file_max_size_mb) %></p>");
|
||||
.append("<p class='dnd-total-error'>" + I18n.t('general.file.total_size', { size: fileMaxSizeMb }) + '</p>');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -102,7 +102,7 @@ function checklistsValidator(ev, checklists, editMode) {
|
|||
}
|
||||
|
||||
var FileTypeEnum = Object.freeze({
|
||||
FILE: <%= Rails.configuration.x.file_max_size_mb.megabytes %>,
|
||||
FILE: $(document.body).data('file-max-size-mb') * 1024 * 1024,
|
||||
AVATAR: <%= Constants::AVATAR_MAX_SIZE_MB.megabytes %>
|
||||
});
|
||||
|
||||
|
@ -140,7 +140,7 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
|
|||
if (file.size > fileTypeEnum) {
|
||||
switch (fileTypeEnum) {
|
||||
case FileTypeEnum.FILE:
|
||||
return "<%= I18n.t 'general.file.size_exceeded', file_size: Rails.configuration.x.file_max_size_mb %>".strToErrorFormat();
|
||||
return I18n.t('general.file.size_exceeded', { file_size: $(document.body).data('file-max-size-mb') }).strToErrorFormat();
|
||||
case FileTypeEnum.AVATAR:
|
||||
return "<%= I18n.t 'general.file.size_exceeded', file_size: Constants::AVATAR_MAX_SIZE_MB %>".strToErrorFormat();
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
|
|||
if (size > fileTypeEnum) {
|
||||
switch (fileTypeEnum) {
|
||||
case FileTypeEnum.FILE:
|
||||
return "<%= I18n.t('general.file.total_size', size: Rails.configuration.x.file_max_size_mb) %>".strToErrorFormat();
|
||||
return I18n.t('general.file.total_size', { size: $(document.body).data('file-max-size-mb') }).strToErrorFormat();
|
||||
case FileTypeEnum.AVATAR:
|
||||
return "<%= I18n.t('users.registrations.edit.avatar_total_size', size: Constants::AVATAR_MAX_SIZE_MB) %>".strToErrorFormat();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
data-atwho-repositories-url="<%= atwho_repositories_team_path(current_team) %>"
|
||||
data-atwho-rep-items-url="<%= atwho_rep_items_team_path(current_team) %>"
|
||||
data-atwho-menu-items="<%= atwho_menu_items_team_path(current_team) %>"
|
||||
data-file-max-size-mb="<%= Rails.configuration.x.file_max_size_mb %>"
|
||||
<% end %>
|
||||
>
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ $('#modal-import-json-protocol').on('hidden.bs.modal', function () {
|
|||
})
|
||||
<% if @protocolsio_too_big %>
|
||||
$('#modal-import-json-protocol').modal('hide');
|
||||
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_size_error',
|
||||
size: Rails.configuration.x.file_max_size_mb ) %>','danger');
|
||||
HelperModule.flashAlertMsg(I18n.t('my_modules.protocols.load_from_file_size_error',
|
||||
{ size: $(document.body).data('file-max-size-mb') ) }, 'danger');
|
||||
<% elsif @protocolsio_invalid_file %>
|
||||
$('#modal-import-json-protocol').modal('hide');
|
||||
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_invalid_error') %>','danger');
|
||||
|
|
Loading…
Add table
Reference in a new issue