TWebControl is the base class for controls that share a common set of UI-related properties and methods. TWebControl-derived controls are usually associated with HTML tags. They thus have tag name, attributes and body contents. You can override {@link getTagName} to specify the tag name, {@link addAttributesToRender} to specify the attributes to be rendered, and {@link renderContents} to customize the body content rendering. TWebControl encapsulates a set of properties related with CSS style fields, such as {@link getBackColor BackColor}, {@link getBorderWidth BorderWidth}, etc. Subclasses of TWebControl typically needs to override {@link addAttributesToRender} and {@link renderContents}. The former is used to render the attributes of the HTML tag associated with the control, while the latter is to render the body contents enclosed within the HTML tag.
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Prado\Web\UI\TControl, implements Prado\Web\UI\WebControls\IStyleable
Ejemplo n.º 1
0
 /**
  * Copies basic control attributes from another control.
  * Properties including AccessKey, ToolTip, TabIndex, Enabled
  * and Attributes are copied.
  * @param TWebControl source control
  */
 public function copyBaseAttributes(TWebControl $control)
 {
     $this->setAccessKey($control->getAccessKey());
     $this->setToolTip($control->getToolTip());
     $this->setTabIndex($control->getTabIndex());
     if (!$control->getEnabled()) {
         $this->setEnabled(false);
     }
     if ($control->getHasAttributes()) {
         $this->getAttributes()->copyFrom($control->getAttributes());
     }
 }
Ejemplo n.º 2
0
 /**
  * Renders the body content of the label.
  * @param THtmlWriter the renderer
  */
 public function renderContents($writer)
 {
     if (($text = $this->getText()) === '') {
         parent::renderContents($writer);
     } else {
         $writer->write($text);
     }
 }
Ejemplo n.º 3
0
 /**
  * Renders body content.
  * This method overrides the parent implementation by replacing
  * the body content with the processed text content.
  * @param THtmlWriter writer
  */
 public function renderContents($writer)
 {
     if (($text = $this->getText()) === '' && $this->getHasControls()) {
         $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
         parent::renderContents($htmlWriter);
         $text = $htmlWriter->flush();
     }
     if ($text !== '') {
         $writer->write($this->processText($text));
     }
 }
Ejemplo n.º 4
0
 /**
  * Adds attributes related to an HTML image element to renderer.
  * @param THtmlWriter the writer used for the rendering purpose
  */
 protected function addAttributesToRender($writer)
 {
     $writer->addAttribute('src', $this->getImageUrl());
     $writer->addAttribute('alt', $this->getAlternateText());
     if (($desc = $this->getDescriptionUrl()) !== '') {
         $writer->addAttribute('longdesc', $desc);
     }
     if (($align = $this->getImageAlign()) !== '') {
         $writer->addAttribute('align', $align);
     }
     parent::addAttributesToRender($writer);
 }
Ejemplo n.º 5
0
 /**
  * Renders the body content of the hyperlink.
  * @param THtmlWriter the writer for rendering
  */
 public function renderContents($writer)
 {
     if (($imageUrl = $this->getImageUrl()) === '') {
         if (($text = $this->getText()) !== '') {
             $writer->write(THttpUtility::htmlEncode($text));
         } else {
             if ($this->getHasControls()) {
                 parent::renderContents($writer);
             } else {
                 $writer->write(THttpUtility::htmlEncode($this->getNavigateUrl()));
             }
         }
     } else {
         $this->createImage($imageUrl)->renderControl($writer);
     }
 }
Ejemplo n.º 6
0
 /**
  * Renders body contents of the tab view.
  * @param THtmlWriter the writer used for the rendering purpose.
  */
 public function renderContents($writer)
 {
     if (($text = $this->getText()) !== '') {
         $writer->write($text);
     } else {
         if ($this->getHasControls()) {
             parent::renderContents($writer);
         }
     }
 }
