summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes6
-rw-r--r--demos/quickstart/protected/pages/Controls/Repeater.page13
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php28
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.tpl34
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.page20
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.page8
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php6
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.page16
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.page27
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php37
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.page18
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php52
-rw-r--r--framework/Web/UI/WebControls/THyperLink.php36
13 files changed, 272 insertions, 29 deletions
diff --git a/.gitattributes b/.gitattributes
index 148ed720..dfb8291c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1098,12 +1098,18 @@ demos/quickstart/protected/pages/Controls/Samples/TRangeValidator/Home.page -tex
demos/quickstart/protected/pages/Controls/Samples/TRangeValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php -text
+demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php -text
+demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.tpl -text
demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.page -text
demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.php -text
demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.page -text
demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php -text
demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.page -text
demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.php -text
+demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.page -text
+demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php -text
+demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.page -text
+demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php -text
demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TSafeHtml/Home.page -text
diff --git a/demos/quickstart/protected/pages/Controls/Repeater.page b/demos/quickstart/protected/pages/Controls/Repeater.page
index 69c6cdba..1e2ac881 100644
--- a/demos/quickstart/protected/pages/Controls/Repeater.page
+++ b/demos/quickstart/protected/pages/Controls/Repeater.page
@@ -11,7 +11,7 @@ The layout of the repeated contents are specified by inline templates. In partic
</p>
<p id="600402" class="block-content">
-Since v3.1.0, the layout can also be specified by <i>renderers</i>. A renderer is a control class that can be instantiated as repeater items, header, etc. A renderer can thus be viewed as an external template (in fact, it can also be non-templated controls). A renderer can be any control class. If implemented with one of the following interfaces, a renderer will be initialized with additional properties relevant to the repeater items:
+Since v3.1.0, the layout can also be specified by <i>renderers</i>. A renderer is a control class that can be instantiated as repeater items, header, etc. A renderer can thus be viewed as an external template (in fact, it can also be non-templated controls). A renderer can be any control class. By using item renderers, one can avoid writing long and messy templates. Since a renderer is a class, it also helps reusing templates that previously might be embedded within other templates. If implemented with one of the following interfaces, a renderer will be initialized with additional properties relevant to the repeater items:
</p>
<ul id="u1" class="block-content">
@@ -99,4 +99,15 @@ See in the following yet another example showing how to use repeater to collect
</p>
<com:RunBar PagePath="Controls.Samples.TRepeater.Sample3" />
+<p id="600414" class="block-content">
+This sample shows how to use "drop-in" item renderers, available since v3.1.0. These renderers come in the PRADO release. They are essentially controls implementing the <tt>IDataRenderer</tt> interface. Common Web controls, such as <tt>TTextBox</tt>, <tt>TLabel</tt>, all implement this interface. When such controls are used item renderers, their <tt>Data</tt> property is assigned with the row of the data being bound to the repeater item.
+</p>
+<com:RunBar PagePath="Controls.Samples.TRepeater.Sample4" />
+
+<p id="600415" class="block-content">
+More often, one needs to customize the layout of repeater items. The sample above relies on <tt>OnItemCreated</tt> to adjust the appearance of the renderer. Templated item renderers are perferred in this situation, as they allow us to put in more complex layout and content in a repeater item. The following sample reimplements the nested repeater sample using a templated item renderer called <tt>RegionDisplay</tt>. As we can see, the new code is much easier to understand and maintain.
+</p>
+<com:RunBar PagePath="Controls.Samples.TRepeater.Sample5" />
+
+
<div class="last-modified">$Id$</div></com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php
new file mode 100644
index 00000000..40d1841e
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php
@@ -0,0 +1,28 @@
+<?php
+
+class RegionDisplay extends TRepeaterItemRenderer
+{
+ /**
+ * This method is invoked when the data is being bound
+ * to the parent repeater.
+ * At this time, the <b>Data</b> is available which
+ * refers to the data row associated with the parent repeater item.
+ */
+ public function onDataBinding($param)
+ {
+ parent::onDataBinding($param);
+ $this->Repeater->DataSource=$this->Data['detail'];
+ $this->Repeater->dataBind();
+ }
+
+ public function itemCreated($sender,$param)
+ {
+ static $itemIndex=0;
+ $item=$param->Item;
+ if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
+ $item->Row->BackColor=$itemIndex%2 ? "#BFCFFF" : "#E6ECFF";
+ $itemIndex++;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.tpl b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.tpl
new file mode 100644
index 00000000..0d0e46d3
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.tpl
@@ -0,0 +1,34 @@
+<tr>
+<com:TTableCell ID="Cell"
+ ForeColor="white"
+ BackColor="<%# $this->ItemIndex%2 ? '#6078BF' : '#809FFF' %>"
+ Text="<%#$this->Data['name'] %>"
+ />
+<td>
+
+<com:TRepeater ID="Repeater" OnItemCreated="itemCreated">
+<prop:HeaderTemplate>
+<table cellspacing="1">
+</prop:HeaderTemplate>
+
+<prop:ItemTemplate>
+<com:TTableRow ID="Row">
+ <com:TTableCell Width="70px">
+ <%#$this->Data['name'] %>
+ </com:TTableCell>
+ <com:TTableCell Width="20">
+ <%#$this->Data['age'] %>
+ </com:TTableCell>
+ <com:TTableCell Width="150px">
+ <%#$this->Data['position'] %>
+ </com:TTableCell>
+</com:TTableRow>
+</prop:ItemTemplate>
+
+<prop:FooterTemplate>
+</table>
+</prop:FooterTemplate>
+</com:TRepeater>
+
+</td>
+</tr>
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.page b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.page
index e3b3f6bd..e05d51bb 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.page
@@ -17,21 +17,21 @@
<prop:ItemTemplate>
<tr style="background-color:#BFCFFF">
-<td><%#$this->DataItem['id']%></td>
-<td><%#$this->DataItem['name']%></td>
-<td><%#$this->DataItem['quantity']%></td>
-<td><%#$this->DataItem['price']%></td>
-<td><%#$this->DataItem['imported']?'Yes':'No'%></td>
+<td><%#$this->Data['id']%></td>
+<td><%#$this->Data['name']%></td>
+<td><%#$this->Data['quantity']%></td>
+<td><%#$this->Data['price']%></td>
+<td><%#$this->Data['imported']?'Yes':'No'%></td>
</tr>
</prop:ItemTemplate>
<prop:AlternatingItemTemplate>
<tr style="background-color:#E6ECFF">
-<td><%#$this->DataItem['id']%></td>
-<td><%#$this->DataItem['name']%></td>
-<td><%#$this->DataItem['quantity']%></td>
-<td><%#$this->DataItem['price']%></td>
-<td><%#$this->DataItem['imported']?'Yes':'No'%></td>
+<td><%#$this->Data['id']%></td>
+<td><%#$this->Data['name']%></td>
+<td><%#$this->Data['quantity']%></td>
+<td><%#$this->Data['price']%></td>
+<td><%#$this->Data['imported']?'Yes':'No'%></td>
</tr>
</prop:AlternatingItemTemplate>
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.page b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.page
index d1d75dc5..bd0e328a 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.page
@@ -14,7 +14,7 @@
<prop:ItemTemplate>
<tr>
<com:TTableCell ID="Cell">
- <%#$this->DataItem %>
+ <%#$this->Data %>
</com:TTableCell>
<td>
<com:TRepeater
@@ -29,13 +29,13 @@
<prop:ItemTemplate>
<com:TTableRow ID="Row">
<com:TTableCell Width="70px">
- <%#$this->DataItem['name'] %>
+ <%#$this->Data['name'] %>
</com:TTableCell>
<com:TTableCell Width="20">
- <%#$this->DataItem['age'] %>
+ <%#$this->Data['age'] %>
</com:TTableCell>
<com:TTableCell Width="150px">
- <%#$this->DataItem['position'] %>
+ <%#$this->Data['position'] %>
</com:TTableCell>
</com:TTableRow>
</prop:ItemTemplate>
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php
index 96096a8a..e84580a2 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php
@@ -60,8 +60,8 @@ class Sample2 extends TPage
{
$item->Cell->BackColor=$itemIndex%2 ? "#6078BF" : "#809FFF";
$item->Cell->ForeColor='white';
+ $itemIndex++;
}
- $itemIndex++;
}
public function repeater2ItemCreated($sender,$param)
@@ -69,8 +69,10 @@ class Sample2 extends TPage
static $itemIndex=0;
$item=$param->Item;
if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
+ {
$item->Row->BackColor=$itemIndex%2 ? "#BFCFFF" : "#E6ECFF";
- $itemIndex++;
+ $itemIndex++;
+ }
}
}
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.page b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.page
index c826420f..d90af751 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.page
@@ -19,7 +19,7 @@ The following example allows users to modify the existing tabular data using a <
<td>
<com:TTextBox
ID="ProductName"
- Text=<%#$this->DataItem['name']%> />
+ Text=<%#$this->Data['name']%> />
</td>
<td>
<com:TDropDownList
@@ -29,12 +29,12 @@ The following example allows users to modify the existing tabular data using a <
<com:TTextBox
ID="ProductPrice"
Columns="7"
- Text=<%#$this->DataItem['price']%> />
+ Text=<%#$this->Data['price']%> />
</td>
<td>
<com:TCheckBox
ID="ProductImported"
- Checked=<%#$this->DataItem['imported']%> />
+ Checked=<%#$this->Data['imported']%> />
<com:TRequiredFieldValidator
ControlToValidate="ProductName"
ErrorMessage="Product name cannot be empty."
@@ -70,11 +70,11 @@ The following example allows users to modify the existing tabular data using a <
<prop:ItemTemplate>
<tr style="<%# 'background-color:' . ($this->ItemIndex%2 ? '#BFCFFF' : '#E6ECFF') %>">
-<td><%#$this->DataItem['id']%></td>
-<td><%#$this->DataItem['name']%></td>
-<td><%#$this->DataItem['category']%></td>
-<td><%#$this->DataItem['price']%></td>
-<td><%#$this->DataItem['imported']?'Yes':'No'%></td>
+<td><%#$this->Data['id']%></td>
+<td><%#$this->Data['name']%></td>
+<td><%#$this->Data['category']%></td>
+<td><%#$this->Data['price']%></td>
+<td><%#$this->Data['imported']?'Yes':'No'%></td>
</tr>
</prop:ItemTemplate>
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.page b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.page
new file mode 100644
index 00000000..3a3c5ec1
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.page
@@ -0,0 +1,27 @@
+<com:TContent ID="body">
+
+<h1>TRepeater Sample 4</h1>
+
+<p>Please enter the URL of your favorite websites in the following:</p>
+<com:TRepeater ID="Repeater"
+ OnItemCreated="itemCreated"
+ ItemRenderer="TTextBox"
+ />
+
+<br/>
+
+<com:TButton Text="Submit" OnClick="buttonClicked" />
+
+<br/><br/>
+
+<com:TLabel Text="You have entered the following URLs:"
+ Visible="<%= $this->IsPostBack %>" />
+<br/>
+
+<com:TRepeater ID="Repeater2"
+ OnItemCreated="itemCreated"
+ ItemRenderer="THyperLink"
+ />
+
+
+<div class="last-modified">$Id$</div></com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php
new file mode 100644
index 00000000..aabab157
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php
@@ -0,0 +1,37 @@
+<?php
+
+Prado::using('System.Collections.TDummyDataSource');
+
+class Sample4 extends TPage
+{
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ // use a dummy data source to create 3 repeater items
+ $this->Repeater->DataSource=new TDummyDataSource(3);
+ $this->Repeater->dataBind();
+ }
+ }
+
+ public function itemCreated($sender,$param)
+ {
+ // $param->Item refers to the newly created repeater item
+ $param->Item->Style="width:300px; margin:10px; margin-left:0px";
+ }
+
+ public function buttonClicked($sender,$param)
+ {
+ $links=array();
+ foreach($this->Repeater->Items as $textBox)
+ {
+ if($textBox->Text!=='')
+ $links[]=$textBox->Text;
+ }
+ $this->Repeater2->DataSource=$links;
+ $this->Repeater2->dataBind();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.page b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.page
new file mode 100644
index 00000000..fa7254bd
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.page
@@ -0,0 +1,18 @@
+<com:TContent ID="body">
+
+<h1>TRepeater Sample 5</h1>
+
+<com:TRepeater ID="Repeater"
+ ItemRenderer="Application.pages.Controls.Samples.TRepeater.RegionDisplay">
+
+<prop:HeaderTemplate>
+<table cellspacing="1" style="border:1px solid silver">
+</prop:HeaderTemplate>
+
+<prop:FooterTemplate>
+</table>
+</prop:FooterTemplate>
+
+</com:TRepeater>
+
+<div class="last-modified">$Id: $</div></com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php
new file mode 100644
index 00000000..60beb30e
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php
@@ -0,0 +1,52 @@
+<?php
+
+class Sample5 extends TPage
+{
+ protected function getData()
+ {
+ return array(
+ array(
+ 'name'=>'North',
+ 'detail'=>array(
+ array('name'=>'John','age'=>30,'position'=>'Program Manager'),
+ array('name'=>'Edward','age'=>35,'position'=>'Developer'),
+ array('name'=>'Walter','age'=>28,'position'=>'Developer'),
+ ),
+ ),
+ array(
+ 'name'=>'West',
+ 'detail'=>array(
+ array('name'=>'Cary','age'=>31,'position'=>'Senior Manager'),
+ array('name'=>'Ted','age'=>25,'position'=>'Developer'),
+ array('name'=>'Kevin','age'=>28,'position'=>'Developer'),
+ ),
+ ),
+ array(
+ 'name'=>'East',
+ 'detail'=>array(
+ array('name'=>'Shawn','age'=>30,'position'=>'Sales Manager'),
+ array('name'=>'Larry','age'=>28,'position'=>'Document Writer'),
+ ),
+ ),
+ array(
+ 'name'=>'South',
+ 'detail'=>array(
+ array('name'=>'King','age'=>30,'position'=>'Program Manager'),
+ array('name'=>'Carter','age'=>22,'position'=>'Developer'),
+ ),
+ ),
+ );
+ }
+
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $this->Repeater->DataSource=$this->getData();
+ $this->Repeater->dataBind();
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/THyperLink.php b/framework/Web/UI/WebControls/THyperLink.php
index af28acef..13a9ab41 100644
--- a/framework/Web/UI/WebControls/THyperLink.php
+++ b/framework/Web/UI/WebControls/THyperLink.php
@@ -27,7 +27,7 @@
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class THyperLink extends TWebControl
+class THyperLink extends TWebControl implements IDataRenderer
{
/**
* @return string tag name of the hyperlink
@@ -63,16 +63,18 @@ class THyperLink extends TWebControl
{
if(($text=$this->getText())!=='')
$writer->write(THttpUtility::htmlEncode($text));
- else
+ else if($this->getHasControls())
parent::renderContents($writer);
+ else
+ $writer->write(THttpUtility::htmlEncode($this->getNavigateUrl()));
}
else
{
$this->createImage($imageUrl)->renderControl($writer);
}
}
-
- /**
+
+ /**
* Gets the TImage for rendering the ImageUrl property. This is not for
* creating dynamic images.
* @param string image url.
@@ -141,6 +143,32 @@ class THyperLink extends TWebControl
}
/**
+ * Returns the URL to link to when the THyperLink component is clicked.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getNavigateUrl()}.
+ * @return string the URL to link to when the THyperLink component is clicked
+ * @see getNavigateUrl
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getNavigateUrl();
+ }
+
+ /**
+ * Sets the URL to link to when the THyperLink component is clicked.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setNavigateUrl()}.
+ * @param string the URL to link to when the THyperLink component is clicked
+ * @see setNavigateUrl
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setNavigateUrl($value);
+ }
+
+ /**
* @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
*/
public function getTarget()