TImageButton creates an image button on the page. It is used to submit data to a page. You can create either a submit button or a command button. A command button has a command name (specified by the {@link setCommandName CommandName} property) and and a command parameter (specified by {@link setCommandParameter CommandParameter} property) associated with the button. This allows you to create multiple TLinkButton components on a Web page and programmatically determine which one is clicked with what parameter. You can provide an event handler for {@link onCommand OnCommand} event to programmatically control the actions performed when the command button is clicked. In the event handler, you can determine the {@link setCommandName CommandName} property value and the {@link setCommandParameter CommandParameter} property value through the {@link TCommandParameter::getName Name} and {@link TCommandParameter::getParameter Parameter} properties of the event parameter which is of type {@link \Prado\Web\UI\TCommandEventParameter}. A submit button does not have a command name associated with the button and clicking on it simply posts the Web page back to the server. By default, a TImageButton control is a submit button. You can provide an event handler for the {@link onClick OnClick} event to programmatically control the actions performed when the submit button is clicked. The coordinates of the clicking point can be obtained from the {@link onClick OnClick} event parameter, which is of type {@link TImageClickEventParameter}. Clicking on button can trigger form validation, if {@link setCausesValidation CausesValidation} is true. And the validation may be restricted within a certain group of validator controls by setting {@link setValidationGroup ValidationGroup} property. If validation is successful, the data will be post back to the same page. TImageButton displays the {@link setText Text} property as the hint text to the displayed image.
부터: 3.0
저자: Qiang Xue (qiang.xue@gmail.com)
상속: extends TImage, implements Prado\Web\UI\IPostBackDataHandler, implements Prado\Web\UI\IPostBackEventHandler, implements Prado\Web\UI\IButtonControl
예제 #1
0
 /**
  * Creates a navigation button.
  * It creates a {@link TButton}, {@link TLinkButton}, or {@link TImageButton},
  * depending on the given parameters.
  * @param TWizardNavigationButtonStyle button style
  * @param boolean whether the button should cause validation
  * @param string command name for the button's OnCommand event
  * @throws TInvalidDataValueException if the button type is not recognized
  */
 protected function createNavigationButton($buttonStyle, $causesValidation, $commandName)
 {
     switch ($buttonStyle->getButtonType()) {
         case TWizardNavigationButtonType::Button:
             $button = new TButton();
             break;
         case TWizardNavigationButtonType::Link:
             $button = new TLinkButton();
             break;
         case TWizardNavigationButtonType::Image:
             $button = new TImageButton();
             $button->setImageUrl($buttonStyle->getImageUrl());
             break;
         default:
             throw new TInvalidDataValueException('wizard_buttontype_unknown', $buttonStyle->getButtonType());
     }
     $button->setText($buttonStyle->getButtonText());
     $button->setCausesValidation($causesValidation);
     $button->setCommandName($commandName);
     return $button;
 }
예제 #2
0
파일: TPager.php 프로젝트: pradosoft/prado
 /**
  * Creates a pager button.
  * Depending on the button type, a TLinkButton or a TButton may be created.
  * If it is enabled (clickable), its command name and parameter will also be set.
  * Derived classes may override this method to create additional types of buttons, such as TImageButton.
  * @param string button type, either LinkButton or PushButton
  * @param boolean whether the button should be enabled
  * @param string caption of the button.
  * @param string CommandName corresponding to the OnCommand event of the button.
  * @param string CommandParameter corresponding to the OnCommand event of the button
  * @return mixed the button instance
  */
 protected function createPagerButton($buttonType, $enabled, $text, $commandName, $commandParameter)
 {
     if ($buttonType === TPagerButtonType::LinkButton) {
         if ($enabled) {
             $button = new TLinkButton();
         } else {
             $button = new TLabel();
             $button->setText($text);
             $button->setCssClass($this->getButtonCssClass());
             return $button;
         }
     } else {
         if ($buttonType === TPagerButtonType::ImageButton) {
             $button = new TImageButton();
             $button->setImageUrl($this->getPageImageUrl($text, $commandName));
         } else {
             $button = new TButton();
         }
         if (!$enabled) {
             $button->setEnabled(false);
         }
     }
     $button->setText($text);
     $button->setCommandName($commandName);
     $button->setCommandParameter($commandParameter);
     $button->setCausesValidation(false);
     $button->setCssClass($this->getButtonCssClass());
     return $button;
 }
