Author: dmorozov
Date: 2008-11-18 09:35:13 -0500 (Tue, 18 Nov 2008)
New Revision: 11214
Modified:
trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
Log:
https://jira.jboss.org/jira/browse/RF-4959
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2008-11-18 14:21:35 UTC (rev
11213)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2008-11-18 14:35:13 UTC (rev
11214)
@@ -22,10 +22,21 @@
submit: function() {
var data = this.items.shift();
if (data) {
- this.request = data.submitWithCallback();
+ this.createRequest(data);
}
},
+ createRequest: function(data) {
+ this.request = data.submit();
+ this.requestId = data.getRequestId();
+ this.request.shouldNotifyQueue = true;
+ },
+
+ clearRequest: function() {
+ this.request = undefined;
+ this.requestId = undefined;
+ },
+
getSize: function() {
var size = this.items.length;
@@ -43,25 +54,27 @@
fireFirst: function() {
var data = this.items.shift();
if (data) {
- data.submitWithoutCallback()
+ data.submit()
}
},
addEvent: function(data) {
if (!this.isFull()) {
+
this.items.push(data);
if (!this.request) {
this.submit();
}
+
} else {
//log error
}
},
submitNext: function() {
- this.request = undefined;
-
+ this.clearRequest();
+
if (this.getSize() > 0) {
this.submit();
} else {
@@ -79,6 +92,20 @@
hasNextItem: function() {
return this.items.length != 0;
+ },
+
+ abortCurrentRequest: function() {
+ if (this.request) {
+ this.request.shouldNotifyQueue = false;
+ this.request.abort();
+ this.clearRequest();
+ }
+ },
+
+ abortDupResponces: function(data) {
+ if (!this.hasNextItem() && data.getRequestId() == this.requestId) {
+ this.abortCurrentRequest();
+ }
}
}
}());
@@ -109,22 +136,22 @@
var _this = this;
this.timer = setTimeout(function() {
try {
- _this.transferIfPipelineEmpty();
+ _this.transferIfEmpty();
_this.timer = undefined;
} finally {
_this = undefined;
}
}, delay);
} else {
- this.transferIfPipelineEmpty();
+ this.transferIfEmpty();
}
},
+
+ transferIfEmpty: function() {
+ this.delayPassed = true;
- transferIfPipelineEmpty: function() {
if (this.pipeline.isEmpty()) {
this.pipeline.addEvent(this.pop());
- } else {
- this.delayPassed = true;
}
},
@@ -152,19 +179,23 @@
var FIRE_NEXT = 'fireNext';
return function(data) {
+ if (data.isIgnoreDupResponses()) {
+ this.pipeline.abortDupResponces(data);
+ }
+
var requestId = data.getRequestId();
if (this.requestId == requestId) {
this.data = data;
data.setEventsCounter(++this.eventsCounter);
-
+
this.resetRequestDelay();
} else {
if (this.data) {
this.stopRequestDelay();
this.pipeline.addEvent(this.pop());
}
-
+
if (this.pipeline.isFull()) {
var behavior = data.getSizeExceededBehavior();
if (behavior == DROP_NEW ||
@@ -174,7 +205,7 @@
} else if (behavior == FIRE_NEW ||
(behavior == FIRE_NEXT && !this.pipeline.hasNextItem())) {
- data.submitWithoutCallback();
+ data.submit();
return;
} else if (behavior == DROP_NEXT) {
this.pipeline.dropFirst();
@@ -192,7 +223,6 @@
}()
});
-
//queue constructor
A4J.AJAX.EventQueue = function(name, queueOptions, requestOptions) {
this.name = name;
@@ -380,21 +410,18 @@
};
extend(EventQueueData.prototype, {
- submitWithoutCallback: function() {
+ submit: function() {
this.query.appendParameter("AJAX:EVENTS_COUNT", this.eventsCount);
var request = A4J.AJAX.SubmitQuery(this.query, this.options)
request.queue = this.queue;
+ if (this.options.queueonsubmit) {
+ this.options.queueonsubmit.call(this.queue, request);
+ }
+
return request;
},
- submitWithCallback: function() {
- var request = this.submitWithoutCallback();
- request.shouldNotifyQueue = true;
-
- return request;
- },
-
getRequestId: function() {
return this.options.requestId;
},
@@ -407,16 +434,16 @@
return this.queue.getSizeExceededBehavior();
},
+ isIgnoreDupResponses: function() {
+ return this.options.ignoreDupResponses;
+ },
+
setEventsCounter: function(count) {
this.eventsCount = count;
},
setRequest: function() {
//TODO nick
- },
-
- shouldSubmitWithoutCallback: function() {
- //TODO nick
}
});