From a6be5564823be40670e0cad8dc758557dbd37549 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 24 Jun 2006 05:46:22 +0000 Subject: Update active controls. --- framework/Web/UI/ActiveControls/TActiveButton.php | 3 + .../Web/UI/ActiveControls/TActiveCheckBox.php | 11 +- .../Web/UI/ActiveControls/TActiveCheckBoxList.php | 100 ++++++++++ .../UI/ActiveControls/TActiveControlAdapter.php | 12 +- .../Web/UI/ActiveControls/TActiveDropDownList.php | 153 +++++++++++++++ .../Web/UI/ActiveControls/TActiveHyperLink.php | 99 ++++++++++ framework/Web/UI/ActiveControls/TActiveImage.php | 27 +++ .../Web/UI/ActiveControls/TActiveImageButton.php | 25 +++ framework/Web/UI/ActiveControls/TActiveLabel.php | 5 + .../Web/UI/ActiveControls/TActiveLinkButton.php | 25 +++ framework/Web/UI/ActiveControls/TActiveListBox.php | 26 +++ .../ActiveControls/TActiveListControlAdapter.php | 212 +++++++++++++++++++++ .../Web/UI/ActiveControls/TActivePageAdapter.php | 2 +- framework/Web/UI/ActiveControls/TActivePanel.php | 5 + .../Web/UI/ActiveControls/TActiveRadioButton.php | 27 +++ .../UI/ActiveControls/TActiveRadioButtonList.php | 25 +++ framework/Web/UI/ActiveControls/TActiveTextBox.php | 11 +- framework/Web/UI/ActiveControls/TAutoComplete.php | 5 + .../Web/UI/ActiveControls/TBaseActiveControl.php | 6 +- framework/Web/UI/ActiveControls/TCallback.php | 5 + .../UI/ActiveControls/TCallbackClientScript.php | 37 +++- framework/Web/UI/ActiveControls/TCallbackTimer.php | 5 + 22 files changed, 802 insertions(+), 24 deletions(-) create mode 100644 framework/Web/UI/ActiveControls/TActiveCheckBoxList.php create mode 100644 framework/Web/UI/ActiveControls/TActiveDropDownList.php create mode 100644 framework/Web/UI/ActiveControls/TActiveHyperLink.php create mode 100644 framework/Web/UI/ActiveControls/TActiveImage.php create mode 100644 framework/Web/UI/ActiveControls/TActiveImageButton.php create mode 100644 framework/Web/UI/ActiveControls/TActiveLinkButton.php create mode 100644 framework/Web/UI/ActiveControls/TActiveListBox.php create mode 100644 framework/Web/UI/ActiveControls/TActiveListControlAdapter.php create mode 100644 framework/Web/UI/ActiveControls/TActiveRadioButton.php create mode 100644 framework/Web/UI/ActiveControls/TActiveRadioButtonList.php (limited to 'framework/Web/UI/ActiveControls') diff --git a/framework/Web/UI/ActiveControls/TActiveButton.php b/framework/Web/UI/ActiveControls/TActiveButton.php index 81744057..232e639c 100644 --- a/framework/Web/UI/ActiveControls/TActiveButton.php +++ b/framework/Web/UI/ActiveControls/TActiveButton.php @@ -10,6 +10,9 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active control adapter. + */ Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); /** diff --git a/framework/Web/UI/ActiveControls/TActiveCheckBox.php b/framework/Web/UI/ActiveControls/TActiveCheckBox.php index 1b34f32d..a7f3ac2a 100644 --- a/framework/Web/UI/ActiveControls/TActiveCheckBox.php +++ b/framework/Web/UI/ActiveControls/TActiveCheckBox.php @@ -10,6 +10,11 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + /** * TActiveCheckBox class. * @@ -49,16 +54,12 @@ class TActiveCheckBox extends TCheckBox implements ICallbackEventHandler, IActiv /** * 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. + * ICallbackEventHandler} interface. * 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); } diff --git a/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php b/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php new file mode 100644 index 00000000..3a33ccc2 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php @@ -0,0 +1,100 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveListControlAdapter'); + +/** + * TActiveCheckBoxList class. + * + * The active control counter part to checkbox list control. + * The {@link setAutoPostBack AutoPostBack} property is set to true by default. + * Thus, when a checkbox is clicked a {@link onCallback OnCallback} event is + * raised after {@link OnSelectedIndexChanged} event. + * + * With {@link TBaseActiveControl::setEnableUpdate() ActiveControl.EnabledUpdate} + * set to true (default is true), changes to the selection will be updated + * on the client side. + * + * @author Wei Zhuo + * @version : $ Sun Jun 25 01:50:27 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveCheckBoxList extends TCheckBoxList implements IActiveControl, ICallbackEventHandler +{ + /** + * Creates a new callback control, sets the adapter to + * TActiveListControlAdapter. 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 TActiveListControlAdapter($this)); + $this->setAutoPostBack(true); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * No client class for this control. + * This method overrides the parent implementation. + * @return null no javascript class name. + */ + protected function getClientClassName() + { + return null; + } + + /** + * Creates a control used for repetition (used as a template). + * @return TControl the control to be repeated + */ + protected function createRepeatedControl() + { + return new TActiveCheckBox; + } + + /** + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($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); + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php index e6e8585f..75c9ba21 100644 --- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php +++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php @@ -90,13 +90,17 @@ class TActiveControlAdapter extends TControlAdapter protected function renderCallbackClientScripts() { $cs = $this->getPage()->getClientScript(); - $key = get_class($this); + $key = 'Prado.CallbackRequest.addPostLoaders'; if(!$cs->isEndScriptRegistered($key)) { $cs->registerPradoScript('ajax'); - $options = TJavascript::encode($this->getPage()->getPostDataLoaders(),false); - $script = "Prado.CallbackRequest.addPostLoaders({$options});"; - $cs->registerEndScript($key, $script); + $data = $this->getPage()->getPostDataLoaders(); + if(count($data) > 0) + { + $options = TJavascript::encode($data,false); + $script = "Prado.CallbackRequest.addPostLoaders({$options});"; + $cs->registerEndScript($key, $script); + } } } diff --git a/framework/Web/UI/ActiveControls/TActiveDropDownList.php b/framework/Web/UI/ActiveControls/TActiveDropDownList.php new file mode 100644 index 00000000..679996b5 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveDropDownList.php @@ -0,0 +1,153 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * Load active list control adapter + */ +Prado::using('System.Web.UI.ActiveControls.TActiveListControlAdapter'); + +/** +/** + * TActiveDropDownList class. + * + * The active control counter part to drop down list control. + * The {@link setAutoPostBack AutoPostBack} property is set to true by default. + * Thus, when the drop down list selection is changed the {@link onCallback OnCallback} event is + * raised after {@link OnSelectedIndexChanged} event. + * + * With {@link TBaseActiveControl::setEnableUpdate() ActiveControl.EnabledUpdate} + * set to true (default is true), changes to the selection, after OnLoad event has + * been raised, will be updated. + * on the client side. + * + * @author Wei Zhuo + * @version : $ Sun Jun 25 19:55:19 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveDropDownList extends TDropDownList implements ICallbackEventHandler, IActiveControl +{ + /** + * Creates a new callback control, sets the adapter to + * TActiveListControlAdapter. 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 TActiveListControlAdapter($this)); + $this->setAutoPostBack(true); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * No client class for this control. + * This method overrides the parent implementation. + * @return null no javascript class name. + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TActiveDropDownList'; + } + + /** + * Loads user input data. + * Disables ActiveControl.EnableUpdate subproperty during loading post data + * to avoid duplicating selection changes. + * @param string the key that can be used to retrieve data from the input data collection + * @param array the input data collection + * @return boolean whether the data of the component has been changed + */ + public function loadPostData($key,$values) + { + $enabled = $this->getActiveControl()->getEnableUpdate(); + $this->getActiveControl()->setEnableUpdate(false); + $result = parent::loadPostData($key, $values); + $this->getActiveControl()->setEnableUpdate($enabled); + return $result; + } + + /** + * 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; + } + + /** + * Override parent implementation, no javascript is rendered here instead + * the javascript required for active control is registered in {@link addAttributesToRender}. + */ + protected function renderClientControlScript($writer) + { + } + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + $writer->addAttribute('id',$this->getClientID()); + $this->getActiveControl()->registerCallbackClientScript( + $this->getClientClassName(), $this->getPostBackOptions()); + } + + /** + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($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 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/TActiveHyperLink.php b/framework/Web/UI/ActiveControls/TActiveHyperLink.php new file mode 100644 index 00000000..ac99089d --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveHyperLink.php @@ -0,0 +1,99 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * TActiveHyperLink class. + * + * The active control counterpart of THyperLink component. When + * {@link TBaseActiveControl::setEnableUpdate ActiveControl.EnableUpdate} + * property is true the during a callback request, setting {@link setText Text} + * property will also set the text of the label on the client upon callback + * completion. Similarly, for other properties such as {@link setImageUrl ImageUrl}, + * {@link setNavigateUrl NavigateUrl} and {@link setTarget Target}. + * + * @author Wei Zhuo + * @version : $ Mon Jun 26 00:08:24 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveHyperLink extends THyperLink implements 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)); + } + + /** + * @return TBaseActiveControl basic active control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * On callback response, the inner HTMl of the label is updated. + * @param string the text value of the label + */ + public function setText($value) + { + parent::setText($value); + if($this->getActiveControl()->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->update($this, $value); + } + + /** + * Sets the location of image file of the THyperLink. + * @param string the image file location + */ + public function setImageUrl($value) + { + parent::setImageUrl($value); + if($this->getActiveControl()->canUpdateClientSide() && $value !== '') + { + $textWriter = new TTextWriter(); + $renderer = new THtmlWriter($textWriter); + $this->createImage($value)->renderControl($renderer); + $this->getPage()->getCallbackClient()->update($this, $textWriter->flush()); + } + } + + /** + * Sets the URL to link to when the THyperLink component is clicked. + * @param string the URL + */ + public function setNavigateUrl($value) + { + parent::setNavigateUrl($value); + if($this->getActiveControl()->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->setAttribute($this, 'href', $value); + } + + /** + * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked. + * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string. + */ + public function setTarget($value) + { + parent::setTarget($value); + if($this->getActiveControl()->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->setAttribute($this, 'target', $value); + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveImage.php b/framework/Web/UI/ActiveControls/TActiveImage.php new file mode 100644 index 00000000..eb0f4ca9 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveImage.php @@ -0,0 +1,27 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.WebControls + */ + + +/** + * TActiveImage class. + * + * @author Wei Zhuo + * @version : $ Mon Jun 26 00:44:25 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveImage extends TImage implements IActiveControl +{ + +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveImageButton.php b/framework/Web/UI/ActiveControls/TActiveImageButton.php new file mode 100644 index 00000000..74e99781 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveImageButton.php @@ -0,0 +1,25 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * TActiveImageButton class. + * + * @author Wei Zhuo + * @version : $ Mon Jun 26 00:45:39 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveImageButton extends TImageButton implements IActiveControl, ICallbackEventHandler +{ +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveLabel.php b/framework/Web/UI/ActiveControls/TActiveLabel.php index f54e0b98..f6c0ce81 100644 --- a/framework/Web/UI/ActiveControls/TActiveLabel.php +++ b/framework/Web/UI/ActiveControls/TActiveLabel.php @@ -10,6 +10,11 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + /** * TActiveLabel class * diff --git a/framework/Web/UI/ActiveControls/TActiveLinkButton.php b/framework/Web/UI/ActiveControls/TActiveLinkButton.php new file mode 100644 index 00000000..40b69391 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveLinkButton.php @@ -0,0 +1,25 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * TActiveLinkButton class. + * + * @author Wei Zhuo + * @version : $ Mon Jun 26 00:49:25 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveLinkButton extends TLinkButton implements IActiveControl, ICallbackEventHandler +{ +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveListBox.php b/framework/Web/UI/ActiveControls/TActiveListBox.php new file mode 100644 index 00000000..37db5e27 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveListBox.php @@ -0,0 +1,26 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * TActiveListBox class. + * + * @author Wei Zhuo + * @version : $ Mon Jun 26 00:50:16 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventHandler +{ + +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveListControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveListControlAdapter.php new file mode 100644 index 00000000..592c4c14 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveListControlAdapter.php @@ -0,0 +1,212 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); +Prado::using('System.Web.UI.WebControls.TListControl'); + +/** + * TActiveListControlAdapter class. + * + * Adapte the list controls to allows the selections on the client-side to be altered + * during callback response. + * + * @author Wei Zhuo + * @version $Revision: $ Sun Jun 25 04:53:43 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveListControlAdapter extends TActiveControlAdapter implements IListControlAdaptee +{ + /** + * @return boolean true if can update client-side attributes. + */ + protected function canUpdateClientSide() + { + return $this->getControl()->getActiveControl()->canUpdateClientSide(); + } + + /** + * Selects an item based on zero-base index on the client side. + * @param integer the index (zero-based) of the item to be selected + */ + public function setSelectedIndex($index) + { + if($this->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->select( + $this->getControl(), 'Index', $index); + } + + /** + * Selects a list of item based on zero-base indices on the client side. + * @param array list of index of items to be selected + */ + public function setSelectedIndices($indices) + { + if($this->canUpdateClientSide()) + { + $n = $this->getControl()->getItemCount(); + $list = array(); + foreach($indices as $index) + { + $index = intval($index); + if($index >= 0 && $index <= $n) + $list[] = $index; + } + if(count($list) > 0) + $this->getPage()->getCallbackClient()->select( + $this->getControl(), 'Indices', $list); + } + } + + /** + * Sets selection by item value on the client side. + * @param string the value of the item to be selected. + */ + public function setSelectedValue($value) + { + if($this->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->select( + $this->getControl(), 'Value', $value); + } + + /** + * Sets selection by a list of item values on the client side. + * @param array list of the selected item values + */ + public function setSelectedValues($values) + { + if($this->canUpdateClientSide()) + { + $list = array(); + foreach($values as $value) + $list[] = $value; + if(count($list) > 0) + $this->getPage()->getCallbackClient()->select( + $this->getControl(), 'Values', $list); + } + } + + /** + * Clears all existing selections on the client side. + */ + public function clearSelection() + { + if($this->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->select($this->getControl(), 'Clear'); + } + + /** + * Update the client-side list options. + */ + public function updateListItems() + { + if($this->canUpdateClientSide() && $this->getControl()->getHasItems()) + { + $items = $this->getControl()->getItems(); + if($items instanceof TActiveListItemCollection && $items->getListHasChanged()) + $this->getPage()->getCallbackClient()->setListItems($this->getControl(), $items); + } + } +} + +/** + * TActiveListItemCollection class. + * + * Allows TActiveDropDownList and TActiveListBox to add new options + * during callback response. New options can only be added after the + * {@link TControl::onLoad OnLoad} event. + * + * The {@link getListHasChanged ListHasChanged} property is true when the + * list items has changed. The control responsible for the list needs to + * repopulate the client-side options. + * + * @author Wei Zhuo + * @version $Revision: $ Sun Jun 25 21:15:05 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveListItemCollection extends TListItemCollection +{ + /** + * @var IActiveControl control instance. + */ + private $_control; + /** + * @var boolean true if list items were changed. + */ + private $_hasChanged=false; + + /** + * @return boolean true if active controls can update client-side and + * the onLoad event has already been raised. + */ + protected function canUpdateClientSide() + { + return $this->getControl()->getActiveControl()->canUpdateClientSide() + && $this->getControl()->getHasLoaded(); + } + + /** + * @param IActiveControl a active list control. + */ + public function setControl(IActiveControl $control) + { + $this->_control = $control; + } + + /** + * @return IActiveControl active control using the collection. + */ + public function getControl() + { + return $this->_control; + } + + /** + * @return boolean true if the list has changed after onLoad event. + */ + public function getListHasChanged() + { + return $this->_hasChanged; + } + + /** + * Inserts an item into the collection. + * The new option is added on the client-side during callback. + * @param integer the location where the item will be inserted. + * The current item at the place and the following ones will be moved backward. + * @param TListItem the item to be inserted. + * @throws TInvalidDataTypeException if the item being inserted is neither a string nor TListItem + */ + public function insertAt($index, $value) + { + parent::insertAt($index, $value); + if($this->canUpdateClientSide()) + $this->_hasChanged = true; + } + + /** + * Removes an item from at specified index. + * @param int zero based index. + */ + public function removeAt($index) + { + parent::removeAt($index); + if($this->canUpdateClientSide()) + $this->_hasChanged = true; + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php index 90c64820..656b959c 100644 --- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php +++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php @@ -142,7 +142,7 @@ class TActivePageAdapter extends TControlAdapter } //output the actions - $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute()->toArray(); + $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute(); $actions = TJavascript::jsonEncode($executeJavascript); $response->appendHeader(self::CALLBACK_ACTION_HEADER.': '.$actions); diff --git a/framework/Web/UI/ActiveControls/TActivePanel.php b/framework/Web/UI/ActiveControls/TActivePanel.php index 787b65d3..b7773e1c 100644 --- a/framework/Web/UI/ActiveControls/TActivePanel.php +++ b/framework/Web/UI/ActiveControls/TActivePanel.php @@ -10,6 +10,11 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + /** * TActivePanel is the TPanel active control counterpart. * diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButton.php b/framework/Web/UI/ActiveControls/TActiveRadioButton.php new file mode 100644 index 00000000..b9497051 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveRadioButton.php @@ -0,0 +1,27 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + + +/** + * TActiveRadioButton class. + * + * @author Wei Zhuo + * @version $Revision: $ Mon Jun 26 00:47:14 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveRadioButton extends TRadioButton implements IActiveControl, ICallbackEventHandler +{ + +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php new file mode 100644 index 00000000..665a8542 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php @@ -0,0 +1,25 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ : $ + * @package System.Web.UI.ActiveControls + */ + +/** + * TActiveRadioButtonList class. + * + * @author Wei Zhuo + * @version : $ Mon Jun 26 00:48:08 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +class TActiveRadioButtonList extends TRadioButtonList implements IActiveControl, ICallbackEventHandler +{ +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveTextBox.php b/framework/Web/UI/ActiveControls/TActiveTextBox.php index 2e207f92..950a5dcb 100644 --- a/framework/Web/UI/ActiveControls/TActiveTextBox.php +++ b/framework/Web/UI/ActiveControls/TActiveTextBox.php @@ -10,6 +10,11 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + /** * TActiveTextBox class. * @@ -58,16 +63,12 @@ class TActiveTextBox extends TTextBox implements ICallbackEventHandler, IActiveC /** * 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 onTextChanged - * onTextChanged} event first and then the {@link onCallback OnCallback} event. + * ICallbackEventHandler} interface. * 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); } diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/ActiveControls/TAutoComplete.php index 55ffde04..7d901e7f 100644 --- a/framework/Web/UI/ActiveControls/TAutoComplete.php +++ b/framework/Web/UI/ActiveControls/TAutoComplete.php @@ -10,6 +10,11 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active text box. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveTextBox'); + /** * TAutoComplete class. * diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php index c42f75e8..dfb7efeb 100644 --- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php +++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php @@ -117,7 +117,7 @@ class TBaseActiveControl extends TComponent */ public function canUpdateClientSide() { - return $this->getControl()->getIsInitialized() + return $this->getControl()->getHasChildInitialized() && $this->getPage()->getIsCallback() && $this->getEnableUpdate(); } @@ -319,7 +319,9 @@ class TBaseActiveCallbackControl extends TBaseActiveControl if(is_array($options)) $options = array_merge($this->getClientSideOptions(),$options); else - $options = $this->getClientSideOptions(); + $options = $this->getClientSideOptions(); + //remove true as default to save bytes + $options['CausesValidation']= $options['CausesValidation'] ? '' : false; $cs->registerCallbackControl($class, $options); } diff --git a/framework/Web/UI/ActiveControls/TCallback.php b/framework/Web/UI/ActiveControls/TCallback.php index 3c7d70c5..e87cea11 100644 --- a/framework/Web/UI/ActiveControls/TCallback.php +++ b/framework/Web/UI/ActiveControls/TCallback.php @@ -10,6 +10,11 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + /** * TCallback component class. * diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php index d83bf90a..0e1dff5c 100644 --- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php +++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php @@ -53,7 +53,7 @@ class TCallbackClientScript extends TApplicationComponent */ public function getClientFunctionsToExecute() { - return $this->_actions; + return $this->_actions->toArray(); } /** @@ -89,18 +89,41 @@ class TCallbackClientScript extends TApplicationComponent * or radio button list. * The second parameter determines the selection method. Valid methods are * - Value, select or check by value - * - Index, select or check by list index (zero based index) - * - All, selects or checks all in the list + * - Values, select or check by a list of values + * - Index, select or check by index (zero based index) + * - Indices, select or check by a list of index (zero based index) * - Clear, clears or selections or checks in the list - * - Invert, inverts the current selection or checks. + * - All, select all + * - Invert, invert the selection. * @param TControl|string list control * @param string selection method * @param string|int the value or index to select/check. + * @param string selection control type, either 'check' or 'select' */ - public function select($listControl, $method="Value", $valueOrIndex=null) + public function select($control, $method='Value', $value=null, $type=null) { - $this->callClientFunction('Prado.Element.select', array($listControl, $method, $valueOrIndex)); + $method = TPropertyValue::ensureEnum($method, + 'Value', 'Index', 'Clear', 'Indices', 'Values', 'All', 'Invert'); + $type = is_null($type) ? $this->getSelectionControlType($control) : $type; + $total = $this->getSelectionControlIsListType($control) ? $control->getItemCount() : 1; + $this->callClientFunction('Prado.Element.select', + array($control, $type.$method, $value, $total)); } + + private function getSelectionControlType($control) + { + if(is_string($control)) return 'check'; + if($control instanceof TCheckBoxList) + return 'check'; + if($control instanceof TCheckBox) + return 'check'; + return 'select'; + } + + private function getSelectionControlIsListType($control) + { + return $control instanceof TListControl; + } /** * Client script to click on an element. This client-side function @@ -138,7 +161,7 @@ class TCallbackClientScript extends TApplicationComponent * @param TControl|string control element or element id * @param TCollection a list of new options */ - public function setOptions($control, $items) + public function setListItems($control, $items) { $options = array(); foreach($items as $item) diff --git a/framework/Web/UI/ActiveControls/TCallbackTimer.php b/framework/Web/UI/ActiveControls/TCallbackTimer.php index 7f1aa692..bae41e1f 100644 --- a/framework/Web/UI/ActiveControls/TCallbackTimer.php +++ b/framework/Web/UI/ActiveControls/TCallbackTimer.php @@ -10,6 +10,11 @@ * @package System.Web.UI.ActiveControls */ +/** + * Load active callback control. + */ +Prado::using('System.Web.UI.ActiveControls.TCallback'); + /** * TCallbackTimer class. * -- cgit v1.2.3