[richfaces-svn-commits] JBoss Rich Faces SVN: r11636 - trunk/framework/impl/src/main/javascript/ajaxjsf.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Dec 8 09:43:40 EST 2008


Author: nbelaevski
Date: 2008-12-08 09:43:40 -0500 (Mon, 08 Dec 2008)
New Revision: 11636

Modified:
   trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
Log:
Queue: clearing on window unload implemented

Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js	2008-12-08 14:43:06 UTC (rev 11635)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js	2008-12-08 14:43:40 UTC (rev 11636)
@@ -1,14 +1,5 @@
-//TODO observe unload
-//unload
-
 A4J.AJAX._eventQueues = {};
 
-var extend = function(target, source) {
-	for (var property in source) {
-		target[property] = source[property];
-	}
-};
-
 //queue constructor
 A4J.AJAX.EventQueue = function() {
 	var DROP_NEW = 'dropNew';
@@ -16,6 +7,12 @@
 	var FIRE_NEW = 'fireNew';
 	var FIRE_NEXT = 'fireNext';
 
+	var extend = function(target, source) {
+		for (var property in source) {
+			target[property] = source[property];
+		}
+	};
+
 	var extendOptions = function(options) {
 		var opts = {};
 		
@@ -69,6 +66,9 @@
 			
 			abort: function() {
 				if (this.request) {
+					//tell request not to notify queue after its processing finished
+					//request.queue = undefined 
+					//is not ok for this case because user might want to obtain queue in any event handler
 					this.request.shouldNotifyQueue = false;
 					this.request.abort();
 					this.request = undefined;
@@ -107,6 +107,14 @@
 				}
 			},
 			
+			clearEntry: function() {
+				this.stopTimer();
+				if (this.request) {
+					this.request.shouldNotifyQueue = false;
+					this.request = undefined;
+				}
+			},
+			
 			getEventsCount: function() {
 				return this.eventsCount;
 			},
@@ -137,6 +145,8 @@
 						LOG.debug("Queue '" + this.name + "' will submit request NOW");
 
 						var req = firstItem.submit();
+
+						//see entry.abort() method for more details about this assignment
 						req.shouldNotifyQueue = true;
 
 						if (this.requestOptions.queueonsubmit) {
@@ -280,6 +290,15 @@
 			LOG.debug("There are " + this.items.length + " requests more in this queue");
 			
 			this.submitFirst();
+		},
+		
+		clear: function() {
+			var length = this.items.length;
+			for ( var i = 0; i < this.items.length; i++) {
+				this.items[i].clearEntry();
+			}
+			
+			this.items.splice(0, length);
 		}
 	});
 	
@@ -292,6 +311,10 @@
 	return A4J.AJAX._eventQueues[name];
 };
 
+A4J.AJAX.EventQueue.getQueues = function() {
+	return A4J.AJAX._eventQueues;
+};
+
 A4J.AJAX.EventQueue.addQueue = function(queue) {
 	var name = queue.name;
 	
@@ -304,6 +327,12 @@
 };
 
 A4J.AJAX.EventQueue.removeQueue = function(name) {
+	var queue = A4J.AJAX._eventQueues[name];
+	
+	if (queue) {
+		queue.clear();
+	}
+	
 	delete A4J.AJAX._eventQueues[name];
 };
 
@@ -373,4 +402,20 @@
 		
 		return queue;
 	}
-}();
\ No newline at end of file
+}();
+
+(function () {
+	var observer = function() {
+		var queues = A4J.AJAX.EventQueue.getQueues();
+		for (var queueName in queues) {
+			var queue = queues[queueName];
+			queue.clear();
+		}
+	};
+	
+	if (window.addEventListener) {
+		window.addEventListener("unload", observer, false);
+	} else {
+		window.attachEvent("onunload", observer);
+	}
+})();
\ No newline at end of file




More information about the richfaces-svn-commits mailing list