summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/base/postback.js82
-rw-r--r--framework/Web/Javascripts/js/base.js72
-rw-r--r--framework/Web/THttpUtility.php1
-rw-r--r--framework/Web/UI/TClientScriptManager.php180
-rw-r--r--framework/Web/UI/WebControls/TButton.php42
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php166
6 files changed, 268 insertions, 275 deletions
diff --git a/framework/Web/Javascripts/base/postback.js b/framework/Web/Javascripts/base/postback.js
index 8b2d522e..7acb945e 100644
--- a/framework/Web/Javascripts/base/postback.js
+++ b/framework/Web/Javascripts/base/postback.js
@@ -1,66 +1,54 @@
-
-Prado.PostBack = Class.create();
-
-Prado.PostBack.Options = Class.create();
-
-Prado.PostBack.Options.prototype =
+Prado.doPostBack = function(formID, eventTarget, eventParameter, performValidation, validationGroup, actionUrl, trackFocus, clientSubmit)
{
- initialize : function(performValidation, validationGroup, actionUrl, trackFocus, clientSubmit)
+ if (typeof(performValidation) == 'undefined')
{
- this.performValidation = performValidation;
- this.validationGroup = validationGroup;
- this.actionUrl = actionUrl;
- this.trackFocus = trackFocus;
- this.clientSubmit = clientSubmit;
- }
-}
-
-Prado.PostBack.perform = function(formID, eventTarget, eventParameter, options)
-{
+ var performValidation = false;
+ var validationGroup = '';
+ var actionUrl = null;
+ var trackFocus = false;
+ var clientSubmit = true;
+ }
var theForm = document.getElementById ? document.getElementById(formID) : document.forms[formID];
var canSubmit = true;
- if ((typeof(options) != 'undefined') || options == null)
+ if (performValidation)
+ {
+ canSubmit = Prado.Validation.validate(validationGroup);
+ }
+ if (canSubmit)
{
- if (options.performValidation)
+ if (actionUrl != null && (actionUrl.length > 0))
{
- canSubmit = Prado.Validation.validate(options.validationGroup);
+ theForm.action = actionUrl;
}
- if (canSubmit)
+ if (trackFocus)
{
- if ((typeof(options.actionUrl) != 'undefined') && (options.actionUrl != null) && (options.actionUrl.length > 0))
+ var lastFocus = theForm.elements['PRADO_LASTFOCUS'];
+ if ((typeof(lastFocus) != 'undefined') && (lastFocus != null))
{
- theForm.action = options.actionUrl;
- }
- if (options.trackFocus)
- {
- var lastFocus = theForm.elements['PRADO_LASTFOCUS'];
- if ((typeof(lastFocus) != 'undefined') && (lastFocus != null))
+ var active = document.activeElement;
+ if (typeof(active) == 'undefined')
{
- var active = document.activeElement;
- if (typeof(active) == 'undefined')
- {
- lastFocus.value = eventTarget;
- }
- else
+ lastFocus.value = eventTarget;
+ }
+ else
+ {
+ if ((active != null) && (typeof(active.id) != 'undefined'))
{
- if ((active != null) && (typeof(active.id) != 'undefined'))
+ if (active.id.length > 0)
+ {
+ lastFocus.value = active.id;
+ }
+ else if (typeof(active.name) != 'undefined')
{
- if (active.id.length > 0)
- {
- lastFocus.value = active.id;
- }
- else if (typeof(active.name) != 'undefined')
- {
- lastFocus.value = active.name;
- }
+ lastFocus.value = active.name;
}
}
}
}
- if (!options.clientSubmit)
- {
- canSubmit = false;
- }
+ }
+ if (!clientSubmit)
+ {
+ canSubmit = false;
}
}
if (canSubmit && (!theForm.onsubmit || theForm.onsubmit()))
diff --git a/framework/Web/Javascripts/js/base.js b/framework/Web/Javascripts/js/base.js
index fdd4ee8f..d16db163 100644
--- a/framework/Web/Javascripts/js/base.js
+++ b/framework/Web/Javascripts/js/base.js
@@ -842,54 +842,50 @@ return _7;
Prado=Class.create();
Prado.version="3.0a";
-Prado.PostBack=Class.create();
-Prado.PostBack.Options=Class.create();
-Prado.PostBack.Options.prototype={initialize:function(_1,_2,_3,_4,_5){
-this.performValidation=_1;
-this.validationGroup=_2;
-this.actionUrl=_3;
-this.trackFocus=_4;
-this.clientSubmit=_5;
-}};
-Prado.PostBack.perform=function(_6,_7,_8,_9){
-var _10=document.getElementById?document.getElementById(_6):document.forms[_6];
-var _11=true;
-if((typeof (_9)!="undefined")||_9==null){
-if(_9.performValidation){
-_11=Prado.Validation.validate(_9.validationGroup);
-}
-if(_11){
-if((typeof (_9.actionUrl)!="undefined")&&(_9.actionUrl!=null)&&(_9.actionUrl.length>0)){
-_10.action=_9.actionUrl;
-}
-if(_9.trackFocus){
-var _12=_10.elements["PRADO_LASTFOCUS"];
-if((typeof (_12)!="undefined")&&(_12!=null)){
-var _13=document.activeElement;
-if(typeof (_13)=="undefined"){
-_12.value=_7;
+Prado.doPostBack=function(_1,_2,_3,_4,_5,_6,_7,_8){
+if(typeof (_4)=="undefined"){
+var _4=false;
+var _5="";
+var _6=null;
+var _7=false;
+var _8=true;
+}
+var _9=document.getElementById?document.getElementById(_1):document.forms[_1];
+var _10=true;
+if(_4){
+_10=Prado.Validation.validate(_5);
+}
+if(_10){
+if(_6!=null&&(_6.length>0)){
+_9.action=_6;
+}
+if(_7){
+var _11=_9.elements["PRADO_LASTFOCUS"];
+if((typeof (_11)!="undefined")&&(_11!=null)){
+var _12=document.activeElement;
+if(typeof (_12)=="undefined"){
+_11.value=_2;
}else{
-if((_13!=null)&&(typeof (_13.id)!="undefined")){
-if(_13.id.length>0){
-_12.value=_13.id;
+if((_12!=null)&&(typeof (_12.id)!="undefined")){
+if(_12.id.length>0){
+_11.value=_12.id;
}else{
-if(typeof (_13.name)!="undefined"){
-_12.value=_13.name;
-}
+if(typeof (_12.name)!="undefined"){
+_11.value=_12.name;
}
}
}
}
}
-if(!_9.clientSubmit){
-_11=false;
}
+if(!_8){
+_10=false;
}
}
-if(_11&&(!_10.onsubmit||_10.onsubmit())){
-_10.PRADO_POSTBACK_TARGET.value=_7;
-_10.PRADO_POSTBACK_PARAMETER.value=_8;
-_10.submit();
+if(_10&&(!_9.onsubmit||_9.onsubmit())){
+_9.PRADO_POSTBACK_TARGET.value=_2;
+_9.PRADO_POSTBACK_PARAMETER.value=_3;
+_9.submit();
}
};
diff --git a/framework/Web/THttpUtility.php b/framework/Web/THttpUtility.php
index 7cb1c01c..8951cbe7 100644
--- a/framework/Web/THttpUtility.php
+++ b/framework/Web/THttpUtility.php
@@ -33,6 +33,7 @@ class THttpUtility
{
if($js!=='' && $js!==null)
{
+ $js=trim($js);
if(($pos=strpos($js,'javascript:'))===0)
$js=substr($js,11);
$js=rtrim($js,';').';';
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 0b88dac8..bb8c44a3 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -2,30 +2,78 @@
class TPostBackOptions extends TComponent
{
- public $ActionUrl;
- public $AutoPostBack;
- public $ClientSubmit;
- public $PerformValidation;
- public $TrackFocus;
- public $ValidationGroup;
-
- public function __construct($actionUrl='',$autoPostBack=false,$clientSubmit=true,
- $performValidation=false,$validationGroup='',$trackFocus=false)
- {
- $this->ActionUrl=$actionUrl;
- $this->AutoPostBack=$autoPostBack;
- $this->ClientSubmit=$clientSubmit;
- $this->PerformValidation=$performValidation;
- $this->ValidationGroup=$validationGroup;
- $this->TrackFocus=$trackFocus;
+ public $_actionUrl='';
+ public $_autoPostBack=false;
+ public $_clientSubmit=true;
+ public $_performValidation=false;
+ public $_validationGroup='';
+ public $_trackFocus=false;
+
+ public function getActionUrl()
+ {
+ return $this->_actionUrl;
+ }
+
+ public function setActionUrl($value)
+ {
+ $this->_actionUrl=THttpUtility::quoteJavaScriptString($value);
+ }
+
+ public function getAutoPostBack()
+ {
+ return $this->_autoPostBack;
+ }
+
+ public function setAutoPostBack($value)
+ {
+ $this->_autoPostBack=$value;
+ }
+
+ public function getClientSubmit()
+ {
+ return $this->_clientSubmit;
+ }
+
+ public function setClientSubmit($value)
+ {
+ $this->_clientSubmit=$value;
+ }
+
+ public function getPerformValidation()
+ {
+ return $this->_performValidation;
+ }
+
+ public function setPerformValidation($value)
+ {
+ $this->_performValidation=$value;
+ }
+
+ public function getValidationGroup()
+ {
+ return $this->_validationGroup;
+ }
+
+ public function setValidationGroup($value)
+ {
+ $this->_validationGroup=$value;
+ }
+
+ public function getTrackFocus()
+ {
+ return $this->_trackFocus;
+ }
+
+ public function setTrackFocus($value)
+ {
+ $this->_trackFocus=$value;
}
}
class TClientScriptManager extends TComponent
{
const SCRIPT_DIR='Web/Javascripts/js';
- const POSTBACK_FUNC='Prado.PostBack.perform';
- const POSTBACK_OPTIONS='Prado.PostBack.Options';
+ const POSTBACK_FUNC='Prado.doPostBack';
private $_page;
private $_hiddenFields=array();
private $_beginScripts=array();
@@ -46,57 +94,61 @@ class TClientScriptManager extends TComponent
public function getPostBackEventReference($control,$parameter='',$options=null,$javascriptPrefix=true)
{
- if($options)
+ if(!$options || (!$options->getPerformValidation() && !$options->getTrackFocus() && $options->getClientSubmit() && $options->getActionUrl()==''))
{
- $flag=false;
- $opt='new '.self::POSTBACK_OPTIONS.'(';
- if($options->PerformValidation)
- {
- $flag=true;
- $this->registerValidationScript();
- $opt.='true,';
- }
- else
- $opt.='false,';
- if($options->ValidationGroup!=='')
- {
- $flag=true;
- $opt.='"'.$options->ValidationGroup.'",';
- }
- else
- $opt.='"",';
- if($options->ActionUrl!=='')
- {
- $flag=true;
- $this->_page->setCrossPagePostBack(true);
- $opt.='"'.THttpUtility::quoteJavaScriptString($options->ActionUrl).'",';
- }
- else
- $opt.='"",';
- if($options->TrackFocus)
- {
- $flag=true;
- $this->registerFocusScript();
- $opt.='true,';
- }
- else
- $opt.='false,';
- if($options->ClientSubmit)
- {
- $flag=true;
- $opt.='true)';
- }
- else
- $opt.='false)';
- if(!$flag)
- return '';
+ $this->registerPostBackScript();
+ $formID=$this->_page->getForm()->getUniqueID();
+ $postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\')';
+ if($options && $options->getAutoPostBack())
+ $postback='setTimeout(\''.THttpUtility::quoteJavaScriptString($postback).'\',0)';
+ return $javascriptPrefix?'javascript:'.$postback:$postback;
+ }
+ $opt='';
+ $flag=false;
+ if($options->getPerformValidation())
+ {
+ $flag=true;
+ $this->registerValidationScript();
+ $opt.=',true,';
+ }
+ else
+ $opt.=',false,';
+ if($options->getValidationGroup()!=='')
+ {
+ $flag=true;
+ $opt.='"'.$options->getValidationGroup().'",';
+ }
+ else
+ $opt.='"",';
+ if($options->getActionUrl()!=='')
+ {
+ $flag=true;
+ $this->_page->setCrossPagePostBack(true);
+ $opt.='"'.$options->getActionUrl().'",';
+ }
+ else
+ $opt.='null,';
+ if($options->getTrackFocus())
+ {
+ $flag=true;
+ $this->registerFocusScript();
+ $opt.='true,';
+ }
+ else
+ $opt.='false,';
+ if($options->getClientSubmit())
+ {
+ $flag=true;
+ $opt.='true)';
}
else
- $opt='null';
+ $opt.='false)';
+ if(!$flag)
+ return '';
$this->registerPostBackScript();
$formID=$this->_page->getForm()->getUniqueID();
- $postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\','.$opt.')';
- if($options && $options->AutoPostBack)
+ $postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\''.$opt.')';
+ if($options && $options->getAutoPostBack())
$postback='setTimeout(\''.THttpUtility::quoteJavaScriptString($postback).'\',0)';
return $javascriptPrefix?'javascript:'.$postback:$postback;
}
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index 2de4e22a..472dd818 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -97,23 +97,25 @@ class TButton extends TWebControl implements IPostBackEventHandler
}
/**
- * OnClick event raiser.
- * This method raises OnClick event.
- * Be sure to invoke the parent implementation if this method is overriden.
- * @param TEventParameter the event parameter
+ * This method is invoked when the button is clicked.
+ * The method raises 'Click' 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 TEventParameter event parameter to be passed to the event handlers
*/
- protected function onClick($param)
+ public function onClick($param)
{
$this->raiseEvent('Click',$this,$param);
}
/**
- * OnCommand event raiser.
- * This method raises OnCommand event.
- * Be sure to invoke the parent implementation if this method is overriden.
- * @param TCommandEventParameter the event parameter
+ * This method is invoked when the button is clicked.
+ * The method raises 'Command' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
*/
- protected function onCommand($param)
+ public function onCommand($param)
{
$this->raiseEvent('Command',$this,$param);
$this->raiseBubbleEvent($this,$param);
@@ -121,10 +123,10 @@ class TButton extends TWebControl implements IPostBackEventHandler
/**
* Raises the postback event.
- * This method is required by IPostBackEventHandler interface.
- * If <b>CausesValidation</b> is true, it will invokes the page's {@validate}
- * method first.
- * It will raise <b>OnClick</b> and <b>OnCommand</b> events.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick Click} and {@link onCommand Command} events.
* This method is mainly used by framework and control developers.
* @param TEventParameter the event parameter
*/
@@ -132,7 +134,7 @@ class TButton extends TWebControl implements IPostBackEventHandler
{
if($this->getCausesValidation())
$this->getPage()->validate($this->getValidationGroup());
- $this->onClick(new TEventParameter);
+ $this->onClick(null);
$this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
}
@@ -144,16 +146,16 @@ class TButton extends TWebControl implements IPostBackEventHandler
protected function getPostBackOptions()
{
$options=new TPostBackOptions();
- $options->ClientSubmit=false;
+ $options->setClientSubmit(false);
$page=$this->getPage();
if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount()>0)
{
- $options->PerformValidation=true;
- $options->ValidationGroup=$this->getValidationGroup();
+ $options->setPerformValidation(true);
+ $options->setValidationGroup($this->getValidationGroup());
}
if($this->getPostBackUrl()!=='')
- $options->ActionUrl=THttpUtility::quoteJavaScriptString($this->getPostBackUrl());
- $options->ClientSubmit=!$this->getUseSubmitBehavior();
+ $options->setActionUrl($this->getPostBackUrl());
+ $options->setClientSubmit(!$this->getUseSubmitBehavior());
return $options;
}
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index 74feb9db..517a2f8b 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -14,55 +14,45 @@
* TLinkButton class
*
* TLinkButton creates a hyperlink style button on the page.
- * TLinkButton has the same appearance as a hyperlink. However, it is only
- * used to submit data to the same page. If you want to link to another Web page
- * when the component is clicked, consider using the THyperLink component.
- * Like TButton, you can create either a <b>submit</b> button or a <b>command</b> button.
+ * TLinkButton has the same appearance as a hyperlink. However, it is mainly
+ * used to submit data to a page. Like {@link TButton}, you can create either
+ * a <b>submit</b> button or a <b>command</b> button.
*
- * A <b>command</b> button has a command name (specified by the <b>CommandName</b> property)
- * and a command parameter (specified by <b>CommandParameter</b> property)
- * associated with the button. This allows you to create multiple TLinkButton components
- * on a Web page and programmatically determine which one is clicked with what parameter.
- * You can provide an event handler for the <b>OnCommand</b> event to programmatically control
- * the actions performed when the command button is clicked.
- * In the event handler, you can also determine
- * the <b>CommandName</b> property value and the <b>CommandParameter</b> property value
- * through <b>name</b> and <b>parameter</b> of the event parameter which is of
- * type <b>TCommandEventParameter</b>.
+ * A <b>command</b> button has a command name (specified by
+ * the {@link setCommandName CommandName} property) and and a command parameter
+ * (specified by {@link setCommandParameter CommandParameter} property)
+ * associated with the button. This allows you to create multiple TLinkButton
+ * components on a Web page and programmatically determine which one is clicked
+ * with what parameter. You can provide an event handler for
+ * {@link onCommand Command} event to programmatically control the actions performed
+ * when the command button is clicked. In the event handler, you can determine
+ * the {@link setCommandName CommandName} property value and
+ * the {@link setCommandParameter CommandParameter} property value
+ * through the {@link TCommandParameter::getName Name} and
+ * {@link TCommandParameter::getParameter Parameter} properties of the event
+ * parameter which is of type {@link TCommandEventParameter}.
*
* A <b>submit</b> button does not have a command name associated with the button
* and clicking on it simply posts the Web page back to the server.
* By default, a TLinkButton component is a submit button.
- * You can provide an event handler for the <b>OnClick</b> event to programmatically
- * control the actions performed when the submit button is clicked.
+ * You can provide an event handler for the {@link onClick Click} event
+ * to programmatically control the actions performed when the submit button is clicked.
*
- * TLinkButton will display the <b>Text</b> property value as the hyperlink text. If <b>Text</b>
- * is empty, the body content of TLinkButton will be displayed.
- * Therefore, you can use TLinkButton as an image button by enclosing an 'img' tag
- * as the body of TLinkButton.
+ * By default, clicking on a TLinkButton will cause input validation (if any)
+ * to be performed. You can turn this on or off by setting
+ * the {@link setCausesValidation CausesValidation} property.
+ * If validation is successful, the data will be post back to the same page.
+ * You can change the postback target by setting the {@link setPostBackUrl PostBackUrl}
+ * property.
*
- * Note, <b>Text</b> will be HTML encoded before it is displayed in the TLinkButton component.
- * If you don't want it to be so, set <b>EncodeText</b> to false.
+ * 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 link button.
*
- * Namespace: System.Web.UI.WebControls
- *
- * Properties
- * - <b>Text</b>, string, kept in viewstate
- * <br>Gets or sets the text caption displayed in the TLinkButton component.
- * - <b>EncodeText</b>, boolean, default=true, kept in viewstate
- * <br>Gets or sets the value indicating whether Text should be HTML-encoded when rendering.
- * - <b>CausesValidation</b>, boolean, default=true, kept in viewstate
- * <br>Gets or sets a value indicating whether validation is performed when the TLinkButton component is clicked.
- * - <b>CommandName</b>, string, kept in viewstate
- * <br>Gets or sets the command name associated with the TLinkButton component that is passed to
- * the <b>OnCommand</b> event.
- * - <b>CommandParameter</b>, string, kept in viewstate
- * <br>Gets or sets an optional parameter passed to the <b>OnCommand</b> event along with
- * the associated <b>CommandName</b>.
- *
- * Events
- * - <b>OnClick</b> Occurs when the TLinkButton component is clicked.
- * - <b>OnCommand</b> Occurs when the TLinkButton component is clicked.
+ * TLinkButton will display the {@link setText Text} property value
+ * as the hyperlink text. If {@link setText Text} is empty, the body content
+ * of TLinkButton will be displayed. Therefore, you can use TLinkButton
+ * as an image button by enclosing an &lt;img&gt; tag as the body of TLinkButton.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -91,20 +81,14 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
$onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):'';
$onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
if(!empty($onclick))
- $writer->addAttribute('onclick',$onclick);
+ $writer->addAttribute('onclick','javascript:'.$onclick);
// We call parent implementation here because some attributes
// may be overwritten in the following
parent::addAttributesToRender($writer);
if($this->getEnabled(true))
- {
- if(($options=$this->getPostBackOptions())===null)
- $href='javascript:void(0)';
- else
- $href=$page->getClientScript()->getPostBackEventReference($this,'',$options,true);
- $writer->addAttribute('href',$href);
- }
+ $writer->addAttribute('href',$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),true));
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
}
@@ -116,17 +100,20 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
*/
protected function getPostBackOptions()
{
+ $flag=false;
$options=new TPostBackOptions();
- $options->ClientSubmit=true;
- $page=$this->getPage();
- if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount()>0)
+ if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0)
{
- $options->PerformValidation=true;
- $options->ValidationGroup=$this->getValidationGroup();
+ $flag=true;
+ $options->setPerformValidation(true);
+ $options->setValidationGroup($this->getValidationGroup());
}
if($this->getPostBackUrl()!=='')
- $options->ActionUrl=THttpUtility::quoteJavaScriptString($this->getPostBackUrl());
- return $options;
+ {
+ $flag=true;
+ $options->setActionUrl($this->getPostBackUrl());
+ }
+ return $flag?$options:null;
}
/**
@@ -260,26 +247,27 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
}
/**
- * Raises postback event.
- * The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand)
- * indicating the component is responsible for the postback event.
- * This method is primarily used by framework developers.
- * @param string the parameter associated with the postback event
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick Click} and {@link onCommand Command} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
*/
public function raisePostBackEvent($param)
{
- $this->onClick(new TEventParameter);
- $cmdParam=new TCommandEventParameter;
- $cmdParam->name=$this->getCommandName();
- $cmdParam->parameter=$this->getCommandParameter();
- $this->onCommand($cmdParam);
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(null);
+ $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
}
/**
- * This method is invoked when the component is clicked.
- * The method raises 'OnClick' event to fire up the event delegates.
+ * This method is invoked when the button is clicked.
+ * The method raises 'Click' event to fire up the event handlers.
* If you override this method, be sure to call the parent implementation
- * so that the event delegates can be invoked.
+ * so that the event handler can be invoked.
* @param TEventParameter event parameter to be passed to the event handlers
*/
public function onClick($param)
@@ -288,10 +276,10 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
}
/**
- * This method is invoked when the component is clicked.
- * The method raises 'OnCommand' event to fire up the event delegates.
+ * This method is invoked when the button is clicked.
+ * The method raises 'Command' event to fire up the event handlers.
* If you override this method, be sure to call the parent implementation
- * so that the event delegates can be invoked.
+ * so that the event handlers can be invoked.
* @param TCommandEventParameter event parameter to be passed to the event handlers
*/
public function onCommand($param)
@@ -299,40 +287,6 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
$this->raiseEvent('Command',$this,$param);
$this->raiseBubbleEvent($this,$param);
}
-
- /**
- * This overrides the parent implementation by rendering more TLinkButton-specific attributes.
- * @return ArrayObject the attributes to be rendered
- */
- protected function getAttributesToRender()
- {
- $attr=parent::getAttributesToRender();
- if($this->isEnabled())
- {
- $page=$this->getPage();
- $postBack=$page->getPostBackClientEvent($this,'');
- if($this->causesValidation() && $this->Page->isEndScriptRegistered('TValidator'))
- {
- $group = $this->getValidationGroup();
- $group = strlen($group) ? ",'".$group."'" : '';
- $script = "Prado.Validation.AddTarget('{$this->ClientID}' {$group});";
- $this->Page->registerEndScript($this->ClientID.'target', $script);
- }
-
- $attr['href']="javascript:{$postBack}";
- }
- return $attr;
- }
-
- /**
- * This overrides the parent implementation by rendering either <b>Text</b> or the body contents.
- * @return string the rendering result
- */
- protected function renderBody()
- {
- $text=$this->isEncodeText()?pradoEncodeData($this->getText()):$this->getText();
- return strlen($text)?$text:parent::renderBody();
- }
}
?> \ No newline at end of file