From: Alexander Ebert Date: Fri, 29 May 2015 12:19:14 +0000 (+0200) Subject: Added `UI/Confirmation` to replace `WCF.System.Confirmation` X-Git-Tag: 3.0.0_Beta_1~2308 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d81268ded00e229585a44655aee572b934fd66ac;p=GitHub%2FWoltLab%2FWCF.git Added `UI/Confirmation` to replace `WCF.System.Confirmation` --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 9eb35d71b2..57cd0022b4 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -6574,38 +6574,10 @@ WCF.System.Notification = Class.extend({ /** * Provides dialog-based confirmations. + * + * @deprecated 2.2 - please use `UI/Confirmation` instead */ WCF.System.Confirmation = { - /** - * notification callback - * @var object - */ - _callback: null, - - /** - * confirmation dialog - * @var jQuery - */ - _dialog: null, - - /** - * callback parameters - * @var object - */ - _parameters: null, - - /** - * dialog visibility - * @var boolean - */ - _visible: false, - - /** - * confirmation button - * @var jQuery - */ - _confirmationButton: null, - /** * Displays a confirmation dialog. * @@ -6615,91 +6587,14 @@ WCF.System.Confirmation = { * @param jQuery template */ show: function(message, callback, parameters, template) { - if (this._visible) { - console.debug('[WCF.System.Confirmation] Confirmation dialog is already open, refusing action.'); - return; - } - - if (!$.isFunction(callback)) { - console.debug('[WCF.System.Confirmation] Given callback is invalid, aborting.'); - return; - } - - this._callback = callback; - this._parameters = parameters; - - var $render = true; - if (this._dialog === null) { - this._createDialog(); - $render = false; - } - - this._dialog.find('#wcfSystemConfirmationContent').empty().hide(); - if (template && template.length) { - template.appendTo(this._dialog.find('#wcfSystemConfirmationContent').show()); - } - - this._dialog.find('p').text(message); - this._dialog.wcfDialog({ - onClose: $.proxy(this._close, this), - onShow: $.proxy(this._show, this), - title: WCF.Language.get('wcf.global.confirmation.title') + require(['UI/Confirmation'], function(UIConfirmation) { + UIConfirmation.show({ + legacyCallback: callback, + message: message, + parameters: parameters, + template: (typeof template === 'object' ? template.html() : '') + }); }); - if ($render) { - this._dialog.wcfDialog('render'); - } - - this._confirmationButton.focus(); - this._visible = true; - }, - - /** - * Creates the confirmation dialog on first use. - */ - _createDialog: function() { - this._dialog = $('

').hide().appendTo(document.body); - var $formButtons = $('
').appendTo(this._dialog); - - this._confirmationButton = $('').data('action', 'confirm').click($.proxy(this._click, this)).appendTo($formButtons); - $('').data('action', 'cancel').click($.proxy(this._click, this)).appendTo($formButtons); - }, - - /** - * Handles button clicks. - * - * @param object event - */ - _click: function(event) { - this._notify($(event.currentTarget).data('action')); - }, - - /** - * Handles dialog being closed. - */ - _close: function() { - if (this._visible) { - this._notify('cancel'); - } - }, - - /** - * Notifies callback upon user's decision. - * - * @param string action - */ - _notify: function(action) { - this._visible = false; - this._dialog.wcfDialog('close'); - this._confirmationButton.blur(); - - this._callback(action, this._parameters); - }, - - /** - * Tries to set focus on confirm button. - */ - _show: function() { - this._dialog.find('button.buttonPrimary').blur().focus(); } }; diff --git a/wcfsetup/install/files/js/require.config.js b/wcfsetup/install/files/js/require.config.js index c1a868f0ae..13b6378a86 100644 --- a/wcfsetup/install/files/js/require.config.js +++ b/wcfsetup/install/files/js/require.config.js @@ -26,6 +26,7 @@ requirejs.config({ 'List': 'WoltLab/WCF/List', 'ObjectMap': 'WoltLab/WCF/ObjectMap', 'UI/Alignment': 'WoltLab/WCF/UI/Alignment', + 'UI/Confirmation': 'WoltLab/WCF/UI/Confirmation', 'UI/Dialog': 'WoltLab/WCF/UI/Dialog', 'UI/SimpleDropdown': 'WoltLab/WCF/UI/Dropdown/Simple', 'UI/TabMenu': 'WoltLab/WCF/UI/TabMenu'