diff options
author | xue <> | 2006-03-17 22:58:05 +0000 |
---|---|---|
committer | xue <> | 2006-03-17 22:58:05 +0000 |
commit | 95764689f7681d5905c199727dd456671f2fd1b6 (patch) | |
tree | 6a7c4f74642de8189420679b2d43c4124fc1bf36 | |
parent | 261c29ece2ccf37e6419b9886cefd29f9dbb3c89 (diff) |
Cleanup of usage of registerPostBackControl.
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 29 | ||||
-rw-r--r-- | framework/Web/UI/TControl.php | 7 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TBulletedList.php | 6 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TButton.php | 9 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TCheckBox.php | 7 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TImageButton.php | 5 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TLinkButton.php | 7 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TListControl.php | 7 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRadioButton.php | 2 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TTextBox.php | 9 |
10 files changed, 37 insertions, 51 deletions
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index a361d32e..01be9944 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -157,34 +157,21 @@ class TClientScriptManager extends TApplicationComponent /** * Registers postback javascript for a control. - * @param TControl control to be registered with postback js - * @param string js namespace for the control + * @param string javascript class responsible for the control being registered for postback + * @param array postback options */ - public function registerPostBackControl($control,$namespace='Prado.WebUI') + public function registerPostBackControl($jsClass,$options) { - $options = $this->getPostBackOptions($control); - $type = get_class($control); - $namespace = empty($namespace) ? "window" : $namespace; - $code = "new {$namespace}.{$type}($options);"; + if(!isset($options['FormID'])) + $options['FormID']=$this->_page->getForm()->getClientID(); + $optionString=TJavaScript::encode($options); + $code="new $jsClass($optionString);"; $this->registerEndScript(sprintf('%08X', crc32($code)), $code); $this->registerHiddenField(TPage::FIELD_POSTBACK_TARGET,''); $this->registerHiddenField(TPage::FIELD_POSTBACK_PARAMETER,''); - $this->registerPradoScript('prado'); - } - /** - * @param TControl postback control - * @return array postback options for the control - */ - protected function getPostBackOptions($control) - { - $postback = $control->getPostBackOptions(); - if(!isset($postback['ID'])) - $postback['ID'] = $control->getClientID(); - if(!isset($postback['FormID'])) - $postback['FormID'] = $this->_page->getForm()->getClientID(); - return TJavaScript::encode($postback); + $this->registerPradoScript('prado'); } /** diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 21482b0a..dba58555 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -1752,13 +1752,6 @@ interface IPostBackEventHandler * @param string the parameter associated with the postback event
*/
public function raisePostBackEvent($param);
-
- /**
- * Return an array of postback options.
- * The array of options are serialized to passed to corresponding javascript component code.
- * @return array options for javascript postback control
- */
- public function getPostBackOptions();
}
diff --git a/framework/Web/UI/WebControls/TBulletedList.php b/framework/Web/UI/WebControls/TBulletedList.php index da9d196e..05cbaab1 100644 --- a/framework/Web/UI/WebControls/TBulletedList.php +++ b/framework/Web/UI/WebControls/TBulletedList.php @@ -321,7 +321,7 @@ class TBulletedList extends TListControl implements IPostBackEventHandler else
{
$this->_currentRenderItemIndex = $index;
- $this->getPage()->getClientScript()->registerPostbackControl($this);
+ $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TBulletedList',$this->getPostBackOptions());
$writer->addAttribute('id', $this->getClientID().$index);
$writer->addAttribute('href', "javascript:;//".$this->getClientID().$index);
}
@@ -333,9 +333,9 @@ class TBulletedList extends TListControl implements IPostBackEventHandler }
/**
- * @return TPostBackOptions postback options used for linkbuttons.
+ * @return array postback options used for linkbuttons.
*/
- public function getPostBackOptions()
+ protected function getPostBackOptions()
{
$options['ValidationGroup'] = $this->getValidationGroup();
$options['CausesValidation'] = $this->getCausesValidation();
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php index 2ced3098..6751687c 100644 --- a/framework/Web/UI/WebControls/TButton.php +++ b/framework/Web/UI/WebControls/TButton.php @@ -77,7 +77,7 @@ class TButton extends TWebControl implements IPostBackEventHandler if($this->canCauseValidation())
{
$writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this);
+ $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TButton',$this->getPostBackOptions());
}
}
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
@@ -105,10 +105,11 @@ class TButton extends TWebControl implements IPostBackEventHandler * This method is used by framework and control developers.
* @return array parameters about how the button defines its postback behavior.
*/
- public function getPostBackOptions()
+ protected function getPostBackOptions()
{
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['ID']=$this->getClientID();
+ $options['CausesValidation']=$this->getCausesValidation();
+ $options['ValidationGroup']=$this->getValidationGroup();
return $options;
}
diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php index f1299849..c3e5e640 100644 --- a/framework/Web/UI/WebControls/TCheckBox.php +++ b/framework/Web/UI/WebControls/TCheckBox.php @@ -351,7 +351,7 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl $page=$this->getPage();
if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- $page->getClientScript()->registerPostBackControl($this);
+ $page->getClientScript()->registerPostBackControl('Prado.WebUI.TCheckBox',$this->getPostBackOptions());
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
@@ -364,11 +364,12 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl }
/**
- * Sets the post back options for this checkbox.
+ * Gets the post back options for this checkbox.
* @return array
*/
- public function getPostBackOptions()
+ protected function getPostBackOptions()
{
+ $options['ID'] = $this->getClientID();
$options['ValidationGroup'] = $this->getValidationGroup();
$options['CausesValidation'] = $this->getCausesValidation();
$options['EventTarget'] = $this->getUniqueID();
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php index f98cccb1..e5e5f3b9 100644 --- a/framework/Web/UI/WebControls/TImageButton.php +++ b/framework/Web/UI/WebControls/TImageButton.php @@ -92,7 +92,7 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven if($this->canCauseValidation())
{
$writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this);
+ $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TImageButton',$this->getPostBackOptions());
}
}
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
@@ -119,8 +119,9 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven * This method is used by framework and control developers.
* @return array parameters about how the button defines its postback behavior.
*/
- public function getPostBackOptions()
+ protected function getPostBackOptions()
{
+ $options['ID'] = $this->getClientID();
$options['CausesValidation'] = $this->getCausesValidation();
$options['ValidationGroup'] = $this->getValidationGroup();
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php index f1ed95f8..95490f8d 100644 --- a/framework/Web/UI/WebControls/TLinkButton.php +++ b/framework/Web/UI/WebControls/TLinkButton.php @@ -85,7 +85,7 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler //create unique no-op url references
$nop = "#".$this->getClientID();
$writer->addAttribute('href', $nop);
- $this->getPage()->getClientScript()->registerPostBackControl($this);
+ $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TLinkButton',$this->getPostBackOptions());
}
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
@@ -94,10 +94,11 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler /**
* Returns postback specifications for the button.
* This method is used by framework and control developers.
- * @return TPostBackOptions parameters about how the button defines its postback behavior.
+ * @return array parameters about how the button defines its postback behavior.
*/
- public function getPostBackOptions()
+ protected function getPostBackOptions()
{
+ $options['ID'] = $this->getClientID();
$options['EventTarget'] = $this->getUniqueID();
$options['CausesValidation'] = $this->getCausesValidation();
$options['ValidationGroup'] = $this->getValidationGroup();
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index be0abd38..7ea22e1d 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -116,7 +116,7 @@ abstract class TListControl extends TDataBoundControl if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
{
$writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this);
+ $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.'.get_class($this),$this->getPostBackOptions());
}
if($this->getEnabled(true) && !$this->getEnabled())
$writer->addAttribute('disabled','disabled');
@@ -124,10 +124,11 @@ abstract class TListControl extends TDataBoundControl }
/**
- * @return TPostBackOptions postback options for JS postback code
+ * @return array postback options for JS postback code
*/
- public function getPostBackOptions()
+ protected function getPostBackOptions()
{
+ $options['ID'] = $this->getClientID();
$options['CausesValidation'] = $this->getCausesValidation();
$options['ValidationGroup'] = $this->getValidationGroup();
$options['EventTarget'] = $this->getUniqueID();
diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index cb0454ae..dc5320b6 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -146,7 +146,7 @@ class TRadioButton extends TCheckBox $page=$this->getPage();
if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- $page->getClientScript()->registerPostBackControl($this);
+ $page->getClientScript()->registerPostBackControl('Prado.WebUI.TRadioButton',$this->getPostBackOptions());
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php index 7d1b9cba..bc490cdc 100644 --- a/framework/Web/UI/WebControls/TTextBox.php +++ b/framework/Web/UI/WebControls/TTextBox.php @@ -144,17 +144,18 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
{
$writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this);
+ $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TTextBox',$this->getPostBackOptions());
}
parent::addAttributesToRender($writer);
}
/**
- * Sets the post back options for this textbox.
- * @return TPostBackOptions
+ * Gets the post back options for this textbox.
+ * @return array
*/
- public function getPostBackOptions()
+ protected function getPostBackOptions()
{
+ $options['ID'] = $this->getClientID();
$options['EventTarget'] = $this->getUniqueID();
$options['CausesValidation'] = $this->getCausesValidation();
$options['ValidationGroup'] = $this->getValidationGroup();
|