summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TButton.php
diff options
context:
space:
mode:
authorwei <>2005-12-13 07:08:30 +0000
committerwei <>2005-12-13 07:08:30 +0000
commit35c7ff28cbc311fba5e394b11fb756a4dc1edcb9 (patch)
tree1ee39944b4cdba1ecc6aeb2a952139b5a3165f67 /framework/Web/UI/WebControls/TButton.php
parent2c383b6050b3d8cc6ac7a9442c999cb903af43ab (diff)
Removed inline javascript from components. Adding TJavascriptLogger and logger.js
Diffstat (limited to 'framework/Web/UI/WebControls/TButton.php')
-rw-r--r--framework/Web/UI/WebControls/TButton.php62
1 files changed, 27 insertions, 35 deletions
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 <b>onclick</b> attribute of the button.
- *
* TButton displays the {@link setText Text} property as the button caption.
*
* @author Qiang Xue <qiang.xue@gmail.com>
@@ -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