Author: pyaschenko
Date: 2010-04-23 13:33:25 -0400 (Fri, 23 Apr 2010)
New Revision: 16802
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-queue.js
Log:
queue changes: named queue options were added (exept dom searching), clear function was
added, small refactoring
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 2010-04-23
17:17:15 UTC (rev 16801)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-queue.js 2010-04-23
17:33:25 UTC (rev 16802)
@@ -37,8 +37,9 @@
};
var QUEUE_MODE_PULL = 'pull';
- var QUEUE_MODE_PUSH = 'push';
- var defaultQueueOptions = {mode: QUEUE_MODE_PULL, requestDelay:0};
+ var QUEUE_MODE_PUSH = 'push';
+ var QUEUE_MODE = QUEUE_MODE_PULL;
+ var DEFAULT_QUEUE_ID = "org.richfaces.queue.global";
/**
* RichFaces Queue API container
@@ -47,12 +48,24 @@
* @static
* @name queue
* */
- richfaces.queue = function(opts){
+ richfaces.queue = (function(){
+
+ var defaultQueueOptions = {};
+ defaultQueueOptions[DEFAULT_QUEUE_ID] = {requestDelay:0, ignoreDupResponse:false,
timeout:0};
var QueueEntry = function(queue, source, event, options) {
this.queue = queue;
this.source = source;
this.options = options || {};
+ this.queueOptions = {}
+ if (options.hasOwnProperty("queueId")) {
+ if (defaultQueueOptions[options.queueId]) {
+ this.queueOptions = defaultQueueOptions[options.queueId];
+ }
+ } else {
+ // TODO: find form options or use view options
+ this.queueOptions = defaultQueueOptions[DEFAULT_QUEUE_ID];
+ }
this.event = event;
//similarityGroupingId is mutable, thus we need special field for it
@@ -99,7 +112,10 @@
},
startTimer: function() {
- var delay = this.options.requestDelay || queueOptions.requestDelay || 0;
+ var delay = this.options.requestDelay;
+ if (typeof delay!="number") {
+ delay = this.queueOptions.requestDelay || 0;
+ }
log.debug("Queue will wait " + (delay || 0) + "ms before
submit");
@@ -149,7 +165,6 @@
var log = richfaces.log;
var items = [];
- var queueOptions = opts || {};
var lastRequestedEntry;
//TODO: instance of this function will be created for each queue
@@ -172,7 +187,7 @@
jsf.ajax.addOnError(onError);
var submitFirst = function() {
- if (queueOptions.mode == QUEUE_MODE_PULL && lastRequestedEntry) {
+ if (QUEUE_MODE == QUEUE_MODE_PULL && lastRequestedEntry) {
log.debug("richfaces.queue: Waiting for previous submit results");
return;
}
@@ -183,14 +198,13 @@
if (items[0].getReadyToSubmit()) {
lastRequestedEntry = items.shift();
log.debug("richfaces.queue: will submit request NOW");
- //TODO: events counter should be submitted
+ //TODO: copy of event should be created otherwise IE will fail
+ var o = lastRequestedEntry.options;
//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,
lastRequestedEntry.options);
- if (lastRequestedEntry.options.queueonsubmit) {
- lastRequestedEntry.options.queueonsubmit.call(lastRequestedEntry);
+ o["AJAX:EVENTS_COUNT"] = lastRequestedEntry.eventsCount;
+ richfaces.ajax.request(lastRequestedEntry.source, lastRequestedEntry.event, o);
+ if (o.queueonsubmit) {
+ o.queueonsubmit.call(lastRequestedEntry);
}
}
};
@@ -237,7 +251,14 @@
* @function
* @name RichFaces.queue.submitFirst
* */
- submitFirst: submitFirst,
+ submitFirst: function () {
+ if (!isEmpty()) {
+ var entry = items[0];
+ entry.stopTimer();
+ entry.setReadyToSubmit(true);
+ submitFirst();
+ }
+ },
/**
* Create and push QueueEntry to the queue for ajax requests
@@ -283,9 +304,41 @@
},
+ /**
+ * Remove all QueueEntry from the queue
+ * @function
+ * @name RichFaces.queue.clear
+ * */
clear: function () {
//TODO: clear queue
+ var lastEntry = getLastEntry();
+ if (lastEntry) {
+ lastEntry.stopTimer();
+ }
+ items = [];
+ },
+
+ /**
+ * Set queue default options
+ * @function
+ * @name RichFaces.queue.setQueueOptions
+ *
+ * @param {string} [id] - Queue id for storing options
+ * @param {object} options - Queue options object
+ * */
+ setQueueOptions: function (id, options) {
+ var queueId = DEFAULT_QUEUE_ID;
+ if (typeof id == "string") {
+ queueId = id;
+ } else {
+ options = id;
+ }
+ if (defaultQueueOptions[queueId]) {
+ throw "Queue already registered";
+ } else {
+ defaultQueueOptions[queueId] = options;
+ }
}
}
- }(jQuery.extend({},defaultQueueOptions));
+ }());
}(jQuery, RichFaces, jsf));
\ No newline at end of file
Show replies by date