summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord
diff options
context:
space:
mode:
authorwei <>2007-02-06 00:51:41 +0000
committerwei <>2007-02-06 00:51:41 +0000
commitec66b8c2c850c0d415e2e670be18d87dfd091a13 (patch)
treee6e85eca4cfd6e0d577a0065707ad3217209e512 /framework/Data/ActiveRecord
parent2fbf5192a27fa9f7680fdc6b8b8fc54a3638d50f (diff)
Update scaffold edit view to use renderers
Diffstat (limited to 'framework/Data/ActiveRecord')
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php80
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl3
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php16
3 files changed, 80 insertions, 19 deletions
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
index 28fc8fb9..a8faa6c8 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
@@ -6,10 +6,22 @@ Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputBase'
class TScaffoldEditView extends TScaffoldBase
{
private static $_builders=array();
+ private $_editRenderer;
public function onLoad($param)
{
- $this->initializeEditForm();
+ if($this->getVisible())
+ $this->initializeEditForm();
+ }
+
+ public function getEditRenderer()
+ {
+ return $this->getViewState('EditRenderer', '');
+ }
+
+ public function setEditRenderer($value)
+ {
+ $this->setViewState('EditRenderer', $value, '');
}
public function setRecordPk($value)
@@ -31,13 +43,40 @@ class TScaffoldEditView extends TScaffoldBase
public function initializeEditForm()
{
- $this->getCurrentRecord();
- $columns = $this->getTableMetaData()->getColumns();
- $this->_repeater->setDataSource($columns);
- $this->_repeater->dataBind();
+ $record = $this->getCurrentRecord();
+ $classPath = $this->getEditRenderer();
+ if($classPath === '')
+ {
+ $columns = $this->getTableMetaData()->getColumns();
+ $this->getInputRepeater()->setDataSource($columns);
+ $this->getInputRepeater()->dataBind();
+ }
+ else
+ {
+ if($this->_editRenderer===null)
+ $this->createEditRenderer($record, $classPath);
+ else
+ $this->_editRenderer->setData($record);
+ }
}
- public function repeaterItemCreated($sender, $param)
+ protected function createEditRenderer($record, $classPath)
+ {
+ $this->_editRenderer = Prado::createComponent($classPath);
+ if($this->_editRenderer instanceof IScaffoldEditRenderer)
+ {
+ $index = $this->getControls()->remove($this->getInputRepeater());
+ $this->getControls()->insertAt($index,$this->_editRenderer);
+ $this->_editRenderer->setData($record);
+ }
+ else
+ {
+ throw new TConfigurationException(
+ 'scaffold_invalid_edit_renderer', $this->getID(), get_class($record));
+ }
+ }
+
+ protected function repeaterItemCreated($sender, $param)
{
$type = $param->getItem()->getItemType();
if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
@@ -73,17 +112,31 @@ class TScaffoldEditView extends TScaffoldBase
protected function doSave()
{
$record = $this->getCurrentRecord();
- $table = $this->getTableMetaData();
- $builder = $this->getScaffoldInputBuilder($record);
- foreach($this->_repeater->getItems() as $item)
+ if($this->_editRenderer===null)
{
- $column = $table->getColumn($item->getCustomData());
- $builder->loadScaffoldInput($this, $item, $column, $record);
+ $table = $this->getTableMetaData();
+ $builder = $this->getScaffoldInputBuilder($record);
+ foreach($this->getInputRepeater()->getItems() as $item)
+ {
+ $column = $table->getColumn($item->getCustomData());
+ $builder->loadScaffoldInput($this, $item, $column, $record);
+ }
}
+ else
+ {
+ $this->_editRenderer->updateRecord($record);
+ }
+
$record->save();
return true;
}
+ protected function getInputRepeater()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_repeater');
+ }
+
public function getSaveButton()
{
$this->ensureChildControls();
@@ -115,5 +168,10 @@ class TScaffoldEditView extends TScaffoldBase
return 'group_'.$this->getUniqueID();
}
}
+
+interface IScaffoldEditRenderer extends IDataRenderer
+{
+ public function updateRecord($record);
+}
?> \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl
index fd599a20..8cba7ec4 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl
@@ -1,7 +1,8 @@
<div class="edit-inputs">
<com:TRepeater ID="_repeater" onItemCreated="repeaterItemCreated">
<prop:ItemTemplate>
- <div class="edit-item item_<%# $this->ItemIndex % 2 %> input_<%# $this->ItemIndex %>">
+ <div class="edit-item item_<%# $this->ItemIndex % 2 %>
+ input_<%# $this->ItemIndex %> property_<%# $this->DataItem->Property %>">
<com:TLabel ID="_label" CssClass="item-label"/>
<span class="item-input">
<com:TPlaceHolder ID="_input" />
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
index 98c0aab8..35c53473 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
@@ -14,7 +14,7 @@ class TScaffoldListView extends TScaffoldBase
protected function initializeSort()
{
$table = $this->getTableMetaData();
- $sorts = array('Sorty By', str_repeat('-',15));
+ $sorts = array('Sort By', str_repeat('-',15));
$headers = array();
foreach($table->getColumns() as $name=>$colum)
{
@@ -97,19 +97,21 @@ class TScaffoldListView extends TScaffoldBase
protected function listItemCreated($sender, $param)
{
- $type = $param->getItem()->getItemType();
- if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
- $this->populateField($sender, $param);
+ $item = $param->getItem();
+ if($item instanceof IItemDataRenderer)
+ {
+ $type = $item->getItemType();
+ if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
+ $this->populateField($sender, $param);
+ }
}
protected function populateField($sender, $param)
{
$item = $param->getItem();
- $data = $item->getDataItem();
- if($data !== null)
+ if(($data = $item->getData()) !== null)
{
$item->setCustomData($this->getRecordObjectPk($data));
-
if(($prop = $item->findControl('_properties'))!==null)
{
$item->_properties->setDataSource($this->getRecordProperties($data));