summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php
blob: 63dea8ddb520b9865e3b4c7bdb36d59a7e09eb54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
 * TScaffoldView class.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2005-2013 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @version $Id: TScaffoldView.php 3245 2013-01-07 20:23:32Z ctrlaltca $
 * @package System.Data.ActiveRecord.Scaffold
 */

/**
 * Import scaffold base, list, edit and search controls.
 */
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');

/**
 * TScaffoldView is a composite control consisting of TScaffoldListView
 * with a TScaffoldSearch. In addition, it will display a TScaffoldEditView
 * when an "edit" command is raised from the TScaffoldListView (when the
 * edit button is clicked). Futher more, the "add" button can be clicked
 * that shows an empty data TScaffoldListView for creating new records.
 *
 * The {@link getListView ListView} property gives a TScaffoldListView for
 * display the record data. The {@link getEditView EditView} is the
 * TScaffoldEditView that renders the
 * inputs for editing and adding records. The {@link getSearchControl SearchControl}
 * is a TScaffoldSearch responsible to the search user interface.
 *
 * Set the {@link setRecordClass RecordClass} property to the name of
 * the Active Record class to be displayed/edited/added.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @version $Id: TScaffoldView.php 3245 2013-01-07 20:23:32Z ctrlaltca $
 * @package System.Data.ActiveRecord.Scaffold
 * @since 3.0
 */
class TScaffoldView extends TScaffoldBase
{
	/**
	 * Copy basic record details to the list/edit/search controls.
	 */
	public function onPreRender($param)
	{
		parent::onPreRender($param);
		$this->getListView()->copyFrom($this);
		$this->getEditView()->copyFrom($this);
		$this->getSearchControl()->copyFrom($this);
	}

	/**
	 * @return TScaffoldListView scaffold list view.
	 */
	public function getListView()
	{
		$this->ensureChildControls();
		return $this->getRegisteredObject('_listView');
	}

	/**
	 * @return TScaffoldEditView scaffold edit view.
	 */
	public function getEditView()
	{
		$this->ensureChildControls();
		return $this->getRegisteredObject('_editView');
	}

	/**
	 * @return TScaffoldSearch scaffold search textbox and button.
	 */
	public function getSearchControl()
	{
		$this->ensureChildControls();
		return $this->getRegisteredObject('_search');
	}

	/**
	 * @return TButton "Add new record" button.
	 */
	public function getAddButton()
	{
		$this->ensureChildControls();
		return $this->getRegisteredObject('_newButton');
	}

	/**
	 * Handle the "edit" and "new" commands by displaying the edit view.
	 * Default command shows the list view.
	 */
	public function bubbleEvent($sender,$param)
	{
		switch(strtolower($param->getCommandName()))
		{
			case 'edit':
				return $this->showEditView($sender, $param);
			case 'new':
				return $this->showAddView($sender, $param);
			default:
				return $this->showListView($sender, $param);
		}
		return false;
	}

	/**
	 * Shows the edit record view.
	 */
	protected function showEditView($sender, $param)
	{
		$this->getListView()->setVisible(false);
		$this->getEditView()->setVisible(true);
		$this->_panForNewButton->setVisible(false);
		$this->_panForSearch->setVisible(false);
		$this->getEditView()->getCancelButton()->setVisible(true);
		$this->getEditView()->getClearButton()->setVisible(false);
	}

	/**
	 * Shows the view for listing the records.
	 */
	protected function showListView($sender, $param)
	{
		$this->getListView()->setVisible(true);
		$this->getEditView()->setVisible(false);
		$this->_panForNewButton->setVisible(true);
		$this->_panForSearch->setVisible(true);
	}

	/**
	 * Shows the add record view.
	 */
	protected function showAddView($sender, $param)
	{
		$this->getEditView()->setRecordPk(null);
		$this->getEditView()->initializeEditForm();
		$this->showEditView($sender, $param);
	}
}