Exemple #1
0
 public function generateForm(Items\Base $item, Nette\Forms\Container &$formContainer, $name, $parentName, $togglingObject, array $userOptions = [])
 {
     $input = $formContainer->addTextArea($name, $name);
     $input->setOption('id', $parentName . '__' . $name);
     $input->setValue($item->getContent());
     if (!is_null($togglingObject)) {
         $togglingObject->toggle($input->getOption('id'));
     }
     $item->applyUserOptions($input, $userOptions);
 }
Exemple #2
0
 public function generateForm(Items\Base $item, Nette\Forms\Container &$formContainer, $name, $parentName, $togglingObject, array $userOptions = [])
 {
     $input = $formContainer->addText($name, $name);
     $input->setOption('id', $parentName . '__' . $name);
     $input->setValue($item->getContent());
     $input->setType('time');
     $input->addCondition(UI\Form::FILLED)->addRule(UI\Form::PATTERN, __('Time must be in format HH:MM'), '([0-9]{2}[-: ]{1}[0-9]{2})');
     if (!is_null($togglingObject)) {
         $togglingObject->toggle($input->getOption('id'));
     }
     $item->applyUserOptions($input, $userOptions);
 }
Exemple #3
0
 public function proceedEditForm(UI\Form $form, Items\Base $itemContainer, $field, $contentName)
 {
     $values = $form->getValues(TRUE);
     $itemContainer->update($values[$field]);
     $this->logObject($itemContainer->getUpdated(), $contentName);
     return TRUE;
 }
Exemple #4
0
 public function update($data)
 {
     $oldData = $this->rawData;
     parent::update($data);
     if ($this->isUpdated) {
         $this->updated = is_null($oldData) ? self::EMPTY_VALUE : $oldData;
     }
 }
