diff options
18 files changed, 529 insertions, 48 deletions
diff --git a/.gitattributes b/.gitattributes index e7683983..11f87750 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1749,6 +1749,9 @@ framework/Web/UI/ActiveControls/TCallback.php -text framework/Web/UI/ActiveControls/TCallbackClientScript.php -text framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php -text framework/Web/UI/ActiveControls/TCallbackOptions.php -text +framework/Web/UI/ActiveControls/TEventTriggeredCallback.php -text +framework/Web/UI/ActiveControls/TTriggeredCallback.php -text +framework/Web/UI/ActiveControls/TValueTriggeredCallback.php -text framework/Web/UI/TClientScriptManager.php -text framework/Web/UI/TCompositeControl.php -text framework/Web/UI/TControl.php -text @@ -1867,17 +1870,23 @@ tests/FunctionalTests/active-controls/protected/pages/CustomTemplateComponent.ph tests/FunctionalTests/active-controls/protected/pages/CustomTemplateComponent.tpl -text tests/FunctionalTests/active-controls/protected/pages/CustomTemplateControlTest.page -text tests/FunctionalTests/active-controls/protected/pages/CustomTemplateControlTest.php -text +tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.page -text +tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.php -text tests/FunctionalTests/active-controls/protected/pages/ReplaceContentTest.page -text tests/FunctionalTests/active-controls/protected/pages/ReplaceContentTest.php -text tests/FunctionalTests/active-controls/protected/pages/TextBoxValidationCallback.page -text tests/FunctionalTests/active-controls/protected/pages/TextBoxValidationCallback.php -text +tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.php -text tests/FunctionalTests/active-controls/tests/ActiveLinkButtonTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveListBoxTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveRadioButtonListTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveRadioButtonTestCase.php -text tests/FunctionalTests/active-controls/tests/CustomTemplateTestCase.php -text +tests/FunctionalTests/active-controls/tests/EventTriggerTestCase.php -text tests/FunctionalTests/active-controls/tests/ReplaceContentTestCase.php -text tests/FunctionalTests/active-controls/tests/TextBoxGroupValidationTestCase.php -text +tests/FunctionalTests/active-controls/tests/ValueTriggerCallbackTestCase.php -text tests/FunctionalTests/features.php -text tests/FunctionalTests/features/index.php -text tests/FunctionalTests/features/protected/application.xml -text diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index 39d304be..89dcb799 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -341,3 +341,5 @@ xmltransform_xslextension_required = TXmlTransform requires the PHP's XSL exten xmltransform_transformpath_invalid = TXmlTransform.TransformPath '{0}' is invalid.
xmltransform_documentpath_invalid = TXmlTransform.DocumentPath '{0}' is invalid.
xmltransform_transform_required = Either TransformContent or TransformPath property must be set for TXmlTransform.
+
+ttriggeredcallback_invalid_controlid = ControlID property for '{0}' must not be empty.
\ No newline at end of file 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 diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js index f75d3684..ca1d5b37 100644 --- a/framework/Web/Javascripts/prado/activecontrols3.js +++ b/framework/Web/Javascripts/prado/activecontrols3.js @@ -112,9 +112,9 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete, });
/**
- * Callback Timer class.
+ * Period Callback class.
*/
-Prado.WebUI.TCallbackTimer = Base.extend(
+Prado.WebUI.TPeriodicCallback = Base.extend(
{
count : 0,
timeout : 0,
@@ -128,7 +128,7 @@ Prado.WebUI.TCallbackTimer = Base.extend( }, options || {})
this.onComplete = this.options.onComplete;
- Prado.WebUI.TCallbackTimer.register(this);
+ Prado.WebUI.TPeriodicCallback.register(this);
},
startTimer : function()
@@ -223,3 +223,117 @@ Prado.WebUI.ActiveListControl = Base.extend( Prado.WebUI.TActiveDropDownList = Prado.WebUI.ActiveListControl;
Prado.WebUI.TActiveListBox = Prado.WebUI.ActiveListControl;
+
+/**
+ * Observe event of a particular control to trigger a callback request.
+ */
+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);
+ }
+});
+
+/**
+ * Observe changes to a property of a particular control to trigger a callback.
+ */
+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();
+ }
+},
+//class methods
+{
+ timers : {},
+
+ register : function(timer)
+ {
+ this.timers[timer.options.ID] = timer;
+ },
+
+ stop : function(id)
+ {
+ if(this.timers[id])
+ this.timers[id].stopObserving();
+ }
+});
diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php index cb944253..c368cb68 100644 --- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php +++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php @@ -328,8 +328,10 @@ class TBaseActiveCallbackControl extends TBaseActiveControl $options = array_merge($this->getClientSideOptions(),$options);
else
$options = $this->getClientSideOptions();
+
//remove true as default to save bytes
- $options['CausesValidation']= $options['CausesValidation'] ? '' : false;
+ if($options['CausesValidation']===true)
+ $options['CausesValidation']='';
$cs->registerCallbackControl($class, $options);
}
diff --git a/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php new file mode 100644 index 00000000..42f49976 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php @@ -0,0 +1,70 @@ +<?php
+
+class TEventTriggeredCallback extends TTriggeredCallback
+{
+ /**
+ * @return string The client-side event name the trigger listens to.
+ */
+ public function getEventName()
+ {
+ return $this->getViewState('EventName', '');
+ }
+
+ /**
+ * Sets the client-side event name that fires the callback request.
+ * @param string The client-side event name the trigger listens to.
+ */
+ public function setEventName($value)
+ {
+ $this->setViewState('EventName', $value, '');
+ }
+
+ /**
+ * @param boolean true to prevent/stop default event action.
+ */
+ public function setPreventDefaultAction($value)
+ {
+ $this->setViewState('StopEvent', TPropertyValue::ensureBoolean($value), false);
+ }
+
+ /**
+ * @return boolean true to prevent/stop default event action.
+ */
+ public function getPreventDefaultAction()
+ {
+ return $this->getViewState('StopEvent', false);
+ }
+
+ /**
+ * @return array list of timer options for client-side.
+ */
+ protected function getTriggerOptions()
+ {
+ $options = parent::getTriggerOptions();
+ $name = preg_replace('/^on/', '', $this->getEventName());
+ $options['EventName'] = strtolower($name);
+ $options['StopEvent'] = $this->getPreventDefaultAction();
+ return $options;
+ }
+
+ /**
+ * Registers the javascript code for initializing the active control.
+ * @param THtmlWriter the renderer.
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getTriggerOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for TEventTriggeredCallback.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TEventTriggeredCallback';
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TCallbackTimer.php b/framework/Web/UI/ActiveControls/TPeriodicCallback.php index bae41e1f..e620ac46 100644 --- a/framework/Web/UI/ActiveControls/TCallbackTimer.php +++ b/framework/Web/UI/ActiveControls/TPeriodicCallback.php @@ -1,6 +1,6 @@ <?php /** - * TCallbackTimer class file. + * TPeriodicCallback class file. * * @author Wei Zhuo <weizhuo[at]gamil[dot]com> * @link http://www.pradosoft.com/ @@ -16,13 +16,13 @@ Prado::using('System.Web.UI.ActiveControls.TCallback'); /** - * TCallbackTimer class. - * - * TCallbackTimer sends callback request every {@link setInterval Interval} seconds. + * TPeriodicCallback class. + * + * TPeriodicCallback sends callback request every {@link setInterval Interval} seconds. * Upon each callback request, the {@link onCallback OnCallback} event is raised. - * + * * The intervals between each request can be increased when the browser is inactive - * by changing the {@link setDecayRate DecayRate} to a positive number. The + * by changing the {@link setDecayRate DecayRate} to a positive number. The * default decay rate, {@link setDecayType DecayType}, is linear and can be changed to * 'Exponential', 'Linear', 'Quadratic' or 'Cubic'. * @@ -31,7 +31,7 @@ Prado::using('System.Web.UI.ActiveControls.TCallback'); * @package System.Web.UI.ActiveControls * @since 3.0 */ -class TCallbackTimer extends TCallback +class TPeriodicCallback extends TCallback { /** * @return float seconds between callback requests. Default is 1 second. @@ -40,7 +40,7 @@ class TCallbackTimer extends TCallback { return $this->getViewState('Interval', 1); } - + /** * @param float seconds between callback requests, must be a positive number, default is 1 second. */ @@ -51,7 +51,7 @@ class TCallbackTimer extends TCallback throw new TConfigurationException('callback_interval_be_positive', $this->getID()); $this->setViewState('Interval', $interval, 1); } - + /** * Gets the decay rate between callbacks. Default is 0; * @return float decay rate between callbacks. @@ -60,7 +60,7 @@ class TCallbackTimer extends TCallback { return $this->getViewState('Decay', 0); } - + /** * Sets the decay rate between callback. Default is 0; * @param float decay rate between callbacks. @@ -72,13 +72,13 @@ class TCallbackTimer extends TCallback throw new TConfigurationException('callback_decay_be_not_negative', $this->getID()); $this->setViewState('Decay', $decay); } - + /** * @param string Decay type, allows 'Exponential', 'Linear', 'Quadratic' and 'Cubic'. Default is 'Linear'. */ public function setDecayType($value) { - $this->setViewState('DecayType', TPropertyValue::ensureEnum($value, + $this->setViewState('DecayType', TPropertyValue::ensureEnum($value, 'Exponential', 'Linear', 'Quadratic', 'Cubic'), 'Linear'); } @@ -89,27 +89,27 @@ class TCallbackTimer extends TCallback { return $this->getViewState('DecayType', 'Linear'); } - + /** * Registers the javascript code to start the timer. */ public function startTimer() { $id = $this->getClientID(); - $code = "Prado.WebUI.TCallbackTimer.start('{$id}');"; + $code = "Prado.WebUI.TPeriodicCallback.start('{$id}');"; $cs = $this->getPage()->getClientScript(); $cs->registerEndScript("{$id}:start", $code); } - + /** * Registers the javascript code to stop the timer. */ public function stopTimer() { $id = $this->getClientID(); - $code = "Prado.WebUI.TCallbackTimer.stop('{$id}');"; + $code = "Prado.WebUI.TPeriodicCallback.stop('{$id}');"; $cs = $this->getPage()->getClientScript(); - $cs->registerEndScript("{$id}:stop", $code); + $cs->registerEndScript("{$id}:stop", $code); } /** @@ -132,15 +132,15 @@ class TCallbackTimer extends TCallback { parent::render($writer); $this->getActiveControl()->registerCallbackClientScript( - $this->getClientClassName(), $this->getTimerOptions()); + $this->getClientClassName(), $this->getTimerOptions()); } /** - * @return string corresponding javascript class name for this TActiveButton. + * @return string corresponding javascript class name for TPeriodicCallback. */ protected function getClientClassName() { - return 'Prado.WebUI.TCallbackTimer'; + return 'Prado.WebUI.TPeriodicCallback'; } } diff --git a/framework/Web/UI/ActiveControls/TTriggeredCallback.php b/framework/Web/UI/ActiveControls/TTriggeredCallback.php new file mode 100644 index 00000000..076166c9 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TTriggeredCallback.php @@ -0,0 +1,49 @@ +<?php
+
+abstract class TTriggeredCallback extends TCallback
+{
+ /**
+ * @return string The ID of the server control the trigger is bounded to.
+ */
+ public function getControlID()
+ {
+ return $this->getViewState('ControlID', '');
+ }
+
+ /**
+ * @param string The ID of the server control the trigger is bounded to.
+ */
+ public function setControlID($value)
+ {
+ $this->setViewState('ControlID', $value, '');
+ }
+
+ /**
+ * @return string target control client ID or html element ID if
+ * control is not found in hierarchy.
+ */
+ protected function getTargetControl()
+ {
+ $id = $this->getControlID();
+ if(($control=$this->findControl($id)) instanceof TControl)
+ return $control->getClientID();
+ if($id==='')
+ {
+ throw new TConfigurationException(
+ 'ttriggeredcallback_invalid_controlid', get_class($this));
+ }
+ return $id;
+ }
+
+ /**
+ * @return array list of trigger callback options.
+ */
+ protected function getTriggerOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['ControlID'] = $this->getTargetControl();
+ return $options;
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php new file mode 100644 index 00000000..bb50e4f1 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php @@ -0,0 +1,92 @@ +<?php
+
+class TValueTriggeredCallback extends TTriggeredCallback
+{
+ /**
+ * @return string The control property name to observe value changes.
+ */
+ public function getPropertyName()
+ {
+ return $this->getViewState('PropertyName', '');
+ }
+
+ /**
+ * Sets the control property name to observe value changes that fires the callback request.
+ * @param string The control property name to observe value changes.
+ */
+ public function setPropertyName($value)
+ {
+ $this->setViewState('PropertyName', $value, '');
+ }
+
+ /**
+ * Sets the polling interval in seconds to observe property changes.
+ * Default is 1 second.
+ * @param float polling interval in seconds.
+ */
+ public function setPollingInterval($value)
+ {
+ $this->setViewState('Interval', TPropertyValue::ensureFloat($value), 1);
+ }
+
+ /**
+ * Gets the decay rate between callbacks. Default is 0;
+ * @return float decay rate between callbacks.
+ */
+ public function getDecayRate()
+ {
+ return $this->getViewState('Decay', 0);
+ }
+
+ /**
+ * Sets the decay rate between callback. Default is 0;
+ * @param float decay rate between callbacks.
+ */
+ public function setDecayRate($value)
+ {
+ $decay = TPropertyValue::ensureFloat($value);
+ if($decay < 0)
+ throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
+ $this->setViewState('Decay', $decay);
+ }
+
+ /**
+ * @return float polling interval, 1 second default.
+ */
+ public function getPollingInterval()
+ {
+ return $this->getViewState('Interval', 1);
+ }
+
+ /**
+ * @return array list of timer options for client-side.
+ */
+ protected function getTriggerOptions()
+ {
+ $options = parent::getTriggerOptions();
+ $options['PropertyName'] = $this->getPropertyName();
+ $options['Interval'] = $this->getPollingInterval();
+ $options['Decay'] = $this->getDecayRate();
+ return $options;
+ }
+
+ /**
+ * Registers the javascript code for initializing the active control.
+ * @param THtmlWriter the renderer.
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getTriggerOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for TEventTriggeredCallback.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TValueTriggeredCallback';
+ }
+}
+?>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.page b/tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.page new file mode 100644 index 00000000..889636f3 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.page @@ -0,0 +1,31 @@ +<com:TForm ID="form1">
+
+ <h1>Event Triggered Callback Test</h1>
+
+ <com:TTextBox ID="text1" Text="Focus me" />
+
+ <com:TPanel ID="panel1" style="padding: 2em; border:1px solid #ccc; background-color: #ffc;">
+ Mouse over this panel
+ </com:TPanel>
+
+ <input id="button1" type="button" value="Click me" />
+
+ <com:TEventTriggeredCallback
+ ControlID="text1"
+ EventName="focus"
+ OnCallback="text1_focused" />
+
+ <com:TEventTriggeredCallback
+ ControlID="panel1"
+ EventName="mouseover"
+ OnCallback="panel1_onmouseover" />
+
+ <com:TEventTriggeredCallback
+ ControlID="button1"
+ OnCallback="button1_clicked" />
+
+ <div style="padding: 2em; border:1px solid #ccc; margin-top:2em">
+ <com:TActiveLabel ID="label1" Text="Label 1" />
+ </div>
+ <com:TJavascriptLogger />
+</com:TForm>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.php b/tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.php new file mode 100644 index 00000000..dc47d867 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.php @@ -0,0 +1,21 @@ +<?php
+
+class EventTriggeredCallback extends TPage
+{
+ function text1_focused($sender, $param)
+ {
+ $this->label1->Text = 'text 1 focused';
+ }
+
+ function panel1_onmouseover($sender, $param)
+ {
+ $this->label1->Text = 'panel 1 on mouse over '.time();
+ }
+
+ function button1_clicked($sender, $param)
+ {
+ $this->label1->Text = 'button 1 clicked';
+ }
+}
+
+?>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/CallbackTimerTest.page b/tests/FunctionalTests/active-controls/protected/pages/PeriodicCallbackTest.page index 8e99e528..bbc12862 100644 --- a/tests/FunctionalTests/active-controls/protected/pages/CallbackTimerTest.page +++ b/tests/FunctionalTests/active-controls/protected/pages/PeriodicCallbackTest.page @@ -1,18 +1,18 @@ <com:TForm ID="form1"> - <h1>TCallbackTimer + ViewState Tests</h1> + <h1>TPeriodicCallback + ViewState Tests</h1> <com:TActiveButton id="button1" Text="Start Timer" OnCallback="start_timer" /> <com:TActiveButton Text="Stop Timer" OnCallback="stop_timer" /> <div style="margin:1em; padding:1em; border:1px solid #ccc;"> <com:TActiveLabel ID="label1" Text="ViewState Counter : " /> </div> - <com:TCallbackTimer ID="timer1" Interval="0.1" OnCallback="tick"> - <prop:ActiveControl.ClientSide - OnLoading="$('status').show()" + <com:TPeriodicCallback ID="timer1" Interval="0.1" OnCallback="tick"> + <prop:ActiveControl.ClientSide + OnLoading="$('status').show()" OnComplete="$('status').hide()" /> - </com:TCallbackTimer> - <div id="status" style="margin:1em; padding:0.5em; - text-align:center; - background-color:#900; + </com:TPeriodicCallback> + <div id="status" style="margin:1em; padding:0.5em; + text-align:center; + background-color:#900; color:white; display: none; position: absolute; right: 0; top: 0"> Loading... diff --git a/tests/FunctionalTests/active-controls/protected/pages/CallbackTimerTest.php b/tests/FunctionalTests/active-controls/protected/pages/PeriodicCallbackTest.php index da87ac0f..13633a00 100644 --- a/tests/FunctionalTests/active-controls/protected/pages/CallbackTimerTest.php +++ b/tests/FunctionalTests/active-controls/protected/pages/PeriodicCallbackTest.php @@ -1,23 +1,23 @@ <?php -class CallbackTimerTest extends TPage +class PeriodicCallbackTest extends TPage { function start_timer($sender, $param) { $this->timer1->startTimer(); $this->setViewState('count', 0); } - + function stop_timer($sender, $param) { $this->timer1->stopTimer(); } - + function tick($sender, $param) { $count = intval($this->getViewState('count')); - $this->setViewState('count', ++$count); - if($count > 10) + $this->setViewState('count', ++$count); + if($count > 10) $this->timer1->stopTimer(); else $this->label1->Text .= " ".$count; diff --git a/tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.page b/tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.page new file mode 100644 index 00000000..1281cc5c --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.page @@ -0,0 +1,14 @@ +<com:TForm>
+<h1>Value Trigger Callback Test</h1>
+
+<com:TTextBox ID="text1" />
+
+<com:TValueTriggeredCallback
+ ControlID="text1"
+ OnCallback="text1_changed" />
+
+<com:TActiveLabel ID="label1" Text="Label 1" />
+
+<com:TJavascriptLogger />
+
+</com:TForm>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.php b/tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.php new file mode 100644 index 00000000..c3c44252 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.php @@ -0,0 +1,12 @@ +<?php
+
+class ValueTriggerCallbackTest extends TPage
+{
+ function text1_changed($sender, $param)
+ {
+ $values = $param->getParameter();
+ $this->label1->Text = "Old = ".$values->OldValue." : New Value = ".$values->NewValue;
+ }
+}
+
+?>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/tests/EventTriggerTestCase.php b/tests/FunctionalTests/active-controls/tests/EventTriggerTestCase.php new file mode 100644 index 00000000..8e400b5b --- /dev/null +++ b/tests/FunctionalTests/active-controls/tests/EventTriggerTestCase.php @@ -0,0 +1,22 @@ +<?php
+
+class EventTriggerTestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $this->open("active-controls/index.php?page=EventTriggeredCallback");
+ $this->verifyTextPresent("Event Triggered Callback Test");
+
+ $this->assertText('label1', 'Label 1');
+
+ $this->click('button1');
+ $this->pause(800);
+ $this->assertText('label1', 'button 1 clicked');
+
+ $this->type('text1', 'test');
+ $this->pause(800);
+ $this->assertText('label1', 'text 1 focused');
+ }
+}
+
+?>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/tests/CallbackTimerTestCase.php b/tests/FunctionalTests/active-controls/tests/PeriodicCallbackTestCase.php index 2954cc51..2468aebf 100644 --- a/tests/FunctionalTests/active-controls/tests/CallbackTimerTestCase.php +++ b/tests/FunctionalTests/active-controls/tests/PeriodicCallbackTestCase.php @@ -1,20 +1,20 @@ <?php -class CallbackTimerTestCase extends SeleniumTestCase +class PeriodicCallbackTestCase extends SeleniumTestCase { function test() { - $this->open("active-controls/index.php?page=CallbackTimerTest"); - $this->verifyTextPresent("TCallbackTimer + ViewState Tests"); - + $this->open("active-controls/index.php?page=PeriodicCallbackTest"); + $this->verifyTextPresent("TPeriodicCallback + ViewState Tests"); + $this->assertText("label1", "ViewState Counter :"); - + $this->click("button1"); - + $this->pause(8000); - + $this->assertText("label1", "ViewState Counter : 1 2 3 4 5 6 7 8 9 10"); - + } } diff --git a/tests/FunctionalTests/active-controls/tests/ValueTriggerCallbackTestCase.php b/tests/FunctionalTests/active-controls/tests/ValueTriggerCallbackTestCase.php new file mode 100644 index 00000000..f98fc4a8 --- /dev/null +++ b/tests/FunctionalTests/active-controls/tests/ValueTriggerCallbackTestCase.php @@ -0,0 +1,22 @@ +<?php
+
+class ValueTriggerTestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $this->open("active-controls/index.php?page=ValueTriggerCallbackTest");
+ $this->verifyTextPresent("Value Trigger Callback Test");
+
+ $this->assertText('label1', 'Label 1');
+
+ $this->type('text1', 'test');
+ $this->pause(2000);
+ $this->assertText('label1', 'Old = : New Value = test');
+
+ $this->type('text1', 'more');
+ $this->pause(3000);
+ $this->assertText('label1', 'Old = test : New Value = more');
+ }
+}
+
+?>
\ No newline at end of file |