[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/UI/WebControls/ -> TButtonColumn.php (source)

   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 &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TButtonColumn.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  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 1397 2006-09-07 07:55:53Z wei $
  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          parent::initializeCell($cell,$columnIndex,$itemType);
 230          if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
 231          {
 232              $buttonType=$this->getButtonType();
 233              if($buttonType===TButtonColumnType::LinkButton)
 234                  $button=new TLinkButton;
 235              else if($buttonType===TButtonColumnType::PushButton)
 236                  $button=new TButton;
 237              else // image button
 238              {
 239                  $button=new TImageButton;
 240                  $button->setImageUrl($this->getImageUrl());
 241              }
 242              $button->setText($this->getText());
 243              $button->setCommandName($this->getCommandName());
 244              $button->setCausesValidation($this->getCausesValidation());
 245              $button->setValidationGroup($this->getValidationGroup());
 246              if($this->getDataTextField()!=='' || ($buttonType===TButtonColumnType::ImageButton && $this->getDataImageUrlField()!==''))
 247                  $button->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
 248              $cell->getControls()->add($button);
 249              $cell->registerObject('Button',$button);
 250          }
 251      }
 252  
 253      /**
 254       * Databinds a cell in the column.
 255       * This method is invoked when datagrid performs databinding.
 256       * It populates the content of the cell with the relevant data from data source.
 257       */
 258  	public function dataBindColumn($sender,$param)
 259      {
 260          if($sender instanceof IButtonControl)
 261          {
 262              if(($field=$this->getDataTextField())!=='')
 263              {
 264                  $value=$this->getDataFieldValue($sender->getNamingContainer()->getDataItem(),$field);
 265                  $text=$this->formatDataValue($this->getDataTextFormatString(),$value);
 266                  $sender->setText($text);
 267              }
 268              if(($sender instanceof TImageButton) && ($field=$this->getDataImageUrlField())!=='')
 269              {
 270                  $value=$this->getDataFieldValue($sender->getNamingContainer()->getDataItem(),$field);
 271                  $url=$this->formatDataValue($this->getDataImageUrlFormatString(),$value);
 272                  $sender->setImageUrl($url);
 273              }
 274          }
 275      }
 276  }
 277  
 278  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7