scinote-web/app/assets/javascripts/sitewide/file_upload_handling.js.erb
2016-07-21 13:11:15 +02:00

30 lines
No EOL
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;
}