summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php5
-rw-r--r--framework/Web/UI/WebControls/TBulletedList.php90
-rw-r--r--framework/Web/UI/WebControls/TButton.php42
-rw-r--r--framework/Web/UI/WebControls/TCheckBox.php22
-rw-r--r--framework/Web/UI/WebControls/THead.php4
-rw-r--r--framework/Web/UI/WebControls/TJavascriptLogger.php2
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php32
-rw-r--r--framework/Web/UI/WebControls/TListControl.php16
-rw-r--r--framework/Web/UI/WebControls/TPanel.php4
-rw-r--r--framework/Web/UI/WebControls/TRadioButton.php7
-rw-r--r--framework/Web/UI/WebControls/TSafeHtml.php42
-rw-r--r--framework/Web/UI/WebControls/TTextBox.php19
-rw-r--r--framework/Web/UI/WebControls/TValidationSummary.php9
13 files changed, 169 insertions, 125 deletions
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);
}