From 35c7ff28cbc311fba5e394b11fb756a4dc1edcb9 Mon Sep 17 00:00:00 2001 From: wei <> Date: Tue, 13 Dec 2005 07:08:30 +0000 Subject: Removed inline javascript from components. Adding TJavascriptLogger and logger.js --- framework/Web/UI/WebControls/TButton.php | 62 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 35 deletions(-) (limited to 'framework/Web/UI/WebControls/TButton.php') diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php index e7c40a75..c18bcc62 100644 --- a/framework/Web/UI/WebControls/TButton.php +++ b/framework/Web/UI/WebControls/TButton.php @@ -44,10 +44,6 @@ * You can change the postback target by setting the {@link setPostBackUrl PostBackUrl} * property. * - * To set the client-side javascript associated with the user's click action, - * use the {@link setOnClientClick OnClientClick} property. The value will be rendered - * as the onclick attribute of the button. - * * TButton displays the {@link setText Text} property as the button caption. * * @author Qiang Xue @@ -78,18 +74,27 @@ class TButton extends TWebControl implements IPostBackEventHandler if(($uniqueID=$this->getUniqueID())!=='') $writer->addAttribute('name',$uniqueID); $writer->addAttribute('value',$this->getText()); + if(!$this->getEnabled()) // in this case, parent will not render 'disabled' + $writer->addAttribute('disabled','disabled'); + parent::addAttributesToRender($writer); + } + /** + * Registers the postback javascript code. + * If you override this method, be sure to call the parent implementation + * so that the event handlers can be invoked. + * @param TEventParameter event parameter to be passed to the event handlers + */ + protected function onPreRender($param) + { if($this->getEnabled(true)) { - $onclick=$this->removeAttribute('onclick'); - $onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick()); - $onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),false); - if(!empty($onclick)) - $writer->addAttribute('onclick','javascript:'.$onclick); + $scripts = $this->getPage()->getClientScript(); + $options = $this->getPostBackOptions(); + $postback = $scripts->getPostBackEventReference($this, '', $options, false); + $scripts->registerClientEvent($this, "click", $postback); } - else if($this->getEnabled()) // in this case, parent will not render 'disabled' - $writer->addAttribute('disabled','disabled'); - parent::addAttributesToRender($writer); + parent::onPreRender($param); } /** @@ -99,16 +104,19 @@ class TButton extends TWebControl implements IPostBackEventHandler */ protected function getPostBackOptions() { - $options=new TPostBackOptions(); - if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0) + $option=new TPostBackOptions(); + $group = $this->getValidationGroup(); + $hasValidators = $this->getPage()->getValidators($group)->getCount()>0; + if($this->getCausesValidation() && $hasValidators) { - $options->setPerformValidation(true); - $options->setValidationGroup($this->getValidationGroup()); + $option->setPerformValidation(true); + $option->setValidationGroup($group); } if($this->getPostBackUrl()!=='') - $options->setActionUrl($this->getPostBackUrl()); - $options->setClientSubmit(!$this->getUseSubmitBehavior()); - return $options; + $option->setActionUrl($this->getPostBackUrl()); + $option->setClientSubmit(!$this->getUseSubmitBehavior()); + + return $option; } /** @@ -275,22 +283,6 @@ class TButton extends TWebControl implements IPostBackEventHandler { $this->setViewState('PostBackUrl',$value,''); } - - /** - * @return string the javascript to be executed when the button is clicked. - */ - public function getOnClientClick() - { - return $this->getViewState('OnClientClick',''); - } - - /** - * @param string the javascript to be executed when the button is clicked. - */ - public function setOnClientClick($value) - { - $this->setViewState('OnClientClick',$value,''); - } } ?> \ No newline at end of file -- cgit v1.2.3