From c1460d36f0067b737c31948f973914ee13d72e51 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 14 Dec 2015 12:00:24 -0500 Subject: [PATCH] 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. --- public/src/admin/settings.js | 7 +++++- public/src/modules/uploader.js | 32 ++++++++++++++++------------ src/views/admin/settings/general.tpl | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/public/src/admin/settings.js b/public/src/admin/settings.js index b80df5450d..117857d5ec 100644 --- a/public/src/admin/settings.js +++ b/public/src/admin/settings.js @@ -110,7 +110,12 @@ define('admin/settings', ['uploader', 'sounds'], function(uploader, sounds) { $('#content input[data-action="upload"]').each(function() { var uploadBtn = $(this); 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); }); }); diff --git a/public/src/modules/uploader.js b/public/src/modules/uploader.js index 05bf9379b6..d15d5ddda0 100644 --- a/public/src/modules/uploader.js +++ b/public/src/modules/uploader.js @@ -2,12 +2,24 @@ /* globals define, templates, translator */ -define('uploader', ['csrf'], function(csrf) { +define('uploader', ['csrf', 'translator'], function(csrf, translator) { var module = {}; 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.modal('show'); @@ -16,16 +28,8 @@ define('uploader', ['csrf'], function(csrf) { }); var uploadForm = uploadModal.find('#uploadForm'); - uploadForm.attr('action', route); - uploadForm.find('#params').val(JSON.stringify(params)); - - if (fileSize) { - uploadForm.find('#file-size-block') - .translateText('([[uploads:maximum-file-size, ' + fileSize + ']])') - .removeClass('hide'); - } else { - uploadForm.find('#file-size-block').addClass('hide'); - } + uploadForm.attr('action', data.route); + uploadForm.find('#params').val(JSON.stringify(data.params)); uploadModal.find('#pictureUploadSubmitBtn').off('click').on('click', function() { uploadForm.submit(); @@ -84,8 +88,8 @@ define('uploader', ['csrf'], function(csrf) { }); }; - function parseModal(callback) { - templates.parse('partials/modals/upload_picture_modal', {}, function(html) { + function parseModal(tplVals, callback) { + templates.parse('partials/modals/upload_picture_modal', tplVals, function(html) { translator.translate(html, callback); }); } diff --git a/src/views/admin/settings/general.tpl b/src/views/admin/settings/general.tpl index e45f1093eb..147657195e 100644 --- a/src/views/admin/settings/general.tpl +++ b/src/views/admin/settings/general.tpl @@ -73,7 +73,7 @@
- +