Added support for a confirm message
authorMagnus Kühn <magnus.khn@gmail.com>
Wed, 2 Jan 2013 20:22:06 +0000 (21:22 +0100)
committerMagnus Kühn <magnus.khn@gmail.com>
Wed, 2 Jan 2013 20:22:06 +0000 (21:22 +0100)
wcfsetup/install/files/js/WCF.js

index 80c433f4578210e20ce899137abe3aaa1b1705be..f45fa2eaaa4a18676567876d3f9244336f828ce6 100755 (executable)
@@ -1895,11 +1895,36 @@ WCF.Action.Toggle = Class.extend({
         * @param       object          event
         */
        _click: function(event) {
+               var $target = $(event.currentTarget);
+               
+               if ($target.data('confirmMessage')) {
+                       WCF.System.Confirmation.show($target.data('confirmMessage'), $.proxy(this._execute, this), { target: $target });
+               }
+               else {
+                       this._sendRequest($target);
+               }
+       },
+       
+       /**
+        * Executes toggeling.
+        * 
+        * @param       string          action
+        * @param       object          parameters
+        */
+       _execute: function(action, parameters) {
+               if (action === 'cancel') {
+                       return;
+               }
+               
+               this._sendRequest(parameters.target);
+       },
+       
+       _sendRequest: function(object) {
                this.proxy.setOption('data', {
                        actionName: 'toggle',
                        className: this._className,
                        interfaceName: 'wcf\\data\\IToggleAction',
-                       objectIDs: [ $(event.target).data('objectID') ]
+                       objectIDs: [ $(object).data('objectID') ]
                });
                
                this.proxy.sendRequest();