From fe60cc221f922ea362826e2d00431c5df28fe85f Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 6 Oct 2006 03:46:05 +0000 Subject: fixed #410 #412 --- framework/Web/UI/ActiveControls/TActiveButton.php | 8 ++ .../Web/UI/ActiveControls/TActiveCheckBox.php | 8 ++ .../Web/UI/ActiveControls/TActiveCheckBoxList.php | 8 ++ .../UI/ActiveControls/TActiveCustomValidator.php | 74 ++++++++++++ .../Web/UI/ActiveControls/TActiveDropDownList.php | 8 ++ .../Web/UI/ActiveControls/TActiveImageButton.php | 8 ++ .../Web/UI/ActiveControls/TActiveLinkButton.php | 8 ++ framework/Web/UI/ActiveControls/TActiveListBox.php | 8 ++ .../Web/UI/ActiveControls/TActiveRadioButton.php | 8 ++ .../UI/ActiveControls/TActiveRadioButtonList.php | 8 ++ .../Web/UI/ActiveControls/TActiveRatingList.php | 125 ++++++++++++++++++--- framework/Web/UI/ActiveControls/TActiveTextBox.php | 8 ++ framework/Web/UI/ActiveControls/TCallback.php | 8 ++ 13 files changed, 269 insertions(+), 18 deletions(-) (limited to 'framework/Web/UI/ActiveControls') diff --git a/framework/Web/UI/ActiveControls/TActiveButton.php b/framework/Web/UI/ActiveControls/TActiveButton.php index 030361fb..62027264 100644 --- a/framework/Web/UI/ActiveControls/TActiveButton.php +++ b/framework/Web/UI/ActiveControls/TActiveButton.php @@ -54,6 +54,14 @@ class TActiveButton extends TButton implements ICallbackEventHandler, IActiveCon return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Raises the callback event. This method is required by {@link * ICallbackEventHandler} interface. If {@link getCausesValidation diff --git a/framework/Web/UI/ActiveControls/TActiveCheckBox.php b/framework/Web/UI/ActiveControls/TActiveCheckBox.php index 7cf5c005..2f60d9fb 100644 --- a/framework/Web/UI/ActiveControls/TActiveCheckBox.php +++ b/framework/Web/UI/ActiveControls/TActiveCheckBox.php @@ -52,6 +52,14 @@ class TActiveCheckBox extends TCheckBox implements ICallbackEventHandler, IActiv return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Raises the callback event. This method is required by {@link * ICallbackEventHandler} interface. diff --git a/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php b/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php index b18d0d0d..09ad9236 100644 --- a/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php +++ b/framework/Web/UI/ActiveControls/TActiveCheckBoxList.php @@ -56,6 +56,14 @@ class TActiveCheckBoxList extends TCheckBoxList implements IActiveControl, ICall return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * @return string javascript client-side control class name. */ diff --git a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php index 686149eb..0a6b7b84 100644 --- a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php +++ b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php @@ -10,6 +10,8 @@ * @package System.Web.UI.ActiveControls */ +Prado::using('System.Web.UI.ActiveControls.TCallbackClientSide'); + /** * TActiveCustomValidator Class * @@ -55,6 +57,7 @@ class TActiveCustomValidator extends TCustomValidator { parent::__construct(); $this->setAdapter(new TActiveControlAdapter($this)); + $this->getActiveControl()->setClientSide(new TActiveCustomValidatorClientSide); } /** @@ -65,6 +68,14 @@ class TActiveCustomValidator extends TCustomValidator return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Client validation function is NOT supported. */ @@ -131,4 +142,67 @@ class TActiveCustomValidator extends TCustomValidator } } +/** + * Custom Validator callback client side options class. + * + * @author Wei Zhuo + * @version $Id$ + * @package System.Web.UI.ActiveControls + * @since 3.1 + */ +class TActiveCustomValidatorClientSide extends TCallbackClientSide +{ + /** + * @return string javascript code for client-side OnValidate event. + */ + public function getOnValidate() + { + return $this->getOption('OnValidate'); + } + + /** + * Client-side OnValidate validator event is raise before the validators + * validation functions are called. + * @param string javascript code for client-side OnValidate event. + */ + public function setOnValidate($javascript) + { + $this->setFunction('OnValidate', $javascript); + } + + /** + * Client-side OnError event is raised after validation failure. + * This will override the default client-side validator behaviour. + * @param string javascript code for client-side OnError event. + */ + public function setOnError($javascript) + { + $this->setFunction('OnError', $javascript); + } + + /** + * @return string javascript code for client-side OnError event. + */ + public function getOnError() + { + return $this->getOption('OnError'); + } + + /** + * @param boolean true to revalidate when the control to validate changes value. + */ + public function setObserveChanges($value) + { + $this->setOption('ObserveChanges', TPropertyValue::ensureBoolean($value)); + } + + /** + * @return boolean true to observe changes. + */ + public function getObserveChanges() + { + $changes = $this->getOption('ObserveChanges'); + return is_null($changes) ? true : $changes; + } +} ?> \ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveDropDownList.php b/framework/Web/UI/ActiveControls/TActiveDropDownList.php index c628e98c..215b1e5a 100644 --- a/framework/Web/UI/ActiveControls/TActiveDropDownList.php +++ b/framework/Web/UI/ActiveControls/TActiveDropDownList.php @@ -58,6 +58,14 @@ class TActiveDropDownList extends TDropDownList implements ICallbackEventHandler return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * No client class for this control. * This method overrides the parent implementation. diff --git a/framework/Web/UI/ActiveControls/TActiveImageButton.php b/framework/Web/UI/ActiveControls/TActiveImageButton.php index fe4cb385..bb20793e 100644 --- a/framework/Web/UI/ActiveControls/TActiveImageButton.php +++ b/framework/Web/UI/ActiveControls/TActiveImageButton.php @@ -46,6 +46,14 @@ class TActiveImageButton extends TImageButton implements IActiveControl, ICallba return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Sets the alternative text to be displayed in the TImage when the image is unavailable. * @param string the alternative text diff --git a/framework/Web/UI/ActiveControls/TActiveLinkButton.php b/framework/Web/UI/ActiveControls/TActiveLinkButton.php index 30c62723..8b86d11a 100644 --- a/framework/Web/UI/ActiveControls/TActiveLinkButton.php +++ b/framework/Web/UI/ActiveControls/TActiveLinkButton.php @@ -49,6 +49,14 @@ class TActiveLinkButton extends TLinkButton implements IActiveControl, ICallback return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Raises the callback event. This method is required by {@link * ICallbackEventHandler} interface. If {@link getCausesValidation diff --git a/framework/Web/UI/ActiveControls/TActiveListBox.php b/framework/Web/UI/ActiveControls/TActiveListBox.php index e433fa09..21816961 100644 --- a/framework/Web/UI/ActiveControls/TActiveListBox.php +++ b/framework/Web/UI/ActiveControls/TActiveListBox.php @@ -42,6 +42,14 @@ class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventH return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Creates a collection object to hold list items. A specialized * TActiveListItemCollection is created to allow the drop down list options diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButton.php b/framework/Web/UI/ActiveControls/TActiveRadioButton.php index fe26165c..425cf1c7 100644 --- a/framework/Web/UI/ActiveControls/TActiveRadioButton.php +++ b/framework/Web/UI/ActiveControls/TActiveRadioButton.php @@ -51,6 +51,14 @@ class TActiveRadioButton extends TRadioButton implements IActiveControl, ICallba return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Raises the callback event. This method is required by {@link * ICallbackEventHandler} interface. diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php index f971228f..0eb3f83a 100644 --- a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php +++ b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php @@ -51,6 +51,14 @@ class TActiveRadioButtonList extends TRadioButtonList implements IActiveControl, return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * @return string javascript client-side control class name. */ diff --git a/framework/Web/UI/ActiveControls/TActiveRatingList.php b/framework/Web/UI/ActiveControls/TActiveRatingList.php index 1ce49a0c..ec8eee46 100644 --- a/framework/Web/UI/ActiveControls/TActiveRatingList.php +++ b/framework/Web/UI/ActiveControls/TActiveRatingList.php @@ -1,9 +1,35 @@ + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Web.UI.ActiveControls + */ +/** + * TActiveRatingList Class + * + * Displays clickable images that represent a TActiveRadioButtonList + * + * @author Wei Zhuo + * @version $Id$ + * @package System.Web.UI.ActiveControls + * @since 3.1 + */ class TActiveRatingList extends TActiveRadioButtonList { + /** + * @var array list of published rating images. + */ private $_ratingImages = array(); + /** + * Sets the default repeat direction to horizontal. + */ public function __construct() { parent::__construct(); @@ -18,6 +44,19 @@ class TActiveRatingList extends TActiveRadioButtonList return $this->getViewState('ReadOnly',false); } + /** + * @param boolean whether the items in the column can be edited + */ + public function setReadOnly($value) + { + $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false); + } + + /** + * The repeat layout must be Table. + * @param string repeat layout type + * @throws TInvaliddataValueException when repeat layout is not Table. + */ public function setRepeatLayout($value) { if($value!==TRepeatLayout::Table) @@ -27,23 +66,24 @@ class TActiveRatingList extends TActiveRadioButtonList } /** - * @param boolean whether the items in the column can be edited + * @return float rating value for read-only display. */ - public function setReadOnly($value) - { - $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false); - } - public function getRating() { return $this->getViewState('Rating',0); } + /** + * @param float rating value for read-only display. + */ public function setRating($value) { $this->setViewState('Rating', TPropertyValue::ensureFloat($value),0); } + /** + * @param int change the rating selection index + */ public function setSelectedIndex($value) { $canUpdate = $this->getActiveControl()->getEnableUpdate(); @@ -54,6 +94,11 @@ class TActiveRatingList extends TActiveRadioButtonList $this->callClientFunction('setRating',$value); } + /** + * Calls the client-side static method for this control class. + * @param string static method name + * @param mixed method parmaeter + */ protected function callClientFunction($func,$value) { $client = $this->getPage()->getCallbackClient(); @@ -62,7 +107,7 @@ class TActiveRatingList extends TActiveRadioButtonList } /** - * @return string caption text. + * @return string control or html element ID for displaying a caption. */ public function getCaptionID() { @@ -70,13 +115,16 @@ class TActiveRatingList extends TActiveRadioButtonList } /** - * @param string caption text + * @param string control or html element ID for displaying a caption. */ public function setCaptionID($value) { $this->setViewState('CaptionID', $value, ''); } + /** + * @param boolean true to enable the rating to be changed. + */ public function setEnabled($value) { parent::setEnabled($value); @@ -85,7 +133,7 @@ class TActiveRatingList extends TActiveRadioButtonList } /** - * @param string set the rating style + * @param string set the rating style, default is "default" */ public function setRatingStyle($value) { @@ -100,22 +148,36 @@ class TActiveRatingList extends TActiveRadioButtonList return $this->getViewState('RatingStyle', 'default'); } - public function setHalfRatingLimit($value) + /** + * Sets the interval such that those rating values within the interval + * will be considered as a half star rating. + * @param array rating display half value interval, default is array(0.3, 0.7); + */ + public function setHalfRatingInterval($value) { $this->setViewState('HalfRating', TPropertyValue::ensureArray($value), array(0.3, 0.7)); } - public function getHalfRatingLimit() + /** + * @return array rating display half value interval, default is array(0.3, 0.7); + */ + public function getHalfRatingInterval() { return $this->getViewState('HalfRating', array(0.3, 0.7)); } + /** + * @return string rating style css class name. + */ protected function getRatingStyleCssClass() { return 'TRatingList_'.$this->getRatingStyle(); } + /** + * @return array list of post back options. + */ protected function getPostBackOptions() { $options = parent::getPostBackOptions(); @@ -126,7 +188,8 @@ class TActiveRatingList extends TActiveRadioButtonList } /** - * Registers the javascript code for initializing the active control. + * Registers the javascript code for initializing the active control + * only if {@link setReadOnly ReadOnly} property is false. */ protected function renderClientControlScript($writer) { @@ -134,6 +197,9 @@ class TActiveRatingList extends TActiveRadioButtonList parent::renderClientControlScript($writer); } + /** + * @return string find the client ID of the caption control. + */ protected function getCaptionControl() { if(($id=$this->getCaptionID())!=='') @@ -149,6 +215,10 @@ class TActiveRatingList extends TActiveRadioButtonList return ''; } + /** + * @param string rating style name + * @return string URL of the css style file + */ protected function publishRatingListStyle($style) { $cs = $this->getPage()->getClientScript(); @@ -161,7 +231,12 @@ class TActiveRatingList extends TActiveRadioButtonList return $url; } - protected function publishRatingListImages($style, $fileExt='.png') + /** + * @param string rating style name + * @param string rating image file extension, default is '.gif' + * @return array URL of publish the rating images + */ + protected function publishRatingListImages($style, $fileExt='.gif') { $images['blank'] = "System.Web.Javascripts.ratings.{$style}_blank"; $images['selected'] = "System.Web.Javascripts.ratings.{$style}_selected"; @@ -177,18 +252,21 @@ class TActiveRatingList extends TActiveRadioButtonList return $files; } + /** + * Add rating style class name to the class attribute + * when {@link setReadOnly ReadOnly} property is true and when the + * {@link setCssClass CssClass} property is empty. + * @param THtmlWriter renderer + */ public function render($writer) { if($this->getReadOnly()) - { $writer->addAttribute('class', $this->getRatingStyleCssClass()); - $writer->addAttribute('title', $this->getRating()); - } parent::render($writer); } /** - * @param THtmlWriter writer + * Publish the the rating style css file and rating image files. */ public function onPreRender($param) { @@ -198,6 +276,10 @@ class TActiveRatingList extends TActiveRadioButtonList $this->_ratingImages = $this->publishRatingListImages($this->getRatingStyle()); } + /** + * Renders the rating images if {@link setReadOnly ReadOnly} is true + * otherwise render the radio buttons. + */ public function renderItem($writer,$repeatInfo,$itemType,$index) { if($this->getReadOnly()) @@ -206,6 +288,9 @@ class TActiveRatingList extends TActiveRadioButtonList parent::renderItem($writer, $repeatInfo, $itemType, $index); } + /** + * Renders the static rating images. + */ protected function renderStaticRating($writer, $repeatInfo, $itemType, $index) { $image = new TImage; @@ -214,11 +299,15 @@ class TActiveRatingList extends TActiveRadioButtonList $image->render($writer); } + /** + * @param integer rating image index + * @return string the rating image corresponding to current index to be rendered. + */ protected function getRatingImageType($index) { $rating = floatval($this->getRating()); $int = intval($rating); - $limit = $this->getHalfRatingLimit(); + $limit = $this->getHalfRatingInterval(); if($index < $int || ($rating < $index+1 && $rating > $index+$limit[1])) return 'selected'; if($rating >= $index+$limit[0] && $rating <= $index+$limit[1]) diff --git a/framework/Web/UI/ActiveControls/TActiveTextBox.php b/framework/Web/UI/ActiveControls/TActiveTextBox.php index bee97dbb..8e6c86dd 100644 --- a/framework/Web/UI/ActiveControls/TActiveTextBox.php +++ b/framework/Web/UI/ActiveControls/TActiveTextBox.php @@ -50,6 +50,14 @@ class TActiveTextBox extends TTextBox implements ICallbackEventHandler, IActiveC return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Client-side Text property can only be updated after the OnLoad stage. * @param string text content for the textbox diff --git a/framework/Web/UI/ActiveControls/TCallback.php b/framework/Web/UI/ActiveControls/TCallback.php index b7444127..60bdaf10 100644 --- a/framework/Web/UI/ActiveControls/TCallback.php +++ b/framework/Web/UI/ActiveControls/TCallback.php @@ -61,6 +61,14 @@ class TCallback extends TControl implements ICallbackEventHandler, IActiveContro return $this->getAdapter()->getBaseActiveControl(); } + /** + * @return TCallbackClientSide client side request options. + */ + public function getClientSide() + { + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); + } + /** * Raises the callback event. This method is required by {@link * ICallbackEventHandler} interface. If {@link getCausesValidation -- cgit v1.2.3