summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-05-05 12:11:24 +0000
committerxue <>2006-05-05 12:11:24 +0000
commitf46eb73c1c34e021cd35378e4e83a136aa7b8d35 (patch)
treecb29625204dab0866671b42a37bc79fa3c6d6138
parent398455e7b319b52667558a62b8760aebb3a33ed8 (diff)
undo changeset 1028.
-rw-r--r--HISTORY2
-rw-r--r--framework/Web/UI/TClientScriptManager.php183
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php65
-rw-r--r--framework/Web/UI/WebControls/TValidationSummary.php55
4 files changed, 106 insertions, 199 deletions
diff --git a/HISTORY b/HISTORY
index 8e11538a..537f5012 100644
--- a/HISTORY
+++ b/HISTORY
@@ -5,10 +5,8 @@ ENH: Ticket#152 - constituent parts of TWizard are exposed (Qiang)
ENH: added sanity check to calling event handlers (Qiang)
CHG: Ticket#151 - URL format is modified to handle empty GET values (Qiang)
CHG: Ticket#153 - TAssetManager now ignores .svn directories (Qiang)
-CHG: Renamed TValidatorClientScript to TClientSideValidatorOptions, TValidationSummaryClientScript to TClientSideValidationSummaryOptions (wei)
NEW: TTableHeaderRow, TTableFooterRow and table section support (Qiang)
NEW: TCompositeControl (Qiang)
-NEW: TClientOptions abstract base class (Wei)
Version 3.0.0 May 1, 2006
=========================
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 064ab34f..015ef1c1 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -1,6 +1,6 @@
<?php
/**
- * TClientScriptManager and TClientSideOptions class file.
+ * TClientScriptManager class file
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
@@ -116,15 +116,6 @@ class TClientScriptManager extends TApplicationComponent
*/
public function registerPradoScript($name)
{
- $this->registerPradoScriptInternal($name);
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerPradoScript',$params);
- }
-
- private function registerPradoScriptInternal($name)
- {
if(!isset($this->_registeredPradoScripts[$name]))
{
$this->_registeredPradoScripts[$name]=true;
@@ -164,21 +155,6 @@ class TClientScriptManager extends TApplicationComponent
}
}
- public function getCallbackReference($callbackHandler, $options=null)
- {
- $options = !is_array($options) ? array() : $options;
- $class = new TReflectionClass($callbackHandler);
- if($class->hasMethod('getClientSide'))
- {
- $clientSide = $callbackHandler->getClientSide();
- $options = array_merge($options, $clientSide->getOptions()->toArray());
- }
- $optionString = TJavascript::encode($options);
- $this->registerPradoScriptInternal('ajax');
- $id = $callbackHandler->getUniqueID();
- return "new Prado.CallbackRequest('{$id}',{$optionString})";
- }
-
/**
* Registers postback javascript for a control.
* @param string javascript class responsible for the control being registered for postback
@@ -186,63 +162,51 @@ class TClientScriptManager extends TApplicationComponent
*/
public function registerPostBackControl($jsClass,$options)
{
- if(!isset($options['FormID']) && ($form=$this->_page->getForm())!==null)
- $options['FormID']=$form->getClientID();
+ 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->_endScripts[sprintf('%08X', crc32($code))]=$code;
- $this->_hiddenFields[TPage::FIELD_POSTBACK_TARGET]='';
- $this->_hiddenFields[TPage::FIELD_POSTBACK_PARAMETER]='';
- $this->registerPradoScriptInternal('prado');
+ $this->registerHiddenField(TPage::FIELD_POSTBACK_TARGET,'');
+ $this->registerHiddenField(TPage::FIELD_POSTBACK_PARAMETER,'');
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerPostBackControl',$params);
+ $this->registerPradoScript('prado');
}
/**
* Register a default button to panel. When the $panel is in focus and
* the 'enter' key is pressed, the $button will be clicked.
- * @param string client ID of the container object
- * @param string client ID of the button
+ * @param TControl panel to register the default button action
+ * @param TControl button to trigger a postback
*/
- public function registerDefaultButton($containerID, $buttonID)
+ public function registerDefaultButton($panel, $button)
{
- $options = TJavaScript::encode($this->getDefaultButtonOptions($containerID, $buttonID));
+ $options = TJavaScript::encode($this->getDefaultButtonOptions($panel, $button));
$code = "new Prado.WebUI.DefaultButton($options);";
-
- $this->_endScripts['prado:'.$containerID]=$code;
- $this->registerPradoScriptInternal('prado');
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerDefaultButton',$params);
+ $this->registerEndScript("prado:".$panel->getClientID(), $code);
+ $this->registerPradoScript('prado');
}
/**
* Registers the control to receive default focus.
- * @param string the client ID of the control to receive default focus
+ * @param TControl|string the control or the client ID of the HTML element to receive default focus
*/
public function registerFocusControl($target)
{
- $this->registerPradoScriptInternal('prado');
- $this->_endScripts['prado:focus']='Prado.Focus.setFocus("'.TJavaScript::quoteString($target).'");';
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerFocusControl',$params);
+ $this->registerPradoScript('prado');
+ if($target instanceof TControl)
+ $target=$target->getClientID();
+ $this->registerEndScript('prado:focus','Prado.Focus.setFocus("'.TJavaScript::quoteString($target).'");');
}
/**
- * @param string client ID of the container object
- * @param string client ID of the button
* @return array default button options.
*/
- protected function getDefaultButtonOptions($containerID, $buttonID)
+ protected function getDefaultButtonOptions($panel, $button)
{
- $options['Panel'] = $containerID;
- $options['Target'] = $buttonID;
+ $options['Panel'] = $panel->getClientID();
+ $options['Target'] = $button->getClientID();
$options['Event'] = 'click';
return $options;
}
@@ -255,10 +219,6 @@ class TClientScriptManager extends TApplicationComponent
public function registerStyleSheetFile($key,$url)
{
$this->_styleSheetFiles[$key]=$url;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerStyleSheetFile',$params);
}
/**
@@ -269,10 +229,6 @@ class TClientScriptManager extends TApplicationComponent
public function registerStyleSheet($key,$css)
{
$this->_styleSheets[$key]=$css;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerStyleSheet',$params);
}
/**
@@ -283,10 +239,6 @@ class TClientScriptManager extends TApplicationComponent
public function registerHeadScriptFile($key,$url)
{
$this->_headScriptFiles[$key]=$url;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerHeadScriptFile',$params);
}
/**
@@ -297,10 +249,6 @@ class TClientScriptManager extends TApplicationComponent
public function registerHeadScript($key,$script)
{
$this->_headScripts[$key]=$script;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerHeadScript',$params);
}
/**
@@ -310,11 +258,8 @@ class TClientScriptManager extends TApplicationComponent
*/
public function registerScriptFile($key,$url)
{
- $this->_scriptFiles[$key]=$url;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerScriptFile',$params);
+ if(!isset($this->_scriptFiles[$key]))
+ $this->_scriptFiles[$key]=$url;
}
/**
@@ -325,10 +270,6 @@ class TClientScriptManager extends TApplicationComponent
public function registerBeginScript($key,$script)
{
$this->_beginScripts[$key]=$script;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerBeginScript',$params);
}
/**
@@ -339,10 +280,6 @@ class TClientScriptManager extends TApplicationComponent
public function registerEndScript($key,$script)
{
$this->_endScripts[$key]=$script;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerEndScript',$params);
}
/**
@@ -353,11 +290,8 @@ class TClientScriptManager extends TApplicationComponent
*/
public function registerHiddenField($name,$value)
{
- $this->_hiddenFields[$name]=$value;
-
- $params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerHiddenField',$params);
+ if(!isset($this->_hiddenFields[$name]))
+ $this->_hiddenFields[$name]=$value;
}
/**
@@ -532,71 +466,4 @@ class TClientScriptManager extends TApplicationComponent
}
}
-/**
- * TClientSideOptions abstract class.
- *
- * TClientSideOptions manages client-side options for components that have
- * common client-side javascript behaviours and client-side events such as
- * between ActiveControls and validators.
- *
- * @author <weizhuo[at]gmail[dot]com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI
- * @since 3.0
- */
-abstract class TClientSideOptions extends TComponent
-{
- /**
- * @var TMap list of client-side options.
- */
- private $_options;
-
- /**
- * Constructor, initialize the options list.
- */
- public function __construct()
- {
- $this->_options = Prado::createComponent('System.Collections.TMap');
- }
-
- /**
- * Adds on client-side event handler by wrapping the code within a
- * javascript function block. If the code begins with "javascript:", the
- * code is assumed to be a javascript function block rather than arbiturary
- * javascript statements.
- * @param string option name
- * @param string javascript statements.
- */
- protected function setFunction($name, $code)
- {
- $this->_options->add($name, $this->ensureFunction($code));
- }
-
- /**
- * @return string gets a particular option, null if not set.
- */
- protected function getOption($name)
- {
- return $this->_options->itemAt($name);
- }
-
- /**
- * @return TMap gets the list of options as TMap
- */
- public function getOptions()
- {
- return $this->_options;
- }
-
- /**
- * Ensure that the javascript statements are wrapped in a javascript
- * function block. Default has no wrapping. Override this method to
- * customize the wrapping javascript function block.
- */
- protected function ensureFunction($javascript)
- {
- return $javascript;
- }
-}
-
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index e7eb7e33..ea1a5836 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -80,9 +80,9 @@ abstract class TBaseValidator extends TLabel implements IValidator
*/
private $_registered=false;
/**
- * @var TClientSideValidatorOptions validator client-script options.
+ * @var TValidatorClientScript validator client-script options.
*/
- private $_clientSide;
+ private $_clientScript;
/**
* Constructor.
@@ -154,14 +154,14 @@ abstract class TBaseValidator extends TLabel implements IValidator
$options['ControlCssClass'] = $this->getControlCssClass();
$options['ControlType'] = get_class($control);
- if(!is_null($this->_clientSide))
- $options = array_merge($options,$this->_clientSide->getOptions()->toArray());
+ if(!is_null($this->_clientScript))
+ $options = array_merge($options,$this->_clientScript->getOptions());
return $options;
}
/**
- * Gets the TClientSideValidatorOptions that allows modification of the client-
+ * Gets the TValidatorClientScript that allows modification of the client-
* side validator events.
*
* The client-side validator supports the following events.
@@ -174,21 +174,21 @@ abstract class TBaseValidator extends TLabel implements IValidator
*
* You can attach custom javascript code to each of these events
*
- * @return TClientSideValidatorOptions javascript validator event options.
+ * @return TValidatorClientScript javascript validator event options.
*/
public function getClientSide()
{
- if(is_null($this->_clientSide))
- $this->_clientSide = $this->createClientSideOptions();
- return $this->_clientSide;
+ if(is_null($this->_clientScript))
+ $this->_clientScript = $this->createClientScript();
+ return $this->_clientScript;
}
/**
- * @return TClientSideValidatorOptions javascript validator event options.
+ * @return TValidatorClientScript javascript validator event options.
*/
- protected function createClientSideOptions()
+ protected function createClientScript()
{
- return new TClientSideValidatorOptions;
+ return new TValidatorClientScript;
}
/**
@@ -491,11 +491,11 @@ abstract class TBaseValidator extends TLabel implements IValidator
}
/**
- * TClientSideValidatorOptions class.
+ * TValidatorClientScript class.
*
* Client-side validator events can be modified through the {@link
* TBaseValidator::getClientSide ClientSide} property of a validator. The
- * subproperties of ClientSide are those of the TClientSideValidatorOptions
+ * subproperties of ClientSide are those of the TValidatorClientScript
* properties. The client-side validator supports the following events.
*
* The <tt>OnValidate</tt> event is raise before the validator validation
@@ -513,14 +513,27 @@ abstract class TBaseValidator extends TLabel implements IValidator
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TClientSideValidatorOptions extends TClientSideOptions
+class TValidatorClientScript extends TComponent
{
/**
+ * @var TMap client-side validator event javascript code.
+ */
+ private $_options;
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ $this->_options = new TMap;
+ }
+
+ /**
* @return string javascript code for client-side OnValidate event.
*/
public function getOnValidate()
{
- return $this->getOption('OnValidate');
+ return $this->_options->itemAt['OnValidate'];
}
/**
@@ -530,7 +543,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
*/
public function setOnValidate($javascript)
{
- $this->getOptions()->add('OnValidate', $this->ensureFunction($javascript));
+ $this->_options->add('OnValidate', $this->ensureFunction($javascript));
}
/**
@@ -540,7 +553,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
*/
public function setOnSuccess($javascript)
{
- $this->getOptions()->add('OnSuccess', $this->ensureFunction($javascript));
+ $this->_options->add('OnSuccess', $this->ensureFunction($javascript));
}
/**
@@ -548,7 +561,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
*/
public function getOnSuccess()
{
- return $this->getOption('OnSuccess');
+ return $this->_options->itemAt('OnSuccess');
}
/**
@@ -558,7 +571,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
*/
public function setOnError($javascript)
{
- $this->getOptions()->add('OnError', $this->ensureFunction($javascript));
+ $this->_options->add('OnError', $this->ensureFunction($javascript));
}
/**
@@ -566,7 +579,15 @@ class TClientSideValidatorOptions extends TClientSideOptions
*/
public function getOnError()
{
- return $this->getOption('OnError');
+ return $this->_options->itemAt('OnError');
+ }
+
+ /**
+ * @return array list of client-side event code.
+ */
+ public function getOptions()
+ {
+ return $this->_options->toArray();
}
/**
@@ -576,7 +597,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
* @param string javascript code.
* @return string javascript function code.
*/
- protected function ensureFunction($javascript)
+ private function ensureFunction($javascript)
{
if(TJavascript::isFunction($javascript))
return $javascript;
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
index 49951e89..87821292 100644
--- a/framework/Web/UI/WebControls/TValidationSummary.php
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -37,9 +37,9 @@
class TValidationSummary extends TWebControl
{
/**
- * @var TClientSideValidationSummaryOptions validation client side options.
+ * @var TValidatorClientScript validator client-script options.
*/
- private $_clientSide;
+ private $_clientScript;
/**
* Constructor.
@@ -248,30 +248,30 @@ class TValidationSummary extends TWebControl
$options['ValidationGroup'] = $this->getValidationGroup();
$options['Display'] = $this->getDisplay();
- if(!is_null($this->_clientSide))
- $options = array_merge($options,$this->_clientSide->getOptions()->toArray());
+ if(!is_null($this->_clientScript))
+ $options = array_merge($options,$this->_clientScript->getOptions());
return $options;
}
/**
- * @return TClientSideValidationSummaryOptions client-side validation summary
+ * @return TValidationSummaryClientScript client-side validation summary
* event options.
*/
public function getClientSide()
{
- if(is_null($this->_clientSide))
- $this->_clientSide = $this->createClientScript();
- return $this->_clientSide;
+ if(is_null($this->_clientScript))
+ $this->_clientScript = $this->createClientScript();
+ return $this->_clientScript;
}
/**
- * @return TClientSideValidationSummaryOptions javascript validation summary
+ * @return TValidationSummaryClientScript javascript validation summary
* event options.
*/
protected function createClientScript()
{
- return new TClientSideValidationSummaryOptions;
+ return new TValidationSummaryClientScript;
}
/**
* Get the list of validation error messages.
@@ -372,7 +372,7 @@ class TValidationSummary extends TWebControl
}
/**
- * TClientSideValidationSummaryOptions class.
+ * TValidationSummaryClientScript class.
*
* Client-side validation summary events such as {@link setOnHideSummary
* OnHideSummary} and {@link setOnShowSummary OnShowSummary} can be modified
@@ -392,14 +392,27 @@ class TValidationSummary extends TWebControl
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TClientSideValidationSummaryOptions extends TClientSideOptions
+class TValidationSummaryClientScript extends TComponent
{
/**
+ * @var TMap client-side validation summary event javascript code.
+ */
+ private $_options;
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ $this->_options = new TMap;
+ }
+
+ /**
* @return string javascript code for client-side OnHideSummary event.
*/
public function getOnHideSummary()
{
- return $this->getOption('OnHideSummary');
+ return $this->_options->itemAt['OnHideSummary'];
}
/**
@@ -410,7 +423,7 @@ class TClientSideValidationSummaryOptions extends TClientSideOptions
*/
public function setOnHideSummary($javascript)
{
- $this->getOptions()->add('OnHideSummary', $this->ensureFunction($javascript));
+ $this->_options->add('OnHideSummary', $this->ensureFunction($javascript));
}
/**
@@ -421,7 +434,7 @@ class TClientSideValidationSummaryOptions extends TClientSideOptions
*/
public function setOnShowSummary($javascript)
{
- $this->getOptions()->add('OnShowSummary', $this->ensureFunction($javascript));
+ $this->_options->add('OnShowSummary', $this->ensureFunction($javascript));
}
/**
@@ -429,7 +442,15 @@ class TClientSideValidationSummaryOptions extends TClientSideOptions
*/
public function getOnShowSummary()
{
- return $this->getOption('OnShowSummary');
+ return $this->_options->itemAt('OnShowSummary');
+ }
+
+ /**
+ * @return array list of client-side event code.
+ */
+ public function getOptions()
+ {
+ return $this->_options->toArray();
}
/**
@@ -439,7 +460,7 @@ class TClientSideValidationSummaryOptions extends TClientSideOptions
* @param string javascript code.
* @return string javascript function code.
*/
- protected function ensureFunction($javascript)
+ private function ensureFunction($javascript)
{
if(TJavascript::isFunction($javascript))
return $javascript;