From 9af56fd93ed071d86f14296cec618073f6c0941a Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 23 Sep 2006 01:08:19 +0000 Subject: Fixed #383 --- .gitattributes | 7 +++ framework/Web/Javascripts/js/compressed/ajax.js | 5 +- framework/Web/Javascripts/js/debug/ajax.js | 5 ++ framework/Web/Javascripts/prado/ajax3.js | 5 ++ .../Web/UI/ActiveControls/TActiveCheckBoxList.php | 2 + .../Web/UI/ActiveControls/TActiveDropDownList.php | 2 + framework/Web/UI/ActiveControls/TActiveListBox.php | 25 ++++++++ .../UI/ActiveControls/TActiveRadioButtonList.php | 2 + .../protected/pages/ActiveBricksTest.page | 42 +++++++++++++ .../protected/pages/ActiveBricksTest.php | 13 ++++ .../active-controls/protected/pages/LTemplate.php | 72 ++++++++++++++++++++++ .../active-controls/protected/pages/LTemplate.tpl | 11 ++++ .../protected/pages/PopulateActiveList.page | 17 +++++ .../protected/pages/PopulateActiveList.php | 34 ++++++++++ .../active-controls/tests/PopulateListTestCase.php | 25 ++++++++ 15 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/LTemplate.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/LTemplate.tpl create mode 100644 tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.php create mode 100644 tests/FunctionalTests/active-controls/tests/PopulateListTestCase.php diff --git a/.gitattributes b/.gitattributes index f7221a5d..7b82cdf1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1922,6 +1922,8 @@ requirements/messages.txt -text requirements/template-bg.html -text requirements/template-zh.html -text requirements/template.html -text +tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveControlWithTinyMce.page -text @@ -1948,6 +1950,10 @@ tests/FunctionalTests/active-controls/protected/pages/CustomTemplateControlTest. 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/LTemplate.php -text +tests/FunctionalTests/active-controls/protected/pages/LTemplate.tpl -text +tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.page -text +tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.php -text tests/FunctionalTests/active-controls/protected/pages/PostLoadingTest.page -text tests/FunctionalTests/active-controls/protected/pages/PostLoadingTest.php -text tests/FunctionalTests/active-controls/protected/pages/ReplaceContentTest.page -text @@ -1971,6 +1977,7 @@ tests/FunctionalTests/active-controls/tests/ActiveRadioButtonListTestCase.php -t 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/PopulateListTestCase.php -text tests/FunctionalTests/active-controls/tests/PostLoadingTestCase.php -text tests/FunctionalTests/active-controls/tests/ReplaceContentTestCase.php -text tests/FunctionalTests/active-controls/tests/TextBoxGroupValidationTestCase.php -text diff --git a/framework/Web/Javascripts/js/compressed/ajax.js b/framework/Web/Javascripts/js/compressed/ajax.js index 6bbb7a7c..1686d86f 100644 --- a/framework/Web/Javascripts/js/compressed/ajax.js +++ b/framework/Web/Javascripts/js/compressed/ajax.js @@ -80,7 +80,7 @@ Ajax.Responders.register({onComplete:function(request) {if(request.options.HasPriority) Prado.CallbackRequest.abortRequestInProgress();}});Event.OnLoad(function() {if(typeof Logger!="undefined") -Ajax.Responders.register(Prado.CallbackRequest.Exception);});Prado.CallbackRequest.prototype={url:window.location.href,options:{},id:null,request:null,initialize:function(id,options) +Ajax.Responders.register(Prado.CallbackRequest.Exception);});Prado.CallbackRequest.prototype={url:window.location.href,options:{},id:null,request:null,Enabled:true,initialize:function(id,options) {this.id=id;this.options=Object.extend({RequestTimeOut:30000,EnablePageStateUpdate:true,HasPriority:true,CausesValidation:true,ValidationGroup:null,PostInputs:true},options||{});},setCallbackParameter:function(value) {this.options['params']=value;},getCallbackParameter:function() {return this.options['params'];},setRequestTimeOut:function(timeout) @@ -95,7 +95,8 @@ tinyMCE.triggerSave();Object.extend(this.options,{postBody:this._getPostData(),p {var form=this.options.Form||Prado.Validation.getForm();if(Prado.Validation.validate(form,this.options.ValidationGroup,this)==false) return false;} if(this.options.onPreDispatch) -this.options.onPreDispatch(this,null);if(this.options.HasPriority) +this.options.onPreDispatch(this,null);if(!this.Enabled) +return;if(this.options.HasPriority) return Prado.CallbackRequest.dispatchPriorityRequest(this);else return Prado.CallbackRequest.dispatchNormalRequest(this);},_getPostData:function() {var data={};var callback=Prado.CallbackRequest;if(this.options.PostInputs!=false) diff --git a/framework/Web/Javascripts/js/debug/ajax.js b/framework/Web/Javascripts/js/debug/ajax.js index a6c8db82..5bd22afa 100644 --- a/framework/Web/Javascripts/js/debug/ajax.js +++ b/framework/Web/Javascripts/js/debug/ajax.js @@ -655,6 +655,8 @@ Prado.CallbackRequest.prototype = */ request : null, + Enabled : true, + /** * Prepare and inititate a callback request. */ @@ -766,6 +768,9 @@ Prado.CallbackRequest.prototype = if(this.options.onPreDispatch) this.options.onPreDispatch(this,null); + if(!this.Enabled) + return; + if(this.options.HasPriority) return Prado.CallbackRequest.dispatchPriorityRequest(this); else diff --git a/framework/Web/Javascripts/prado/ajax3.js b/framework/Web/Javascripts/prado/ajax3.js index 6e1b7d38..43f159f4 100644 --- a/framework/Web/Javascripts/prado/ajax3.js +++ b/framework/Web/Javascripts/prado/ajax3.js @@ -367,6 +367,8 @@ Prado.CallbackRequest.prototype = */ request : null, + Enabled : true, + /** * Prepare and inititate a callback request. */ @@ -478,6 +480,9 @@ Prado.CallbackRequest.prototype = if(this.options.onPreDispatch) this.options.onPreDispatch(this,null); + if(!this.Enabled) + return; + if(this.options.HasPriority) return Prado.CallbackRequest.dispatchPriorityRequest(this); else diff --git a/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php b/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php index 1cb2c442..f70a6407 100644 --- a/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php +++ b/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php @@ -27,6 +27,8 @@ Prado::using('System.Web.UI.ActiveControls.TActiveListControlAdapter'); * set to true (default is true), changes to the selection will be updated * on the client side. * + * List items can not be changed dynamically during a callback request. + * * @author Wei Zhuo * @version $Id$ * @package System.Web.UI.ActiveControls diff --git a/framework/Web/UI/ActiveControls/TActiveDropDownList.php b/framework/Web/UI/ActiveControls/TActiveDropDownList.php index 32f309c2..c628e98c 100644 --- a/framework/Web/UI/ActiveControls/TActiveDropDownList.php +++ b/framework/Web/UI/ActiveControls/TActiveDropDownList.php @@ -29,6 +29,8 @@ Prado::using('System.Web.UI.ActiveControls.TActiveListControlAdapter'); * been raised, will be updated. * on the client side. * + * List items can be changed dynamically during a callback request. + * * @author Wei Zhuo * @version $Id$ * @package System.Web.UI.ActiveControls diff --git a/framework/Web/UI/ActiveControls/TActiveListBox.php b/framework/Web/UI/ActiveControls/TActiveListBox.php index 0620e734..e433fa09 100644 --- a/framework/Web/UI/ActiveControls/TActiveListBox.php +++ b/framework/Web/UI/ActiveControls/TActiveListBox.php @@ -13,6 +13,8 @@ /** * TActiveListBox class. * + * List items can be added dynamically during a callback request. + * * @author Wei Zhuo * @version $Id$ * @package System.Web.UI.ActiveControls @@ -40,6 +42,20 @@ class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventH return $this->getAdapter()->getBaseActiveControl(); } + /** + * Creates a collection object to hold list items. A specialized + * TActiveListItemCollection is created to allow the drop down list options + * to be added. + * This method may be overriden to create a customized collection. + * @return TActiveListItemCollection the collection object + */ + protected function createListItemCollection() + { + $collection = new TActiveListItemCollection; + $collection->setControl($this); + return $collection; + } + /** * Javascript client class for this control. * This method overrides the parent implementation. @@ -95,6 +111,15 @@ class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventH { $this->raiseEvent('OnCallback', $this, $param); } + + /** + * Updates the client-side options if the item list has changed after the OnLoad event. + */ + public function onPreRender($param) + { + parent::onPreRender($param); + $this->getAdapter()->updateListItems(); + } } ?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php index a3236e4d..3eb57ec7 100644 --- a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php +++ b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php @@ -22,6 +22,8 @@ * set to true (default is true), changes to the selection will be updated * on the client side. * + * List items can not be changed dynamically during a callback request. + * * @author Wei Zhuo * @version $Id$ * @package System.Web.UI.ActiveControls diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.page new file mode 100644 index 00000000..7cb8c6b3 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.page @@ -0,0 +1,42 @@ + +

