[TASK] RTE: Migrate Ajax class to jQuery 41/35041/2
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 4 Dec 2014 14:37:05 +0000 (09:37 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 4 Dec 2014 14:40:02 +0000 (15:40 +0100)
Releases: master
Resolves: #62720
Change-Id: Ifb96642f101bb72813e200b2488d25fd32693627
Reviewed-on: http://review.typo3.org/35041
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
typo3/sysext/rtehtmlarea/Classes/Controller/FrontendRteController.php
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Ajax/Ajax.js

index a1a7384..27d8a5b 100644 (file)
@@ -226,6 +226,7 @@ class FrontendRteController extends \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase {
                $this->addSkin();
                $this->pageRenderer->addCssFile($this->siteURL . 'typo3/js/extjs/ux/resize.css');
                // Add RTE JavaScript
+               $this->pageRenderer->loadJquery();
                $this->addRteJsFiles($this->TCEform->RTEcounter);
                $this->pageRenderer->addJsFile($this->buildJSMainLangFile($this->TCEform->RTEcounter));
                $this->pageRenderer->addJsInlineCode('HTMLArea-init', $this->getRteInitJsCode(), TRUE);
index 024004c..561ac07 100644 (file)
@@ -13,7 +13,7 @@
 /**
  * Ajax object
  */
-HTMLArea.Ajax = function(Util) {
+HTMLArea.Ajax = function($, Util) {
 
        /**
         * Constructor method
@@ -32,21 +32,26 @@ HTMLArea.Ajax = function(Util) {
         * @return      boolean         true on success of the request submission
         */
        Ajax.prototype.getJavascriptFile = function (url, callback, scope) {
-               var success = false;
-               var self = this;
-               Ext.Ajax.request({
-                       method: 'GET',
-                       url: url,
-                       callback: callback,
-                       success: function (response) {
-                               success = true;
-                       },
-                       failure: function (response) {
-                               self.editor.inhibitKeyboardInput = false;
-                               self.editor.appendToLog('HTMLArea.Ajax', 'getJavascriptFile', 'Unable to get ' + url + ' . Server reported ' + response.status, 'error');
-                       },
-                       scope: scope
-               });
+               var success = false,
+                       self = this,
+                       options = {
+                               callback: callback,
+                               complete: function (response, status) {
+                                       this.callback.call(scope, options, success, response);
+                               },
+                               dataType: 'script',
+                               error: function (response, status, error) {
+                                       self.editor.inhibitKeyboardInput = false;
+                                       self.editor.appendToLog('HTMLArea/Ajax/Ajax', 'getJavascriptFile', 'Unable to get ' + url + ' . Server reported ' + error, 'error');
+                               },
+                               success: function (data, status, response) {
+                                       success = true;
+                               },
+                               scope: scope,
+                               type: 'GET',
+                               url: url
+                       };
+               $.ajax(options);
                return success;
        };
 
@@ -61,37 +66,39 @@ HTMLArea.Ajax = function(Util) {
         * @return      boolean         true on success
         */
        Ajax.prototype.postData = function (url, data, callback, scope) {
-               var success = false;
-               var self = this;
+               var success = false,
+                       self = this;
                data.charset = this.editor.config.typo3ContentCharset ? this.editor.config.typo3ContentCharset : 'utf-8';
                var params = '';
                for (var parameter in data) {
                        params += (params.length ? '&' : '') + parameter + '=' + encodeURIComponent(data[parameter]);
                }
                params += this.editor.config.RTEtsConfigParams;
-               Ext.Ajax.request({
-                       method: 'POST',
-                       headers: {
-                               'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
-                       },
-                       url: url,
-                       params: params,
+               var options = {
                        callback: typeof callback === 'function' ? callback : function (options, success, response) {
                                if (!success) {
-                                       self.editor.appendToLog('HTMLArea.Ajax', 'postData', 'Post request to ' + url + ' failed. Server reported ' + response.status, 'error');
+                                       self.editor.appendToLog('HTMLArea/Ajax/Ajax', 'postData', 'Post request to ' + url + ' failed. Server reported ' + response.status, 'error');
                                }
                        },
+                       complete: function (response, status) {
+                               this.callback.call(scope, options, success, response);
+                       },
+                       contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
+                       data: params,
+                       error: function (response) {
+                               self.editor.appendToLog('HTMLArea/Ajax/Ajax', 'postData', 'Unable to post ' + url + ' . Server reported ' + response.status, 'error');
+                       },
                        success: function (response) {
                                success = true;
                        },
-                       failure: function (response) {
-                               self.editor.appendToLog('HTMLArea.Ajax', 'postData', 'Unable to post ' + url + ' . Server reported ' + response.status, 'error');
-                       },
-                       scope: scope
-               });
+                       scope: scope,
+                       type: 'POST',
+                       url: url
+               };
+               $.ajax(options);
                return success;
        };
 
        return Ajax;
 
-}(HTMLArea.util);
+}(HTMLArea.jQuery, HTMLArea.util);