[otrs-cvs] otrs/var/httpd/htdocs/js Core.AJAX.js,1.37,1.38

"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-serv25785/var/httpd/htdocs/js

Modified Files:
	Core.AJAX.js 
Log Message:
Fixed bug#8993 - OTRS JavaScript does not handle session timeouts gracefully.

Author: mn

Index: Core.AJAX.js
===================================================================
RCS file: /home/cvs/otrs/var/httpd/htdocs/js/Core.AJAX.js,v
retrieving revision 1.37
retrieving revision 1.38
diff -2 -u -d -r1.37 -r1.38
--- Core.AJAX.js	27 Dec 2012 12:28:01 -0000	1.37
+++ Core.AJAX.js	7 Jan 2013 10:18:49 -0000	1.38
@@ -1,5 +1,5 @@
 // --
 // Core.AJAX.js - provides the functionality for AJAX calls
-// Copyright (C) 2001-2012 OTRS AG, http://otrs.org/
+// Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
 // --
 // $Id$
@@ -166,4 +166,17 @@
     }
 
+    function RedirectAfterSessionTimeOut(XHRObject) {
+        var Headers = XHRObject.getAllResponseHeaders(),
+            OldUrl = location.href,
+            NewUrl = Core.Config.Get('Baselink') + "RequestedURL=" + encodeURIComponent(OldUrl);
+
+        if (Headers.match(/X-OTRS-Login: /)) {
+            location.href = NewUrl;
+            return true;
+        }
+
+        return false;
+    }
+
     /**
      * @function
@@ -238,5 +251,9 @@
             data: QueryString,
             dataType: 'json',
-            success: function (Response) {
+            success: function (Response, Status, XHRObject) {
+                if (RedirectAfterSessionTimeOut(XHRObject)) {
+                    return false;
+                };
+
                 if (!Response) {
                     // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
@@ -259,4 +276,8 @@
             },
             error: function (XHRObject, Status, Error) {
+                if (RedirectAfterSessionTimeOut(XHRObject)) {
+                    return false;
+                };
+
                 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.
@@ -289,5 +310,9 @@
             data: QueryString,
             dataType: 'html',
-            success: function (Response) {
+            success: function (Response, Status, XHRObject) {
+                if (RedirectAfterSessionTimeOut(XHRObject)) {
+                    return false;
+                };
+
                 if (!Response) {
                     // We are out of the OTRS App scope, that's why an exception would not be caught. Therefore we handle the error manually.
@@ -310,4 +335,8 @@
             },
             error: function (XHRObject, Status, Error) {
+                if (RedirectAfterSessionTimeOut(XHRObject)) {
+                    return false;
+                };
+
                 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.
@@ -340,4 +369,8 @@
             dataType: (typeof DataType === 'undefined') ? 'json' : DataType,
             success: function (Response, Status, XHRObject) {
+                if (RedirectAfterSessionTimeOut(XHRObject)) {
+                    return false;
+                };
+
                 // call the callback
                 if ($.isFunction(Callback)) {
@@ -352,4 +385,8 @@
             },
             error: function (XHRObject, Status, Error) {
+                if (RedirectAfterSessionTimeOut(XHRObject)) {
+                    return false;
+                };
+
                 // We sometimes manually abort an ajax request (e.g. in autocompletion). This should not throw a global error message
                 if (Status !== 'abort') {
---------------------------------------------------------------------
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.