summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList
diff options
context:
space:
mode:
Diffstat (limited to 'demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList')
-rw-r--r--demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.page125
-rw-r--r--demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php132
2 files changed, 257 insertions, 0 deletions
diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.page b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.page
new file mode 100644
index 00000000..ebd88424
--- /dev/null
+++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.page
@@ -0,0 +1,125 @@
+<com:TContent ID="body">
+
+<h1>TActiveDataList Sample</h1>
+
+<com:TActiveDataList
+ ID="DataList"
+ DataKeyField="id"
+ OnEditCommand="editItem"
+ OnCancelCommand="cancelItem"
+ OnUpdateCommand="updateItem"
+ OnDeleteCommand="deleteItem"
+ OnSelectedIndexChanged="selectItem"
+ HeaderStyle.BackColor="black"
+ HeaderStyle.ForeColor="white"
+ ItemStyle.BackColor="#BFCFFF"
+ AlternatingItemStyle.BackColor="#E6ECFF"
+ EditItemStyle.BackColor="lightgreen"
+ SelectedItemStyle.BackColor="lightyellow">
+
+<prop:HeaderTemplate>
+<div style="font-weight:bold; text-align:center;">Computer Parts</div>
+</prop:HeaderTemplate>
+
+<prop:ItemTemplate>
+<table border="0" width="100%">
+<tr>
+ <td>
+ <com:TActiveLinkButton
+ Text=<%#$this->DataItem['id']%>
+ CommandName="select"
+ />
+ <%#$this->DataItem['name']%>
+ </td>
+ <td align="right">
+ <com:TActiveLinkButton
+ Text="Edit"
+ CommandName="edit"
+ />
+ <com:TActiveLinkButton
+ Text="Delete"
+ CommandName="delete"
+ Attributes.onclick="if(!confirm('Are you sure?')) return false;"
+ />
+ </td>
+</tr>
+</table>
+</prop:ItemTemplate>
+
+<prop:SelectedItemTemplate>
+<table border="1" width="100%">
+<tr>
+ <th>ID</th><th>Name</th><th>Quantity</th><th>Price</th>
+</tr>
+<tr>
+ <td align="right"><%#$this->DataItem['id'] %></td>
+ <td align="right"><%#$this->DataItem['name'] %></td>
+ <td align="right"><%#$this->DataItem['quantity'] %></td>
+ <td align="right">$<%#$this->DataItem['price'] %></td>
+</tr>
+<tr>
+ <td colspan="4" align="right">
+ <com:TActiveLinkButton
+ Text="Edit"
+ CommandName="edit"
+ />
+ <com:TActiveLinkButton
+ Text="Delete"
+ CommandName="delete"
+ Attributes.onclick="if(!confirm('Are you sure?')) return false;"
+ />
+ </td>
+</tr>
+</table>
+</prop:SelectedItemTemplate>
+
+<prop:EditItemTemplate>
+<table border="0" width="100%">
+<tr>
+ <td align="right">ID</td>
+ <td><b><%#$this->DataItem['id']%></b></td>
+</tr>
+<tr>
+ <td align="right">Name</td>
+ <td><com:TTextBox
+ ID="ProductName"
+ Text=<%#$this->DataItem['name'] %>
+ />
+ </td>
+</tr>
+<tr>
+ <td align="right">Quantity</td>
+ <td><com:TTextBox
+ ID="ProductQuantity"
+ Text=<%#$this->DataItem['quantity'] %>
+ />
+ </td>
+</tr>
+<tr>
+ <td align="right">Price</td>
+ <td><com:TTextBox
+ ID="ProductPrice"
+ Text=<%#$this->DataItem['price'] %>
+ />
+ </td>
+</tr>
+<tr>
+ <td align="right">Imported</td>
+ <td><com:TCheckBox
+ ID="ProductImported"
+ Checked=<%#$this->DataItem['imported'] %>
+ />
+ </td>
+</tr>
+<tr>
+ <td colspan="2" align="right">
+ <com:TActiveLinkButton Text="Save" CommandName="update" />
+ <com:TActiveLinkButton Text="Cancel" CommandName="cancel" />
+ </td>
+</tr>
+</table>
+</prop:EditItemTemplate>
+
+</com:TActiveDataList>
+
+<div class="last-modified">$Id$</div></com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php
new file mode 100644
index 00000000..c62a239d
--- /dev/null
+++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php
@@ -0,0 +1,132 @@
+<?php
+
+class Home extends TPage
+{
+ private $_data=null;
+
+ protected function getData()
+ {
+ if($this->_data===null)
+ $this->loadData();
+ return $this->_data;
+ }
+
+ protected function loadData()
+ {
+ // We use viewstate keep track of data.
+ // In real applications, data should come from database using an SQL SELECT statement.
+ // In the following tabular data, field 'id' is the primary key.
+ // All update and delete operations should come with an 'id' value in order to go through.
+ if(($this->_data=$this->getViewState('Data',null))===null)
+ {
+ $this->_data=array(
+ array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true),
+ array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true),
+ array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>false),
+ array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false),
+ array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true),
+ array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>true),
+ array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>false),
+ );
+ $this->saveData();
+ }
+ }
+
+ protected function saveData()
+ {
+ $this->setViewState('Data',$this->_data);
+ }
+
+ protected function updateProduct($id,$name,$quantity,$price,$imported)
+ {
+ // In real applications, data should be saved to database using an SQL UPDATE statement
+ if($this->_data===null)
+ $this->loadData();
+ $updateRow=null;
+ foreach($this->_data as $index=>$row)
+ if($row['id']===$id)
+ $updateRow=&$this->_data[$index];
+ if($updateRow!==null)
+ {
+ $updateRow['name']=$name;
+ $updateRow['quantity']=TPropertyValue::ensureInteger($quantity);
+ $updateRow['price']=TPropertyValue::ensureFloat($price);
+ $updateRow['imported']=TPropertyValue::ensureBoolean($imported);
+ $this->saveData();
+ }
+ }
+
+ protected function deleteProduct($id)
+ {
+ // In real applications, data should be saved to database using an SQL DELETE statement
+ if($this->_data===null)
+ $this->loadData();
+ $deleteIndex=-1;
+ foreach($this->_data as $index=>$row)
+ if($row['id']===$id)
+ $deleteIndex=$index;
+ if($deleteIndex>=0)
+ {
+ unset($this->_data[$deleteIndex]);
+ $this->saveData();
+ }
+ }
+
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+ }
+
+ public function editItem($sender,$param)
+ {
+ $this->DataList->SelectedItemIndex=-1;
+ $this->DataList->EditItemIndex=$param->Item->ItemIndex;
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+
+ public function cancelItem($sender,$param)
+ {
+ $this->DataList->SelectedItemIndex=-1;
+ $this->DataList->EditItemIndex=-1;
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+
+ public function updateItem($sender,$param)
+ {
+ $item=$param->Item;
+ $this->updateProduct(
+ $this->DataList->DataKeys[$item->ItemIndex],
+ $item->ProductName->Text,
+ $item->ProductQuantity->Text,
+ $item->ProductPrice->Text,
+ $item->ProductImported->Checked);
+ $this->DataList->EditItemIndex=-1;
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+
+ public function deleteItem($sender,$param)
+ {
+ $this->deleteProduct($this->DataList->DataKeys[$param->Item->ItemIndex]);
+ $this->DataList->SelectedItemIndex=-1;
+ $this->DataList->EditItemIndex=-1;
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+
+ public function selectItem($sender,$param)
+ {
+ $this->DataList->EditItemIndex=-1;
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+}
+
+?> \ No newline at end of file