summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwei <>2006-06-18 06:49:29 +0000
committerwei <>2006-06-18 06:49:29 +0000
commit2d88e84697fa4a36b7a2077b9e086aa2f9d3d67a (patch)
tree0c2c4e1cbe197018e264cf1de3ed6a2351771cfa
parent313378ad2905fc07be00183b2acc61284c1c2c39 (diff)
Add ActiveCheckBox
-rw-r--r--framework/Exceptions/messages.txt2
-rw-r--r--framework/Web/Javascripts/js/ajax.js3
-rw-r--r--framework/Web/Javascripts/js/prado.js2
-rw-r--r--framework/Web/Javascripts/prado/activecontrols3.js11
-rw-r--r--framework/Web/Javascripts/prado/element.js2
-rw-r--r--framework/Web/UI/ActiveControls/TActiveCheckBox.php156
-rw-r--r--tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.page29
-rw-r--r--tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.php32
-rw-r--r--tests/FunctionalTests/active-controls/tests/ActiveCheckBoxTestCase.php61
9 files changed, 295 insertions, 3 deletions
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index 273d713d..582195f3 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -313,6 +313,8 @@ callback_invalid_target = Invalid callback target, no such control with ID {
callback_interval_be_positive = Interval for TCallbackTimer "{0}" must be strictly greater than zero seconds.
callback_decay_be_not_negative = Decay rate for TCallbackTimer "{0}" must be not negative.
+callback_no_autopostback = Control "{0}" can not enable AutoPostBack.
+
xmltransform_xslextension_required = TXmlTransform require the PHP's XSL extension
xmltransform_transformpath_invalid = TransformPath '{0}' is invalid.
xmltransform_documentpath_invalid = DocumentPath '{0}' is invalid.
diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js
index c2fb8f82..e0e9ae7e 100644
--- a/framework/Web/Javascripts/js/ajax.js
+++ b/framework/Web/Javascripts/js/ajax.js
@@ -189,7 +189,8 @@ if(this.saving)return;this.effect=new Effect.Highlight(this.element,{startcolor:
this.editing=false;this.saving=false;this.oldInnerHTML=null;this.onLeaveEditMode();},onComplete:function(transport){this.leaveEditMode();this.options.onComplete.bind(this)(transport,this.element);},onEnterEditMode:function(){},onLeaveEditMode:function(){},dispose:function(){if(this.oldInnerHTML){this.element.innerHTML=this.oldInnerHTML;}
this.leaveEditMode();Event.stopObserving(this.element,'click',this.onclickListener);Event.stopObserving(this.element,'mouseover',this.mouseoverListener);Event.stopObserving(this.element,'mouseout',this.mouseoutListener);if(this.options.externalControl){Event.stopObserving(this.options.externalControl,'click',this.onclickListener);Event.stopObserving(this.options.externalControl,'mouseover',this.mouseoverListener);Event.stopObserving(this.options.externalControl,'mouseout',this.mouseoutListener);}}};Ajax.InPlaceCollectionEditor=Class.create();Object.extend(Ajax.InPlaceCollectionEditor.prototype,Ajax.InPlaceEditor.prototype);Object.extend(Ajax.InPlaceCollectionEditor.prototype,{createEditField:function(){if(!this.cached_selectTag){var selectTag=document.createElement("select");var collection=this.options.collection||[];var optionTag;collection.each(function(e,i){optionTag=document.createElement("option");optionTag.value=(e instanceof Array)?e[0]:e;if(this.options.value==optionTag.value)optionTag.selected=true;optionTag.appendChild(document.createTextNode((e instanceof Array)?e[1]:e));selectTag.appendChild(optionTag);}.bind(this));this.cached_selectTag=selectTag;}
this.editField=this.cached_selectTag;if(this.options.loadTextURL)this.loadExternalText();this.form.appendChild(this.editField);this.options.callback=function(form,value){return"value="+encodeURIComponent(value);}}});Form.Element.DelayedObserver=Class.create();Form.Element.DelayedObserver.prototype={initialize:function(element,delay,callback){this.delay=delay||0.5;this.element=$(element);this.callback=callback;this.timer=null;this.lastValue=$F(this.element);Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));},delayedListener:function(event){if(this.lastValue==$F(this.element))return;if(this.timer)clearTimeout(this.timer);this.timer=setTimeout(this.onTimerEvent.bind(this),this.delay*1000);this.lastValue=$F(this.element);},onTimerEvent:function(){this.timer=null;this.callback(this.element,$F(this.element));}};Prado.WebUI.CallbackControl=Class.extend(Prado.WebUI.PostBackControl,{onPostBack:function(event,options)
-{new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveTextBox=Class.extend(Prado.WebUI.TTextBox,{onInit:function(options)
+{new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveCheckBox=Class.extend(Prado.WebUI.CallbackControl,{onPostBack:function(event,options)
+{new Prado.CallbackRequest(options.EventTarget,options);}});Prado.WebUI.TActiveTextBox=Class.extend(Prado.WebUI.TTextBox,{onInit:function(options)
{if(options['TextMode']!='MultiLine')
Event.observe(this.element,"keydown",this.handleReturnKey.bind(this));Event.observe(this.element,"change",this.doCallback.bindEvent(this,options));},doCallback:function(event,options)
{new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}});Prado.WebUI.TAutoComplete=Class.extend(Autocompleter.Base,Prado.WebUI.TActiveTextBox.prototype);Prado.WebUI.TAutoComplete=Class.extend(Prado.WebUI.TAutoComplete,{initialize:function(options)
diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js
index 2cd37002..f77fe0f2 100644
--- a/framework/Web/Javascripts/js/prado.js
+++ b/framework/Web/Javascripts/js/prado.js
@@ -252,7 +252,7 @@ $('PRADO_POSTBACK_TARGET').value=options['EventTarget'];$('PRADO_POSTBACK_PARAME
Prado.Element={setValue:function(element,value)
{var el=$(element);if(el&&typeof(el.value)!="undefined")
el.value=value;},select:function(element,method,value)
-{var el=$(element);var isList=element.indexOf('[]')>-1;if(!el&&!isList)return;method=isList?'check'+method:el.tagName.toLowerCase()+method;var selection=Prado.Element.Selection;if(isFunction(selection[method]))
+{var el=$(element);var isList=element.indexOf('[]')>-1;if(!el&&!isList)return;method=isList?'check'+method:el.tagName.toLowerCase()+method;var selection=Prado.Element.Selection;if(typeof(selection[method])=="function")
selection[method](isList?element:el,value);},click:function(element)
{var el=$(element);if(el)
Event.fireEvent(el,'click');},setAttribute:function(element,attribute,value)
diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js
index 50ff39d6..7039feec 100644
--- a/framework/Web/Javascripts/prado/activecontrols3.js
+++ b/framework/Web/Javascripts/prado/activecontrols3.js
@@ -15,6 +15,17 @@ Prado.WebUI.CallbackControl = Class.extend(Prado.WebUI.PostBackControl,
*/
Prado.WebUI.TActiveButton = Class.extend(Prado.WebUI.CallbackControl);
+/**
+ * Active check box.
+ */
+Prado.WebUI.TActiveCheckBox = Class.extend(Prado.WebUI.CallbackControl,
+{
+ onPostBack : function(event, options)
+ {
+ new Prado.CallbackRequest(options.EventTarget, options);
+ }
+});
+
/**
* TActiveTextBox control, handles onchange event.
*/
diff --git a/framework/Web/Javascripts/prado/element.js b/framework/Web/Javascripts/prado/element.js
index 5c76d4e6..59a8ea1e 100644
--- a/framework/Web/Javascripts/prado/element.js
+++ b/framework/Web/Javascripts/prado/element.js
@@ -19,7 +19,7 @@ Prado.Element =
if(!el && !isList) return;
method = isList ? 'check'+method : el.tagName.toLowerCase()+method;
var selection = Prado.Element.Selection;
- if(isFunction(selection[method]))
+ if(typeof(selection[method]) == "function")
selection[method](isList ? element : el,value);
},
diff --git a/framework/Web/UI/ActiveControls/TActiveCheckBox.php b/framework/Web/UI/ActiveControls/TActiveCheckBox.php
new file mode 100644
index 00000000..1b34f32d
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TActiveCheckBox.php
@@ -0,0 +1,156 @@
+<?php
+/**
+ * TActiveCheckBox class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ : $
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TActiveCheckBox class.
+ *
+ * The active control counter part to checkbox. The {@link setAutoPostBack AutoPostBack}
+ * property is set to true by default. Thus, when the checkbox is clicked a
+ * {@link onCallback OnCallback} event is raise after {@link OnCheckedChanged} event.
+ *
+ * The {@link setText Text} and {@link setChecked Checked} properties can be
+ * changed during a callback.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version : $ Tue Jun 20 01:29:35 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
+class TActiveCheckBox extends TCheckBox implements ICallbackEventHandler, IActiveControl
+{
+ /**
+ * Creates a new callback control, sets the adapter to
+ * TActiveControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, by calling this constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAdapter(new TActiveControlAdapter($this));
+ $this->setAutoPostBack(true);
+ }
+
+ /**
+ * @return TBaseActiveCallbackControl standard callback control options.
+ */
+ public function getActiveControl()
+ {
+ return $this->getAdapter()->getBaseActiveControl();
+ }
+
+ /**
+ * Raises the callback event. This method is required by {@link
+ * ICallbackEventHandler} interface. If {@link getCausesValidation
+ * CausesValidation} is true, it will invoke the page's {@link TPage::
+ * validate validate} method first. It will raise {@link onCheckedChanged
+ * OnCheckedChanged} event first and then the {@link onCallback OnCallback} event.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ $this->raisePostDataChangedEvent($param);
+ $this->onCallback($param);
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+
+ /**
+ * Updates the button text on the client-side if the
+ * {@link setEnableUpdate EnableUpdate} property is set to true.
+ * @param string caption of the button
+ */
+ public function setText($value)
+ {
+ parent::setText($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->getPage()->getCallbackClient()->update(
+ $this->getDefaultLabelID(), $value);
+ }
+
+ /**
+ * Sets a value indicating whether the checkbox is to be checked or not.
+ * Updates checkbox checked state on the client-side if the
+ * {@link setEnableUpdate EnableUpdate} property is set to true.
+ * @param boolean whether the checkbox is to be checked or not.
+ */
+ public function setChecked($value)
+ {
+ $value = TPropertyValue::ensureBoolean($value);
+ parent::setChecked($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->getPage()->getCallbackClient()->check($this, $value);
+ }
+
+ /**
+ * Registers the javascript code for initializing the active control.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getPostBackOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for this TActiveCheckBox.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TActiveCheckBox';
+ }
+
+ /**
+ * Overrides parent implementation to ensure label has ID.
+ * @return TMap list of attributes to be rendered for label beside the checkbox
+ */
+ public function getLabelAttributes()
+ {
+ $attributes = parent::getLabelAttributes();
+ $attributes['id'] = $this->getDefaultLabelID();
+ return $attributes;
+ }
+
+ /**
+ * Renders a label beside the checkbox.
+ * @param THtmlWriter the writer for the rendering purpose
+ * @param string checkbox id
+ * @param string label text
+ */
+ protected function renderLabel($writer,$clientID,$text)
+ {
+ $writer->addAttribute('id', $this->getDefaultLabelID());
+ parent::renderLabel($writer, $clientID, $text);
+ }
+
+ /**
+ * @return string checkbox label ID;
+ */
+ protected function getDefaultLabelID()
+ {
+ if($attributes=$this->getViewState('LabelAttributes',null))
+ return $this->getLabelAttributes()->itemAt('id');
+ else
+ return $this->getClientID().'_label';
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.page
new file mode 100644
index 00000000..9ff09bb6
--- /dev/null
+++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.page
@@ -0,0 +1,29 @@
+<com:TForm ID="form1">
+ <h1>Active CheckBox Test</h1>
+ <com:TActiveCheckBox ID="checkbox1" Text="CheckBox 1" OnCallback="checkbox_requested" />
+ <com:TActiveCheckBox ID="checkbox2" Text="CheckBox 2" OnCallback="checkbox_requested">
+ <prop:ActiveControl.ClientSide OnLoading="$('status').show()" OnComplete="$('status').hide()" />
+ </com:TActiveCheckBox>
+ <div style="margin:1em; padding:0.5em; text-align:center; border:1px solid #ccc;">
+ <com:TActiveLabel ID="label1" Text="Label 1" />
+ </div>
+ <div style="margin:1em; padding: 1em; text-align: center">
+ <com:TActiveButton id="change_text1"
+ OnClick="change_checkbox1_text" Text="Change CheckBox 1 Text"/>
+ <com:TActiveButton id="change_checked1"
+ OnClick="change_checkbox1_checked" Text="Toggle CheckBox 1"/>
+
+ <com:TActiveButton id="change_text2"
+ OnClick="change_checkbox2_text" Text="Change CheckBox 2 Text"/>
+ <com:TActiveButton id="change_checked2"
+ OnClick="change_checkbox2_checked" Text="Toggle CheckBox 2"/>
+ </div>
+ <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...
+ </div>
+ <com:TJavascriptLogger />
+</com:TForm> \ No newline at end of file
diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.php
new file mode 100644
index 00000000..d762ab28
--- /dev/null
+++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveCheckBoxTest.php
@@ -0,0 +1,32 @@
+<?php
+
+class ActiveCheckBoxTest extends TPage
+{
+ function change_checkbox1_text()
+ {
+ $this->checkbox1->Text = "Hello CheckBox 1";
+ }
+
+ function change_checkbox1_checked()
+ {
+ $this->checkbox1->Checked = !$this->checkbox1->Checked;
+ }
+
+ function change_checkbox2_text()
+ {
+ $this->checkbox2->Text = "CheckBox 2 World";
+ }
+
+ function change_checkbox2_checked()
+ {
+ $this->checkbox2->Checked = !$this->checkbox2->Checked;
+ }
+
+ function checkbox_requested($sender, $param)
+ {
+ $this->label1->Text = "Label 1:".$sender->Text.
+ ($sender->checked ? ' Checked ' : ' Not Checked');
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/FunctionalTests/active-controls/tests/ActiveCheckBoxTestCase.php b/tests/FunctionalTests/active-controls/tests/ActiveCheckBoxTestCase.php
new file mode 100644
index 00000000..30dda753
--- /dev/null
+++ b/tests/FunctionalTests/active-controls/tests/ActiveCheckBoxTestCase.php
@@ -0,0 +1,61 @@
+<?php
+
+class ActiveCheckBoxTestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $this->open("active-controls/index.php?page=ActiveCheckBoxTest");
+ $this->verifyTextPresent("Active CheckBox Test");
+
+ $this->assertText("checkbox1_label", "CheckBox 1");
+ $this->assertText("checkbox2_label", "CheckBox 2");
+ $this->assertText('label1', 'Label 1');
+
+ $this->click("change_text1");
+ $this->pause(500);
+ $this->assertText('checkbox1_label', 'Hello CheckBox 1');
+
+ $this->click("change_text2");
+ $this->pause(500);
+ $this->assertText('checkbox2_label', 'CheckBox 2 World');
+
+ //check box 1
+ $this->click('change_checked1');
+ $this->pause(500);
+ $this->assertChecked('checkbox1');
+
+ $this->click('change_checked1');
+ $this->pause(500);
+ $this->assertNotChecked('checkbox1');
+
+ //check box 2
+ $this->click('change_checked2');
+ $this->pause(500);
+ $this->assertChecked('checkbox2');
+
+ $this->click('change_checked2');
+ $this->pause(500);
+ $this->assertNotChecked('checkbox2');
+
+ //click checkbox 1
+ $this->click("checkbox1");
+ $this->pause(500);
+ $this->assertText("label1", "Label 1:Hello CheckBox 1 Checked");
+
+ $this->click("checkbox1");
+ $this->pause(500);
+ $this->assertText("label1", "Label 1:Hello CheckBox 1 Not Checked");
+
+ //click checkbox 2
+ $this->click("checkbox2");
+ $this->pause(500);
+ $this->assertText("label1", "Label 1:CheckBox 2 World Checked");
+
+ $this->click("checkbox2");
+ $this->pause(500);
+ $this->assertText("label1", "Label 1:CheckBox 2 World Not Checked");
+
+ }
+}
+
+?> \ No newline at end of file