parse upload picture modal on demand

v1.18.x
barisusakli 10 years ago
parent d992e64687
commit 30bc401797

@ -1,17 +1,21 @@
'use strict'; 'use strict';
/* globals define */ /* globals define, templates, translator */
define('uploader', ['csrf'], function(csrf) { define('uploader', ['csrf'], function(csrf) {
var module = {}; var module = {};
module.open = function(route, params, fileSize, callback) { module.open = function(route, params, fileSize, callback) {
var uploadModal = $('#upload-picture-modal'); parseModal(function(uploadModal) {
uploadModal.modal('show').removeClass('hide'); uploadModal = $(uploadModal);
module.hideAlerts();
var uploadForm = $('#uploadForm'); uploadModal.modal('show');
uploadForm[0].reset(); uploadModal.on('hidden.bs.modal', function() {
uploadModal.remove();
});
var uploadForm = uploadModal.find('#uploadForm');
uploadForm.attr('action', route); uploadForm.attr('action', route);
uploadForm.find('#params').val(JSON.stringify(params)); uploadForm.find('#params').val(JSON.stringify(params));
@ -23,14 +27,14 @@ define('uploader', ['csrf'], function(csrf) {
uploadForm.find('#file-size-block').addClass('hide'); uploadForm.find('#file-size-block').addClass('hide');
} }
$('#pictureUploadSubmitBtn').off('click').on('click', function() { uploadModal.find('#pictureUploadSubmitBtn').off('click').on('click', function() {
uploadForm.submit(); uploadForm.submit();
}); });
uploadForm.off('submit').submit(function() { uploadForm.off('submit').submit(function() {
function showAlert(type, message) { function showAlert(type, message) {
module.hideAlerts(); module.hideAlerts(uploadModal);
uploadModal.find('#alert-' + type).translateText(message).removeClass('hide'); uploadModal.find('#alert-' + type).translateText(message).removeClass('hide');
} }
@ -39,7 +43,7 @@ define('uploader', ['csrf'], function(csrf) {
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 (!$('#userPhotoInput').val()) { if (!uploadModal.find('#userPhotoInput').val()) {
showAlert('error', '[[uploads:select-file-to-upload]]'); showAlert('error', '[[uploads:select-file-to-upload]]');
return false; return false;
} }
@ -77,8 +81,15 @@ define('uploader', ['csrf'], function(csrf) {
return false; return false;
}); });
});
}; };
function parseModal(callback) {
templates.parse('partials/modals/upload_picture_modal', {}, function(html) {
translator.translate(html, callback);
});
}
function maybeParse(response) { function maybeParse(response) {
if (typeof response === 'string') { if (typeof response === 'string') {
try { try {
@ -90,8 +101,8 @@ define('uploader', ['csrf'], function(csrf) {
return response; return response;
} }
module.hideAlerts = function() { module.hideAlerts = function(modal) {
$('#upload-picture-modal').find('#alert-status, #alert-success, #alert-error, #upload-progress-box').addClass('hide'); modal.find('#alert-status, #alert-success, #alert-error, #upload-progress-box').addClass('hide');
}; };
return module; return module;

Loading…
Cancel
Save