| [ Index ] |
|
Code source de PRADO 3.0.6 |
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 © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TEditCommandColumn.php 1397 2006-09-07 07:55:53Z wei $ 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 1397 2006-09-07 07:55:53Z wei $ 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 parent::initializeCell($cell,$columnIndex,$itemType); 212 if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem) 213 { 214 $button=$this->createButton('Edit',$this->getEditText(),false,''); 215 $cell->getControls()->add($button); 216 $cell->registerObject('EditButton',$button); 217 } 218 else if($itemType===TListItemType::EditItem) 219 { 220 $controls=$cell->getControls(); 221 $button=$this->createButton('Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup()); 222 $controls->add($button); 223 $cell->registerObject('UpdateButton',$button); 224 $controls->add(' '); 225 $button=$this->createButton('Cancel',$this->getCancelText(),false,''); 226 $controls->add($button); 227 $cell->registerObject('CancelButton',$button); 228 } 229 } 230 231 /** 232 * Creates a button and initializes its properties. 233 * The button type is determined by {@link getButtonType ButtonType}. 234 * @param string command name associated with the button 235 * @param string button caption 236 * @param boolean whether the button should cause validation 237 * @param string the validation group that the button belongs to 238 * @return mixed the newly created button. 239 */ 240 protected function createButton($commandName,$text,$causesValidation,$validationGroup) 241 { 242 if($this->getButtonType()===TButtonColumnType::LinkButton) 243 $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton'); 244 else if($this->getButtonType()===TButtonColumnType::PushButton) 245 $button=Prado::createComponent('System.Web.UI.WebControls.TButton'); 246 else // image buttons 247 { 248 $button=Prado::createComponent('System.Web.UI.WebControls.TImageButton'); 249 if(strcasecmp($commandName,'Update')===0) 250 $url=$this->getUpdateImageUrl(); 251 else if(strcasecmp($commandName,'Cancel')===0) 252 $url=$this->getCancelImageUrl(); 253 else 254 $url=$this->getEditImageUrl(); 255 $button->setImageUrl($url); 256 } 257 $button->setText($text); 258 $button->setCommandName($commandName); 259 $button->setCausesValidation($causesValidation); 260 $button->setValidationGroup($validationGroup); 261 return $button; 262 } 263 } 264 265 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |