Deprecated uploader.open, use uploader.show instead

... as it now takes a single Object argument instead of multiple
parameters.

Also, closes #3942. Help text is just omitted now.
v1.18.x
Julian Lam 9 years ago
parent 84a039446c
commit c1460d36f0

@ -110,7 +110,12 @@ define('admin/settings', ['uploader', 'sounds'], function(uploader, sounds) {
$('#content input[data-action="upload"]').each(function() { $('#content input[data-action="upload"]').each(function() {
var uploadBtn = $(this); var uploadBtn = $(this);
uploadBtn.on('click', function() { uploadBtn.on('click', function() {
uploader.open(uploadBtn.attr('data-route'), {}, 0, function(image) { uploader.show({
route: uploadBtn.attr('data-route'),
params: {},
fileSize: 0,
showHelp: uploadBtn.attr('data-help') ? uploadBtn.attr('data-help') === 1 : undefined
}, function(image) {
$('#' + uploadBtn.attr('data-target')).val(image); $('#' + uploadBtn.attr('data-target')).val(image);
}); });
}); });

@ -2,12 +2,24 @@
/* globals define, templates, translator */ /* globals define, templates, translator */
define('uploader', ['csrf'], function(csrf) { define('uploader', ['csrf', 'translator'], function(csrf, translator) {
var module = {}; var module = {};
module.open = function(route, params, fileSize, callback) { module.open = function(route, params, fileSize, callback) {
parseModal(function(uploadModal) { console.warn('[uploader] uploader.open() is deprecated, please use uploader.show() instead, and pass parameters as a singe option with callback, e.g. uploader.show({}, callback);');
module.show({
route: route,
params: params,
fileSize: fileSize
}, callback);
};
module.show = function(data, callback) {
parseModal({
showHelp: data.hasOwnProperty('showHelp') && data.showHelp !== undefined ? data.showHelp : true,
fileSize: data.hasOwnProperty('fileSize') && data.fileSize !== undefined ? parseInt(data.fileSize, 10) : false
}, function(uploadModal) {
uploadModal = $(uploadModal); uploadModal = $(uploadModal);
uploadModal.modal('show'); uploadModal.modal('show');
@ -16,16 +28,8 @@ define('uploader', ['csrf'], function(csrf) {
}); });
var uploadForm = uploadModal.find('#uploadForm'); var uploadForm = uploadModal.find('#uploadForm');
uploadForm.attr('action', route); uploadForm.attr('action', data.route);
uploadForm.find('#params').val(JSON.stringify(params)); uploadForm.find('#params').val(JSON.stringify(data.params));
if (fileSize) {
uploadForm.find('#file-size-block')
.translateText('([[uploads:maximum-file-size, ' + fileSize + ']])')
.removeClass('hide');
} else {
uploadForm.find('#file-size-block').addClass('hide');
}
uploadModal.find('#pictureUploadSubmitBtn').off('click').on('click', function() { uploadModal.find('#pictureUploadSubmitBtn').off('click').on('click', function() {
uploadForm.submit(); uploadForm.submit();
@ -84,8 +88,8 @@ define('uploader', ['csrf'], function(csrf) {
}); });
}; };
function parseModal(callback) { function parseModal(tplVals, callback) {
templates.parse('partials/modals/upload_picture_modal', {}, function(html) { templates.parse('partials/modals/upload_picture_modal', tplVals, function(html) {
translator.translate(html, callback); translator.translate(html, callback);
}); });
} }

@ -73,7 +73,7 @@
<div class="input-group"> <div class="input-group">
<input id="faviconUrl" type="text" class="form-control" placeholder="favicon.ico" data-field="brand:favicon" data-action="upload" data-target="faviconUrl" data-route="{config.relative_path}/api/admin/uploadfavicon" readonly /> <input id="faviconUrl" type="text" class="form-control" placeholder="favicon.ico" data-field="brand:favicon" data-action="upload" data-target="faviconUrl" data-route="{config.relative_path}/api/admin/uploadfavicon" readonly />
<span class="input-group-btn"> <span class="input-group-btn">
<input data-action="upload" data-target="faviconUrl" data-route="{config.relative_path}/api/admin/uploadfavicon" type="button" class="btn btn-default" value="Upload"></input> <input data-action="upload" data-target="faviconUrl" data-route="{config.relative_path}/api/admin/uploadfavicon" data-help="0" type="button" class="btn btn-default" value="Upload"></input>
<button data-action="removeFavicon" type="button" class="btn btn-default btn-danger"><i class="fa fa-times"></i></button> <button data-action="removeFavicon" type="button" class="btn btn-default btn-danger"><i class="fa fa-times"></i></button>
</span> </span>
</div> </div>

Loading…
Cancel
Save