Added `UI/Confirmation` to replace `WCF.System.Confirmation`
authorAlexander Ebert <ebert@woltlab.com>
Fri, 29 May 2015 12:19:14 +0000 (14:19 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 29 May 2015 12:19:14 +0000 (14:19 +0200)
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/js/require.config.js

index 9eb35d71b2f8fc0bc952f818dc8613482b168e18..57cd0022b48532c1808640b380ec38afc1108f36 100755 (executable)
@@ -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 = $('<div id="wcfSystemConfirmation" class="systemConfirmation"><p /><div id="wcfSystemConfirmationContent" /></div>').hide().appendTo(document.body);
-               var $formButtons = $('<div class="formSubmit" />').appendTo(this._dialog);
-               
-               this._confirmationButton = $('<button class="buttonPrimary">' + WCF.Language.get('wcf.global.confirmation.confirm') + '</button>').data('action', 'confirm').click($.proxy(this._click, this)).appendTo($formButtons);
-               $('<button>' + WCF.Language.get('wcf.global.confirmation.cancel') + '</button>').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();
        }
 };
 
index c1a868f0aea08f56911c0695d6cbb3fa3a0bba9c..13b6378a86cf976cfab424041d93e915467b5828 100644 (file)
@@ -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'