/** * @param Form $form */ public function configure(Form $form) { $form->addGroup(); $form->addText('name', 'Name'); $form->addText('localUrl', 'URL'); $form->addText('title', 'Title'); $form->addText('keywords', 'Keywords'); $form->addText('description', 'Description'); $form->addManyToOne('author', 'Author'); $form->addSelect('robots', 'Robots')->setItems(RouteEntity::getRobotsValues(), FALSE); $form->addSelect('changefreq', 'Change frequency')->setItems(RouteEntity::getChangefreqValues(), FALSE)->setPrompt('-------'); $form->addSelect('priority', 'Priority')->setItems(RouteEntity::getPriorityValues(), FALSE)->setPrompt('-------'); // layout $form->setCurrentGroup($form->addGroup()); $form->addCheckbox('copyLayoutFromParent', 'Layout from parent'); $form['copyLayoutFromParent']->addCondition($form::EQUAL, FALSE)->toggle('group-layout_' . $form->data->id); $form->setCurrentGroup($form->getForm()->addGroup()->setOption('id', 'group-layout_' . $form->data->id)); $form->addManyToOne('layout', 'Layout'); $form->setCurrentGroup($form->addGroup()); $form->addCheckbox('copyLayoutToChildren', 'Share layout with children'); $form['copyLayoutToChildren']->addCondition($form::EQUAL, FALSE)->toggle('group-layout2_' . $form->data->id); $form->setCurrentGroup($form->getForm()->addGroup()->setOption('id', 'group-layout2_' . $form->data->id)); $form->addManyToOne('childrenLayout', 'Share new layout'); // cache $form->setCurrentGroup($form->addGroup()); $form->addCheckbox('copyCacheModeFromParent', 'Cache mode from parent'); $form['copyCacheModeFromParent']->addCondition($form::EQUAL, FALSE)->toggle('group-cache_' . $form->data->id); $form->setCurrentGroup($form->getForm()->addGroup()->setOption('id', 'group-cache_' . $form->data->id)); $form->addSelect('cacheMode', 'Cache strategy')->setItems(\CmsModule\Content\Entities\RouteEntity::getCacheModes(), FALSE)->setPrompt('off'); $form->setCurrentGroup($form->addGroup()); $form->addFileEntityInput('photo', 'Photo'); $form->addTextArea('notation', 'Notation'); $form->addTextArea('text', 'Text'); $form->addGroup('Dates'); $form->addDateTime('created', 'Created')->setDisabled(TRUE); $form->addDateTime('updated', 'Updated')->setDisabled(TRUE); $form->addDateTime('released', 'Released')->addRule($form::FILLED); $form->addDateTime('expired', 'Expired'); $form->addGroup('Tags'); $form->addContentTags('tags'); $aliases = $form->addMany('aliases', function (\Venne\Forms\Container $container) use($form) { $container->setCurrentGroup($form->addGroup('URL alias')); $container->addText('aliasUrl', 'Url')->setRequired(); $container->addText('aliasLang', 'Language alias'); $container->addText('aliasDomain', 'Domain url'); $container->addSubmit('remove', 'Remove alias')->addRemoveOnClick(); }); $aliases->addSubmit('add', 'Add alias')->addCreateOnClick(); $form->setCurrentGroup(); $form->addSaveButton('Save'); }
/** * @param Form $form */ public function configure(Form $form) { $infoGroup = $form->addGroup('Informations'); // route $page = $form->addOne('page'); $mainRoute = $page->addOne('mainRoute'); $mainRoute->setCurrentGroup($infoGroup); $name = $mainRoute->addText('name', 'Name'); if (!$form->data->page->mainRoute->locale) { $name->addRule($form::FILLED); } $mainRoute->addHidden('localUrlTemplate')->getControlPrototype()->class[] = 'localUrlTemplate'; $input = \Nette\Utils\Html::el('input'); $input->id = 'form-checkbox'; $input->type = 'checkbox'; $htmlUrl = \Nette\Utils\Html::el('span'); $htmlUrl->setHtml(' <label>' . $input . ' ' . ($form->getTranslator() ? $form->getTranslator()->translate('autogenerated') : 'autogenerated') . '</label>'); $input = \Nette\Utils\Html::el('input'); $input->id = 'form-checkbox-title'; $input->type = 'checkbox'; $htmlTitle = \Nette\Utils\Html::el('span'); $htmlTitle->setHtml(' <label>' . $input . ' ' . ($form->getTranslator() ? $form->getTranslator()->translate('autogenerated') : 'autogenerated') . '</label>'); $input = \Nette\Utils\Html::el('input'); $input->id = 'form-checkbox-navigationTitle'; $input->type = 'checkbox'; $htmlNavigation = \Nette\Utils\Html::el('span'); $htmlNavigation->setHtml(' <label>' . $input . ' ' . ($form->getTranslator() ? $form->getTranslator()->translate('autogenerated') : 'autogenerated') . '</label>'); $mainRoute->addText('localUrl', 'URL')->addRule($form::REGEXP, "URL can not contain '/'", "/^[a-zA-z0-9._-]*\$/"); $mainRoute['localUrl']->setOption('description', $htmlUrl)->getControlPrototype()->class[] = 'localUrl'; if (!$form->data->page->mainRoute->locale) { $mainRoute['localUrl']->addRule($form::FILLED); } $mainRoute->setCurrentGroup($group = $form->addGroup()); $mainRoute->addText('title', 'Title')->setOption('description', $htmlTitle)->getControlPrototype()->class[] = 'formTitle'; $page->setCurrentGroup($group); $navigationTitle = $page->addText('navigationTitle', 'Navigation title')->setOption('description', $htmlNavigation); $navigationTitle->getControlPrototype()->class[] = 'formNavigation'; if (!$form->data->page->mainRoute->locale) { $navigationTitle->addRule($form::FILLED); } if ($form->data->page->parent) { /** @var ManyToOne $parent */ $parent = $page->addManyToOne('parent', 'Parent'); $parent->setQuery($this->getPagesQueryBuilder($form->data->page))->setPrompt(NULL); } if ($this->getUserPage()) { $mainRoute->addManyToOne('author', 'Author')->setDisabled(TRUE); } if ($this->getTagPage()) { $mainRoute->addContentTags('tags', 'Tags')->getControlPrototype()->class[] = 'input-block-level'; } $mainRoute->setCurrentGroup($form->addGroup('Layout')); if ($form->data->page->parent) { $mainRoute->addCheckbox('copyLayoutFromParent', 'Layout from parent'); } else { $mainRoute->addHidden('copyLayoutFromParent', 'Layout from parent'); } $mainRoute['copyLayoutFromParent']->addCondition($form::EQUAL, FALSE)->toggle('group-layout_' . $form->data->id); if ($form->data->page->parent) { $mainRoute->setCurrentGroup($form->getForm()->addGroup()->setOption('id', 'group-layout_' . $form->data->id)); } else { $mainRoute->setCurrentGroup($form->getForm()->addGroup('Layout')->setOption('id', 'group-layout_' . $form->data->id)); } $mainRoute->addManyToOne('layout', 'Layout'); $mainRoute->setCurrentGroup($form->addGroup()); $mainRoute->addCheckbox('copyLayoutToChildren', 'Share layout with children'); $mainRoute['copyLayoutToChildren']->addCondition($form::EQUAL, FALSE)->toggle('group-layout2_' . $form->data->id); $mainRoute->setCurrentGroup($form->getForm()->addGroup()->setOption('id', 'group-layout2_' . $form->data->id)); $mainRoute->addManyToOne('childrenLayout', 'Share new layout'); // Navigation $page->setCurrentGroup($form->addGroup('Navigation')); $page->addCheckbox('navigationShow', 'Show in navigation')->addCondition($form::EQUAL, TRUE)->toggle('form-navigation-own'); if (!$form->data->page->mainRoute->locale) { // languages /** @var $repository \DoctrineModule\Repositories\BaseRepository */ $repository = $form->mapper->entityManager->getRepository('CmsModule\\Content\\Entities\\LanguageEntity'); if ($repository->createQueryBuilder('a')->select('COUNT(a.id)')->getQuery()->getSingleScalarResult() > 1) { $page->setCurrentGroup($form->addGroup('Languages')); $page->addManyToOne("language", "Content is in")->setPrompt('shared'); } } $form->setCurrentGroup(); $form->addSaveButton('Save'); $js = ' function detectAuto() { $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").unbind("keyup keydown blur"); $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").stringToSlug({getPut: ".localUrlTemplate", space: "-" }); $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").trigger("keyup"); if($("#form-checkbox").is(":checked")) { $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").stringToSlug({getPut: ".localUrl", space: "-" }); } if($("#form-checkbox-title").is(":checked")) { $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").bind("keydown keyup blur", function(){ $(".formTitle").val($(this).val()); }); } if($("#form-checkbox-navigationTitle").is(":checked")) { $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").bind("keydown keyup blur", function(){ $(".formNavigation").val($(this).val()); }); } } function detectCheckbox() { if($("#' . $form['page']['mainRoute']['localUrlTemplate']->getHtmlId() . '").val() == $(".localUrl").val()){ $("#form-checkbox").attr("checked", true); } if($("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").val() == $(".formTitle").val()){ $("#form-checkbox-title").attr("checked", true); } if($("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").val() == $(".formNavigation").val()){ $("#form-checkbox-navigationTitle").attr("checked", true); } } $(document).ready( function() { detectAuto(); detectCheckbox(); detectAuto(); $(".localUrl").on("keydown keyup blur", function(){ $("#form-checkbox").attr("checked", false); detectCheckbox(); detectAuto(); }); $(".formTitle").on("keydown keyup blur", function(){ $("#form-checkbox-title").attr("checked", false); detectCheckbox(); detectAuto(); }); $(".formNavigation").on("keydown keyup blur", function(){ $("#form-checkbox-navigationTitle").attr("checked", false); detectCheckbox(); detectAuto(); }); $("#form-checkbox").on("click", function(event){ detectAuto(); $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").trigger("keyup"); }); $("#form-checkbox-title").on("click", function(){ detectAuto(); $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").trigger("keyup"); }); $("#form-checkbox-navigationTitle").on("click", function(){ detectAuto(); $("#' . $form['page']['mainRoute']['name']->getHtmlId() . '").trigger("keyup"); }); }); '; $script = \Nette\Utils\Html::el('script'); $script->setHtml($js); $form['page']['mainRoute']['name']->setOption('description', $script); }