Exemple #5
0
 /**
  * @param Base|ListContainer                 $item
  * @param Nette\Forms\Container              $formContainer
  * @param                                    $name
  * @param                                    $parentName
  * @param Nette\Forms\Rules                  $togglingObject
  * @param array                              $userOptions
  */
 public function generateForm(Base $item, Nette\Forms\Container &$formContainer, $name, $parentName, $togglingObject, array $userOptions = [])
 {
     $container = $formContainer->addContainer($name);
     $newParent = NULL;
     if (!isset($item->configuration['count']) && (!isset($item->configuration['max']) || $item->configuration['max'] > count($item->getChild()))) {
         $newParent = $parentName . '__' . $name . Base::NEW_CONTAINER;
         $new = $container->addSubmit(Base::NEW_ITEM_BUTTON, $this->getConfigValue('addItemLabel', 'new', $userOptions));
         $new->setValidationScope(FALSE)->setAttribute('id', $newParent . Base::NEW_ITEM_BUTTON);
         $new->onClick[] = function (Nette\Forms\Controls\SubmitButton $button) use($container) {
             if (count($container->getComponent(Base::NEW_ITEM_CONTENT)->getComponents()) < 1) {
                 /** @var Nette\Forms\Controls\SelectBox $listSelect */
                 $listSelect = $container->getComponent(self::LIST_BOX);
                 $items = $listSelect->getItems();
                 $items[$newItemId = count($items)] = Base::NEW_ITEM_BUTTON_LABEL;
                 $listSelect->setItems($items);
                 $listSelect->setValue($newItemId);
                 $button->getParent()->getComponent(Base::NEW_ITEM_CONTENT)->createOne();
                 $button->getForm()->onSuccess = [];
             }
         };
         $container->addDynamic($item::NEW_ITEM_CONTENT, function (Nette\Forms\Container $container) use($item, $newParent, $togglingObject, $userOptions) {
             $child = isset($this->configuration['child']) ? $this->configuration['child'] : (isset($this->configuration['listItem']) ? $this->configuration['listItem'] : []);
             /** @var Nette\Forms\Controls\SelectBox $listSelect */
             $listSelect = $container->getParent()->getParent()->getComponent(self::LIST_BOX);
             $items = $listSelect->getItems();
             if (is_null($togglingObject)) {
                 $subTogglingObject = $listSelect->addCondition(Nette\Application\UI\Form::EQUAL, count($items) - 1);
             } else {
                 $subTogglingObject = $togglingObject->addConditionOn($listSelect, Nette\Application\UI\Form::EQUAL, count($items) - 1);
             }
             $newListItem = Contents\Factory::getItemObject(['type' => 'container', 'child' => $child], NULL, $item->subTypes);
             $newListItem->generateForm($newListItem, $container, NULL, $newParent, $subTogglingObject, $userOptions);
         });
     }
     if (!isset($item->configuration['count'])) {
         $deleteContainer = $container->addContainer(ListContainer::DELETE_ITEM);
     }
     $listSelect = new Contents\NoValidateSelectBox($this->getConfigValue('listLabel', 'list', $userOptions), NULL);
     $container[self::LIST_BOX] = $listSelect;
     $listSelect->setOption('id', $parentName . self::LIST_BOX . $name);
     if (!is_null($togglingObject)) {
         $togglingObject->toggle($listSelect->getOption('id'));
         if (!is_null($newParent)) {
             $togglingObject->toggle($newParent . Base::NEW_ITEM_BUTTON);
         }
     }
     $items = [];
     $listHead = $this->getConfigValue('listHead', NULL, $userOptions);
     foreach ($this->getChild() as $childName => $child) {
         if (is_null($togglingObject)) {
             /** @var Nette\Forms\Rules $subTogglingObject */
             $subTogglingObject = $listSelect->addCondition(Nette\Application\UI\Form::EQUAL, $childName);
         } else {
             /** @var Nette\Forms\Rules $subTogglingObject */
             $subTogglingObject = $togglingObject->addConditionOn($listSelect, Nette\Application\UI\Form::EQUAL, $childName);
         }
         if (!isset($item->configuration['count'])) {
             $removeButton = $deleteContainer->addCheckbox($childName, $this->getConfigValue('deleteLabel', 'remove item', $userOptions));
             $removeButton->setOption('id', $parentName . '__' . $name . ListContainer::DELETE_ITEM . $childName);
             $subTogglingObject->toggle($removeButton->getOption('id'));
         }
         $child->generateForm($child, $container, $childName, $parentName . '__' . $name, $subTogglingObject, isset($userOptions['child']) && is_array($userOptions['child']) ? ['child' => $userOptions['child']] : []);
         try {
             $itemName = is_null($listHead) ? $childName : Trejjam\Utils\Utils::getValue($child->getContent(), $listHead);
         } catch (Trejjam\Utils\LogicException $e) {
             if ($e->getCode() & Trejjam\Utils\Exception::UTILS_KEY_NOT_FOUND) {
                 $itemName = $childName;
             } else {
                 throw $e;
             }
         }
         if (empty($itemName)) {
             $itemName = $childName;
         }
         $items[$childName] = $itemName;
     }
     $postedValue = (string) $listSelect->getRawValue();
     if ($postedValue != '' && !isset($items[$postedValue])) {
         $items[$postedValue] = '';
     }
     $listSelect->setItems($items);
     if (count($items) > 0) {
         $listSelect->setDefaultValue('0');
     }
     $item->applyUserOptions($container, $userOptions);
 }
Exemple #6
0
 /**
  * @param Base|Container                   $item
  * @param Nette\Forms\Container            $formContainer
  * @param                                  $name
  * @param                                  $parentName
  * @param Nette\Forms\Rules                $togglingObject
  * @param array                            $userOptions
  */
 public function generateForm(Base $item, Nette\Forms\Container &$formContainer, $name, $parentName, $togglingObject, array $userOptions = [])
 {
     $container = is_null($name) ? $formContainer : $formContainer->addContainer($name);
     foreach ($this->getChild() as $childName => $child) {
         $child->generateForm($child, $container, $childName, $parentName . '__' . $name, $togglingObject, isset($userOptions['child']) && isset($userOptions['child'][$childName]) && is_array($userOptions['child'][$childName]) ? $userOptions['child'][$childName] : []);
     }
     $item->applyUserOptions($container, $userOptions);
 }