Exemple #1
0
 /**
  * @param string $key
  * @param mixed $value
  * @param bool $append
  * @param bool $translated
  */
 public function setAttribute($key, $value, $append = false, $translated = false)
 {
     if ($key === 'class' && !$this->inRendering) {
         throw new Mesour\NotSupportedException('Can not set class directly. Use methods setType and setPrefix for specify class name.');
     }
     parent::setAttribute($key, $value, $append, $translated);
 }
Exemple #2
0
 public function create()
 {
     parent::create();
     $wrapper = $this->getControlPrototype();
     $oldWrapper = clone $wrapper;
     foreach ($oldWrapper->attrs as $key => $attr) {
         if (is_object($attr)) {
             $oldWrapper->attrs[$key] = clone $attr;
         }
     }
     if ($this->ajaxLoading) {
         $application = $this->lookup(Mesour\Components\Application\IApplication::class, false, true);
         if (!$application) {
             throw new Mesour\InvalidStateException(sprintf('If use ajax loading, modal component must be attached to %s.', Mesour\UI\Application::class));
         }
     }
     $wrapper->addAttributes(['data-ajax-loading' => $this->ajaxLoading ? $this->createLinkName() : 'false', 'data-is-cached' => $this->cached ? 'true' : 'false']);
     $wrapper->add($this->getContent());
     $this->onRender($this);
     $this->setHtmlElement($oldWrapper);
     return $wrapper;
 }
Exemple #3
0
 public function create()
 {
     parent::create();
     $wrapper = $this->getControlPrototype();
     $oldWrapper = clone $wrapper;
     foreach ($oldWrapper->attrs as $key => $attr) {
         if (is_object($attr)) {
             $oldWrapper->attrs[$key] = clone $attr;
         }
     }
     $wrapper->add($this->getClosePrototype());
     if ($this->title) {
         $title = $this->getTitlePrototype();
         $title->setText($this->getTranslator()->translate($this->title));
         $wrapper->add($title);
     }
     foreach ($this->getComponents() as $component) {
         $wrapper->add($component->create());
     }
     $this->onRender($this);
     $this->setHtmlElement($oldWrapper);
     return $wrapper;
 }
Exemple #4
0
 public function create()
 {
     parent::create();
     $wrapper = $this->getControlPrototype();
     $oldWrapper = clone $wrapper;
     foreach ($oldWrapper->attrs as $key => $attr) {
         if (is_object($attr)) {
             $oldWrapper->attrs[$key] = clone $attr;
         }
     }
     $closeButton = $this->getCloseButton();
     if (!$closeButton->isDisabled() && $closeButton->isAllowed()) {
         $wrapper->add($this->getCloseButton());
     }
     foreach ($this->getComponents() as $component) {
         if ($component->getName() === 'closeButton') {
             continue;
         }
         $wrapper->add($component->create());
     }
     $this->onRender($this);
     $this->setHtmlElement($oldWrapper);
     return $wrapper;
 }
Exemple #5
0
 public function create()
 {
     parent::create();
     if ($this->getDataStructure() instanceof Mesour\Editable\Structures\DataStructure && !$this->getDataStructure()->getSource(false)) {
         throw new Mesour\InvalidStateException(sprintf('Source is required if use %s.', Mesour\Editable\Structures\DataStructure::class));
     }
     $wrapper = $this->getControlPrototype();
     $oldWrapper = clone $wrapper;
     foreach ($oldWrapper->attrs as $key => $attr) {
         if (is_object($attr)) {
             $oldWrapper->attrs[$key] = clone $attr;
         }
     }
     $script = Mesour\Components\Utils\Html::el('script');
     $script->setHtml($this->createCoreScript());
     $wrapper->add($script);
     $modal = $this->getModal();
     $modal->getModalFooter()->addButton('saveButton')->setType('primary')->setAttribute('data-editable-form-save', 'true')->setText('Save');
     $modal->setAttribute('data-editable-modal', $this->createLinkName());
     $wrapper->add($this->getModal()->create());
     $this->onRender($this);
     $this->setHtmlElement($oldWrapper);
     return $wrapper;
 }
Exemple #6
0
 public function create()
 {
     parent::create();
     $wrapper = $this->getWrapperPrototype();
     $fullData = $this->beforeCreate(true);
     $hidden = $this->createHiddenInput($fullData);
     $this->onRender($this);
     $dataStructure = $this->getSource()->getDataStructure();
     $hasCheckers = count($fullData) > 0;
     foreach ($this as $name => $itemInstance) {
         /** @var Mesour\Filter\IFilterItem $itemInstance */
         $itemInstance->setCheckers($hasCheckers);
         $item = $this->getItem($name);
         $source = $this->getSource(false);
         if ($source && $source->getTotalCount() > 0) {
             if ($dataStructure->hasColumn($name) && $dataStructure->getColumn($name) instanceof BaseTableColumnStructure) {
                 /** @var BaseTableColumnStructure $column */
                 $column = $dataStructure->getColumn($name);
                 $item->setReferenceSettings($column->getTableStructure()->getName());
             } elseif (isset($this->predefinedData[$name])) {
                 $item->setReferenceSettings(self::PREDEFINED_KEY);
             }
         }
         $wrapper->add($item->create());
     }
     $wrapper->add($this->createResetButton());
     $wrapper->add($hidden);
     return $wrapper;
 }
Exemple #7
0
 public function create()
 {
     parent::create();
     $wrapper = $this->getControlPrototype();
     $oldWrapper = clone $wrapper;
     foreach ($oldWrapper->attrs as $key => $attr) {
         if (is_object($attr)) {
             $oldWrapper->attrs[$key] = clone $attr;
         }
     }
     $this->onBeforeRender($this, $wrapper);
     $rendererFactory = $this->getRendererFactory();
     $this->useRendererFactory();
     $dialog = $rendererFactory->createDialog();
     $dialog->setAttribute('class', $this->getOption(self::DIALOG), true);
     $header = $this->getModalHeader();
     $body = $this->getModalBody();
     $footer = $this->getModalFooter();
     $content = $rendererFactory->createContent();
     $content->setAttribute('class', $this->getOption(self::CONTENT), true);
     $content->setHeader($header);
     $content->setBody($body);
     $content->setFooter($footer);
     $dialog->setContent($content);
     $wrapper->add($dialog->create());
     $wrapper->addAttributes(['data-mesour-modal' => $this->createLinkName(), 'data-show' => 'false', 'data-mesour-show' => $this->showed ? 'true' : 'false', 'data-keyboard' => $this->keyboard ? 'true' : 'false', 'data-backdrop' => $this->backdrop ? 'true' : 'false']);
     $this->onRender($this);
     $this->setHtmlElement($oldWrapper);
     return $wrapper;
 }
Exemple #8
0
 public function create()
 {
     parent::create();
     $wrapper = $this->getControlPrototype();
     $oldWrapper = clone $wrapper;
     foreach ($oldWrapper->attrs as $key => $attr) {
         if (is_object($attr)) {
             $oldWrapper->attrs[$key] = clone $attr;
         }
     }
     if ($this->hasLeftIcon()) {
         $oldLeftIcon = clone $this->getLeftIcon();
     }
     if ($this->hasRightIcon()) {
         $oldRightIcon = clone $this->getRightIcon();
     }
     $this->onRender($this);
     $optionData = $this->getOption(self::DEFAULTS);
     if (!$this->isAllowed()) {
         $this->setDisabled(true);
     }
     foreach ($this->getOption(self::WRAPPER, 'attributes') as $key => $value) {
         if ($value instanceof Mesour\Components\Link\IUrl) {
             continue;
         }
         if (!$this->hasAttribute($key) || $this->getAttribute($key, false) !== false) {
             $value = trim(Mesour\Components\Utils\Helpers::parseValue($value, $optionData));
             if ($this->hasAttribute($key)) {
                 $value .= ' ' . $this->getAttribute($key);
             }
             $this->setAttribute($key, $value);
         }
     }
     if (!is_null($this->className)) {
         $this->setAttribute('class', $this->className === '' ? false : $this->className);
     }
     $this->getAttributes($this->isDisabled());
     if ($this->hasLeftIcon()) {
         $leftIcon = $this->getLeftIcon();
         $leftIcon->setOption('data', $this->getOption('data'));
         $wrapper->add($leftIcon->create());
         if (strlen($this->text) > 0) {
             $wrapper->add(' ');
         }
         if (isset($oldLeftIcon)) {
             unset($this['leftIcon']);
             $this['leftIcon'] = $oldLeftIcon;
         }
     }
     if ($this->text) {
         $wrapper->add($this->getTranslator()->translate($this->text));
     }
     if ($this->html) {
         $wrapper->add($this->html);
     }
     if ($this->hasRightIcon()) {
         $rightIcon = $this->getRightIcon();
         $rightIcon->setOption('data', $this->getOption('data'));
         if (strlen($this->text) > 0) {
             $wrapper->add(' ');
         }
         $wrapper->add($rightIcon->create());
         if (isset($oldRightIcon)) {
             unset($this['rightIcon']);
             $this['rightIcon'] = $oldRightIcon;
         }
     }
     $this->setHtmlElement($oldWrapper);
     return $wrapper;
 }
