[ 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/ -> TLinkButton.php (source)

   1  <?php
   2  /**
   3   * TLinkButton 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: TLinkButton.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.Web.UI.WebControls
  11   */
  12  
  13  /**
  14   * TLinkButton class
  15   *
  16   * TLinkButton creates a hyperlink style button on the page.
  17   * TLinkButton has the same appearance as a hyperlink. However, it is mainly
  18   * used to submit data to a page. Like {@link TButton}, you can create either
  19   * a <b>submit</b> button or a <b>command</b> button.
  20   *
  21   * A <b>command</b> button has a command name (specified by
  22   * the {@link setCommandName CommandName} property) and and a command parameter
  23   * (specified by {@link setCommandParameter CommandParameter} property)
  24   * associated with the button. This allows you to create multiple TLinkButton
  25   * components on a Web page and programmatically determine which one is clicked
  26   * with what parameter. You can provide an event handler for
  27   * {@link onCommand OnCommand} event to programmatically control the actions performed
  28   * when the command button is clicked. In the event handler, you can determine
  29   * the {@link setCommandName CommandName} property value and
  30   * the {@link setCommandParameter CommandParameter} property value
  31   * through the {@link TCommandParameter::getName Name} and
  32   * {@link TCommandParameter::getParameter Parameter} properties of the event
  33   * parameter which is of type {@link TCommandEventParameter}.
  34   *
  35   * A <b>submit</b> button does not have a command name associated with the button
  36   * and clicking on it simply posts the Web page back to the server.
  37   * By default, a TLinkButton component is a submit button.
  38   * You can provide an event handler for the {@link onClick OnClick} event
  39   * to programmatically control the actions performed when the submit button is clicked.
  40   *
  41   * Clicking on button can trigger form validation, if
  42   * {@link setCausesValidation CausesValidation} is true.
  43   * And the validation may be restricted within a certain group of validator
  44   * controls by setting {@link setValidationGroup ValidationGroup} property.
  45   * If validation is successful, the data will be post back to the same page.
  46   *
  47   * TLinkButton will display the {@link setText Text} property value
  48   * as the hyperlink text. If {@link setText Text} is empty, the body content
  49   * of TLinkButton will be displayed. Therefore, you can use TLinkButton
  50   * as an image button by enclosing an &lt;img&gt; tag as the body of TLinkButton.
  51   *
  52   * @author Qiang Xue <qiang.xue@gmail.com>
  53   * @version $Id: TLinkButton.php 1397 2006-09-07 07:55:53Z wei $
  54   * @package System.Web.UI.WebControls
  55   * @since 3.0
  56   */
  57  class TLinkButton extends TWebControl implements IPostBackEventHandler, IButtonControl
  58  {
  59      /**
  60       * @return string tag name of the button
  61       */
  62  	protected function getTagName()
  63      {
  64          return 'a';
  65      }
  66  
  67      /**
  68       * Adds attribute name-value pairs to renderer.
  69       * This overrides the parent implementation with additional button specific attributes.
  70       * @param THtmlWriter the writer used for the rendering purpose
  71       */
  72  	protected function addAttributesToRender($writer)
  73      {
  74          $page=$this->getPage();
  75          $page->ensureRenderInForm($this);
  76  
  77          $writer->addAttribute('id',$this->getClientID());
  78  
  79          // We call parent implementation here because some attributes
  80          // may be overwritten in the following
  81          parent::addAttributesToRender($writer);
  82  
  83          if($this->getEnabled(true))
  84          {
  85              //create unique no-op url references
  86              //$nop = "#".$this->getClientID();
  87              $nop = "javascript:;//".$this->getClientID();
  88              $writer->addAttribute('href', $nop);
  89              $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TLinkButton',$this->getPostBackOptions());
  90          }
  91          else if($this->getEnabled()) // in this case, parent will not render 'disabled'
  92              $writer->addAttribute('disabled','disabled');
  93      }
  94  
  95      /**
  96       * Returns postback specifications for the button.
  97       * This method is used by framework and control developers.
  98       * @return array parameters about how the button defines its postback behavior.
  99       */
 100  	protected function getPostBackOptions()
 101      {
 102          $options['ID'] = $this->getClientID();
 103          $options['EventTarget'] = $this->getUniqueID();
 104          $options['CausesValidation'] = $this->getCausesValidation();
 105          $options['ValidationGroup'] = $this->getValidationGroup();
 106          $options['StopEvent'] = true;
 107  
 108          return $options;
 109      }
 110  
 111      /**
 112       * Renders the body content enclosed between the control tag.
 113       * If {@link getText Text} is not empty, it will be rendered. Otherwise,
 114       * the body content enclosed in the control tag will be rendered.
 115       * @param THtmlWriter the writer used for the rendering purpose
 116       */
 117  	public function renderContents($writer)
 118      {
 119          if(($text=$this->getText())==='')
 120              parent::renderContents($writer);
 121          else
 122              $writer->write($text);
 123      }
 124  
 125      /**
 126       * @return string the text caption of the button
 127       */
 128  	public function getText()
 129      {
 130          return $this->getViewState('Text','');
 131      }
 132  
 133      /**
 134       * @param string the text caption to be set
 135       */
 136  	public function setText($value)
 137      {
 138          $this->setViewState('Text',$value,'');
 139      }
 140  
 141      /**
 142       * @return string the command name associated with the {@link onCommand OnCommand} event.
 143       */
 144  	public function getCommandName()
 145      {
 146          return $this->getViewState('CommandName','');
 147      }
 148  
 149      /**
 150       * @param string the command name associated with the {@link onCommand OnCommand} event.
 151       */
 152  	public function setCommandName($value)
 153      {
 154          $this->setViewState('CommandName',$value,'');
 155      }
 156  
 157      /**
 158       * @return string the parameter associated with the {@link onCommand OnCommand} event
 159       */
 160  	public function getCommandParameter()
 161      {
 162          return $this->getViewState('CommandParameter','');
 163      }
 164  
 165      /**
 166       * @param string the parameter associated with the {@link onCommand OnCommand} event.
 167       */
 168  	public function setCommandParameter($value)
 169      {
 170          $this->setViewState('CommandParameter',$value,'');
 171      }
 172  
 173      /**
 174       * @return boolean whether postback event trigger by this button will cause input validation
 175       */
 176  	public function getCausesValidation()
 177      {
 178          return $this->getViewState('CausesValidation',true);
 179      }
 180  
 181      /**
 182       * Sets the value indicating whether postback event trigger by this button will cause input validation.
 183       * @param string the text caption to be set
 184       */
 185  	public function setCausesValidation($value)
 186      {
 187          $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
 188      }
 189  
 190      /**
 191       * @return string the group of validators which the button causes validation upon postback
 192       */
 193  	public function getValidationGroup()
 194      {
 195          return $this->getViewState('ValidationGroup','');
 196      }
 197  
 198      /**
 199       * @param string the group of validators which the button causes validation upon postback
 200       */
 201  	public function setValidationGroup($value)
 202      {
 203          $this->setViewState('ValidationGroup',$value,'');
 204      }
 205  
 206      /**
 207       * Raises the postback event.
 208       * This method is required by {@link IPostBackEventHandler} interface.
 209       * If {@link getCausesValidation CausesValidation} is true, it will
 210       * invoke the page's {@link TPage::validate validate} method first.
 211       * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
 212       * This method is mainly used by framework and control developers.
 213       * @param TEventParameter the event parameter
 214       */
 215  	public function raisePostBackEvent($param)
 216      {
 217          if($this->getCausesValidation())
 218              $this->getPage()->validate($this->getValidationGroup());
 219          $this->onClick(null);
 220          $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
 221      }
 222  
 223      /**
 224       * This method is invoked when the button is clicked.
 225       * The method raises 'OnClick' event to fire up the event handlers.
 226       * If you override this method, be sure to call the parent implementation
 227       * so that the event handler can be invoked.
 228       * @param TEventParameter event parameter to be passed to the event handlers
 229       */
 230  	public function onClick($param)
 231      {
 232          $this->raiseEvent('OnClick',$this,$param);
 233      }
 234  
 235      /**
 236       * This method is invoked when the button is clicked.
 237       * The method raises 'OnCommand' event to fire up the event handlers.
 238       * If you override this method, be sure to call the parent implementation
 239       * so that the event handlers can be invoked.
 240       * @param TCommandEventParameter event parameter to be passed to the event handlers
 241       */
 242  	public function onCommand($param)
 243      {
 244          $this->raiseEvent('OnCommand',$this,$param);
 245          $this->raiseBubbleEvent($this,$param);
 246      }
 247  }
 248  
 249  ?>


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