mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-23 07:58:49 +08:00
30 lines
874 B
Text
30 lines
874 B
Text
|
function checkFilesValidity(fileInputs) {
|
||
|
|
||
|
function getFileError(file) {
|
||
|
if (!file) {
|
||
|
return ;
|
||
|
}
|
||
|
var size = parseInt(file.size);
|
||
|
<% sizeLimit = FILE_SIZE_LIMIT %>;
|
||
|
if (size > <%= sizeLimit.megabytes %>) {
|
||
|
return "<%= I18n.t 'general.file_size_exceeded', file_size: sizeLimit %>";
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var isValid = true;
|
||
|
_.each(fileInputs, function(fileInput) {
|
||
|
var file = fileInput.files[0];
|
||
|
var assetError = getFileError(file);
|
||
|
var input = $(fileInput);
|
||
|
input.closest('.form-group').removeClass('has-error');
|
||
|
input.parent().find("[data-error='file-size']").remove();
|
||
|
if (assetError) {
|
||
|
input.closest('.form-group').addClass('has-error');
|
||
|
input.parent().append(
|
||
|
"<span class='help-block' data-error='file-size'>" + assetError + "</span>"
|
||
|
);
|
||
|
isValid = false;
|
||
|
}
|
||
|
});
|
||
|
return isValid;
|
||
|
}
|