|
|
@ -16,9 +16,10 @@ define('uploader', ['csrf', 'translator'], function(csrf, translator) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.show = function(data, callback) {
|
|
|
|
module.show = function(data, callback) {
|
|
|
|
|
|
|
|
var fileSize = data.hasOwnProperty('fileSize') && data.fileSize !== undefined ? parseInt(data.fileSize, 10) : false;
|
|
|
|
parseModal({
|
|
|
|
parseModal({
|
|
|
|
showHelp: data.hasOwnProperty('showHelp') && data.showHelp !== undefined ? data.showHelp : true,
|
|
|
|
showHelp: data.hasOwnProperty('showHelp') && data.showHelp !== undefined ? data.showHelp : true,
|
|
|
|
fileSize: data.hasOwnProperty('fileSize') && data.fileSize !== undefined ? parseInt(data.fileSize, 10) : false,
|
|
|
|
fileSize: fileSize,
|
|
|
|
title: data.title || '[[global:upload_file]]',
|
|
|
|
title: data.title || '[[global:upload_file]]',
|
|
|
|
description: data.description || '',
|
|
|
|
description: data.description || '',
|
|
|
|
button: data.button || '[[global:upload]]',
|
|
|
|
button: data.button || '[[global:upload]]',
|
|
|
@ -40,13 +41,17 @@ define('uploader', ['csrf', 'translator'], function(csrf, translator) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
uploadForm.submit(function() {
|
|
|
|
uploadForm.submit(function() {
|
|
|
|
onSubmit(uploadModal, callback);
|
|
|
|
onSubmit(uploadModal, fileSize, callback);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function onSubmit(uploadModal, callback) {
|
|
|
|
module.hideAlerts = function(modal) {
|
|
|
|
|
|
|
|
$(modal).find('#alert-status, #alert-success, #alert-error, #upload-progress-box').addClass('hide');
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onSubmit(uploadModal, fileSize, callback) {
|
|
|
|
function showAlert(type, message) {
|
|
|
|
function showAlert(type, message) {
|
|
|
|
module.hideAlerts(uploadModal);
|
|
|
|
module.hideAlerts(uploadModal);
|
|
|
|
uploadModal.find('#alert-' + type).translateText(message).removeClass('hide');
|
|
|
|
uploadModal.find('#alert-' + type).translateText(message).removeClass('hide');
|
|
|
@ -57,9 +62,13 @@ define('uploader', ['csrf', 'translator'], function(csrf, translator) {
|
|
|
|
uploadModal.find('#upload-progress-bar').css('width', '0%');
|
|
|
|
uploadModal.find('#upload-progress-bar').css('width', '0%');
|
|
|
|
uploadModal.find('#upload-progress-box').show().removeClass('hide');
|
|
|
|
uploadModal.find('#upload-progress-box').show().removeClass('hide');
|
|
|
|
|
|
|
|
|
|
|
|
if (!uploadModal.find('#fileInput').val()) {
|
|
|
|
var fileInput = uploadModal.find('#fileInput');
|
|
|
|
|
|
|
|
if (!fileInput.val()) {
|
|
|
|
return showAlert('error', '[[uploads:select-file-to-upload]]');
|
|
|
|
return showAlert('error', '[[uploads:select-file-to-upload]]');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasValidFileSize(fileInput[0], fileSize) === false) {
|
|
|
|
|
|
|
|
return showAlert('error', '[[error:file-too-big, ' + fileSize + ']]');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uploadModal.find('#uploadForm').ajaxSubmit({
|
|
|
|
uploadModal.find('#uploadForm').ajaxSubmit({
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
@ -107,9 +116,11 @@ define('uploader', ['csrf', 'translator'], function(csrf, translator) {
|
|
|
|
return response;
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.hideAlerts = function(modal) {
|
|
|
|
function hasValidFileSize(fileElement, maxSize) {
|
|
|
|
$(modal).find('#alert-status, #alert-success, #alert-error, #upload-progress-box').addClass('hide');
|
|
|
|
if (window.FileReader && maxSize) {
|
|
|
|
};
|
|
|
|
return fileElement.files[0].size <= maxSize * 1000;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return module;
|
|
|
|
return module;
|
|
|
|
});
|
|
|
|
});
|
|
|
|