[otrs-cvs] otrs/var/httpd/htdocs/js Core.AJAX.js, 1.36, 1.37 Core.Agent.CustomerSearch.js, 1.47, 1.48

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/otrs/var/httpd/htdocs/js
In directory lancelot:/tmp/cvs-serv17844/var/httpd/htdocs/js

Modified Files:
	Core.AJAX.js Core.Agent.CustomerSearch.js 
Log Message:
Fixed bug#8990 - Autocompletion returns stale requests.

Author: mn

Index: Core.AJAX.js
===================================================================
RCS file: /home/cvs/otrs/var/httpd/htdocs/js/Core.AJAX.js,v
retrieving revision 1.36
retrieving revision 1.37
diff -2 -u -d -r1.36 -r1.37
--- Core.AJAX.js	18 Dec 2012 09:12:59 -0000	1.36
+++ Core.AJAX.js	27 Dec 2012 12:28:01 -0000	1.37
@@ -216,5 +216,5 @@
      *                      but is not needed any more and will be removed in a future version of OTRS.
      * @param {Function} [SuccessCallback] Callback function to be executed on AJAX success (optional).
-     * @return nothing
+     * @return {Object} jqXHR object
      */
     TargetNS.FormUpdate = function ($EventElement, Subaction, ChangedElement, FieldsToUpdate, SuccessCallback) {
@@ -233,5 +233,5 @@
         }
 
-        $.ajax({
+        return $.ajax({
             type: 'POST',
             url: URL,
@@ -258,11 +258,11 @@
                 }
             },
-            error: function () {
-                // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
-                Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("Error during AJAX communication", 'CommunicationError'));
+            error: function (XHRObject, Status, Error) {
+                if (Status !== 'abort') {
+                    // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
+                    Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("Error during AJAX communication. Status: " + Status + ", Error: " + Error, 'CommunicationError'));
+                }
             }
         });
-
-        return false;
     };
 
@@ -273,5 +273,5 @@
      * @param {String} URL The URL which is called via Ajax
      * @param {Function} Callback The additional callback function which is called after the request returned from the server
-     * @return nothing
+     * @return {Object} jqXHR object
      */
     TargetNS.ContentUpdate = function ($ElementToUpdate, URL, Callback) {
@@ -284,5 +284,5 @@
         QueryString += SerializeData(GetSessionInformation());
 
-        $.ajax({
+        return $.ajax({
             type: 'POST',
             url: URL,
@@ -309,11 +309,11 @@
                 Core.App.Publish('Event.AJAX.ContentUpdate.Callback', [GlobalResponse]);
             },
-            error: function () {
-                // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
-                Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("Error during AJAX communication", 'CommunicationError'));
+            error: function (XHRObject, Status, Error) {
+                if (Status !== 'abort') {
+                    // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
+                    Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("Error during AJAX communication. Status: " + Status + ", Error: " + Error, 'CommunicationError'));
+                }
             }
         });
-
-        return false;
     };
 
@@ -325,5 +325,5 @@
      * @param {Function} Callback The callback function which is called after the request returned from the server
      * @param {String} DataType Optional, defines the datatype, default 'json', could also be 'html'
-     * @return nothing
+     * @return {Object} jqXHR object
      */
     TargetNS.FunctionCall = function (URL, Data, Callback, DataType) {
@@ -334,10 +334,10 @@
         }
 
-        $.ajax({
+        return $.ajax({
             type: 'POST',
             url: URL,
             data: Data,
             dataType: (typeof DataType === 'undefined') ? 'json' : DataType,
-            success: function (Response) {
+            success: function (Response, Status, XHRObject) {
                 // call the callback
                 if ($.isFunction(Callback)) {
@@ -351,7 +351,10 @@
                 }
             },
-            error: function () {
-                // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
-                Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("Error during AJAX communication", 'CommunicationError'));
+            error: function (XHRObject, Status, Error) {
+                // We sometimes manually abort an ajax request (e.g. in autocompletion). This should not throw a global error message
+                if (Status !== 'abort') {
+                    // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
+                    Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("Error during AJAX communication. Status: " + Status + ", Error: " + Error, 'CommunicationError'));
+                }
             }
         });

Author: mn

Index: Core.Agent.CustomerSearch.js
===================================================================
RCS file: /home/cvs/otrs/var/httpd/htdocs/js/Core.Agent.CustomerSearch.js,v
retrieving revision 1.47
retrieving revision 1.48
diff -2 -u -d -r1.47 -r1.48
--- Core.Agent.CustomerSearch.js	17 Dec 2012 11:41:14 -0000	1.47
+++ Core.Agent.CustomerSearch.js	27 Dec 2012 12:28:01 -0000	1.48
@@ -219,11 +219,22 @@
                 delay: Core.Config.Get('Autocomplete.QueryDelay'),
                 source: function (Request, Response) {
-                    var URL = Core.Config.Get('Baselink'), Data = {
-                        Action: 'AgentCustomerSearch',
-                        Term: Request.term,
-                        MaxResults: Core.Config.Get('Autocomplete.MaxResultsDisplayed')
-                    };
-                    Core.AJAX.FunctionCall(URL, Data, function (Result) {
+                    var URL = Core.Config.Get('Baselink'),
+                        Data = {
+                            Action: 'AgentCustomerSearch',
+                            Term: Request.term,
+                            MaxResults: Core.Config.Get('Autocomplete.MaxResultsDisplayed')
+                        };
+
+                    // if an old ajax request is already running, stop the old request and start the new one
+                    if ($Element.data('AutoCompleteXHR')) {
+                        $Element.data('AutoCompleteXHR').abort();
+                        $Element.removeData('AutoCompleteXHR');
+                        // run the response function to hide the request animation
+                        Response({});
+                    }
+
+                    $Element.data('AutoCompleteXHR', Core.AJAX.FunctionCall(URL, Data, function (Result) {
                         var Data = [];
+                        $Element.removeData('AutoCompleteXHR');
                         $.each(Result, function () {
                             Data.push({
@@ -236,5 +247,5 @@
                         });
                         Response(Data);
-                    });
+                    }));
                 },
                 select: function (Event, UI) {
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.