summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/js/ajax.js
diff options
context:
space:
mode:
authorwei <>2006-08-12 12:54:27 +0000
committerwei <>2006-08-12 12:54:27 +0000
commit1180e6486139a9c9662984367c4f624394e06f35 (patch)
treef89a379960284595d5a425e22424582eea57422c /framework/Web/Javascripts/js/ajax.js
parent54d4919e3f1b00b644fa3c107acdf20159a1b154 (diff)
Add Triggered Callbacks
Diffstat (limited to 'framework/Web/Javascripts/js/ajax.js')
-rw-r--r--framework/Web/Javascripts/js/ajax.js27
1 files changed, 24 insertions, 3 deletions
diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js
index 0836f094..95869ade 100644
--- a/framework/Web/Javascripts/js/ajax.js
+++ b/framework/Web/Javascripts/js/ajax.js
@@ -212,9 +212,9 @@ this.onInit(options);},doCallback:function(event,options)
{var element=Event.findElement(event,'LI');this.index=element.autocompleteIndex;this.selectEntry();this.hide();Event.fireEvent(this.element,"change");},getUpdatedChoices:function()
{options=new Array(this.getToken(),"__TAutoComplete_onSuggest__");Prado.Callback(this.options.EventTarget,options,null,this.options);},onComplete:function(request,boundary)
{result=Prado.Element.extractContent(request.responseText,boundary);if(typeof(result)=="string"&&result.length>0)
-this.updateChoices(result);}});Prado.WebUI.TCallbackTimer=Base.extend({count:0,timeout:0,constructor:function(options)
+this.updateChoices(result);}});Prado.WebUI.TPeriodicCallback=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.onComplete=this.options.onComplete;Prado.WebUI.TPeriodicCallback.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;request=new Prado.CallbackRequest(this.options.ID,this.options);request.dispatch();},onRequestComplete:function()
@@ -228,4 +228,25 @@ this.timers[id].startTimer();},stop:function(id)
{if(this.timers[id])
this.timers[id].stopTimer();}});Prado.WebUI.ActiveListControl=Base.extend({constructor:function(options)
{this.element=$(options.ID);this.options=options;Event.observe(this.element,"change",this.doCallback.bind(this));},doCallback:function(event)
-{request=new Prado.CallbackRequest(this.options.EventTarget,this.options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveDropDownList=Prado.WebUI.ActiveListControl;Prado.WebUI.TActiveListBox=Prado.WebUI.ActiveListControl; \ No newline at end of file
+{request=new Prado.CallbackRequest(this.options.EventTarget,this.options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveDropDownList=Prado.WebUI.ActiveListControl;Prado.WebUI.TActiveListBox=Prado.WebUI.ActiveListControl;Prado.WebUI.TEventTriggeredCallback=Base.extend({constructor:function(options)
+{this.options=options;element=$(options['ControlID']);if(element)
+Event.observe(element,this.getEventName(element),this.doCallback.bind(this));},getEventName:function(element)
+{name=this.options.EventName;if(typeof(name)=="undefined"&&element.type)
+{switch(element.type.toLowerCase())
+{case'password':case'text':case'textarea':case'select-one':case'select-multiple':return'change';}}
+return typeof(name)=="undefined"||name=="undefined"?'click':name;},doCallback:function(event)
+{request=new Prado.CallbackRequest(this.options.ID,this.options);request.dispatch();if(this.options.StopEvent==true)
+Event.stop(event);}});Prado.WebUI.TValueTriggeredCallback=Base.extend({count:1,observing:true,constructor:function(options)
+{this.options=options;this.options.PropertyName=this.options.PropertyName||'value';element=$(options['ControlID']);this.value=element?element[this.options.PropertyName]:undefined;Prado.WebUI.TValueTriggeredCallback.register(this);this.startObserving();},stopObserving:function()
+{clearTimeout(this.timer);this.observing=false;},startObserving:function()
+{this.timer=setTimeout(this.checkChanges.bind(this),this.options.Interval*1000);},checkChanges:function()
+{element=$(this.options.ControlID);if(element)
+{value=element[this.options.PropertyName];if(this.value!=value)
+{this.doCallback(this.value,value);this.value=value;this.count=1;}
+else
+this.count=this.count+this.options.Decay;if(this.observing)
+this.time=setTimeout(this.checkChanges.bind(this),parseInt(this.options.Interval*1000*this.count));}},doCallback:function(oldValue,newValue)
+{request=new Prado.CallbackRequest(this.options.ID,this.options);param={'OldValue':oldValue,'NewValue':newValue};request.setParameter(param);request.dispatch();}},{timers:{},register:function(timer)
+{this.timers[timer.options.ID]=timer;},stop:function(id)
+{if(this.timers[id])
+this.timers[id].stopObserving();}}); \ No newline at end of file