From 313378ad2905fc07be00183b2acc61284c1c2c39 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 18 Jun 2006 05:02:24 +0000 Subject: Add TCallbackTimer --- framework/Web/Javascripts/prado/activecontrols3.js | 97 +++++++++++++++++++++- framework/Web/Javascripts/prado/ajax3.js | 2 +- 2 files changed, 97 insertions(+), 2 deletions(-) (limited to 'framework/Web/Javascripts/prado') diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js index c0964dcb..50ff39d6 100644 --- a/framework/Web/Javascripts/prado/activecontrols3.js +++ b/framework/Web/Javascripts/prado/activecontrols3.js @@ -84,4 +84,99 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete, if(typeof(result) == "string" && result.length > 0) this.updateChoices(result); } -}); \ No newline at end of file +}); + +/** + * Callback Timer class. + */ +Prado.WebUI.TCallbackTimer = Base.extend( +{ + count : 0, + timeout : 0, + + constructor : function(options) + { + this.options = Object.extend( + { + Interval : 1, + DecayRate : 0 + }, options || {}) + + this.onComplete = this.options.onComplete; + Prado.WebUI.TCallbackTimer.register(this); + }, + + startTimer : function() + { + this.options.onComplete = this.onRequestComplete.bind(this); + setTimeout(this.onTimerEvent.bind(this), 200); + }, + + stopTimer : function() + { + (this.onComplete || Prototype.emptyFunction).apply(this, arguments); + this.options.onComplete = undefined; + clearTimeout(this.timer); + this.timer = undefined; + this.count = 0; + }, + + onTimerEvent : function() + { + this.options.params = this.timeout/1000; + new Prado.CallbackRequest(this.options.ID, this.options); + }, + + onRequestComplete : function() + { + (this.onComplete || Prototype.emptyFunction).apply(this, arguments); + this.timer = setTimeout(this.onTimerEvent.bind(this), this.getNewTimeout()) + }, + + getNewTimeout : function() + { + switch(this.options.DecayType) + { + case 'Exponential': + t = (Math.exp(this.options.DecayRate*this.count*this.options.Interval))-1; + break; + case 'Linear': + t = this.options.DecayRate*this.count*this.options.Interval; + break; + case 'Quadratic': + t = this.options.DecayRate*this.count*this.count*this.options.Interval; + break; + case 'Cubic': + t = this.options.DecayRate*this.count*this.count*this.count*this.options.Interval; + break; + default : t = 0; + } + this.timeout = (t + this.options.Interval)*1000; + this.count++; + return parseInt(this.timeout); + } +}, +//class methods +{ + timers : {}, + + register : function(timer) + { + this.timers[timer.options.ID] = timer; + }, + + start : function(id) + { + if(this.timers[id]) + this.timers[id].startTimer(); + }, + + stop : function(id) + { + if(this.timers[id]) + this.timers[id].stopTimer(); + } +}); + + + diff --git a/framework/Web/Javascripts/prado/ajax3.js b/framework/Web/Javascripts/prado/ajax3.js index adf8534a..bae60d89 100644 --- a/framework/Web/Javascripts/prado/ajax3.js +++ b/framework/Web/Javascripts/prado/ajax3.js @@ -11,7 +11,7 @@ Object.extend(Ajax.Request.prototype, { var event = Ajax.Request.Events[readyState]; var transport = this.transport, json = this.getHeaderData(Prado.CallbackRequest.DATA_HEADER); - + if (event == 'Complete') { try -- cgit v1.2.3