Ejemplo n.º 7
0
 public function render($writer)
 {
     parent::render($writer);
     if (($butt = $this->getDefaultButton()) !== '') {
         if (($button = $this->findControl($butt)) === null) {
             throw new TInvalidDataValueException('panel_defaultbutton_invalid', $butt);
         } else {
             $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Adds attribute name-value pairs to renderer.
  * This overrides the parent implementation with additional button specific attributes.
  * @param THtmlWriter the writer used for the rendering purpose
  */
 protected function addAttributesToRender($writer)
 {
     if ($this->getID() !== '') {
         $writer->addAttribute('name', $this->getUniqueID());
     }
     if (($src = $this->getFrameUrl()) !== '') {
         $writer->addAttribute('src', $src);
     }
     if (($align = strtolower($this->getAlign())) !== 'notset') {
         $writer->addAttribute('align', $align);
     }
     $scrollBars = $this->getScrollBars();
     if ($scrollBars === TInlineFrameScrollBars::None) {
         $writer->addAttribute('scrolling', 'no');
     } else {
         if ($scrollBars === TInlineFrameScrollBars::Both) {
             $writer->addAttribute('scrolling', 'yes');
         }
     }
     if (!$this->getShowBorder()) {
         $writer->addAttribute('frameborder', '0');
     }
     if (($longdesc = $this->getDescriptionUrl()) !== '') {
         $writer->addAttribute('longdesc', $longdesc);
     }
     if (($width = $this->getWidth()) !== -1) {
         $writer->addAttribute('width', $width);
     }
     if (($height = $this->getHeight()) !== -1) {
         $writer->addAttribute('height', $height);
     }
     if (($marginheight = $this->getMarginHeight()) !== -1) {
         $writer->addAttribute('marginheight', $marginheight);
     }
     if (($marginwidth = $this->getMarginWidth()) !== -1) {
         $writer->addAttribute('marginwidth', $marginwidth);
     }
     parent::addAttributesToRender($writer);
 }
Ejemplo n.º 9
0
 /**
  * Renders the openning tag for the table control which will render table caption if present.
  * @param THtmlWriter the writer used for the rendering purpose
  */
 public function renderBeginTag($writer)
 {
     parent::renderBeginTag($writer);
     if (($caption = $this->getCaption()) !== '') {
         if (($align = $this->getCaptionAlign()) !== TTableCaptionAlign::NotSet) {
             $writer->addAttribute('align', strtolower($align));
         }
         $writer->renderBeginTag('caption');
         $writer->write($caption);
         $writer->renderEndTag();
     }
 }
Ejemplo n.º 10
0
 /**
  * Renders the body content enclosed between the control tag.
  * This overrides the parent implementation with nothing to be rendered for input tags,
  * button tags are rendered normally.
  * @param THtmlWriter the writer used for the rendering purpose
  */
 public function renderContents($writer)
 {
     if ($this->getButtonTag() === TButtonTag::Button) {
         parent::renderContents($writer);
     }
 }
Ejemplo n.º 11
0
 public function render($writer)
 {
     $this->registerClientScript();
     parent::render($writer);
 }
Ejemplo n.º 12
0
 /**
  * Renders the datagrid.
  * @param THtmlWriter writer for the rendering purpose
  */
 public function render($writer)
 {
     if ($this->getHasControls()) {
         $this->groupCells();
         if ($this->_useEmptyTemplate) {
             $control = new TWebControl();
             $control->setID($this->getClientID());
             $control->copyBaseAttributes($this);
             if ($this->getHasStyle()) {
                 $control->getStyle()->copyFrom($this->getStyle());
             }
             $control->renderBeginTag($writer);
             $this->renderContents($writer);
             $control->renderEndTag($writer);
         } else {
             if ($this->getViewState('ItemCount', 0) > 0) {
                 $this->applyItemStyles();
                 if ($this->_topPager) {
                     $this->_topPager->renderControl($writer);
                     $writer->writeLine();
                 }
                 $this->renderTable($writer);
                 if ($this->_bottomPager) {
                     $writer->writeLine();
                     $this->_bottomPager->renderControl($writer);
                 }
             }
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Creates the child controls of the wizard.
  * This method overrides the parent implementation.
  * @param TEventParameter event parameter
  */
 public function onInit($param)
 {
     parent::onInit($param);
     $this->ensureChildControls();
     $this->setEnsureId(true);
     if ($this->getActiveStepIndex() < 0 && $this->getWizardSteps()->getCount() > 0) {
         $this->setActiveStepIndex(0);
     }
 }
Ejemplo n.º 14
0
 /**
  * Renders the control.
  * The method overrides the parent implementation by rendering
  * the pager only when there are two or more pages.
  * @param THtmlWriter the writer
  */
 public function render($writer)
 {
     if ($this->_pageCount > 1) {
         parent::render($writer);
     }
 }
Ejemplo n.º 15
0
 /**
  * Ensures any pending databind is performed.
  * This method overrides the parent implementation.
  * @param TEventParameter event parameter
  */
 public function onPreRender($param)
 {
     $this->_prerendered = true;
     $this->ensureDataBound();
     parent::onPreRender($param);
 }
Ejemplo n.º 16
0
 /**
  * Registers the checkbox to receive postback data during postback.
  * This is necessary because a checkbox if unchecked, when postback,
  * does not have direct mapping between post data and the checkbox name.
  *
  * This method overrides the parent implementation and is invoked before render.
  * @param mixed event parameter
  */
 public function onPreRender($param)
 {
     parent::onPreRender($param);
     if ($this->getEnabled(true)) {
         $this->getPage()->registerRequiresPostData($this);
     }
 }
Ejemplo n.º 17
0
 /**
  * Adds attribute name-value pairs to renderer.
  * This method overrides the parent implementation with additional TKeyboard specific attributes.
  * @param THtmlWriter the writer used for the rendering purpose
  */
 protected function addAttributesToRender($writer)
 {
     parent::addAttributesToRender($writer);
     if ($this->getPage()->getClientSupportsJavaScript()) {
         $writer->addAttribute('id', $this->getClientID());
     }
 }
Ejemplo n.º 18
0
 /**
  * Ensure that the ID attribute is rendered and registers the javascript code
  * for initializing the active control.
  */
 protected function addAttributesToRender($writer)
 {
     //calls the TWebControl to avoid rendering other attribute normally render for a textbox.
     TWebControl::addAttributesToRender($writer);
     $writer->addAttribute('id', $this->getLabelClientID());
     $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getPostBackOptions());
 }
Ejemplo n.º 19
0
 public function render($writer)
 {
     if ($this->getHasPreRendered()) {
         $this->setDisplay($this->getPageCount() == 1 ? TDisplayStyle::None : TDisplayStyle::Dynamic);
         TWebControl::render($writer);
         if ($this->getActiveControl()->canUpdateClientSide()) {
             $this->getPage()->getCallbackClient()->replaceContent($this, $writer);
         }
     } else {
         $this->getPage()->getAdapter()->registerControlToRender($this, $writer);
     }
 }
Ejemplo n.º 20
0
 /**
  * Sets Enctype of the form on the page.
  * This method overrides the parent implementation and is invoked before render.
  * @param mixed event parameter
  */
 public function onPreRender($param)
 {
     parent::onPreRender($param);
     if (($form = $this->getPage()->getForm()) !== null) {
         $form->setEnctype('multipart/form-data');
     }
     $this->getPage()->getClientScript()->registerHiddenField('MAX_FILE_SIZE', $this->getMaxFileSize());
     if ($this->getEnabled(true)) {
         $this->getPage()->registerRequiresPostData($this);
     }
 }
Ejemplo n.º 21
0
 protected function addAttributesToRender($writer)
 {
     $display = $this->getDisplay();
     $visible = $this->getEnabled(true) && count($this->getErrorMessages()) > 0;
     if (!$visible) {
         if ($display === TValidationSummaryDisplayStyle::None || $display === TValidationSummaryDisplayStyle::Dynamic) {
             $writer->addStyleAttribute('display', 'none');
         } else {
             $writer->addStyleAttribute('visibility', 'hidden');
         }
     }
     $writer->addAttribute('id', $this->getClientID());
     parent::addAttributesToRender($writer);
 }
Ejemplo n.º 22
0
 /**
  * Renders the repeated items.
  * @param THtmlWriter writer for the rendering purpose
  * @param IRepeatInfoUser repeat information user
  */
 public function renderRepeater($writer, IRepeatInfoUser $user)
 {
     if ($this->_repeatLayout === TRepeatLayout::Table) {
         $control = new TTable();
         if ($this->_caption !== '') {
             $control->setCaption($this->_caption);
             $control->setCaptionAlign($this->_captionAlign);
         }
     } else {
         if ($this->_repeatLayout === TRepeatLayout::Raw) {
             $this->renderRawContents($writer, $user);
             return;
         } else {
             $control = new TWebControl();
         }
     }
     $control->setID($user->getClientID());
     $control->copyBaseAttributes($user);
     if ($user->getHasStyle()) {
         $control->getStyle()->copyFrom($user->getStyle());
     }
     $control->renderBeginTag($writer);
     $writer->writeLine();
     if ($this->_repeatDirection === TRepeatDirection::Vertical) {
         $this->renderVerticalContents($writer, $user);
     } else {
         $this->renderHorizontalContents($writer, $user);
     }
     $control->renderEndTag($writer);
 }
Ejemplo n.º 23
0
 /**
  * Registers CSS and JS.
  * This method is invoked right before the control rendering, if the control is visible.
  * @param mixed event parameter
  */
 public function onPreRender($param)
 {
     parent::onPreRender($param);
     $this->registerStyleSheet();
     $this->registerSliderClientScript();
 }
Ejemplo n.º 24
0
 /**
  * Renders an additional line-break after the opening tag when it
  * is in MultiLine text mode.
  * @param THtmlWriter the writer used for the rendering purpose^M
  */
 public function renderBeginTag($writer)
 {
     parent::renderBeginTag($writer);
     if ($this->getTextMode() === 'MultiLine') {
         $writer->write("\n");
     }
 }
Ejemplo n.º 25
0
 protected function addAttributesToRender($writer)
 {
     parent::addAttributesToRender($writer);
     $writer->addAttribute('id', $this->getClientID());
 }