Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TEditCommandColumn class file
4
 *
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TEditCommandColumn.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Web.UI.WebControls
11
 */
12
 
13
/**
14
 * TDataGridColumn class file
15
 */
16
Prado::using('System.Web.UI.WebControls.TDataGridColumn');
17
 
18
/**
19
 * TEditCommandColumn class
20
 *
21
 * TEditCommandColumn contains the Edit command buttons for editing data items in each row.
22
 *
23
 * TEditCommandColumn will create an edit button if a cell is not in edit mode.
24
 * Otherwise an update button and a cancel button will be created within the cell.
25
 * The button captions are specified using {@link setEditText EditText},
26
 * {@link setUpdateText UpdateText}, and {@link setCancelText CancelText}.
27
 *
28
 * The buttons in the column can be set to display as hyperlinks, push or image buttons
29
 * by setting the {@link setButtonType ButtonType} property.
30
 *
31
 * When an edit button is clicked, the datagrid will generate an
32
 * {@link onEditCommand OnEditCommand} event. When an update/cancel button
33
 * is clicked, the datagrid will generate an
34
 * {@link onUpdateCommand OnUpdateCommand} or an {@link onCancelCommand OnCancelCommand}
35
 * You can write these event handlers to change the state of specific datagrid item.
36
 *
37
 * The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup}
38
 * properties affect the corresponding properties of the edit and update buttons.
39
 * The cancel button does not cause validation by default.
40
 *
41
 * The command buttons in the column can be accessed by one of the following methods:
42
 * <code>
43
 * $datagridItem->ButtonColumnID->EditButton (or UpdateButton, CancelButton)
44
 * $datagridItem->ButtonColumnID->Controls[0]
45
 * </code>
46
 * The second method is possible because the button control created within the
47
 * datagrid cell is the first child.
48
 *
49
 * @author Qiang Xue <qiang.xue@gmail.com>
50
 * @version $Id: TEditCommandColumn.php 2541 2008-10-21 15:05:13Z qiang.xue $
51
 * @package System.Web.UI.WebControls
52
 * @since 3.0
53
 */
