Fixed ACP worker
authorAlexander Ebert <ebert@woltlab.com>
Thu, 13 Dec 2012 20:09:16 +0000 (21:09 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 13 Dec 2012 20:09:16 +0000 (21:09 +0100)
Fixes #977

wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/worker.tpl
wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php
wcfsetup/install/lang/de.xml

index ff98f34143aa726b1a9e1685188bdc9c2f070fb7..5922a7167ed8e48120ed8f9a1ee534c84bd72f76 100644 (file)
@@ -966,6 +966,12 @@ WCF.ACP.Options.Group = Class.extend({
  * @param      object          options
  */
 WCF.ACP.Worker = Class.extend({
+       /**
+        * true, if worker was aborted
+        * @var boolean
+        */
+       _aborted: false,
+       
        /**
         * dialog id
         * @var string
@@ -978,16 +984,29 @@ WCF.ACP.Worker = Class.extend({
         */
        _dialog: null,
        
+       /**
+        * action proxy
+        * @var WCF.Action.Proxy
+        */
+       _proxy: null,
+       
        /**
         * Initializes a new worker instance.
         * 
         * @param       string          dialogID
         * @param       string          className
-        * @param       object          options
+        * @param       string          title
+        * @param       object          parameters
         */
-       init: function(dialogID, className, options) {
+       init: function(dialogID, className, title, parameters) {
+               this._aborted = false;
                this._dialogID = dialogID + 'Worker';
-               options = options || { };
+               this._dialog = null;
+               this._proxy = new WCF.Action.Proxy({
+                       showLoadingOverlay: false,
+                       success: $.proxy(this._success, this),
+                       url: 'index.php/WorkerProxy/?t=' + SECURITY_TOKEN + SID_ARG_2ND
+               });
                
                // initialize AJAX-based dialog
                WCF.showAJAXDialog(this._dialogID, true, {
@@ -995,52 +1014,46 @@ WCF.ACP.Worker = Class.extend({
                        type: 'POST',
                        data: {
                                className: className,
-                               parameters: options
+                               parameters: parameters || { }
                        },
-                       success: $.proxy(this._handleResponse, this),
-                       
-                       preventClose: true,
-                       hideTitle: true
+                       success: $.proxy(this._success, this),
+                       onClose: $.proxy(function() { this._aborted = true; }, this),
+                       title: title
                });
        },
        
        /**
         * Handles response from server.
+        * 
+        * @param       object          data
         */
-       _handleResponse: function($data) {
+       _success: function(data) {
+               if (this._aborted) {
+                       return;
+               }
+               
                // init binding
                if (this._dialog === null) {
                        this._dialog = $('#' + $.wcfEscapeID(this._dialogID));
                }
                
                // update progress
-               this._dialog.find('#workerProgress').attr('value', $data.progress).text($data.progress + '%');
+               this._dialog.find('progress').attr('value', data.progress).text(data.progress + '%').next('span').text(data.progress + '%');
                
                // worker is still busy with it's business, carry on
-               if ($data.progress < 100) {
+               if (data.progress < 100) {
                        // send request for next loop
-                       $.ajax({
-                               url: 'index.php/WorkerProxy/?t=' + SECURITY_TOKEN + SID_ARG_2ND,
-                               type: 'POST',
-                               data: {
-                                       className: $data.className,
-                                       loopCount: $data.loopCount,
-                                       parameters: $data.parameters
-                               },
-                               success: $.proxy(this._handleResponse, this),
-                               error: function(transport) {
-                                       alert(transport.responseText);
-                               }
+                       this._proxy.setOption('data', {
+                               className: data.className,
+                               loopCount: data.loopCount,
+                               parameter: data.parameters
                        });
+                       this._proxy.sendRequest();
                }
                else {
-                       // display proceed button
-                       var $proceedButton = $('<input type="submit" value="Proceed" />').appendTo('#workerInnerContent');
-                       $proceedButton.click(function() {
-                               window.location = $data.proceedURL;
-                       });
-                       
-                       $('#workerInnerContentContainer').wcfBlindIn();
+                       // display continue button
+                       var $formSubmit = $('<div class="formSubmit" />').appendTo(this._dialog);
+                       $('<button>' + WCF.Language.get('wcf.global.button.next') + '</button>').appendTo($formSubmit).click(function() { window.location = data.proceedURL; });
                        
                        this._dialog.wcfDialog('render');
                }
index a646d7b69d38f14a7509e7db397c66382cd4a309..73f6f1fcc28ad82a3753677312765754801e4739 100644 (file)
@@ -1,14 +1,9 @@
 <div id="workerContainer">
        <header class="box48 boxHeadline">
                <img src="{@$__wcf->getPath()}icon/working.svg" alt="" class="icon48" />
-               <hgroup class="wcf-containerIcon">
-                       <h1>Aufgaben werden ausgeführt &hellip;</h1><!--ToDo: Language variables -->
-                       <h2>Aktueller Schritt: <span id="workerAction">{lang}wcf.package.installation.step.prepare{/lang}</span></h2>
-                       <p><progress id="workerProgress" value="0" max="100">0%</progress></p>
+               <hgroup>
+                       <h1>{lang}wcf.acp.worker.executing{/lang}</h1>
+                       <small><progress value="0" max="100">0%</progress> <span>0%</span></small>
                </hgroup>
        </header>
-       
-       <div id="workerInnerContentContainer" style="display: none;">
-               <div id="workerInnerContent"></div>
-       </div>
 </div>
index 87a17ff470251b11569dabfbc7c32559792c9c29..f89366cb87b54bdb4f67312a905ff8e27530fd9c 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\acp\action;
 use wcf\action\AbstractSecureAction;
+use wcf\action\AJAXInvokeAction;
 use wcf\system\exception\AJAXException;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
@@ -17,13 +18,7 @@ use wcf\util\JSON;
  * @subpackage acp.action
  * @category   Community Framework
  */
-class WorkerProxyAction extends AbstractSecureAction {
-       /**
-        * worker class name
-        * @var string
-        */
-       protected $className = '';
-       
+class WorkerProxyAction extends AJAXInvokeAction {
        /**
         * loop counter
         * @var integer
@@ -42,28 +37,11 @@ class WorkerProxyAction extends AbstractSecureAction {
         */
        protected $worker = null;
        
-       /**
-        * @see wcf\action\AbstractAction::_construct()
-        */
-       public function __run() {
-               try {
-                       parent::__run();
-               }
-               catch (\Exception $e) {
-                       if ($e instanceof AJAXException) {
-                               throw $e;
-                       }
-                       else {
-                               throw new AJAXException($e->getMessage());
-                       }
-               }
-       }
-       
        /**
         * @see wcf\action\IAction::readParameters()
         */
        public function readParameters() {
-               parent::readParameters();
+               AbstractSecureAction::readParameters();
                
                if (isset($_POST['className'])) $this->className = $_POST['className'];
                if (isset($_POST['loopCount'])) $this->loopCount = intval($_POST['loopCount']);
@@ -89,7 +67,7 @@ class WorkerProxyAction extends AbstractSecureAction {
         * @see wcf\action\IAction::execute()
         */
        public function execute() {
-               parent::execute();
+               AbstractSecureAction::execute();
                
                if ($this->loopCount == -1) {
                        $this->sendResponse();
index 1abea7785f39937b132ad44beb86363a2b801336..4468b912f0a0fdf0c08fb6edd43c945f57c6ecc1 100644 (file)
                <item name="wcf.acp.user.sendMail.text"><![CDATA[Nachricht]]></item>
        </category>
        
+       <category name="wcf.acp.worker">
+               <item name="wcf.acp.worker.executing"><![CDATA[Aufgaben werden ausgeführt …]]></item>
+       </category>
+       
        <category name="wcf.category">
                <item name="wcf.category.add"><![CDATA[Kategorie hinzufügen]]></item>
                <item name="wcf.category.button.list"><![CDATA[Kategorien auflisten]]></item>