Some AJAX Tests

+ + + + + + + + + + + + + + + + cell: + + in + + + + AIP + + + + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.php new file mode 100644 index 00000000..c60d4c67 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveBricksTest.php @@ -0,0 +1,13 @@ +Size = $sender->NamingContainer->findControl("MySize")->SelectedValue; + $this->placeholder->getControls()->add($x); + $this->Page->CallbackClient->insertContentAfter($this->AjaxInsertPoint, $x); + } +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/LTemplate.php b/tests/FunctionalTests/active-controls/protected/pages/LTemplate.php new file mode 100644 index 00000000..0a5c311e --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/LTemplate.php @@ -0,0 +1,72 @@ +setEnableViewState(false); + } + + function setSize($value) + { + $this->setViewState("Size", $value); + } + + function getSize() + { + return $this->getViewState("Size", "Small"); + } + + function onInit($param) + { + parent :: onInit($param); + $this->Controls[] = "OnInit"; + } + + function onLoad($param) + { + parent :: onLoad($param); + $this->Controls[] = "OnLoad"; + $this->adjustLayout(); + } + + function onPreRender($param) + { + parent :: onPreRender($param); + $this->Controls[] = "OnPreRender"; + } + + function adjustLayout() + { + if ($this->getSize() == "Large") + { + $this->Small->setVisible(false); + } + else + { + $this->Large->setVisible(false); + } + } + +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/LTemplate.tpl b/tests/FunctionalTests/active-controls/protected/pages/LTemplate.tpl new file mode 100644 index 00000000..fd2bacd1 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/LTemplate.tpl @@ -0,0 +1,11 @@ + + +