예제 #3
0
 /**
  * Initializes the specified cell to its initial values.
  * This method overrides the parent implementation.
  * It creates a command button within the cell.
  * @param TTableCell the cell to be initialized.
  * @param integer the index to the Columns property that the cell resides in.
  * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
  */
 public function initializeCell($cell, $columnIndex, $itemType)
 {
     if ($itemType === TListItemType::Item || $itemType === TListItemType::AlternatingItem || $itemType === TListItemType::SelectedItem || $itemType === TListItemType::EditItem) {
         $buttonType = $this->getButtonType();
         if ($buttonType === TButtonColumnType::LinkButton) {
             $button = new TLinkButton();
         } else {
             if ($buttonType === TButtonColumnType::PushButton) {
                 $button = new TButton();
             } else {
                 $button = new TImageButton();
                 $button->setImageUrl($this->getImageUrl());
                 $button->setToolTip($this->getText());
             }
         }
         $button->setText($this->getText());
         $button->setCommandName($this->getCommandName());
         $button->setCausesValidation($this->getCausesValidation());
         $button->setValidationGroup($this->getValidationGroup());
         if ($this->getDataTextField() !== '' || $buttonType === TButtonColumnType::ImageButton && $this->getDataImageUrlField() !== '') {
             $button->attachEventHandler('OnDataBinding', array($this, 'dataBindColumn'));
         }
         $cell->getControls()->add($button);
         $cell->registerObject('Button', $button);
     } else {
         parent::initializeCell($cell, $columnIndex, $itemType);
     }
 }
예제 #4
0
 /**
  * Initializes the header cell.
  *
  * This method attempts to use {@link getHeaderRenderer HeaderRenderer} to
  * instantiate the header cell. If that is not available, it will populate
  * the cell with an image or a text string, depending on {@link getHeaderImageUrl HeaderImageUrl}
  * and {@link getHeaderText HeaderText} property values.
  *
  * If the column allows sorting, image or text will be created as
  * a button which issues <b>Sort</b> command upon user click.
  *
  * @param TTableCell the cell to be initialized
  * @param integer the index to the Columns property that the cell resides in.
  */
 protected function initializeHeaderCell($cell, $columnIndex)
 {
     $text = $this->getHeaderText();
     if (($classPath = $this->getHeaderRenderer()) !== '') {
         $control = Prado::createComponent($classPath);
         $cell->getControls()->add($control);
         if ($control instanceof \Prado\IDataRenderer) {
             if ($control instanceof IItemDataRenderer) {
                 $item = $cell->getParent();
                 $control->setItemIndex($item->getItemIndex());
                 $control->setItemType($item->getItemType());
             }
             $control->setData($text);
         }
     } else {
         if ($this->getAllowSorting()) {
             $sortExpression = $this->getSortExpression();
             if (($url = $this->getHeaderImageUrl()) !== '') {
                 $button = new TImageButton();
                 $button->setImageUrl($url);
                 $button->setCommandName(TDataGrid::CMD_SORT);
                 $button->setCommandParameter($sortExpression);
                 if ($text !== '') {
                     $button->setAlternateText($text);
                 }
                 $button->setCausesValidation(false);
                 $cell->getControls()->add($button);
             } else {
                 if ($text !== '') {
                     $button = new TLinkButton();
                     $button->setText($text);
                     $button->setCommandName(TDataGrid::CMD_SORT);
                     $button->setCommandParameter($sortExpression);
                     $button->setCausesValidation(false);
                     $cell->getControls()->add($button);
                 } else {
                     $cell->setText('&nbsp;');
                 }
             }
         } else {
             if (($url = $this->getHeaderImageUrl()) !== '') {
                 $image = new TImage();
                 $image->setImageUrl($url);
                 if ($text !== '') {
                     $image->setAlternateText($text);
                 }
                 $cell->getControls()->add($image);
             } else {
                 if ($text !== '') {
                     $cell->setText($text);
                 } else {
                     $cell->setText('&nbsp;');
                 }
             }
         }
     }
 }
예제 #5
0
 /**
  * Creates a button and initializes its properties.
  * The button type is determined by {@link getButtonType ButtonType}.
  * @param string command name associated with the button
  * @param string button caption
  * @param boolean whether the button should cause validation
  * @param string the validation group that the button belongs to
  * @return mixed the newly created button.
  */
 protected function createButton($commandName, $text, $causesValidation, $validationGroup)
 {
     if ($this->getButtonType() === TButtonColumnType::LinkButton) {
         $button = new TLinkButton();
     } else {
         if ($this->getButtonType() === TButtonColumnType::PushButton) {
             $button = new TButton();
         } else {
             $button = new TImageButton();
             if (strcasecmp($commandName, 'Update') === 0) {
                 $url = $this->getUpdateImageUrl();
             } else {
                 if (strcasecmp($commandName, 'Cancel') === 0) {
                     $url = $this->getCancelImageUrl();
                 } else {
                     $url = $this->getEditImageUrl();
                 }
             }
             $button->setImageUrl($url);
         }
     }
     $button->setText($text);
     $button->setCommandName($commandName);
     $button->setCausesValidation($causesValidation);
     $button->setValidationGroup($validationGroup);
     return $button;
 }
예제 #6
0
 /**
  * Ensure that the ID attribute is rendered and registers the javascript code
  * for initializing the active control.
  */
 protected function addAttributesToRender($writer)
 {
     parent::addAttributesToRender($writer);
     $writer->addAttribute('id', $this->getClientID());
     $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getPostBackOptions());
 }