Author: pyaschenko
Date: 2009-12-08 08:19:19 -0500 (Tue, 08 Dec 2009)
New Revision: 16096
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-queue.js
Log:
richfaces.queue code fixes & improvements
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-queue.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-queue.js 2009-12-08
12:12:29 UTC (rev 16095)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-queue.js 2009-12-08
13:19:19 UTC (rev 16096)
@@ -13,9 +13,9 @@
richfaces.queue = function(opts){
- //TODO: naming - class should be called QueueEntry, and first argument is
"source", not query
- var queueEntry = function(query, event, options) {
- this.query = query;
+ var QueueEntry = function(queue, source, event, options) {
+ this.queue = queue;
+ this.source = source;
this.options = options || {};
this.event = event;
@@ -24,77 +24,86 @@
this.eventsCount = 1;
};
- //TODO: fix bad indentation of code
- jQuery.extend(queueEntry.prototype, {
-
- isIgnoreDupResponses: function() {
- return this.options.ignoreDupResponses;
- },
-
- getSimilarityGroupingId: function() {
- return this.similarityGroupingId;
- },
-
- setSimilarityGroupingId: function(id) {
- this.similarityGroupingId = id;
- },
-
- ondrop: function() {
- var callback = this.options.onqueuerequestdrop;
- if (callback) {
- callback.call(this.queue, this.query, this.options, this.event);
- }
- },
-
- onRequestDelayPassed: function() {
- this.readyToSubmit = true;
- //TODO: should be this.queue.submitFirst
- submitFirst();
- },
-
- startTimer: function() {
- var delay = this.options.requestDelay || queueRequestDelay || 0;
+ jQuery.extend(QueueEntry.prototype, {
- log.debug("Queue will wait " + (delay || 0) + "ms before
submit");
-
- if (delay) {
- var _this = this;
- this.timer = setTimeout(function() {
- try {
- _this.onRequestDelayPassed();
- } finally {
- _this.timer = undefined;
- _this = undefined;
- }
- }, delay);
- } else {
- this.onRequestDelayPassed();
- }
- },
-
- stopTimer: function() {
- if (this.timer) {
- clearTimeout(this.timer);
- this.timer = undefined;
- }
- },
-
- clearEntry: function() { //???
- this.stopTimer();
- if (this.request) {
- this.request.shouldNotifyQueue = false;
- this.request = undefined;
- }
- },
-
- getEventsCount: function() {
- return this.eventsCount;
- },
-
- setEventsCount: function(newCount) {
- this.eventsCount = newCount;
- },
-
+ isIgnoreDupResponses: function() {
+ return this.options.ignoreDupResponses;
+ },
+
+ getSimilarityGroupingId: function() {
+ return this.similarityGroupingId;
+ },
+
+ setSimilarityGroupingId: function(id) {
+ this.similarityGroupingId = id;
+ },
+
+ resetSimilarityGroupingId: function() {
+ this.similarityGroupingId = undefined;
+ },
+
+ setReadyToSubmit: function(isReady) {
+ this.readyToSubmit = isReady;
+ },
+
+ getReadyToSubmit: function() {
+ return this.readyToSubmit;
+ },
+
+ ondrop: function() {
+ var callback = this.options.onqueuerequestdrop;
+ if (callback) {
+ callback.call(this.queue, this.source, this.options, this.event);
+ }
+ },
+
+ onRequestDelayPassed: function() {
+ this.readyToSubmit = true;
+ this.queue.submitFirst();
+ },
+
+ startTimer: function() {
+ var delay = this.options.requestDelay || queueOptions.requestDelay || 0;
+
+ log.debug("Queue will wait " + (delay || 0) + "ms before
submit");
+
+ if (delay) {
+ var _this = this;
+ this.timer = setTimeout(function() {
+ try {
+ _this.onRequestDelayPassed();
+ } finally {
+ _this.timer = undefined;
+ _this = undefined;
+ }
+ }, delay);
+ } else {
+ this.onRequestDelayPassed();
+ }
+ },
+
+ stopTimer: function() {
+ if (this.timer) {
+ clearTimeout(this.timer);
+ this.timer = undefined;
+ }
+ },
+
+ clearEntry: function() { //???
+ this.stopTimer();
+ if (this.request) {
+ this.request.shouldNotifyQueue = false;
+ this.request = undefined;
+ }
+ },
+
+ getEventsCount: function() {
+ return this.eventsCount;
+ },
+
+ setEventsCount: function(newCount) {
+ this.eventsCount = newCount;
+ }
});
// TODO: add this two variables to richfaces and report bug to jsf about constants
@@ -105,18 +114,12 @@
var log = richfaces.log;
var items = [];
var queueOptions = opts || {};
- //TODO: that's not last, but first
- var last;
+ var lastRequestedEntry;
- //TODO: inline this variable
- var queueMode = queueOptions.mode;
- //TODO: inline this variable
- var queueRequestDelay = queueOptions.requestDelay;
-
//TODO: instance of this function will be created for each queue
var onError = function (data) {
log.debug("richfaces.queue: ajax submit error");
- last = null;
+ lastRequestedEntry = null;
//TODO: what if somebody is going to clear queue on error?
submitFirst();
};
@@ -124,7 +127,7 @@
var onComplete = function (data) {
if (jsfDataTypes[data.type]=='event' &&
jsfEventNames[data.status]=='success') {
log.debug("richfaces.queue: ajax submit successfull");
- last = null;
+ lastRequestedEntry = null;
submitFirst();
}
};
@@ -133,7 +136,7 @@
jsf.ajax.addOnError(onError);
var submitFirst = function() {
- if (queueMode == QUEUE_MODE_PULL && last) {
+ if (queueOptions.mode == QUEUE_MODE_PULL && lastRequestedEntry) {
log.debug("richfaces.queue: Waiting for previous submit results");
return;
}
@@ -141,20 +144,17 @@
log.debug("richfaces.queue: Nothing to submit");
return;
}
- if (items[0].readyToSubmit) {
- last = items.shift();
- //TODO: unnecessary check
- if (last.readyToSubmit) {
- log.debug("richfaces.queue: will submit request NOW");
- //TODO: events counter should be submitted
- //last.query.appendParameter("AJAX:EVENTS_COUNT", last.eventsCount);
- var params = richfaces.processRequestParams(last.query, last.options);
- //TODO: jsf.ajax.request should be used
- //TODO: copy of event should be created otherwise IE will fail
- richfaces.ajax.request(last.query, last.event, params);
- if (last.options.queueonsubmit) {
- last.options.queueonsubmit.call(last);
- }
+ if (items[0].getReadyToSubmit()) {
+ lastRequestedEntry = items.shift();
+ log.debug("richfaces.queue: will submit request NOW");
+ //TODO: events counter should be submitted
+ //lastRequestedEntry.source.appendParameter("AJAX:EVENTS_COUNT",
lastRequestedEntry.eventsCount);
+ var params = richfaces.processRequestParams(lastRequestedEntry.source,
lastRequestedEntry.options);
+ //TODO: copy of event should be created otherwise IE will fail
+ //richfaces.ajax.request = jsf.ajax.request
+ richfaces.ajax.request(lastRequestedEntry.source, lastRequestedEntry.event, params);
+ if (lastRequestedEntry.options.queueonsubmit) {
+ lastRequestedEntry.options.queueonsubmit.call(lastRequestedEntry);
}
}
};
@@ -180,9 +180,10 @@
getSize: getSize,
isEmpty: isEmpty,
+ submitFirst: submitFirst,
push: function (source, event, options) {
- var entry = new queueEntry(source, event, options);
+ var entry = new QueueEntry(this, source, event, options);
var similarityGroupingId = entry.getSimilarityGroupingId();
var lastEntry = getLastEntry();
@@ -201,10 +202,8 @@
log.debug("Last queue entry is not the last anymore. Stopping requestDelay
timer and marking entry as ready for submission")
lastEntry.stopTimer();
- //TODO: create method resetSimilarityGroupingId()
- lastEntry.setSimilarityGroupingId(undefined);
- //TODO: create method setReadyToSubmit()
- lastEntry.readyToSubmit = true;
+ lastEntry.resetSimilarityGroupingId();
+ lastEntry.setReadyToSubmit(true);
items.push(entry);
log.debug("New request added to queue. Queue similarityGroupingId changed to
" + similarityGroupingId);
@@ -218,11 +217,8 @@
},
- //TODO: remove empty functions
- pop: function () {
- },
-
clear: function () {
+ //TODO: clear queue
}
}
}(jQuery.extend({},defaultQueueOptions));