summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/WebControls/TDataBoundControl.php17
-rw-r--r--framework/Web/UI/WebControls/TListControl.php37
-rw-r--r--framework/Web/UI/WebControls/TRepeater.php25
-rw-r--r--framework/Web/UI/WebControls/TTable.php2
-rw-r--r--framework/Web/UI/WebControls/TTextBox.php56
5 files changed, 74 insertions, 63 deletions
diff --git a/framework/Web/UI/WebControls/TDataBoundControl.php b/framework/Web/UI/WebControls/TDataBoundControl.php
index ea2a0602..1108e0f6 100644
--- a/framework/Web/UI/WebControls/TDataBoundControl.php
+++ b/framework/Web/UI/WebControls/TDataBoundControl.php
@@ -192,15 +192,14 @@ abstract class TDataBoundControl extends TWebControl
*/
public function dataBind()
{
- // TODO: databinding should only be raised after data is ready
- // what about property bindings? should they be after data is ready?
$this->setRequiresDataBinding(false);
$this->dataBindProperties();
- if(($view=$this->getDataSourceView())!==null)
- $data=$view->select($this->getSelectParameters());
$this->onDataBinding(null);
- if($view!==null)
+ $data=$this->getData();
+ if($data instanceof Traversable)
$this->performDataBinding($data);
+ else if($data!==null)
+ throw new TInvalidDataTypeException('databoundcontrol_data_nontraversable');
$this->setIsDataBound(true);
$this->onDataBound(null);
}
@@ -211,6 +210,14 @@ abstract class TDataBoundControl extends TWebControl
$this->setRequiresDataBinding(true);
}
+ protected function getData()
+ {
+ if(($view=$this->getDataSourceView())!==null)
+ return $view->select($this->getSelectParameters());
+ else
+ return null;
+ }
+
protected function getDataSourceView()
{
if(!$this->_currentViewValid)
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 7057e119..cb740124 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -156,27 +156,24 @@ abstract class TListControl extends TDataBoundControl
$items=$this->getItems();
if(!$this->getAppendDataBoundItems())
$items->clear();
- if($data instanceof Traversable)
+ $textField=$this->getDataTextField();
+ if($textField==='')
+ $textField=0;
+ $valueField=$this->getDataValueField();
+ if($valueField==='')
+ $valueField=1;
+ $textFormat=$this->getDataTextFormatString();
+ foreach($data as $object)
{
- $textField=$this->getDataTextField();
- if($textField==='')
- $textField=0;
- $valueField=$this->getDataValueField();
- if($valueField==='')
- $valueField=1;
- $textFormat=$this->getDataTextFormatString();
- foreach($data as $object)
- {
- $item=new TListItem;
- if(isset($object[$textField]))
- $text=$object[$textField];
- else
- $text=TPropertyValue::ensureString($object);
- $item->setText($textFormat===''?$text:sprintf($textFormat,$text));
- if(isset($object[$valueField]))
- $item->setValue($object[$valueField]);
- $items->add($item);
- }
+ $item=new TListItem;
+ if(isset($object[$textField]))
+ $text=$object[$textField];
+ else
+ $text=TPropertyValue::ensureString($object);
+ $item->setText($textFormat===''?$text:sprintf($textFormat,$text));
+ if(isset($object[$valueField]))
+ $item->setValue($object[$valueField]);
+ $items->add($item);
}
}
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index c9ecd255..d0d513b0 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -370,22 +370,19 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$items=$this->getItems();
$items->clear();
$itemIndex=0;
- if($data!==null)
+ $hasSeparator=$this->_separatorTemplate!=='';
+ foreach($data as $dataItem)
{
- $hasSeparator=$this->_separatorTemplate!=='';
- foreach($data as $dataItem)
- {
- if($itemIndex===0 && $this->_headerTemplate!=='')
- $this->_header=$this->createItemInternal(-1,'Header',true,null);
- if($hasSeparator && $itemIndex>0)
- $this->createItemInternal($itemIndex-1,'Separator',true,null);
- $itemType=$itemIndex%2==0?'Item':'AlternatingItem';
- $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
- $itemIndex++;
- }
- if($itemIndex>0 && $this->_footerTemplate!=='')
- $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
+ if($itemIndex===0 && $this->_headerTemplate!=='')
+ $this->_header=$this->createItemInternal(-1,'Header',true,null);
+ if($hasSeparator && $itemIndex>0)
+ $this->createItemInternal($itemIndex-1,'Separator',true,null);
+ $itemType=$itemIndex%2==0?'Item':'AlternatingItem';
+ $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
+ $itemIndex++;
}
+ if($itemIndex>0 && $this->_footerTemplate!=='')
+ $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
$this->setViewState('ItemCount',$itemIndex,0);
}
diff --git a/framework/Web/UI/WebControls/TTable.php b/framework/Web/UI/WebControls/TTable.php
index 66485399..13cbd0b1 100644
--- a/framework/Web/UI/WebControls/TTable.php
+++ b/framework/Web/UI/WebControls/TTable.php
@@ -90,7 +90,7 @@ class TTable extends TWebControl
/**
* Creates a style object for the control.
* This method creates a {@link TTableStyle} to be used by the table.
- * @return TStyle control style to be used
+ * @return TTableStyle control style to be used
*/
protected function createStyle()
{
diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php
index dae0ccf8..4eb42313 100644
--- a/framework/Web/UI/WebControls/TTextBox.php
+++ b/framework/Web/UI/WebControls/TTextBox.php
@@ -10,8 +10,6 @@
* @package System.Web.UI.WebControls
*/
-Prado::using('System.3rdParty.SafeHtml.TSafeHtmlParser');
-
/**
* TTextBox class
*
@@ -56,8 +54,14 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
* @var array list of auto complete types
*/
private static $_autoCompleteTypes=array('BusinessCity','BusinessCountryRegion','BusinessFax','BusinessPhone','BusinessState','BusinessStreetAddress','BusinessUrl','BusinessZipCode','Cellular','Company','Department','Disabled','DisplayName','Email','FirstName','Gender','HomeCity','HomeCountryRegion','HomeFax','Homepage','HomePhone','HomeState','HomeStreetAddress','HomeZipCode','JobTitle','LastName','MiddleName','None','Notes','Office','Pager','Search');
-
- protected $_safeContent;
+ /**
+ * @var mixed safe text parser
+ */
+ private static $_safeTextParser=null;
+ /**
+ * @var string safe textbox content with javascript stripped off
+ */
+ private $_safeText;
/**
* @return string tag name of the textbox
@@ -94,7 +98,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
if($textMode==='SingleLine')
{
$writer->addAttribute('type','text');
- if(($text=$this->getRawText())!=='')
+ if(($text=$this->getText())!=='')
$writer->addAttribute('value',$text);
if(($act=$this->getAutoCompleteType())!=='None')
{
@@ -173,7 +177,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
public function loadPostData($key,$values)
{
$value=$values[$key];
- if(!$this->getReadOnly() && $this->getRawText()!==$value)
+ if(!$this->getReadOnly() && $this->getText()!==$value)
{
$this->setText($value);
return true;
@@ -230,7 +234,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
protected function renderContents($writer)
{
if($this->getTextMode()==='MultiLine')
- $writer->write(THttpUtility::htmlEncode($this->getRawText()));
+ $writer->write(THttpUtility::htmlEncode($this->getText()));
}
/**
@@ -362,35 +366,41 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * @return string the unmodified text content of the TTextBox control.
+ * @return string the text content of the TTextBox control.
*/
- public function getRawText()
+ public function getText()
{
return $this->getViewState('Text','');
}
/**
- * @return string safe text content.
+ * Sets the text content of the TTextBox control.
+ * @param string the text content
*/
- public function getText()
+ public function setText($value)
{
- $text = $this->getRawText();
- if(is_null($this->_safeContent))
- {
- $renderer = new TSafeHtmlParser();
- $this->_safeContent = $renderer->parse($text);
- }
- return $this->_safeContent;
+ $this->setViewState('Text',$value,'');
+ $this->_safeText = null;
}
/**
- * Sets the text content of the TTextBox control.
- * @param string the text content
+ * @return string safe text content with javascript stripped off
*/
- public function setText($value)
+ public function getSafeText()
{
- $this->setViewState('Text',$value,'');
- $this->_safeContent = null;
+ if($this->_safeText===null)
+ $this->_safeText=$this->getSafeTextParser()->parse($this->getText());
+ return $this->_safeText;
+ }
+
+ /**
+ * @return mixed safe text parser
+ */
+ protected function getSafeTextParser()
+ {
+ if(!self::$_safeTextParser)
+ self::$_safeTextParser=Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser');
+ return self::$_safeTextParser;
}
/**