summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Scaffold
diff options
context:
space:
mode:
authorwei <>2007-02-12 12:46:11 +0000
committerwei <>2007-02-12 12:46:11 +0000
commitfd4b8d9f45d1707035021bc19b8d5bc17ede66ce (patch)
tree093b8b3f92d4d6421f19a6d1e7c8211817f3d51d /framework/Data/ActiveRecord/Scaffold
parentf4c525abc3d4d3f3eecf1019770936e4ca39fd62 (diff)
Add IBM DB2 driver for active record.
Diffstat (limited to 'framework/Data/ActiveRecord/Scaffold')
-rw-r--r--framework/Data/ActiveRecord/Scaffold/InputBuilder/TMysqlScaffoldInput.php2
-rw-r--r--framework/Data/ActiveRecord/Scaffold/InputBuilder/TPgsqlScaffoldInput.php2
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php115
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php168
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl6
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php85
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldListView.tpl19
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php89
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.tpl4
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldView.php10
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldView.tpl10
-rw-r--r--framework/Data/ActiveRecord/Scaffold/style.css3
12 files changed, 435 insertions, 78 deletions
diff --git a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMysqlScaffoldInput.php b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMysqlScaffoldInput.php
index c6fc6902..89df0f2e 100644
--- a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMysqlScaffoldInput.php
+++ b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMysqlScaffoldInput.php
@@ -2,7 +2,7 @@
Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputCommon');
-class MysqlScaffoldInput extends TScaffoldInputCommon
+class TMysqlScaffoldInput extends TScaffoldInputCommon
{
protected function createControl($container, $column, $record)
{
diff --git a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TPgsqlScaffoldInput.php b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TPgsqlScaffoldInput.php
index 40a14fbc..f5e11eae 100644
--- a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TPgsqlScaffoldInput.php
+++ b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TPgsqlScaffoldInput.php
@@ -2,7 +2,7 @@
Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputCommon');
-class PgsqlScaffoldInput extends ScaffoldInputCommon
+class TPgsqlScaffoldInput extends TScaffoldInputCommon
{
protected function createControl($container, $column, $record)
{
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
index dc464245..b55ceedc 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
@@ -1,12 +1,49 @@
<?php
-
+/**
+ * TScaffoldBase class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+
+/**
+ * Include the base Active Record class.
+ */
Prado::using('System.Data.ActiveRecord.TActiveRecord');
+/**
+ * Base class for Active Record scaffold views.
+ *
+ * Provides common properties for all scaffold views (such as, TScaffoldListView,
+ * TScaffoldEditView, TScaffoldListView and TScaffoldView).
+ *
+ * During the OnPrRender stage the default css style file (filename style.css)
+ * is published and registered. To override the default style, provide your own stylesheet
+ * file explicitly.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
abstract class TScaffoldBase extends TTemplateControl
{
+ /**
+ * @var TActiveRecord record instance (may be new or retrieved from db)
+ */
private $_record;
+ /**
+ * @var TDbMetaData table/view information.
+ */
private $_meta;
+ /**
+ * @return TDbMetaData table/view information
+ */
protected function getTableMetaData()
{
if($this->_meta===null)
@@ -18,7 +55,11 @@ abstract class TScaffoldBase extends TTemplateControl
return $this->_meta;
}
- protected function getRecordProperties($record)
+ /**
+ * @param TActiveRecord record instance
+ * @return array record property values
+ */
+ protected function getRecordPropertyValues($record)
{
$data = array();
foreach($this->getTableMetaData()->getColumns() as $name=>$column)
@@ -26,7 +67,11 @@ abstract class TScaffoldBase extends TTemplateControl
return $data;
}
- public function getRecordObjectPk($record)
+ /**
+ * @param TActiveRecord record instance
+ * @return array record primary key values.
+ */
+ protected function getRecordPkValues($record)
{
$pk = array();
foreach($this->getTableMetaData()->getColumns() as $name=>$column)
@@ -37,76 +82,116 @@ abstract class TScaffoldBase extends TTemplateControl
return $data;
}
+ /**
+ * Name of the Active Record class to be viewed or scaffolded.
+ * @return string Active Record class name.
+ */
public function getRecordClass()
{
return $this->getViewState('RecordClass');
}
+ /**
+ * Name of the Active Record class to be viewed or scaffolded.
+ * @param string Active Record class name.
+ */
public function setRecordClass($value)
{
$this->setViewState('RecordClass', $value);
}
- public function copyFrom(TScaffoldBase $obj)
+ /**
+ * Copy the view details from another scaffold view instance.
+ * @param TScaffoldBase scaffold view.
+ */
+ protected function copyFrom(TScaffoldBase $obj)
{
$this->_record = $obj->_record;
$this->_meta = $obj->_meta;
$this->setRecordClass($obj->getRecordClass());
}
+ /**
+ * Unset the current record instance and table information.
+ */
protected function clearRecordObject()
{
$this->_record=null;
$this->_meta=null;
}
- public function getRecordObject($pk=null)
+ /**
+ * Gets the current Active Record instance. Creates new instance if the
+ * primary key value is null otherwise the record is fetched from the db.
+ * @param array primary key value
+ * @return TActiveRecord record instance
+ */
+ protected function getRecordObject($pk=null)
{
if($this->_record===null)
{
if($pk!==null)
+ {
$this->_record=$this->getRecordFinder()->findByPk($pk);
+ if($this->_record===null)
+ throw new TConfigurationException('scaffold_invalid_record_pk',
+ $this->getRecordClass(), $pk);
+ }
else
{
$class = $this->getRecordClass();
if($class!==null)
$this->_record=Prado::createComponent($class);
else
- throw new TConfigurationException('scaffold_invalid_record_class', $this->getID());
+ {
+ throw new TConfigurationException('scaffold_invalid_record_class',
+ $this->getRecordClass(),$this->getID());
+ }
}
}
return $this->_record;
}
- public function getRecordFinder()
+ /**
+ * @param TActiveRecord Active Record instance.
+ */
+ protected function setRecordObject(TActiveRecord $value)
{
- return TActiveRecord::getRecordFinder(get_class($this->getRecordObject()));
+ $this->_record=$value;
}
- public function setRecordObject($value)
+ /**
+ * @return TActiveRecord Active Record finder instance
+ */
+ protected function getRecordFinder()
{
- if($value instanceof TActiveRecord)
- $this->_record=$value;
- else
- throw new TConfigurationException('scaffold_object_must_be_tactiverecord', $this->getID());
+ return TActiveRecord::getRecordFinder($this->getRecordClass());
}
+ /**
+ * @return string default scaffold stylesheet name
+ */
public function getDefaultStyle()
{
return $this->getViewState('DefaultStyle', 'style');
}
+ /**
+ * @param string default scaffold stylesheet name
+ */
public function setDefaultStyle($value)
{
$this->setViewState('DefaultStyle', TPropertyValue::ensureString($value), 'style');
}
+ /**
+ * Publish the default stylesheet file.
+ */
public function onPreRender($param)
{
parent::onPreRender($param);
$url = $this->publishAsset($this->getDefaultStyle().'.css');
- $cs = $this->getPage()->getClientScript();
- $cs->registerStyleSheetFile($url,$url);
+ $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
}
}
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
index a8faa6c8..a792aeb9 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
@@ -1,29 +1,82 @@
<?php
+/**
+ * TScaffoldEditView class and IScaffoldEditRenderer interface file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+/**
+ * Load scaffold base.
+ */
Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
-Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputBase');
+/**
+ * Template control for editing an Active Record instance.
+ *
+ * The default editor input controls are created based on the column types.
+ *
+ * The editor layout can be specified by a renderer. A renderer is an external
+ * template control that implements IScaffoldEditRenderer.
+ *
+ * The <b>Data</b> of the IScaffoldEditRenderer will be set as the current Active
+ * Record to be edited. The <b>UpdateRecord()</b> method of IScaffoldEditRenderer
+ * is called when request to save the record is requested.
+ *
+ * Validators in the custom external editor template should have the
+ * {@link TBaseValidator::setValidationGroup ValidationGroup} property set to the
+ * value of the {@link getValidationGroup} of the TScaffoldEditView instance
+ * (the edit view instance is the <b>Parent</b> of the IScaffoldEditRenderer in most
+ * cases.
+ *
+ * The <b>RecordClass</b> determines the Active Record class to be edited.
+ * A particular record can be edited by specifying the {@link setRecordPk RecordPk}
+ * value (may be an array for composite keys).
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
class TScaffoldEditView extends TScaffoldBase
{
- private static $_builders=array();
+ /**
+ * @var IScaffoldEditRenderer custom scaffold edit renderer
+ */
private $_editRenderer;
+ /**
+ * Initialize the editor form if it is Visible.
+ */
public function onLoad($param)
{
if($this->getVisible())
$this->initializeEditForm();
}
+ /**
+ * @return string the class name for scaffold editor. Defaults to empty, meaning not set.
+ */
public function getEditRenderer()
{
return $this->getViewState('EditRenderer', '');
}
+ /**
+ * @param string the class name for scaffold editor. Defaults to empty, meaning not set.
+ */
public function setEditRenderer($value)
{
$this->setViewState('EditRenderer', $value, '');
}
+ /**
+ * @param array Active Record primary key value to be edited.
+ */
public function setRecordPk($value)
{
$this->clearRecordObject();
@@ -31,16 +84,25 @@ class TScaffoldEditView extends TScaffoldBase
$this->setViewState('PK', count($val) > 0 ? $val : null);
}
+ /**
+ * @return array Active Record primary key value.
+ */
public function getRecordPk()
{
return $this->getViewState('PK');
}
+ /**
+ * @return TActiveRecord current Active Record instance
+ */
protected function getCurrentRecord()
{
return $this->getRecordObject($this->getRecordPk());
}
+ /**
+ * Initialize the editor form
+ */
public function initializeEditForm()
{
$record = $this->getCurrentRecord();
@@ -60,6 +122,13 @@ class TScaffoldEditView extends TScaffoldBase
}
}
+ /**
+ * Instantiate the external edit renderer.
+ * @param TActiveRecord record to be edited
+ * @param string external edit renderer class name.
+ * @throws TConfigurationException raised when renderer is not an
+ * instance of IScaffoldEditRenderer.
+ */
protected function createEditRenderer($record, $classPath)
{
$this->_editRenderer = Prado::createComponent($classPath);
@@ -76,7 +145,10 @@ class TScaffoldEditView extends TScaffoldBase
}
}
- protected function repeaterItemCreated($sender, $param)
+ /**
+ * Initialize the default editor using the scaffold input builder.
+ */
+ protected function createRepeaterEditItem($sender, $param)
{
$type = $param->getItem()->getItemType();
if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
@@ -92,14 +164,16 @@ class TScaffoldEditView extends TScaffoldBase
}
}
+ /**
+ * Bubble the command name event. Stops bubbling when the page validator false.
+ * Otherwise, the bubble event is continued.
+ */
public function bubbleEvent($sender, $param)
{
switch(strtolower($param->getCommandName()))
{
case 'save':
- if($this->getPage()->getIsValid())
- return $this->doSave() === true ? false : true;
- return true;
+ return $this->doSave() ? false : true;
case 'clear':
$this->setRecordPk(null);
$this->initializeEditForm();
@@ -109,68 +183,116 @@ class TScaffoldEditView extends TScaffoldBase
}
}
+ /**
+ * Check the validators, then tries to save the record.
+ * @return boolean true if the validators are true, false otherwise.
+ */
protected function doSave()
{
- $record = $this->getCurrentRecord();
- if($this->_editRenderer===null)
+ if($this->getPage()->getIsValid())
{
- $table = $this->getTableMetaData();
- $builder = $this->getScaffoldInputBuilder($record);
- foreach($this->getInputRepeater()->getItems() as $item)
+ $record = $this->getCurrentRecord();
+ 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;
}
- else
- {
- $this->_editRenderer->updateRecord($record);
- }
-
- $record->save();
- return true;
+ return false;
}
+ /**
+ * @return TRepeater default editor input controls repeater
+ */
protected function getInputRepeater()
{
$this->ensureChildControls();
return $this->getRegisteredObject('_repeater');
}
+ /**
+ * @return TButton Button triggered to save the Active Record.
+ */
public function getSaveButton()
{
$this->ensureChildControls();
return $this->getRegisteredObject('_save');
}
+ /**
+ * @return TButton Button to clear the editor inputs.
+ */
public function getClearButton()
{
$this->ensureChildControls();
return $this->getRegisteredObject('_clear');
}
+ /**
+ * @return TButton Button to cancel the edit action (e.g. hide the edit view).
+ */
public function getCancelButton()
{
$this->ensureChildControls();
return $this->getRegisteredObject('_cancel');
}
+ /**
+ * Create the default scaffold editor control factory.
+ * @param TActiveRecord record instance.
+ * @return TScaffoldInputBase scaffold editor control factory.
+ */
protected function getScaffoldInputBuilder($record)
{
+ static $_builders=array();
$class = get_class($record);
- if(!isset(self::$_builders[$class]))
- self::$_builders[$class] = TScaffoldInputBase::createInputBuilder($record);
- return self::$_builders[$class];
+ if(!isset($_builders[$class]))
+ {
+ Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputBase');
+ $_builders[$class] = TScaffoldInputBase::createInputBuilder($record);
+ }
+ return $_builders[$class];
}
+ /**
+ * @return string editor validation group name.
+ */
public function getValidationGroup()
{
return 'group_'.$this->getUniqueID();
}
}
+/**
+ * IScaffoldEditRenderer interface.
+ *
+ * IScaffoldEditRenderer defines the interface that an edit renderer
+ * needs to implement. Besides the {@link getData Data} property, an edit
+ * renderer also needs to provide {@link updateRecord updateRecord} method
+ * that is called before the save() method is called on the TActiveRecord.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
interface IScaffoldEditRenderer extends IDataRenderer
{
+ /**
+ * This method should update the record with the user input data.
+ * @param TActiveRecord record to be saved.
+ */
public function updateRecord($record);
}
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl
index 8cba7ec4..884ec2a3 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.tpl
@@ -1,7 +1,8 @@
+<div class="scaffold_edit_view">
<div class="edit-inputs">
-<com:TRepeater ID="_repeater" onItemCreated="repeaterItemCreated">
+<com:TRepeater ID="_repeater" onItemCreated="createRepeaterEditItem">
<prop:ItemTemplate>
- <div class="edit-item item_<%# $this->ItemIndex % 2 %>
+ <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">
@@ -16,4 +17,5 @@
<com:TButton ID="_save" Text="Save" CommandName="save" ValidationGroup=<%= $this->ValidationGroup %>/>
<com:TButton ID="_clear" Text="Clear" CommandName="clear" CausesValidation="false"/>
<com:TButton ID="_cancel" Text="Cancel" CommandName="cancel" CausesValidation="false" Visible="false"/>
+</div>
</div> \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
index 35c53473..2ac3fe99 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
@@ -1,7 +1,28 @@
<?php
-
+/**
+ * TScaffoldListView class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+
+/**
+ * Load the scaffold base class.
+ */
Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
+/**
+ * TScaffoldListView displays instance of Active Record class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
class TScaffoldListView extends TScaffoldBase
{
public function onLoad($param)
@@ -32,31 +53,26 @@ class TScaffoldListView extends TScaffoldBase
public function onPreRender($param)
{
parent::onPreRender($param);
- $this->initializeItemCount();
$this->loadRecordData();
}
- protected function initializeItemCount()
- {
- $this->_list->setVirtualItemCount($this->getRecordFinder()->count());
- }
-
protected function loadRecordData()
{
+ $this->_list->setVirtualItemCount($this->getRecordFinder()->count());
$finder = $this->getRecordFinder();
- $criteria = $this->getPagingCriteria();
+ $criteria = $this->getRecordCriteria();
$this->_list->setDataSource($finder->findAll($criteria));
$this->_list->dataBind();
}
- protected function getPagingCriteria()
+ protected function getRecordCriteria()
{
$total = $this->_list->getVirtualItemCount();
$limit = $this->_list->getPageSize();
$offset = $this->_list->getCurrentPageIndex()*$limit;
if($offset + $limit > $total)
$limit = $total - $offset;
- $criteria = new TActiveRecordCriteria;
+ $criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters());
$criteria->setLimit($limit);
$criteria->setOffset($offset);
$order = explode(' ',$this->_sort->getSelectedValue(), 2);
@@ -65,6 +81,26 @@ class TScaffoldListView extends TScaffoldBase
return $criteria;
}
+ public function setSearchCondition($value)
+ {
+ $this->setViewState('SearchCondition', $value);
+ }
+
+ public function getSearchCondition()
+ {
+ return $this->getViewState('SearchCondition');
+ }
+
+ public function setSearchParameters($value)
+ {
+ $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value),array());
+ }
+
+ public function getSearchParameters()
+ {
+ return $this->getViewState('SearchParameters', array());
+ }
+
public function bubbleEvent($sender, $param)
{
switch(strtolower($param->getCommandName()))
@@ -72,21 +108,26 @@ class TScaffoldListView extends TScaffoldBase
case 'delete':
return $this->deleteRecord($sender, $param);
case 'edit':
- if(($ctrl=$this->getEditViewControl())!==null)
- {
- if($param instanceof TRepeaterCommandEventParameter)
- {
- $pk = $param->getItem()->getCustomData();
- $ctrl->setRecordPk($pk);
- $ctrl->initializeEditForm();
- }
- }
+ $this->initializeEdit($sender, $param);
}
$this->raiseBubbleEvent($this, $param);
return true;
}
- public function deleteRecord($sender, $param)
+ protected function initializeEdit($sender, $param)
+ {
+ if(($ctrl=$this->getEditViewControl())!==null)
+ {
+ if($param instanceof TRepeaterCommandEventParameter)
+ {
+ $pk = $param->getItem()->getCustomData();
+ $ctrl->setRecordPk($pk);
+ $ctrl->initializeEditForm();
+ }
+ }
+ }
+
+ protected function deleteRecord($sender, $param)
{
if($param instanceof TRepeaterCommandEventParameter)
{
@@ -111,10 +152,10 @@ class TScaffoldListView extends TScaffoldBase
$item = $param->getItem();
if(($data = $item->getData()) !== null)
{
- $item->setCustomData($this->getRecordObjectPk($data));
+ $item->setCustomData($this->getRecordPkValues($data));
if(($prop = $item->findControl('_properties'))!==null)
{
- $item->_properties->setDataSource($this->getRecordProperties($data));
+ $item->_properties->setDataSource($this->getRecordPropertyValues($data));
$item->_properties->dataBind();
}
}
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.tpl b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.tpl
index 7b8854f0..c70e864d 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.tpl
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.tpl
@@ -1,4 +1,4 @@
-
+<div class="scaffold_list_view">
<div class="item-header">
<com:TRepeater ID="_header">
<prop:ItemTemplate>
@@ -21,7 +21,7 @@
PageSize="10">
<prop:ItemTemplate>
<div class="item item_<%# $this->ItemIndex % 2 %>">
-
+
<com:TRepeater ID="_properties">
<prop:ItemTemplate>
<span class="field field_<%# $this->ItemIndex %>">
@@ -29,20 +29,20 @@
</span>
</prop:ItemTemplate>
</com:TRepeater>
-
+
<span class="edit-delete-buttons">
- <com:TButton Text="Edit"
+ <com:TButton Text="Edit"
Visible=<%# $this->NamingContainer->Parent->EditViewID !== Null %>
- CommandName="edit"
+ CommandName="edit"
CssClass="edit-button"
CausesValidation="false" />
- <com:TButton Text="Delete"
- CommandName="delete"
+ <com:TButton Text="Delete"
+ CommandName="delete"
CssClass="delete-button"
CausesValidation="false"
Attributes.onclick="if(!confirm('Are you sure?')) return false;" />
</span>
-
+
</div>
</prop:ItemTemplate>
</com:TRepeater>
@@ -53,4 +53,5 @@
ControlToPaginate="_list"
PageButtonCount="10"
Mode="Numeric"
- OnPageIndexChanged="pageChanged" /> \ No newline at end of file
+ OnPageIndexChanged="pageChanged" />
+</div> \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php
new file mode 100644
index 00000000..a47a1a47
--- /dev/null
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php
@@ -0,0 +1,89 @@
+<?php
+
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
+
+class TScaffoldSearch extends TScaffoldBase
+{
+ private $_list;
+
+ public function getListView()
+ {
+ if($this->_list===null && ($id = $this->getListViewID()) !== null)
+ {
+ $this->_list = $this->getParent()->findControl($id);
+ if($this->_list ===null)
+ throw new TConfigurationException('scaffold_unable_to_find_list_view', $id);
+ }
+ return $this->_list;
+ }
+
+ public function setListView($value)
+ {
+ $this->_list = $value;
+ }
+
+ public function setListViewID($value)
+ {
+ $this->setViewState('ListViewID', $value);
+ }
+
+ public function getListViewID()
+ {
+ return $this->getViewState('ListViewID');
+ }
+
+ public function bubbleEvent($sender, $param)
+ {
+ if(strtolower($param->getCommandName())==='search')
+ {
+ if(($list = $this->getListView()) !== null)
+ {
+ $list->setSearchCondition($this->createSearchCondition());
+ $list->setSearchParameters(array());
+ return false;
+ }
+ }
+ $this->raiseBubbleEvent($this, $param);
+ return true;
+ }
+
+ protected function createSearchCondition()
+ {
+ $table = $this->getTableMetaData();
+ if(strlen($str=$this->getSearchText()->getText()) > 0)
+ return $table->getSearchRegExpCriteria($this->getFields(), $str);
+ }
+
+ protected function getFields()
+ {
+ if(strlen(trim($str=$this->getSearchableFields()))>0)
+ $fields = preg_split('/\s*,\s*/', $str);
+ else
+ $fields = array_keys($this->getTableMetaData()->getColumns());
+ return $fields;
+ }
+
+ public function getSearchableFields()
+ {
+ return $this->getViewState('SearchableFields','');
+ }
+
+ public function setSearchableFields($value)
+ {
+ $this->setViewState('SearchableFields', $value, '');
+ }
+
+ public function getSearchButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_search');
+ }
+
+ public function getSearchText()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_textbox');
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.tpl b/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.tpl
new file mode 100644
index 00000000..a5f56b55
--- /dev/null
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.tpl
@@ -0,0 +1,4 @@
+<span class="scaffold_search">
+<com:TTextBox ID="_textbox" />
+<com:TButton ID="_search" Text="Search" CommandName="search" />
+</span> \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php
index 668ede61..5401c764 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php
@@ -3,6 +3,7 @@
Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldListView');
Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldEditView');
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldSearch');
class TScaffoldView extends TScaffoldBase
{
@@ -11,6 +12,7 @@ class TScaffoldView extends TScaffoldBase
parent::onLoad($param);
$this->getListView()->copyFrom($this);
$this->getEditView()->copyFrom($this);
+ $this->getSearchControl()->copyFrom($this);
}
public function getListView()
@@ -25,6 +27,12 @@ class TScaffoldView extends TScaffoldBase
return $this->getRegisteredObject('_editView');
}
+ public function getSearchControl()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_search');
+ }
+
public function getAddButton()
{
$this->ensureChildControls();
@@ -50,6 +58,7 @@ class TScaffoldView extends TScaffoldBase
$this->getListView()->setVisible(false);
$this->getEditView()->setVisible(true);
$this->getAddButton()->setVisible(false);
+ $this->getSearchControl()->setVisible(false);
$this->getEditView()->getCancelButton()->setVisible(true);
$this->getEditView()->getClearButton()->setVisible(false);
}
@@ -59,6 +68,7 @@ class TScaffoldView extends TScaffoldBase
$this->getListView()->setVisible(true);
$this->getEditView()->setVisible(false);
$this->getAddButton()->setVisible(true);
+ $this->getSearchControl()->setVisible(true);
}
protected function showAddView($sender, $param)
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.tpl b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.tpl
index 0ae8b8b0..01cceb07 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.tpl
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.tpl
@@ -1,7 +1,9 @@
+<div class="scaffold_view">
+<com:TScaffoldSearch ID="_search" ListViewID="_listView" />
<com:TScaffoldListView ID="_listView" EditViewID="_editView" />
-
-<div class="auxilary-button buttons">
+<span class="auxilary-button buttons">
<com:TButton ID="_newButton" Text="Add new record" CssClass="new-button" CommandName="new" />
-</div>
+</span>
-<com:TScaffoldEditView ID="_editView" Visible="false"/> \ No newline at end of file
+<com:TScaffoldEditView ID="_editView" Visible="false"/>
+</div> \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/Scaffold/style.css b/framework/Data/ActiveRecord/Scaffold/style.css
index eb31e9a5..a1fc7a16 100644
--- a/framework/Data/ActiveRecord/Scaffold/style.css
+++ b/framework/Data/ActiveRecord/Scaffold/style.css
@@ -1,3 +1,4 @@
+/* $Id$ */
body
{
font-family: Cambria, Georgia, "Times New Roman", Times, serif;
@@ -116,7 +117,7 @@ body
font-weight: bold;
padding: 0.2em;
}
-.edit-inputs .required-input
+.edit-inputs .required-input, .edit-inputs .required-input2
{
border: 1px solid red;
background-color: #FFF5EE;