Exemple #9
0
 public function __clone()
 {
     $this->ul = null;
     $this->paginator = clone $this->paginator;
     parent::__clone();
 }
Exemple #10
0
 public function create()
 {
     parent::create();
     $wrapper = $this->getWrapperPrototype();
     if ($this->referenceSettings) {
         $wrapper->addAttributes(['data-reference-settings' => $this->referenceSettings]);
     }
     $button = $this->getButtonPrototype();
     $this->onRender($this);
     /** @var Mesour\UI\Icon $icon */
     $iconClass = $this->getIconClass();
     $icon = new $iconClass();
     $icon->setType($this->iconOk);
     $icon->setAttribute('style', 'display: none');
     $icon->setAttribute('data-filter-icon', 'check');
     $button->add($icon->render());
     $button->add(' ' . $this->getText() . ' ');
     $button->add('<span class="caret"></span>');
     $icon->setAttribute('style', false);
     if (count($this->valueTranslates)) {
         $wrapper->add(Mesour\Components\Utils\Html::el('input', ['value' => json_encode($this->valueTranslates), 'type' => 'hidden', 'data-translates' => 1]));
     }
     $wrapper->add($button);
     $ul = $this->getListUlPrototype();
     if ($this->hasMainFilter && count($this->filters) > 0) {
         $subMenu = $this->getListLiPrototype(['class' => 'dropdown-submenu']);
         $icons = '<span><button type="button" class="btn btn-success btn-xs reset-filter" title="';
         $icons .= $this->getTranslator()->translate('Reset filter') . '" style="display: none;">';
         $icon->setAttribute('data-filter-icon', 'has-custom');
         $icons .= $icon->render();
         $icon->setAttribute('style', 'display: none');
         $icon->setType($this->iconClose);
         $icon->setAttribute('data-filter-icon', 'reset');
         $icons .= $icon->render();
         $icon->setAttribute('style', false);
         $icons .= '</button><button type="button" class="btn btn-primary btn-xs mesour-open-modal edit-filter" title="';
         $icons .= $this->getTranslator()->translate('Edit filter') . '" style="display: none;">';
         $icon->setAttribute('data-filter-icon', 'edit');
         $icon->setType($this->iconEdit);
         $icons .= $icon->render();
         $icons .= sprintf('</button>%s</span>', $this->getTranslator()->translate($this->filtersName));
         $subMenu->add($icons);
         $subUl = Mesour\Components\Utils\Html::el('ul', ['class' => 'dropdown-menu']);
         foreach ($this->filters as $filter) {
             $this->createCustomFilterItem($subUl, $filter);
         }
         $subMenu->add($subUl);
         $ul->add($subMenu);
     }
     if ($this->hasCheckers || $this->referenceSettings !== false) {
         if ($this->hasMainFilter) {
             $ul->add($this->getListLiPrototype(['class' => 'divider']));
         }
         $checkersLi = $this->getListLiPrototype();
         $inlineBox = Mesour\Components\Utils\Html::el('div', ['class' => 'inline-box']);
         $search = Mesour\Components\Utils\Html::el('div', ['class' => 'search']);
         $search->add('<input type="text" class="form-control search-input" placeholder="' . $this->getTranslator()->translate('Search...') . '">');
         $checkersLi->add($inlineBox);
         $inlineBox->add($search);
         $boxInner = Mesour\Components\Utils\Html::el('div', ['class' => 'box-inner']);
         $checkersLi->add($boxInner);
         $innerUl = Mesour\Components\Utils\Html::el('ul');
         $boxInner->add($innerUl);
         $linkName = $this->createLinkName();
         $innerUl->add('<li class="all-select-li">
                             <input type="checkbox" class="select-all" id="select-all-' . $linkName . '">
                             <label for="select-all-' . $linkName . '">' . $this->getTranslator()->translate('Select all') . '</label>
                         </li>
                         <li class="all-select-searched-li">
                             <input type="checkbox" class="select-all-searched" id="selected-' . $linkName . '">
                             <label for="selected-' . $linkName . '">' . $this->getTranslator()->translate('Select all searched') . '</label>
                         </li>');
         $ul->add($checkersLi);
     }
     $wrapper->add($ul);
     return $wrapper;
 }
Exemple #11
0
 public function create()
 {
     parent::create();
     $id = $this->getRandomStringGenerator()->generate();
     $wrapper = $this->getControlPrototype();
     $oldWrapper = clone $wrapper;
     $menu = $this->getMenuPrototype();
     $oldMenu = clone $menu;
     $this->onRender($this);
     $optionData = $this->getOption(self::DEFAULTS);
     foreach ($this->getOption(self::WRAPPER, 'attributes') as $key => $value) {
         if (!$wrapper->{$key} && $wrapper->{$key} !== false) {
             $menu->addAttributes([$key => trim(Mesour\Components\Utils\Helpers::parseValue($value, $optionData))]);
         }
     }
     $main = $this->getMainButton();
     $main->setOption('data', $this->getOption('data'));
     $main->setAttribute('id', $id);
     foreach ($this->getOption(self::MENU, 'attributes') as $key => $value) {
         if (!$menu->{$key}) {
             $menu->addAttributes([$key => Mesour\Components\Utils\Helpers::parseValue($value, $optionData)]);
         }
     }
     $menu->addAttributes(['aria-labelledby' => $id]);
     if ($this->hasPullRight) {
         $menu->addAttributes(['class' => $menu->class . ' dropdown-menu-right']);
     }
     if (!$this->isDisabled()) {
         $isFirst = true;
         $items = $this->getItems();
         foreach ($items as $key => $item) {
             if ($item instanceof Mesour\DropDown\Item) {
                 if (!$item->isAllowed()) {
                     continue;
                 }
                 $item->setOption('data', $this->getOption('data'));
                 $currentItem = $this->getMenuItemPrototype();
                 $currentItem->class($this->getOption(self::ITEMS, 'button_class'));
                 $currentItem->add($item->create());
                 $menu->add($currentItem);
                 $isFirst = false;
             } else {
                 $isNext = $this->isSomeNext($items, $key + 1);
                 if (isset($items[$key + 1]) && $isNext) {
                     $isNext = $this->isSomeNext($items, $key + 1);
                     $menu->add($item);
                     $isFirst = false;
                 }
                 if (!$isNext && ($this->isDivider($items[$key]) && !$isFirst) && $this->isHeader($items[$key + 1]) && (isset($items[$key + 2]) && $this->isSomeNext($items, $key + 2))) {
                     $menu->add($item);
                     $isFirst = false;
                 }
             }
         }
         if ($isFirst) {
             $main->setDisabled();
         }
     } else {
         $main->setDisabled();
     }
     $wrapper->add($main->create()->add($this->getOption(self::CARET)));
     $wrapper->add($menu);
     $out = $wrapper;
     $this->menu = $oldMenu;
     $this->setHtmlElement($oldWrapper);
     return $out;
 }