diff --git a/src/Dravencms/AdminModule/Components/Form/ItemGrid/ItemGrid.php b/src/Dravencms/AdminModule/Components/Form/ItemGrid/ItemGrid.php index 6418903..5492b15 100644 --- a/src/Dravencms/AdminModule/Components/Form/ItemGrid/ItemGrid.php +++ b/src/Dravencms/AdminModule/Components/Form/ItemGrid/ItemGrid.php @@ -101,7 +101,7 @@ public function createComponentGrid($name) $grid = $this->baseGridFactory->create($this, $name); $grid->setDataSource($this->itemRepository->getItemQueryBuilder($this->itemGroup)); - + $grid->setDefaultSort(['position' => 'ASC']); $grid->addColumnText('name', 'Name') ->setSortable() ->setFilterText(); @@ -117,6 +117,7 @@ public function createComponentGrid($name) }) ->setFilterText(); + $grid->addColumnPosition('position', 'Position', 'up!', 'down!'); $grid->addAction('itemOption', 'Options', 'ItemOption:', ['itemId' => 'id']) ->setIcon('bars') @@ -144,7 +145,7 @@ public function createComponentGrid($name) ->setClass('btn btn-xs btn-danger ajax') ->setConfirm('Do you really want to delete row %s?', 'name'); - $grid->addGroupAction('Smazat')->onSelect[] = [$this, 'gridGroupActionDelete']; + $grid->addGroupAction('Smazat')->onSelect[] = [$this, 'handleDelete']; } $grid->addExportCsvFiltered('Csv export (filtered)', 'acl_resource_filtered.csv') @@ -156,14 +157,6 @@ public function createComponentGrid($name) return $grid; } - /** - * @param array $ids - */ - public function gridGroupActionDelete(array $ids) - { - $this->handleDelete($ids); - } - /** * @param $id * @throws \Exception @@ -186,6 +179,23 @@ public function handleDelete($id) $this->onDelete(); } + public function handleUp($id) + { + $item = $this->itemRepository->getOneById($id); + $item->setPosition($item->getPosition() - 1); + $this->entityManager->persist($item); + $this->entityManager->flush(); + } + + public function handleDown($id) + { + $item = $this->itemRepository->getOneById($id); + $item->setPosition($item->getPosition() + 1); + $this->entityManager->persist($item); + $this->entityManager->flush(); + } + + public function render() { $template = $this->template; diff --git a/src/Dravencms/AdminModule/Components/Form/ItemGroupGrid/ItemGroupGrid.php b/src/Dravencms/AdminModule/Components/Form/ItemGroupGrid/ItemGroupGrid.php index 795308f..a43cf1d 100644 --- a/src/Dravencms/AdminModule/Components/Form/ItemGroupGrid/ItemGroupGrid.php +++ b/src/Dravencms/AdminModule/Components/Form/ItemGroupGrid/ItemGroupGrid.php @@ -101,11 +101,13 @@ public function createComponentGrid($name) $grid = $this->baseGridFactory->create($this, $name); $grid->setDataSource($this->itemGroupRepository->getItemGroupQueryBuilder($this->form)); - + $grid->setDefaultSort(['position' => 'ASC']); $grid->addColumnText('identifier', 'Identifier') ->setSortable() ->setFilterText(); + $grid->addColumnPosition('position', 'Position', 'up!', 'down!'); + $grid->addColumnBoolean('isShowName', 'Show name'); if ($this->presenter->isAllowed('form', 'edit')) { @@ -126,7 +128,7 @@ public function createComponentGrid($name) ->setClass('btn btn-xs btn-danger ajax') ->setConfirm('Do you really want to delete row %s?', 'identifier'); - $grid->addGroupAction('Smazat')->onSelect[] = [$this, 'gridGroupActionDelete']; + $grid->addGroupAction('Smazat')->onSelect[] = [$this, 'handleDelete']; } $grid->addExportCsvFiltered('Csv export (filtered)', 'acl_resource_filtered.csv') @@ -138,14 +140,6 @@ public function createComponentGrid($name) return $grid; } - /** - * @param array $ids - */ - public function gridGroupActionDelete(array $ids) - { - $this->handleDelete($ids); - } - /** * @param $id * @throws \Exception @@ -172,6 +166,23 @@ public function handleDelete($id) $this->onDelete(); } + public function handleUp($id) + { + $item = $this->itemGroupRepository->getOneById($id); + $item->setPosition($item->getPosition() - 1); + $this->entityManager->persist($item); + $this->entityManager->flush(); + } + + public function handleDown($id) + { + $item = $this->itemGroupRepository->getOneById($id); + $item->setPosition($item->getPosition() + 1); + $this->entityManager->persist($item); + $this->entityManager->flush(); + } + + public function render() { $template = $this->template; diff --git a/src/Dravencms/AdminModule/Components/Form/ItemOptionGrid/ItemOptionGrid.php b/src/Dravencms/AdminModule/Components/Form/ItemOptionGrid/ItemOptionGrid.php index a80043e..d51cc73 100644 --- a/src/Dravencms/AdminModule/Components/Form/ItemOptionGrid/ItemOptionGrid.php +++ b/src/Dravencms/AdminModule/Components/Form/ItemOptionGrid/ItemOptionGrid.php @@ -80,11 +80,12 @@ public function createComponentGrid($name) $grid = $this->baseGridFactory->create($this, $name); $grid->setDataSource($this->itemOptionRepository->getItemOptionQueryBuilder($this->item)); - + $grid->setDefaultSort(['position' => 'ASC']); $grid->addColumnText('identifier', 'Identifier') ->setSortable() ->setFilterText(); + $grid->addColumnPosition('position', 'Position', 'up!', 'down!'); if ($this->presenter->isAllowed('form', 'edit')) { @@ -100,9 +101,9 @@ public function createComponentGrid($name) ->setIcon('trash') ->setTitle('Smazat') ->setClass('btn btn-xs btn-danger ajax') - ->setConfirm('Do you really want to delete row %s?', 'name'); + ->setConfirm('Do you really want to delete row %s?', 'identifier'); - $grid->addGroupAction('Smazat')->onSelect[] = [$this, 'gridGroupActionDelete']; + $grid->addGroupAction('Smazat')->onSelect[] = [$this, 'handleDelete']; } $grid->addExportCsvFiltered('Csv export (filtered)', 'acl_resource_filtered.csv') @@ -114,13 +115,6 @@ public function createComponentGrid($name) return $grid; } - /** - * @param array $ids - */ - public function gridGroupActionDelete(array $ids) - { - $this->handleDelete($ids); - } /** * @param $id @@ -140,6 +134,22 @@ public function handleDelete($id) $this->onDelete(); } + public function handleUp($id) + { + $item = $this->itemOptionRepository->getOneById($id); + $item->setPosition($item->getPosition() - 1); + $this->entityManager->persist($item); + $this->entityManager->flush(); + } + + public function handleDown($id) + { + $item = $this->itemOptionRepository->getOneById($id); + $item->setPosition($item->getPosition() + 1); + $this->entityManager->persist($item); + $this->entityManager->flush(); + } + public function render() { $template = $this->template; diff --git a/src/Dravencms/FrontModule/Components/Form/Form/Detail/Detail.php b/src/Dravencms/FrontModule/Components/Form/Form/Detail/Detail.php index aebd798..68cd59c 100644 --- a/src/Dravencms/FrontModule/Components/Form/Form/Detail/Detail.php +++ b/src/Dravencms/FrontModule/Components/Form/Form/Detail/Detail.php @@ -211,6 +211,16 @@ public function createComponentForm() $objInput->addRule(Form::MAX_LENGTH, 'Input must have maximaly %d characters', $formsItems->getMaxValue()); } + break; + case Item::TYPE_NUMBER: + $objInput->addRule(Form::NUMERIC, 'You must enter an number'); + if ($formsItems->getMinValue()) { + $objInput->addRule(Form::MIN, 'Minimal number is %d', $formsItems->getMinValue()); + } + + if ($formsItems->getMaxValue()) { + $objInput->addRule(Form::MAX, 'Maximal number is %d', $formsItems->getMaxValue()); + } break; } @@ -252,7 +262,7 @@ public function createComponentForm() $objInput->setAttribute('placeholder', $itemTranslation->getPlaceholder()); } - if ($itemTranslation->getDefaultValue() && !$form->isSubmitted()) { + if ($itemTranslation->getDefaultValue()) { $objInput->setValue($itemTranslation->getDefaultValue()); } } diff --git a/src/Dravencms/Model/Form/Entities/Form.php b/src/Dravencms/Model/Form/Entities/Form.php index 16c7c5c..78336c2 100644 --- a/src/Dravencms/Model/Form/Entities/Form.php +++ b/src/Dravencms/Model/Form/Entities/Form.php @@ -60,6 +60,7 @@ class Form /** * @var ArrayCollection|ItemGroup[] * @ORM\OneToMany(targetEntity="ItemGroup", mappedBy="form",cascade={"persist"}) + * @ORM\OrderBy({"position" = "ASC"}) */ private $itemGroups; diff --git a/src/Dravencms/Model/Form/Entities/ItemGroup.php b/src/Dravencms/Model/Form/Entities/ItemGroup.php index 50a3190..25f0b09 100644 --- a/src/Dravencms/Model/Form/Entities/ItemGroup.php +++ b/src/Dravencms/Model/Form/Entities/ItemGroup.php @@ -52,6 +52,7 @@ class ItemGroup /** * @var ArrayCollection|Item[] * @ORM\OneToMany(targetEntity="Item", mappedBy="itemGroup",cascade={"persist"}) + * @ORM\OrderBy({"position" = "ASC"}) */ private $items;