Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TScaffoldView class.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TScaffoldView.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Data.ActiveRecord.Scaffold
11
 */
12
 
13
/**
14
 * Import scaffold base, list, edit and search controls.
15
 */
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');
20
 
21
/**
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.
27
 *
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.
33
 *
34
 * Set the {@link setRecordClass RecordClass} property to the name of
35
 * the Active Record class to be displayed/edited/added.
36
 *
37
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
38
 * @version $Id: TScaffoldView.php 2541 2008-10-21 15:05:13Z qiang.xue $
39
 * @package System.Data.ActiveRecord.Scaffold
40
 * @since 3.0
41
 */
42
class TScaffoldView extends TScaffoldBase
43
{
44
	/**
45
	 * Copy basic record details to the list/edit/search controls.
46
	 */
47
	public function onPreRender($param)
48
	{
49
		parent::onPreRender($param);
50
		$this->getListView()->copyFrom($this);
51
		$this->getEditView()->copyFrom($this);
52
		$this->getSearchControl()->copyFrom($this);
53
	}
54
 
55
	/**
56
	 * @return TScaffoldListView scaffold list view.
57
	 */
58
	public function getListView()
59
	{
60
		$this->ensureChildControls();
61
		return $this->getRegisteredObject('_listView');
62
	}
63
 
64
	/**
65
	 * @return TScaffoldEditView scaffold edit view.
66
	 */
67
	public function getEditView()
68
	{
69
		$this->ensureChildControls();
70
		return $this->getRegisteredObject('_editView');
71
	}
72
 
73
	/**
74
	 * @return TScaffoldSearch scaffold search textbox and button.
75
	 */
76
	public function getSearchControl()
77
	{
78
		$this->ensureChildControls();
79
		return $this->getRegisteredObject('_search');
80
	}
81
 
82
	/**
83
	 * @return TButton "Add new record" button.
84
	 */
85
	public function getAddButton()
86
	{
87
		$this->ensureChildControls();
88
		return $this->getRegisteredObject('_newButton');
89
	}
90
 
91
	/**
92
	 * Handle the "edit" and "new" commands by displaying the edit view.
93
	 * Default command shows the list view.
94
	 */
95
	public function bubbleEvent($sender,$param)
96
	{
97
		switch(strtolower($param->getCommandName()))
98
		{
99
			case 'edit':
100
				return $this->showEditView($sender, $param);
101
			case 'new':
102
				return $this->showAddView($sender, $param);
103
			default:
104
				return $this->showListView($sender, $param);
105
		}
106
		return false;
107
	}
108
 
109
	/**
110
	 * Shows the edit record view.
111
	 */
112
	protected function showEditView($sender, $param)
113
	{
114
		$this->getListView()->setVisible(false);
115
		$this->getEditView()->setVisible(true);
116
		$this->getAddButton()->setVisible(false);
117
		$this->getSearchControl()->setVisible(false);
118
		$this->getEditView()->getCancelButton()->setVisible(true);
119
		$this->getEditView()->getClearButton()->setVisible(false);
120
	}
121
 
122
	/**
123
	 * Shows the view for listing the records.
124
	 */
125
	protected function showListView($sender, $param)
126
	{
127
		$this->getListView()->setVisible(true);
128
		$this->getEditView()->setVisible(false);
129
		$this->getAddButton()->setVisible(true);
130
		$this->getSearchControl()->setVisible(true);
131
	}
132
 
133
	/**
134
	 * Shows the add record view.
135
	 */
136
	protected function showAddView($sender, $param)
137
	{
138
		$this->getEditView()->setRecordPk(null);
139
		$this->getEditView()->initializeEditForm();
140
		$this->showEditView($sender, $param);
141
	}
142
}
143