| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TButtonColumn class file
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TButtonColumn.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 |
Prado::using('System.Web.UI.WebControls.TButton');
|
|
|
18 |
Prado::using('System.Web.UI.WebControls.TLinkButton');
|
|
|
19 |
Prado::using('System.Web.UI.WebControls.TImageButton');
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* TButtonColumn class
|
|
|
23 |
*
|
|
|
24 |
* TButtonColumn contains a user-defined command button, such as Add or Remove,
|
|
|
25 |
* that corresponds with each row in the column.
|
|
|
26 |
*
|
|
|
27 |
* The caption of the buttons in the column is determined by {@link setText Text}
|
|
|
28 |
* and {@link setDataTextField DataTextField} properties. If both are present,
|
|
|
29 |
* the latter takes precedence. The {@link setDataTextField DataTextField} property
|
|
|
30 |
* refers to the name of the field in datasource whose value will be used as the button caption.
|
|
|
31 |
* If {@link setDataTextFormatString DataTextFormatString} is not empty,
|
|
|
32 |
* the value will be formatted before rendering.
|
|
|
33 |
*
|
|
|
34 |
* The buttons in the column can be set to display as hyperlinks or push buttons
|
|
|
35 |
* by setting the {@link setButtonType ButtonType} property.
|
|
|
36 |
* The {@link setCommandName CommandName} will assign its value to
|
|
|
37 |
* all button's <b>CommandName</b> property. The datagrid will capture
|
|
|
38 |
* the command event where you can write event handlers based on different command names.
|
|
|
39 |
* The buttons' <b>CausesValidation</b> and <b>ValidationGroup</b> property values
|
|
|
40 |
* are determined by the column's corresponding properties.
|
|
|
41 |
*
|
|
|
42 |
* The buttons in the column can be accessed by one of the following two methods:
|
|
|
43 |
* <code>
|
|
|
44 |
* $datagridItem->ButtonColumnID->Button
|
|
|
45 |
* $datagridItem->ButtonColumnID->Controls[0]
|
|
|
46 |
* </code>
|
|
|
47 |
* The second method is possible because the button control created within the
|
|
|
48 |
* datagrid cell is the first child.
|
|
|
49 |
*
|
|
|
50 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
51 |
* @version $Id: TButtonColumn.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
52 |
* @package System.Web.UI.WebControls
|
|
|
53 |
* @since 3.0
|
|
|
54 |
*/
|
|
|
55 |
class TButtonColumn extends TDataGridColumn
|
|
|
56 |
{
|
|
|
57 |
/**
|
|
|
58 |
* @return string the text caption of the button
|
|
|
59 |
*/
|
|
|
60 |
public function getText()
|
|
|
61 |
{
|
|
|
62 |
return $this->getViewState('Text','');
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Sets the text caption of the button.
|
|
|
67 |
* @param string the text caption to be set
|
|
|
68 |
*/
|
|
|
69 |
public function setText($value)
|
|
|
70 |
{
|
|
|
71 |
$this->setViewState('Text',$value,'');
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* @return string the field name from the data source to bind to the button caption
|
|
|
76 |
*/
|
|
|
77 |
public function getDataTextField()
|
|
|
78 |
{
|
|
|
79 |
return $this->getViewState('DataTextField','');
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* @param string the field name from the data source to bind to the button caption
|
|
|
84 |
*/
|
|
|
85 |
public function setDataTextField($value)
|
|
|
86 |
{
|
|
|
87 |
$this->setViewState('DataTextField',$value,'');
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* @return string the formatting string used to control how the button caption will be displayed.
|
|
|
92 |
*/
|
|
|
93 |
public function getDataTextFormatString()
|
|
|
94 |
{
|
|
|
95 |
return $this->getViewState('DataTextFormatString','');
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* @param string the formatting string used to control how the button caption will be displayed.
|
|
|
100 |
*/
|
|
|
101 |
public function setDataTextFormatString($value)
|
|
|
102 |
{
|
|
|
103 |
$this->setViewState('DataTextFormatString',$value,'');
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
/**
|
|
|
107 |
* @return string the URL of the image file for image buttons
|
|
|
108 |
*/
|
|
|
109 |
public function getImageUrl()
|
|
|
110 |
{
|
|
|
111 |
return $this->getViewState('ImageUrl','');
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* @param string the URL of the image file for image buttons
|
|
|
116 |
*/
|
|
|
117 |
public function setImageUrl($value)
|
|
|
118 |
{
|
|
|
119 |
$this->setViewState('ImageUrl',$value,'');
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* @return string the field name from the data source to bind to the button image url
|
|
|
124 |
*/
|
|
|
125 |
public function getDataImageUrlField()
|
|
|
126 |
{
|
|
|
127 |
return $this->getViewState('DataImageUrlField','');
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* @param string the field name from the data source to bind to the button image url
|
|
|
132 |
*/
|
|
|
133 |
public function setDataImageUrlField($value)
|
|
|
134 |
{
|
|
|
135 |
$this->setViewState('DataImageUrlField',$value,'');
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* @return string the formatting string used to control how the button image url will be displayed.
|
|
|
140 |
*/
|
|
|
141 |
public function getDataImageUrlFormatString()
|
|
|
142 |
{
|
|
|
143 |
return $this->getViewState('DataImageUrlFormatString','');
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* @param string the formatting string used to control how the button image url will be displayed.
|
|
|
148 |
*/
|
|
|
149 |
public function setDataImageUrlFormatString($value)
|
|
|
150 |
{
|
|
|
151 |
$this->setViewState('DataImageUrlFormatString',$value,'');
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* @return TButtonColumnType the type of command button. Defaults to TButtonColumnType::LinkButton.
|
|
|
156 |
*/
|
|
|
157 |
public function getButtonType()
|
|
|
158 |
{
|
|
|
159 |
return $this->getViewState('ButtonType',TButtonColumnType::LinkButton);
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
/**
|
|
|
163 |
* @param TButtonColumnType the type of command button
|
|
|
164 |
*/
|
|
|
165 |
public function setButtonType($value)
|
|
|
166 |
{
|
|
|
167 |
$this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonColumnType'),TButtonColumnType::LinkButton);
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
/**
|
|
|
171 |
* @return string the command name associated with the <b>OnCommand</b> event.
|
|
|
172 |
*/
|
|
|
173 |
public function getCommandName()
|
|
|
174 |
{
|
|
|
175 |
return $this->getViewState('CommandName','');
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
/**
|
|
|
179 |
* Sets the command name associated with the <b>Command</b> event.
|
|
|
180 |
* @param string the text caption to be set
|
|
|
181 |
*/
|
|
|
182 |
public function setCommandName($value)
|
|
|
183 |
{
|
|
|
184 |
$this->setViewState('CommandName',$value,'');
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
/**
|
|
|
188 |
* @return boolean whether postback event trigger by this button will cause input validation, default is true
|
|
|
189 |
*/
|
|
|
190 |
public function getCausesValidation()
|
|
|
191 |
{
|
|
|
192 |
return $this->getViewState('CausesValidation',true);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
/**
|
|
|
196 |
* @param boolean whether postback event trigger by this button will cause input validation
|
|
|
197 |
*/
|
|
|
198 |
public function setCausesValidation($value)
|
|
|
199 |
{
|
|
|
200 |
$this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
/**
|
|
|
204 |
* @return string the group of validators which the button causes validation upon postback
|
|
|
205 |
*/
|
|
|
206 |
public function getValidationGroup()
|
|
|
207 |
{
|
|
|
208 |
return $this->getViewState('ValidationGroup','');
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
/**
|
|
|
212 |
* @param string the group of validators which the button causes validation upon postback
|
|
|
213 |
*/
|
|
|
214 |
public function setValidationGroup($value)
|
|
|
215 |
{
|
|
|
216 |
$this->setViewState('ValidationGroup',$value,'');
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
/**
|
|
|
220 |
* Initializes the specified cell to its initial values.
|
|
|
221 |
* This method overrides the parent implementation.
|
|
|
222 |
* It creates a command button within the cell.
|
|
|
223 |
* @param TTableCell the cell to be initialized.
|
|
|
224 |
* @param integer the index to the Columns property that the cell resides in.
|
|
|
225 |
* @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
|
|
|
226 |
*/
|
|
|
227 |
public function initializeCell($cell,$columnIndex,$itemType)
|
|
|
228 |
{
|
|
|
229 |
if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
|
|
|
230 |
{
|
|
|
231 |
$buttonType=$this->getButtonType();
|
|
|
232 |
if($buttonType===TButtonColumnType::LinkButton)
|
|
|
233 |
$button=new TLinkButton;
|
|
|
234 |
else if($buttonType===TButtonColumnType::PushButton)
|
|
|
235 |
$button=new TButton;
|
|
|
236 |
else // image button
|
|
|
237 |
{
|
|
|
238 |
$button=new TImageButton;
|
|
|
239 |
$button->setImageUrl($this->getImageUrl());
|
|
|
240 |
}
|
|
|
241 |
$button->setText($this->getText());
|
|
|
242 |
$button->setCommandName($this->getCommandName());
|
|
|
243 |
$button->setCausesValidation($this->getCausesValidation());
|
|
|
244 |
$button->setValidationGroup($this->getValidationGroup());
|
|
|
245 |
if($this->getDataTextField()!=='' || ($buttonType===TButtonColumnType::ImageButton && $this->getDataImageUrlField()!==''))
|
|
|
246 |
$button->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
|
|
|
247 |
$cell->getControls()->add($button);
|
|
|
248 |
$cell->registerObject('Button',$button);
|
|
|
249 |
}
|
|
|
250 |
else
|
|
|
251 |
parent::initializeCell($cell,$columnIndex,$itemType);
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
/**
|
|
|
255 |
* Databinds a cell in the column.
|
|
|
256 |
* This method is invoked when datagrid performs databinding.
|
|
|
257 |
* It populates the content of the cell with the relevant data from data source.
|
|
|
258 |
*/
|
|
|
259 |
public function dataBindColumn($sender,$param)
|
|
|
260 |
{
|
|
|
261 |
if($sender instanceof IButtonControl)
|
|
|
262 |
{
|
|
|
263 |
if(($field=$this->getDataTextField())!=='')
|
|
|
264 |
{
|
|
|
265 |
$value=$this->getDataFieldValue($sender->getNamingContainer()->getData(),$field);
|
|
|
266 |
$text=$this->formatDataValue($this->getDataTextFormatString(),$value);
|
|
|
267 |
$sender->setText($text);
|
|
|
268 |
}
|
|
|
269 |
if(($sender instanceof TImageButton) && ($field=$this->getDataImageUrlField())!=='')
|
|
|
270 |
{
|
|
|
271 |
$value=$this->getDataFieldValue($sender->getNamingContainer()->getData(),$field);
|
|
|
272 |
$url=$this->formatDataValue($this->getDataImageUrlFormatString(),$value);
|
|
|
273 |
$sender->setImageUrl($url);
|
|
|
274 |
}
|
|
|
275 |
}
|
|
|
276 |
}
|
|
|
277 |
}
|
|
|
278 |
|