diff options
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 355 | ||||
-rw-r--r-- | framework/Web/UI/TControl.php | 7 | ||||
-rw-r--r-- | framework/Web/UI/TPage.php | 4 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TBaseValidator.php | 5 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TBulletedList.php | 90 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TButton.php | 42 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TCheckBox.php | 22 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/THead.php | 4 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TJavascriptLogger.php | 2 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TLinkButton.php | 32 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TListControl.php | 16 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TPanel.php | 4 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRadioButton.php | 7 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TSafeHtml.php | 42 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TTextBox.php | 19 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TValidationSummary.php | 9 |
16 files changed, 243 insertions, 417 deletions
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index c5b828dc..72b4ce21 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -70,127 +70,77 @@ class TPostBackOptions extends TComponent } } +Prado::using('System.Web.Javascripts.*'); + class TClientScriptManager extends TComponent { const SCRIPT_DIR='Web/Javascripts/js'; - const POSTBACK_FUNC='Prado.doPostBack'; + //const POSTBACK_FUNC='Prado.doPostBack'; + private $_page; private $_hiddenFields=array(); private $_beginScripts=array(); private $_endScripts=array(); private $_scriptFiles=array(); - private $_headScriptFiles=array(); - private $_headScripts=array(); + + //private $_headScriptFiles=array(); + //private $_headScripts=array(); + private $_styleSheetFiles=array(); private $_styleSheets=array(); - private $_onSubmitStatements=array(); + + private $_client; + + /*private $_onSubmitStatements=array(); private $_arrayDeclares=array(); private $_expandoAttributes=array(); private $_postBackScriptRegistered=false; private $_focusScriptRegistered=false; private $_scrollScriptRegistered=false; + */ + private $_publishedScriptFiles=array(); + public function __construct(TPage $owner) { $this->_page=$owner; + $this->_client = new TClientScript($this); } - - public function getPostBackEventReference($control,$parameter='',$options=null,$javascriptPrefix=true) + + + public function registerPostBackControl($control,$namespace='Prado.WebUI') { - if(!$options || (!$options->getPerformValidation() && !$options->getTrackFocus() && $options->getClientSubmit() && $options->getActionUrl()=='')) - { - $this->registerPostBackScript(); - if(($form=$this->_page->getForm())!==null) - $formID=$form->getClientID(); - else - throw new TConfigurationException('clientscriptmanager_form_required'); - $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.='false'; - if(!$flag) - return ''; - $this->registerPostBackScript(); - if(($form=$this->_page->getForm())!==null) - $formID=$form->getClientID(); - else - throw new TConfigurationException('clientscriptmanager_form_required'); - $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; + $options = $this->getPostBackOptions($control); + $type = get_class($control); + $code = "new {$namespace}.{$type}($options);"; + $this->registerEndScript(sprintf('%08X', crc32($code)), $code); + + $this->registerHiddenField(TPage::FIELD_POSTBACK_TARGET,''); + $this->registerHiddenField(TPage::FIELD_POSTBACK_PARAMETER,''); + $this->registerClientScript('prado'); } - /*public function registerPradoScript($script) + protected function getPostBackOptions($control) { - foreach(TPradoClientScript::getScripts($script) as $scriptFile) - { - if(isset($this->_publishedScriptFiles[$scriptFile])) - $url=$this->_publishedScriptFiles[$scriptFile]; - else - { - $base = Prado::getFrameworkPath(); - $clientScripts = self::SCRIPT_DIR; - $file = "{$base}/{$clientScripts}/{$scriptFile}.js"; - $assetManager = $this->_page->getService()->getAssetManager(); - $url= $assetManager->publishFilePath($file); - $this->_publishedScriptFiles[$scriptFile]=$url; - $this->registerScriptFile('prado:'.$scriptFile,$url); - } - } - //return $url; - }*/ + $postback = $control->getPostBackOptions(); + if(!isset($postback['ID'])) + $postback['ID'] = $control->getClientID(); + if(!isset($postback['FormID'])) + $postback['FormID'] = $this->_page->getForm()->getClientID(); + $options = new TJavascriptSerializer($postback); + return $options->toJavascript(); + } + /** - * Register Prado client scripts. + * Register client scripts. */ - public function registerPradoScript($script) + public function registerClientScript($script) { static $scripts = array(); $scripts = array_unique(array_merge($scripts, - TPradoClientScript::getScripts($script))); + TClientScript::getScripts($script))); $this->publishClientScriptAssets($scripts); @@ -205,7 +155,7 @@ class TClientScriptManager extends TComponent /** * Publish each individual javascript file. */ - private function publishClientScriptAssets($scripts) + protected function publishClientScriptAssets($scripts) { foreach($scripts as $lib) { @@ -224,7 +174,7 @@ class TClientScriptManager extends TComponent /** * @return string URL of the compressor asset script. */ - private function publishClientScriptCompressorAsset() + protected function publishClientScriptCompressorAsset() { $scriptFile = 'clientscripts.php'; if(isset($this->_publishedScriptFiles[$scriptFile])) @@ -241,8 +191,7 @@ class TClientScriptManager extends TComponent } } - - protected function registerPostBackScript() +/* protected function registerPostBackScript() { if(!$this->_postBackScriptRegistered) { @@ -279,12 +228,12 @@ class TClientScriptManager extends TComponent $this->registerPradoScript('prado'); $button = $target->getClientID(); $panel = $source->getClientID(); - return "Event.observe('{$panel}', 'keypress', Prado.Button.fireButton.bindEvent($('{$panel}'), '$button'));"; + return "Event.observe('{$panel}', 'keyup', Prado.Button.fireButton.bindEvent($('{$panel}'), '$button'));"; } public function registerValidationScript() { - } + }*/ public function isHiddenFieldRegistered($key) { @@ -311,7 +260,7 @@ class TClientScriptManager extends TComponent return isset($this->_endScripts[$key]); } - public function isHeadScriptFileRegistered($key) +/* public function isHeadScriptFileRegistered($key) { return isset($this->_headScriptFiles[$key]); } @@ -320,6 +269,7 @@ class TClientScriptManager extends TComponent { return isset($this->_headScripts[$key]); } +*/ public function isStyleSheetFileRegistered($key) { @@ -331,7 +281,7 @@ class TClientScriptManager extends TComponent return isset($this->_styleSheets[$key]); } - public function isOnSubmitStatementRegistered($key) +/* public function isOnSubmitStatementRegistered($key) { return isset($this->_onSubmitStatements[$key]); } @@ -340,7 +290,7 @@ class TClientScriptManager extends TComponent { $this->_arrayDeclares[$name][]=$value; } - +*/ public function registerScriptFile($key,$url) { $this->_scriptFiles[$key]=$url; @@ -353,11 +303,11 @@ class TClientScriptManager extends TComponent $this->_hiddenFields[$name]=$value; } - public function registerOnSubmitStatement($key,$script) +/* public function registerOnSubmitStatement($key,$script) { $this->_onSubmitStatements[$key]=$script; } - +*/ public function registerBeginScript($key,$script) { $this->_beginScripts[$key]=$script; @@ -368,7 +318,7 @@ class TClientScriptManager extends TComponent $this->_endScripts[$key]=$script; } - public function registerHeadScriptFile($key,$url) +/* public function registerHeadScriptFile($key,$url) { $this->_headScriptFiles[$key]=$url; } @@ -377,7 +327,7 @@ class TClientScriptManager extends TComponent { $this->_headScripts[$key]=$script; } - +*/ public function registerStyleSheetFile($key,$url) { $this->_styleSheetFiles[$key]=$url; @@ -388,7 +338,7 @@ class TClientScriptManager extends TComponent $this->_styleSheets[$key]=$css; } - public function registerExpandoAttribute($controlID,$name,$value) +/* public function registerExpandoAttribute($controlID,$name,$value) { $this->_expandoAttributes[$controlID][$name]=$value; } @@ -404,7 +354,7 @@ class TClientScriptManager extends TComponent $writer->write($str); } } - +*/ public function renderScriptFiles($writer) { $str=''; @@ -413,11 +363,11 @@ class TClientScriptManager extends TComponent $writer->write($str); } - public function renderOnSubmitStatements($writer) +/* public function renderOnSubmitStatements($writer) { // ??? } - +*/ public function renderBeginScripts($writer) { if(count($this->_beginScripts)) @@ -448,7 +398,7 @@ class TClientScriptManager extends TComponent $writer->write("<div>\n".$str."</div>\n"); } - public function renderExpandoAttributes($writer) +/* public function renderExpandoAttributes($writer) { if(count($this->_expandoAttributes)) { @@ -468,8 +418,9 @@ class TClientScriptManager extends TComponent $writer->write($str); } } +*/ - public function renderHeadScriptFiles($writer) +/* public function renderHeadScriptFiles($writer) { $str=''; foreach($this->_headScriptFiles as $url) @@ -482,6 +433,7 @@ class TClientScriptManager extends TComponent if(count($this->_headScripts)) $writer->write("<script type=\"text/javascript\">\n//<![CDATA[\n".implode("\n",$this->_headScripts)."\n//]]>\n</script>\n"); } +*/ public function renderStyleSheetFiles($writer) { @@ -504,12 +456,12 @@ class TClientScriptManager extends TComponent return count($this->_hiddenFields)>0; } - public function getHasSubmitStatements() +/* public function getHasSubmitStatements() { return count($this->_onSubmitStatements)>0; } - - public function registerClientEvent($control, $event, $code) +*/ +/* public function registerClientEvent($control, $event, $code) { if(empty($code)) return; $this->registerPradoScript("prado"); @@ -517,7 +469,7 @@ class TClientScriptManager extends TComponent $key = "prado:{$control->ClientID}:{$event}"; $this->registerEndScript($key, $script); } - +*/ /* @@ -532,181 +484,4 @@ class TClientScriptManager extends TComponent */ } -/** - * TJavascript class file. Javascript utilties, converts basic PHP types into - * appropriate javascript types. - * - * Example: - * <code> - * $options['onLoading'] = "doit"; - * $options['onComplete'] = "more"; - * $js = TJavascript::toList($options); - * //expects the following javascript code - * // {'onLoading':'doit','onComplete':'more'} - * </code> - * - * Namespace: System.Web.UI - * - * @author Wei Zhuo<weizhuo[at]gmail[dot]com> - * @version $Revision: 1.3 $ $Date: 2005/11/10 23:43:26 $ - * @package System.Web.UI - */ -class TJavascript -{ - /** - * Coverts PHP arrays (only the array values) into javascript array. - * @param array the array data to convert - * @param string append additional javascript array data - * @param boolean if true empty string and empty array will be converted - * @return string javascript array as string. - */ - public static function toArray($array,$append=null,$strict=false) - { - $results = array(); - $converter = new TJavascript(); - foreach($array as $v) - { - if($strict || (!$strict && $v !== '' && $v !== array())) - { - $type = 'to_'.gettype($v); - if($type == 'to_array') - $results[] = $converter->toArray($v, $append, $strict); - else - $results[] = $converter->{$type}($v); - } - } - $extra = ''; - if(strlen($append) > 0) - $extra .= count($results) > 0 ? ','.$append : $append; - return '['.implode(',', $results).$extra.']'; - } - - /** - * Coverts PHP arrays (both key and value) into javascript objects. - * @param array the array data to convert - * @param string append additional javascript object data - * @param boolean if true empty string and empty array will be converted - * @return string javascript object as string. - */ - public static function toList($array,$append=null, $strict=false) - { - $results = array(); - $converter = new TJavascript(); - foreach($array as $k => $v) - { - if($strict || (!$strict && $v !== '' && $v !== array())) - { - $type = 'to_'.gettype($v); - if($type == 'to_array') - $results[] = "'{$k}':".$converter->toList($v, $append, $strict); - else - $results[] = "'{$k}':".$converter->{$type}($v); - } - } - $extra = ''; - if(strlen($append) > 0) - $extra .= count($results) > 0 ? ','.$append : $append; - - return '{'.implode(',', $results).$extra.'}'; - } - - public function to_boolean($v) - { - return $v ? 'true' : 'false'; - } - - public function to_integer($v) - { - return "{$v}"; - } - - public function to_double($v) - { - return "{$v}"; - } - - /** - * If string begins with [ and ends ], or begins with { and ends } - * it is assumed to be javascript arrays or objects and no further - * conversion is applied. - */ - public function to_string($v) - { - if(strlen($v)>1) - { - $first = $v{0}; $last = $v{strlen($v)-1}; - if($first == '[' && $last == ']' || - ($first == '{' && $last == '}')) - return $v; - } - return "'".addslashes($v)."'"; - } - - public function to_array($v) - { - return TJavascript::toArray($v); - } - - public function to_null($v) - { - return 'null'; - } -} - -/** - * PradoClientScript class. - * - * Resolves Prado client script dependencies. e.g. TPradoClientScript::getScripts("dom"); - * - * - <b>base</b> basic javascript utilities, e.g. $() - * - <b>dom</b> DOM and Form functions, e.g. $F(inputID) to retrive form input values. - * - <b>effects</b> Effects such as fade, shake, move - * - <b>controls</b> Prado client-side components, e.g. Slider, AJAX components - * - <b>validator</b> Prado client-side validators. - * - <b>ajax</b> Prado AJAX library including Prototype's AJAX and JSON. - * - * Dependencies for each library are automatically resolved. - * - * Namespace: System.Web.UI - * - * @author Wei Zhuo<weizhuo[at]gmail[dot]com> - * @version $Revision: 1.1 $ $Date: 2005/11/06 23:02:33 $ - * @package System.Web.UI - */ -class TPradoClientScript -{ - /** - * Client-side javascript library dependencies - * @var array - */ - protected static $dependencies = array( - 'prado' => array('prado'), - 'effects' => array('prado', 'effects'), - 'ajax' => array('prado', 'effects', 'ajax'), - 'validator' => array('prado', 'validator'), - 'logger' => array('prado', 'logger'), - 'datepicker' => array('prado', 'datepicker'), - 'rico' => array('prado', 'effects', 'ajax', 'rico') - ); - - /** - * Resolve dependencies for the given library. - * @param array list of libraries to load. - * @return array list of libraries including its dependencies. - */ - public static function getScripts($scripts) - { - $files = array(); - if(!is_array($scripts)) $scripts = array($scripts); - foreach($scripts as $script) - { - if(isset(self::$dependencies[$script])) - $files = array_merge($files, self::$dependencies[$script]); - $files[] = $script; - } - $files = array_unique($files); - return $files; - } -} - ?>
\ No newline at end of file diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 26aa5dc4..f9c07a8a 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -1549,6 +1549,13 @@ 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/TPage.php b/framework/Web/UI/TPage.php index 9808e143..ba0d8003 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -737,8 +737,8 @@ class TPage extends TTemplateControl $cs->registerScrollScript($x,$y);
}
$cs->renderHiddenFields($writer);
- $cs->renderArrayDeclarations($writer);
- $cs->renderExpandoAttributes($writer);
+ //$cs->renderArrayDeclarations($writer);
+ //$cs->renderExpandoAttributes($writer);
$cs->renderScriptFiles($writer);
$cs->renderEndScripts($writer);
}
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index e3fc8b2f..9c4dd1be 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -159,7 +159,7 @@ abstract class TBaseValidator extends TLabel implements IValidator $scriptKey = "TBaseValidator"; if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey)) { - $scripts->registerPradoScript('validator'); + $scripts->registerClientScript('validator'); $formID=$this->getPage()->getForm()->getClientID(); $js = "Prado.Validation.AddForm('$formID');"; $scripts->registerEndScript($scriptKey, $js); @@ -179,7 +179,8 @@ abstract class TBaseValidator extends TLabel implements IValidator $class = get_class($this); $scriptKey = "prado:".$this->getClientID(); $scripts = $this->getPage()->getClientScript(); - $options = TJavascript::toList($this->getClientScriptOptions()); + $serializer = new TJavascriptSerializer($this->getClientScriptOptions()); + $options = $serializer->toJavascript(); $js = "new Prado.Validation(Prado.Validation.{$class}, {$options});"; $scripts->registerEndScript($scriptKey, $js); } diff --git a/framework/Web/UI/WebControls/TBulletedList.php b/framework/Web/UI/WebControls/TBulletedList.php index 8256237d..63183233 100644 --- a/framework/Web/UI/WebControls/TBulletedList.php +++ b/framework/Web/UI/WebControls/TBulletedList.php @@ -48,6 +48,8 @@ class TBulletedList extends TListControl implements IPostBackEventHandler */
private $_postBackOptions;
+ private $_currentRenderItemIndex;
+
/**
* Raises the postback event.
* This method is required by {@link IPostBackEventHandler} interface.
@@ -274,34 +276,12 @@ class TBulletedList extends TListControl implements IPostBackEventHandler switch($this->getDisplayMode())
{
case 'Text':
- if($item->getEnabled())
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- else
- {
- $writer->addAttribute('disabled','disabled');
- $writer->renderBeginTag('span');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- }
- return;
+ return $this->renderTextItem($writer, $item, $index);
case 'HyperLink':
- if(!$this->_isEnabled || !$item->getEnabled())
- $writer->addAttribute('disabled','disabled');
- else
- {
- $writer->addAttribute('href',$item->getValue());
- if(($target=$this->getTarget())!=='')
- $writer->addAttribute('target',$target);
- }
+ $this->renderHyperLinkItem($writer, $item, $index);
break;
case 'LinkButton':
- if(!$this->_isEnabled || !$item->getEnabled())
- $writer->addAttribute('disabled','disabled');
- else
- {
- $postback=$this->getPage()->getClientScript()->getPostBackEventReference($this,"$index",$this->_postBackOptions);
- $writer->addAttribute('href',$postback);
- }
+ $this->renderLinkButtonItem($writer, $item, $index);
}
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
@@ -310,22 +290,62 @@ class TBulletedList extends TListControl implements IPostBackEventHandler $writer->renderEndTag();
}
+ protected function renderTextItem($writer, $item, $index)
+ {
+ if($item->getEnabled())
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ else
+ {
+ $writer->addAttribute('disabled','disabled');
+ $writer->renderBeginTag('span');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ }
+ }
+
+ protected function renderHyperLinkItem($writer, $item, $index)
+ {
+ if(!$this->_isEnabled || !$item->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ else
+ {
+ $writer->addAttribute('href',$item->getValue());
+ if(($target=$this->getTarget())!=='')
+ $writer->addAttribute('target',$target);
+ }
+ }
+
+ protected function renderLinkButtonItem($writer, $item, $index)
+ {
+ if(!$this->_isEnabled || !$item->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ else
+ {
+ $this->_currentRenderItemIndex = $index;
+ $this->getPage()->getClientScript()->registerPostbackControl($this);
+ $writer->addAttribute('id', $this->getClientID().$index);
+ $writer->addAttribute('href', "javascript:;//".$this->getClientID().$index);
+ }
+ }
+
/**
* @return TPostBackOptions postback options used for linkbuttons.
*/
- protected function getPostBackOptions()
+ public function getPostBackOptions()
+ {
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['EventParameter'] = $this->_currentRenderItemIndex;
+ $options['ID'] = $this->getClientID().$this->_currentRenderItemIndex;
+ return $options;
+ }
+
+ protected function canCauseValidation()
{
- $option=new TPostBackOptions();
$group = $this->getValidationGroup();
$hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
- if($this->getCausesValidation() && $hasValidators)
- {
- $options->setPerformValidation(true);
- $options->setValidationGroup($this->getValidationGroup());
- return $options;
- }
- else
- return null;
+ return $this->getCausesValidation() && $hasValidators;
}
/**
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php index 0b4f3e37..bffb4009 100644 --- a/framework/Web/UI/WebControls/TButton.php +++ b/framework/Web/UI/WebControls/TButton.php @@ -76,16 +76,8 @@ class TButton extends TWebControl implements IPostBackEventHandler $writer->addAttribute('value',$this->getText());
if($this->getEnabled(true))
{
- $scripts = $this->getPage()->getClientScript();
- if($scripts->isEndScriptRegistered("TBaseValidator"))
- {
- $group = $this->getValidationGroup();
- $group = strlen($group) ? ",'".$group."'" : '';
- $clientID=$this->getClientID();
- //$script = "Prado.Validation.AddTarget('{$uniqueID}'{$group});";
- $script = "Prado.Validation.AddTarget('{$clientID}'{$group});";
- $scripts->registerEndScript("{$uniqueID}:target", $script);
- }
+ if($this->canCauseValidation())
+ $this->getPage()->getClientScript()->registerPostBackControl($this);
}
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
@@ -94,26 +86,26 @@ class TButton extends TWebControl implements IPostBackEventHandler parent::addAttributesToRender($writer);
}
+ protected function canCauseValidation()
+ {
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ return $this->getCausesValidation() && $hasValidators;
+ }
+
/**
* 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.
*/
- protected function getPostBackOptions()
+ public function getPostBackOptions()
{
- $option=new TPostBackOptions();
- $group = $this->getValidationGroup();
- $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
- if($this->getCausesValidation() && $hasValidators)
- {
- $option->setPerformValidation(true);
- $option->setValidationGroup($group);
- }
- if($this->getPostBackUrl()!=='')
- $option->setActionUrl($this->getPostBackUrl());
- $option->setClientSubmit(!$this->getUseSubmitBehavior());
-
- return $option;
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['PostBackUrl'] = $this->getPostBackUrl();
+ $options['ClientSubmit'] = !$this->getUseSubmitBehavior();
+
+ return $options;
}
/**
diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php index 72d15822..385eca06 100644 --- a/framework/Web/UI/WebControls/TCheckBox.php +++ b/framework/Web/UI/WebControls/TCheckBox.php @@ -349,12 +349,7 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl $page=$this->getPage();
if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- {
- $options = $this->getAutoPostBackOptions();
- $scripts = $page->getClientScript();
- $postback = $scripts->getPostBackEventReference($this,'',$options,false);
- $scripts->registerClientEvent($this, "click", $postback);
- }
+ $page->getClientScript()->registerPostBackControl($this);
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
@@ -370,17 +365,12 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl * Sets the post back options for this textbox.
* @return TPostBackOptions
*/
- protected function getAutoPostBackOptions()
+ public function getPostBackOptions()
{
- $option=new TPostBackOptions();
- $group = $this->getValidationGroup();
- $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
- if($this->getCausesValidation() && $hasValidators)
- {
- $option->setPerformValidation(true);
- $option->setValidationGroup($group);
- }
- $option->setAutoPostBack(true);
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ return $options;
}
}
diff --git a/framework/Web/UI/WebControls/THead.php b/framework/Web/UI/WebControls/THead.php index c3d111de..3cdd19aa 100644 --- a/framework/Web/UI/WebControls/THead.php +++ b/framework/Web/UI/WebControls/THead.php @@ -112,8 +112,8 @@ class THead extends TControl $cs=$page->getClientScript();
$cs->renderStyleSheetFiles($writer);
$cs->renderStyleSheets($writer);
- $cs->renderHeadScriptFiles($writer);
- $cs->renderHeadScripts($writer);
+ $cs->renderScriptFiles($writer);
+ //$cs->renderHeadScripts($writer);
parent::render($writer);
$writer->write("</head>\n");
}
diff --git a/framework/Web/UI/WebControls/TJavascriptLogger.php b/framework/Web/UI/WebControls/TJavascriptLogger.php index d5761a90..48c752e4 100644 --- a/framework/Web/UI/WebControls/TJavascriptLogger.php +++ b/framework/Web/UI/WebControls/TJavascriptLogger.php @@ -54,7 +54,7 @@ class TJavascriptLogger extends TWebControl */
protected function renderContents($writer)
{
- $this->Page->ClientScript->registerPradoScript('logger');
+ $this->Page->ClientScript->registerClientScript('logger');
$info = '(<a href="http://gleepglop.com/javascripts/logger/" target="_blank">more info</a>).';
$usage = 'Press ALT-D (Or CTRL-D on OS X) to toggle the javascript log console';
$writer->write("{$usage} {$info}");
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php index 16d670b3..01441d99 100644 --- a/framework/Web/UI/WebControls/TLinkButton.php +++ b/framework/Web/UI/WebControls/TLinkButton.php @@ -88,12 +88,7 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler //create unique no-op url references
$nop = "javascript:;//".$this->getClientID();
$writer->addAttribute('href', $url ? $url : $nop);
-
- $scripts = $this->getPage()->getClientScript();
- $options = $this->getPostBackOptions();
- $postback = $scripts->getPostBackEventReference($this, '', $options, false);
- $code = "{$postback}; Event.stop(e);";
- $scripts->registerClientEvent($this, "click", $code);
+ $this->getPage()->getClientScript()->registerPostBackControl($this);
}
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
@@ -104,25 +99,14 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler * This method is used by framework and control developers.
* @return TPostBackOptions parameters about how the button defines its postback behavior.
*/
- protected function getPostBackOptions()
+ public function getPostBackOptions()
{
- $flag=false;
-
- $option=new TPostBackOptions();
- $group = $this->getValidationGroup();
- $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
- if($this->getCausesValidation() && $hasValidators)
- {
- $flag=true;
- $options->setPerformValidation(true);
- $options->setValidationGroup($this->getValidationGroup());
- }
- if($this->getPostBackUrl()!=='')
- {
- $flag=true;
- $options->setActionUrl($this->getPostBackUrl());
- }
- return $flag?$options:null;
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['PostBackUrl'] = $this->getPostBackUrl();
+
+ return $options;
}
/**
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index cb740124..537df7c5 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -105,10 +105,11 @@ abstract class TListControl extends TDataBoundControl if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
{
$writer->addAttribute('id',$this->getClientID());
- $options = $this->getAutoPostBackOptions();
+ $this->getPage()->getClientScript()->registerPostBackControl($this);
+ /*$options = $this->getAutoPostBackOptions();
$scripts = $this->getPage()->getClientScript();
$postback = $scripts->getPostBackEventReference($this,'',$options,false);
- $scripts->registerClientEvent($this, "change", $postback);
+ $scripts->registerClientEvent($this, "change", $postback);*/
}
if($this->getEnabled(true) && !$this->getEnabled())
$writer->addAttribute('disabled','disabled');
@@ -118,9 +119,9 @@ abstract class TListControl extends TDataBoundControl /**
* @return TPostBackOptions postback options for JS postback code
*/
- protected function getAutoPostBackOptions()
+ public function getPostBackOptions()
{
- $option=new TPostBackOptions();
+/* $option=new TPostBackOptions();
$group = $this->getValidationGroup();
$hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
if($this->getCausesValidation() && $hasValidators)
@@ -128,8 +129,11 @@ abstract class TListControl extends TDataBoundControl $option->setPerformValidation(true);
$option->setValidationGroup($group);
}
- $option->setAutoPostBack(true);
- return $option;
+ $option->setAutoPostBack(true);*/
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['EventTarget'] = $this->getUniqueID();
+ return $options;
}
/**
diff --git a/framework/Web/UI/WebControls/TPanel.php b/framework/Web/UI/WebControls/TPanel.php index 6661eadb..9eab135e 100644 --- a/framework/Web/UI/WebControls/TPanel.php +++ b/framework/Web/UI/WebControls/TPanel.php @@ -72,11 +72,13 @@ class TPanel extends TWebControl throw new TInvalidDataValueException('panel_defaultbutton_invalid',$butt);
else
{
- $scripts = $this->getPage()->getClientScript();
+ //TODO
+ /*$scripts = $this->getPage()->getClientScript();
$js = $scripts->registerDefaultButtonScript($this,$button);
$clientID=$this->getClientID();
$scripts->registerEndScript($clientID.'defaultButton', $js);
$writer->addAttribute('id',$clientID);
+ $writer->addAttribute('onkeypress', "return false;");*/
}
}
}
diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index a3d4d0c0..d965b64f 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -161,12 +161,7 @@ class TRadioButton extends TCheckBox $page=$this->getPage();
if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- {
- $options = $this->getAutoPostBackOptions();
- $scripts = $page->getClientScript();
- $postback = $scripts->getPostBackEventReference($this,'',$options,false);
- $scripts->registerClientEvent($this, "click", $postback);
- }
+ $page->getClientScript()->registerPostBackControl($this);
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
diff --git a/framework/Web/UI/WebControls/TSafeHtml.php b/framework/Web/UI/WebControls/TSafeHtml.php new file mode 100644 index 00000000..b9f1156c --- /dev/null +++ b/framework/Web/UI/WebControls/TSafeHtml.php @@ -0,0 +1,42 @@ +<?php
+
+Prado::using('System.3rdParty.SafeHtml.TSafeHtmlParser');
+Prado::using('System.IO.TTextWriter');
+
+/**
+ * ${classname}
+ *
+ * ${description}
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
+ * @package ${package}
+ */
+class TSafeHtml extends TControl
+{
+ /**
+ * Renders body content.
+ * This method overrides parent implementation by removing
+ * malicious javascript code from the body content
+ * @param THtmlWriter writer
+ */
+ protected function renderContents($writer)
+ {
+ $textWriter=new TTextWriter;
+ parent::renderContents(new THtmlWriter($textWriter));
+ $writer->write($this->parseSafeHtml($textWriter->flush()));
+ }
+
+ /**
+ * Use SafeHTML to remove malicous javascript from the HTML content.
+ * @param string HTML content
+ * @return string safer HTML content
+ */
+ protected function parseSafeHtml($text)
+ {
+ $renderer = new TSafeHtmlParser();
+ return $renderer->parse($content);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php index 4eb42313..edf74a75 100644 --- a/framework/Web/UI/WebControls/TTextBox.php +++ b/framework/Web/UI/WebControls/TTextBox.php @@ -135,17 +135,18 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable $writer->addAttribute('disabled','disabled');
if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
{
- $writer->addAttribute('id',$this->getClientID());
- $options = $this->getAutoPostBackOptions();
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getPage()->getClientScript()->registerPostBackControl($this);
+ /*$options = $this->getAutoPostBackOptions();
$scripts = $this->getPage()->getClientScript();
$postback = $scripts->getPostBackEventReference($this,'',$options,false);
$scripts->registerClientEvent($this, "change", $postback);
-
+ *
if($this->getTextMode() !== 'MultiLine')
{
$code = "if(Prado.TextBox.handleReturnKey(e)==false) Event.stop(e);";
$scripts->registerClientEvent($this, "keypress", $code);
- }
+ }*/
}
parent::addAttributesToRender($writer);
}
@@ -154,8 +155,14 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable * Sets the post back options for this textbox.
* @return TPostBackOptions
*/
- protected function getAutoPostBackOptions()
+ public function getPostBackOptions()
{
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['TextMode'] = $this->getTextMode();
+ return $options;
+ /*
$option=new TPostBackOptions();
$group = $this->getValidationGroup();
$hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
@@ -164,7 +171,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable $option->setPerformValidation(true);
$option->setValidationGroup($group);
}
- $option->setAutoPostBack(true);
+ $option->setAutoPostBack(true);*/
}
/**
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php index 14cf869d..0ac7584a 100644 --- a/framework/Web/UI/WebControls/TValidationSummary.php +++ b/framework/Web/UI/WebControls/TValidationSummary.php @@ -213,6 +213,12 @@ class TValidationSummary extends TWebControl return $validators;
}
+ protected function addAttributesToRender($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ parent::addAttributesToRender($writer);
+ }
+
/**
* Render the javascript for validation summary.
* @param array list of options for validation summary.
@@ -221,7 +227,8 @@ class TValidationSummary extends TWebControl {
if(!$this->getEnabled(true) || !$this->getEnableClientScript())
return;
- $options = TJavascript::toList($this->getClientScriptOptions());
+ $serializer = new TJavascriptSerializer($this->getClientScriptOptions());
+ $options = $serializer->toJavascript();
$script = "new Prado.Validation.Summary({$options});";
$this->getPage()->getClientScript()->registerEndScript($this->getClientID(), $script);
}
|