5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2013 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @version $Id: TScaffoldView.php 3245 2013-01-07 20:23:32Z ctrlaltca $
10 * @package System.Data.ActiveRecord.Scaffold
14 * Import scaffold base, list, edit and search controls.
16 Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
17 Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldListView');
18 Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldEditView');
19 Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldSearch');
22 * TScaffoldView is a composite control consisting of TScaffoldListView
23 * with a TScaffoldSearch. In addition, it will display a TScaffoldEditView
24 * when an "edit" command is raised from the TScaffoldListView (when the
25 * edit button is clicked). Futher more, the "add" button can be clicked
26 * that shows an empty data TScaffoldListView for creating new records.
28 * The {@link getListView ListView} property gives a TScaffoldListView for
29 * display the record data. The {@link getEditView EditView} is the
30 * TScaffoldEditView that renders the
31 * inputs for editing and adding records. The {@link getSearchControl SearchControl}
32 * is a TScaffoldSearch responsible to the search user interface.
34 * Set the {@link setRecordClass RecordClass} property to the name of
35 * the Active Record class to be displayed/edited/added.
37 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
38 * @version $Id: TScaffoldView.php 3245 2013-01-07 20:23:32Z ctrlaltca $
39 * @package System.Data.ActiveRecord.Scaffold
42 class TScaffoldView extends TScaffoldBase
45 * Copy basic record details to the list/edit/search controls.
47 public function onPreRender($param)
49 parent::onPreRender($param);
50 $this->getListView()->copyFrom($this);
51 $this->getEditView()->copyFrom($this);
52 $this->getSearchControl()->copyFrom($this);
56 * @return TScaffoldListView scaffold list view.
58 public function getListView()
60 $this->ensureChildControls();
61 return $this->getRegisteredObject('_listView');
65 * @return TScaffoldEditView scaffold edit view.
67 public function getEditView()
69 $this->ensureChildControls();
70 return $this->getRegisteredObject('_editView');
74 * @return TScaffoldSearch scaffold search textbox and button.
76 public function getSearchControl()
78 $this->ensureChildControls();
79 return $this->getRegisteredObject('_search');
83 * @return TButton "Add new record" button.
85 public function getAddButton()
87 $this->ensureChildControls();
88 return $this->getRegisteredObject('_newButton');
92 * Handle the "edit" and "new" commands by displaying the edit view.
93 * Default command shows the list view.
95 public function bubbleEvent($sender,$param)
97 switch(strtolower($param->getCommandName()))
100 return $this->showEditView($sender, $param);
102 return $this->showAddView($sender, $param);
104 return $this->showListView($sender, $param);
110 * Shows the edit record view.
112 protected function showEditView($sender, $param)
114 $this->getListView()->setVisible(false);
115 $this->getEditView()->setVisible(true);
116 $this->_panForNewButton->setVisible(false);
117 $this->_panForSearch->setVisible(false);
118 $this->getEditView()->getCancelButton()->setVisible(true);
119 $this->getEditView()->getClearButton()->setVisible(false);
123 * Shows the view for listing the records.
125 protected function showListView($sender, $param)
127 $this->getListView()->setVisible(true);
128 $this->getEditView()->setVisible(false);
129 $this->_panForNewButton->setVisible(true);
130 $this->_panForSearch->setVisible(true);
134 * Shows the add record view.
136 protected function showAddView($sender, $param)
138 $this->getEditView()->setRecordPk(null);
139 $this->getEditView()->initializeEditForm();
140 $this->showEditView($sender, $param);