54
class TEditCommandColumn extends TDataGridColumn
55
{
56
	/**
57
	 * @return TButtonColumnType the type of command button. Defaults to TButtonColumnType::LinkButton.
58
	 */
59
	public function getButtonType()
60
	{
61
		return $this->getViewState('ButtonType',TButtonColumnType::LinkButton);
62
	}
63
 
64
	/**
65
	 * @param TButtonColumnType the type of command button.
66
	 */
67
	public function setButtonType($value)
68
	{
69
		$this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonColumnType'),TButtonColumnType::LinkButton);
70
	}
71
 
72
	/**
73
	 * @return string the caption of the edit button. Defaults to 'Edit'.
74
	 */
75
	public function getEditText()
76
	{
77
		return $this->getViewState('EditText','Edit');
78
	}
79
 
80
	/**
81
	 * @param string the caption of the edit button
82
	 */
83
	public function setEditText($value)
84
	{
85
		$this->setViewState('EditText',$value,'Edit');
86
	}
87
 
88
	/**
89
	 * @return string the URL of the image file for edit image buttons
90
	 */
91
	public function getEditImageUrl()
92
	{
93
		return $this->getViewState('EditImageUrl','');
94
	}
95
 
96
	/**
97
	 * @param string the URL of the image file for edit image buttons
98
	 */
99
	public function setEditImageUrl($value)
100
	{
101
		$this->setViewState('EditImageUrl',$value,'');
102
	}
103
 
104
	/**
105
	 * @return string the caption of the update button. Defaults to 'Update'.
106
	 */
107
	public function getUpdateText()
108
	{
109
		return $this->getViewState('UpdateText','Update');
110
	}
111
 
112
	/**
113
	 * @param string the caption of the update button
114
	 */
115
	public function setUpdateText($value)
116
	{
117
		$this->setViewState('UpdateText',$value,'Update');
118
	}
119
 
120
	/**
121
	 * @return string the URL of the image file for update image buttons
122
	 */
123
	public function getUpdateImageUrl()
124
	{
125
		return $this->getViewState('UpdateImageUrl','');
126
	}
127
 
128
	/**
129
	 * @param string the URL of the image file for update image buttons
130
	 */
131
	public function setUpdateImageUrl($value)
132
	{
133
		$this->setViewState('UpdateImageUrl',$value,'');
134
	}
135
 
136
	/**
137
	 * @return string the caption of the cancel button. Defaults to 'Cancel'.
138
	 */
139
	public function getCancelText()
140
	{
141
		return $this->getViewState('CancelText','Cancel');
142
	}
143
 
144
	/**
145
	 * @param string the caption of the cancel button
146
	 */
147
	public function setCancelText($value)
148
	{
149
		$this->setViewState('CancelText',$value,'Cancel');
150
	}
151
 
152
	/**
153
	 * @return string the URL of the image file for cancel image buttons
154
	 */
155
	public function getCancelImageUrl()
156
	{
157
		return $this->getViewState('CancelImageUrl','');
158
	}
159
 
160
	/**
161
	 * @param string the URL of the image file for cancel image buttons
162
	 */
163
	public function setCancelImageUrl($value)
164
	{
165
		$this->setViewState('CancelImageUrl',$value,'');
166
	}
167
 
168
	/**
169
	 * @return boolean whether postback event trigger by edit or update button will cause input validation, default is true
170
	 */
171
	public function getCausesValidation()
172
	{
173
		return $this->getViewState('CausesValidation',true);
174
	}
175
 
176
	/**
177
	 * @param boolean whether postback event trigger by edit or update button will cause input validation
178
	 */
179
	public function setCausesValidation($value)
180
	{
181
		$this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
182
	}
183
 
184
	/**
185
	 * @return string the group of validators which the edit or update button causes validation upon postback
186
	 */
187
	public function getValidationGroup()
188
	{
189
		return $this->getViewState('ValidationGroup','');
190
	}
191
 
192
	/**
193
	 * @param string the group of validators which the edit or update button causes validation upon postback
194
	 */
195
	public function setValidationGroup($value)
196
	{
197
		$this->setViewState('ValidationGroup',$value,'');
198
	}
199
 
200
	/**
201
	 * Initializes the specified cell to its initial values.
202
	 * This method overrides the parent implementation.
203
	 * It creates an update and a cancel button for cell in edit mode.
204
	 * Otherwise it creates an edit button.
205
	 * @param TTableCell the cell to be initialized.
206
	 * @param integer the index to the Columns property that the cell resides in.
207
	 * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
208
	 */
209
	public function initializeCell($cell,$columnIndex,$itemType)
210
	{
211
		if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem)
212
		{
213
			$button=$this->createButton('Edit',$this->getEditText(),false,'');
214
			$cell->getControls()->add($button);
215
			$cell->registerObject('EditButton',$button);
216
		}
217
		else if($itemType===TListItemType::EditItem)
218
		{
219
			$controls=$cell->getControls();
220
			$button=$this->createButton('Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup());
221
			$controls->add($button);
222
			$cell->registerObject('UpdateButton',$button);
223
			$controls->add('&nbsp;');
224
			$button=$this->createButton('Cancel',$this->getCancelText(),false,'');
225
			$controls->add($button);
226
			$cell->registerObject('CancelButton',$button);
227
		}
228
		else
229
			parent::initializeCell($cell,$columnIndex,$itemType);
230
	}
231
 
232
	/**
233
	 * Creates a button and initializes its properties.
234
	 * The button type is determined by {@link getButtonType ButtonType}.
235
	 * @param string command name associated with the button
236
	 * @param string button caption
237
	 * @param boolean whether the button should cause validation
238
	 * @param string the validation group that the button belongs to
239
	 * @return mixed the newly created button.
240
	 */
241
	protected function createButton($commandName,$text,$causesValidation,$validationGroup)
242
	{
243
		if($this->getButtonType()===TButtonColumnType::LinkButton)
244
			$button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
245
		else if($this->getButtonType()===TButtonColumnType::PushButton)
246
			$button=Prado::createComponent('System.Web.UI.WebControls.TButton');
247
		else	// image buttons
248
		{
249
			$button=Prado::createComponent('System.Web.UI.WebControls.TImageButton');
250
			if(strcasecmp($commandName,'Update')===0)
251
				$url=$this->getUpdateImageUrl();
252
			else if(strcasecmp($commandName,'Cancel')===0)
253
				$url=$this->getCancelImageUrl();
254
			else
255
				$url=$this->getEditImageUrl();
256
			$button->setImageUrl($url);
257
		}
258
		$button->setText($text);
259
		$button->setCommandName($commandName);
260
		$button->setCausesValidation($causesValidation);
261
		$button->setValidationGroup($validationGroup);
262
		return $button;
263
	}
264
}
265