L A R G E

+
+ + + small + + diff --git a/tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.page b/tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.page new file mode 100644 index 00000000..c7bf0952 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.page @@ -0,0 +1,17 @@ + +

Populate active list controls

+ + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.php b/tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.php new file mode 100644 index 00000000..022f6dad --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/PopulateActiveList.php @@ -0,0 +1,34 @@ +list1->Items->clear(); + for($i = 0,$k=count($data); $i<$k; $i++) + { + $item = new TListItem($data[$i], $i); + $this->list1->Items[] = $item; + } + } + + public function populate_list2($sender, $param) + { + $data = array('Hello', 'World', 'Prado'); + $this->list2->Items->clear(); + for($i = 0,$k=count($data); $i<$k; $i++) + { + $item = new TListItem($data[$i], $i); + $this->list2->Items[] = $item; + } + } + + public function list_changed($sender, $param) + { + $text = $sender->SelectedItem ? $sender->SelectedItem->Text : 'Not selected'; + $this->label1->Text = $sender->ID . ': '.$text; + } +} + +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/tests/PopulateListTestCase.php b/tests/FunctionalTests/active-controls/tests/PopulateListTestCase.php new file mode 100644 index 00000000..4929b879 --- /dev/null +++ b/tests/FunctionalTests/active-controls/tests/PopulateListTestCase.php @@ -0,0 +1,25 @@ +open("active-controls/index.php?page=PopulateActiveList"); + $this->verifyTextPresent("Populate active list controls"); + $this->assertText("label1", ""); + + $this->click("button1"); + $this->pause(800); + $this->select("list1", "World"); + $this->pause(800); + $this->assertText("label1", "list1: World"); + + $this->click("button2"); + $this->pause(800); + $this->select("list2", "Prado"); + $this->pause(800); + $this->assertText("label1", "list2: Prado"); + } +} + +?> \ No newline at end of file -- cgit v1.2.3