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