/** * compile */ protected function compile() { if ($this->cssID[0] == '') { $cssID = $this->cssID; $cssID[0] = 'modal-' . $this->id; $this->cssID = $cssID; } $modal = new Component(); $modal->setId($this->cssID[0])->setSize($this->bootstrap_modalSize); if ($this->cssID[1]) { $modal->addClass($this->cssID[1]); } // check if ajax is used if ($this->bootstrap_modalAjax) { $this->Template->hideFrame = $this->isAjax; $this->Template->hideContent = !$this->Template->hideFrame; } if ($this->Template->hideContent) { $url = \Controller::generateFrontendUrl($GLOBALS['objPage']->row()) . '?bootstrap_modal=' . $this->id; //$url = sprintf(Bootstrap::getConfigVar('modal.remoteUrl'), $GLOBALS['objPage']->id, $this->id); $modal->setAttribute('data-remote', $url)->render($this->Template); return; } if ($this->headline) { $headline = Element::create($this->hl)->addClass('modal-title')->addChild($this->headline); $modal->setTitle($headline); } $modal->setContent($this->getContent())->setFooter($this->getButtons())->setCloseButton(Bootstrap::getConfigVar('modal.dismiss'), true)->render($this->Template); }
/** * Compile the module. * * @return void */ protected function compile() { if ($this->cssID[0] == '') { $cssID = $this->cssID; $cssID[0] = 'modal-' . $this->id; $this->cssID = $cssID; } $modal = new Component(); $modal->setId($this->cssID[0])->setSize($this->bootstrap_modalSize)->setAttribute('role', 'dialog')->setAttribute('aria-hidden', 'true')->setAttribute('taxindex', '-1'); if ($this->cssID[1]) { $modal->addClass($this->cssID[1]); } // check if ajax is used if ($this->bootstrap_modalAjax) { $this->Template->hideFrame = $this->isAjax; $this->Template->hideContent = !$this->Template->hideFrame; } if ($this->Template->hideContent) { $modal->render($this->Template); return; } if ($this->headline) { $headline = Element::create($this->hl)->addClass('modal-title')->addChild($this->headline); $modal->setTitle($headline); } $modal->setContent($this->getContent())->setFooter($this->getButtons())->setCloseButton(Bootstrap::getConfigVar('modal.dismiss'), true)->render($this->Template); }
/** * @param CastsToString $closeButton * @param bool $create * @return $this */ public function setCloseButton($closeButton, $create = false) { if ($create) { $closeButton = Element::create('button')->addClass('close')->setAttribute('data-dismiss', 'modal')->setAttribute('aria-hidden', 'true')->addChild($closeButton); } $this->closeButton = $closeButton; return $this; }
public function generate() { // import assets $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/bootstrap-datepicker/assets/bootstrap-datepicker/dist/js/bootstrap-datepicker.js'; $GLOBALS['TL_CSS'][] = 'system/modules/bootstrap-datepicker/assets/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css'; // import localized assets, except for 'en' since its embedded $langCode = strtolower(substr($GLOBALS['TL_LANGUAGE'], 0, 2)); if ($langCode != 'en') { $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/bootstrap-datepicker/assets/bootstrap-datepicker/dist/locales/bootstrap-datepicker.' . $langCode . '.min.js'; } // derive input format for calendar $this->inputFormat = strtolower(\Date::getInputFormat()); // fallback format if (!$this->inputFormat) { $this->inputFormat == 'mm/dd/yyyy'; } // create the input field $input = Element::create('input')->addAttributes(array('name' => specialchars($this->name), 'placeholder' => $this->placeholder, 'maxlength' => strlen($this->inputFormat), 'value' => $this->value)); if ($this->mandatory) { $input->addClass('mandatory')->addAttributes(array('required' => true)); } // pass min and max date to the input field if ($this->bsdp_range != '') { $objToday = new \Date(); if ($this->bsdp_range == 'past') { $this->endDate = $objToday->date; } elseif ($this->bsdp_range == 'future') { $this->startDate = $objToday->date; } elseif ($this->bsdp_range == 'range') { $this->startDate = $this->bsdp_datemin; $this->endDate = $this->bsdp_datemax; } } // return result return $input; }
/** * Generate the widget and return it as string. * * @return string */ public function generate() { $buttonClass = $this->strClass ? $this->strClass : Bootstrap::getConfigVar('form.default-submit-btn'); $button = Element::create('button', $this->arrAttributes)->setId('ctrl_' . $this->strId)->addAttributes(array('type' => 'submit', 'class' => array('submit', 'btn', $buttonClass), 'title' => specialchars($this->slabel))); if ($this->imageSubmit) { $model = \FilesModel::findByPk($this->singleSRC); if ($model !== null && is_file(TL_ROOT . '/' . $model->path)) { $button->addChild(\Image::getHtml($model->path, $this->slabel)); return $button; } } $label = specialchars($this->slabel); if ($this->bootstrap_addIcon) { $icon = Bootstrap::generateIcon($this->bootstrap_icon); if ($this->bootstrap_iconPosition == 'right') { $button->addChild($label)->addChild(' ' . $icon); } else { $button->addChild($icon . ' ')->addChild($label); } } else { $button->addChild($label); } return $button; }
/** * Create a text based element. * * @param \Widget $widget The form widget. * * @return Element\Node|Element\Standalone */ public function createTextBasedElement($widget) { $element = Element::create('input', array('type' => $widget->type)); $element->setAttribute('name', $widget->name); return $element; }
/** * @param $tag * @param array $attributes * @param string $position * @return Node|Standalone */ public function createChild($tag, $attributes = array(), $position = Node::POSITION_LAST) { $child = Element::create($tag, $attributes); $this->addChild($child, $position); return $child; }
/** * Create link from insert tag. * * @param int $modelId Modal model id. * @param string $label Optional custom label. * * @return Standalone|null * * @SuppressWarnings(PHPMD.Superglobals) */ private function createLink($modelId, $label = null) { $model = \ModuleModel::findByPk($modelId); if (!$model) { return null; } $cssId = deserialize($model->cssID, true); $selector = '#' . ($cssId[0] ?: 'modal-' . $model->id); $this->loadModal($modelId); $element = Element::create('a'); if ($model->bootstrap_modalAjax && TL_MODE === 'FE') { $page = $GLOBALS['objPage']->row(); $link = \Controller::generateFrontendUrl($page) . '?bootstrap_modal=' . $model->id; $element->setAttribute('href', $link)->setAttribute('data-target', $selector); } else { $element->setAttribute('href', $selector); } $element->setAttribute('data-toggle', 'modal'); if (!$label) { $element->addChild($model->name); } else { $element->addChild($label); } return $element; }
/** * @param $addon * @return string */ protected function generateAddon($addon) { if (!is_array($addon)) { return ''; } return Element::create('div')->addClass($addon['type'])->addChild($addon['addon'])->generate(); }
/** * Preset the submit button. * * @param ViewEvent $event Event listened to. * * @return void */ public function presetSubmit(ViewEvent $event) { $view = $event->getView(); $widget = $view->getWidget(); $container = $view->getContainer(); $element = $container->getElement(); if ($view->getWidgetType() == 'submit') { // Unknown element type or pre rendered element. if (!$element instanceof Element || $widget instanceof GeneratesAnElement) { return; } $element->setAttribute('value', $widget->slabel); if (!$widget->imageSubmit) { return; } $element->setAttribute('type', 'image'); if (version_compare(VERSION, '3', '>=')) { $path = \FilesModel::findByPk($widget->singleSRC)->path; } else { $path = $widget->singleSRC; } $element->setAttribute('src', $path); $element->setAttribute('title', $widget->slabel); if ($widget->imageSubmit) { $element->setAttribute('type', 'image')->setAttribute('src', \FilesModel::findByPk($widget->singleSRC)->path); } } elseif ($widget->addSubmit) { $submit = Element::create('input'); $submit->setAttribute('type', 'submit'); $submit->setAttribute('value', $widget->slabel); $container->addChild('submit', $submit); } }
/** * Generate the upload field. * * @param ContextualConfig|Config $config The bootstrap config. * @param Container $container Form element container. * @param \Widget $widget Form widget. * * @return void */ private function generateUpload($config, Container $container, $widget) { $config = $config->get('form.styled-upload'); $element = $container->getElement(); /** @var Element $element */ $element->addClass('sr-only'); $element->setAttribute('onchange', sprintf($config['onchange'], $element->getId())); $input = Element::create('input', array('type' => 'text'))->setId($element->getId() . '_value')->addClass('form-control')->setAttribute('disabled', true)->setAttribute('name', $element->getAttribute('name') . '_value'); if ($element->hasAttribute('placeholder')) { $input->setAttribute('placeholder', $element->getAttribute('placeholder')); } elseif ($widget->placeholder) { $input->setAttribute('placeholder', $widget->placeholder); } $click = sprintf('$(%s).click();return false;', $element->getId()); $submit = Element::create('button', array('type' => 'submit'))->addChild($config['label'])->addClass($config['class'])->setAttribute('onclick', $click); $inputGroup = new InputGroup(); $inputGroup->setElement($input); if ($config['position'] == 'left') { $inputGroup->setLeft($submit, $inputGroup::BUTTON); } else { $inputGroup->setRight($submit, $inputGroup::BUTTON); } $container->addChild('upload', $inputGroup); }
/** * @param $container * @param $widget * @param $inputGroup */ private function adjustSubmitButton(Container $container, $widget, InputGroup $inputGroup) { if ($container->hasChild('submit')) { /** @var Node $submit */ $submit = $container->removeChild('submit'); // recreate as button if ($submit->getTag() != 'button') { $submit = Element::create('button'); $submit->setAttribute('type', 'submit'); $submit->addChild($widget->slabel); } $submit->addClass('btn'); if ($widget->bootstrap_addSubmitClass) { $submit->addClass($widget->bootstrap_addSubmitClass); } if ($widget->bootstrap_addSubmitIcon) { $icon = Icons::generateIcon($widget->bootstrap_addSubmitIcon); $position = null; if ($widget->bootstrap_addSubmitIconPosition == 'left') { $position = Node::POSITION_FIRST; $icon .= ' '; } else { $icon = ' ' . $icon; } $submit->addChild(new StaticHtml($icon), $position); } $inputGroup->setRight($submit, $inputGroup::BUTTON); } }