예제 #1
0
 public function createForm()
 {
     $f = parent::createForm();
     $id = $this->lookupPath('Nette\\Application\\UI\\Presenter') . '-form';
     $main = $f->addContainer('main');
     $main->addText('firstName', 'common.form.humanName');
     $main->addText('surname', 'common.form.surname');
     $main->addTexyArea('perex', 'article.form.perex')->getControlPrototype()->rows(5);
     $main->addTexyArea('aboutAuthor', 'article.form.aboutAuthor')->getControlPrototype()->rows(10);
     $pic = $f->addContainer('pic');
     $this->createImageUpload($pic, $this->author->image);
     $sidebar = $f->addContainer('sidebar');
     $sidebar->addTexyArea('sidebarContent', 'common.form.sidebarContent')->getControlPrototype()->rows(10);
     $footer = $f->addContainer('footer');
     $footer->addButtonSubmit('saveAuthor', 'common.button.save', 'ok');
     $footer->addLinkSubmit('cancel', '', 'remove', $this->link('cancel!'));
     $f->addProtection();
     $f->enableBootstrap(['success' => ['saveAuthor'], 'default' => ['cancel']], TRUE);
     // fill the form from entity
     $this->binder->entityToForm($this->author, $main);
     $this->binder->entityToForm($this->author, $pic);
     $this->binder->entityToForm($this->author, $sidebar);
     $f->autofocus('main-firstName');
     return $f;
 }
예제 #2
0
 public function createForm()
 {
     $f = parent::createForm();
     $id = $this->lookupPath('Nette\\Application\\UI\\Presenter') . '-form';
     $main = $f->addContainer('main');
     $main->addStatic('parent', 'article.form.parentCategory')->addFilter(function ($cat) {
         return $cat === NULL ? '(' . $this->translator->translate('common.general.nothing') . ')' : $cat->title;
     });
     if ($this->category->depth === 0) {
         $main->addStatic('title', 'article.form.title');
     } else {
         $main->addText('title', 'article.form.title')->setRequired();
     }
     $main->addTexyArea('perex', 'article.form.perex')->getControlPrototype()->rows(5);
     $pic = $f->addContainer('pic');
     $this->createImageUpload($pic, $this->category->image);
     $sidebar = $f->addContainer('sidebar');
     if ($this->category->depth !== 0) {
         $sidebar->addCheckbox('sidebarParent', 'article.form.useParentCategorySidebar');
     }
     $sidebar->addTexyArea('sidebarContent', 'common.form.sidebarContent')->setOption('id', $id . '-sidebar')->getControlPrototype()->rows(15);
     if ($this->category->depth !== 0) {
         $sidebar['sidebarParent']->addCondition($f::EQUAL, FALSE)->toggle($id . '-sidebar');
     }
     $footer = $f->addContainer('footer');
     $footer->addButtonSubmit('saveCategory', 'common.button.save', 'ok');
     $footer->addLinkSubmit('cancel', '', 'remove', $this->link('cancel!'));
     $f->enableBootstrap(['success' => ['saveCategory'], 'default' => ['cancel']], TRUE);
     $this->binder->entityToForm($this->category, $main);
     $this->binder->entityToForm($this->category, $pic);
     $this->binder->entityToForm($this->category, $sidebar);
     return $f;
 }
예제 #3
0
 public function createForm()
 {
     $f = parent::createForm();
     $id = $this->lookupPath('Nette\\Application\\UI\\Presenter') . '-form';
     $main = $f->addContainer('main');
     $main->addStatic('category', 'article.form.category')->addFilter(function ($cat) {
         return $cat->title;
     });
     $main->addTextarea('title', 'article.form.title')->setRequired()->getControlPrototype()->addClass('input-lg');
     $main['title']->getLabelPrototype()->addClass('lead');
     $allAuthors = $this->authorService->findAll();
     $authors = [];
     foreach ($allAuthors as $author) {
         $authors[] = $author->firstName . ' ' . $author->surname;
     }
     $filledAuthors = Arrays::objectsToString($this->article->authors, function ($author) {
         return $author->firstName . ' ' . $author->surname;
     });
     $main->addMultiAutoComplete('authorsList', $this->label('article.form.authors', 'article.formHint.authors'), $authors)->setDefaultValue($filledAuthors);
     $allTags = $this->tagService->findPairs(NULL, 'title');
     $filledTags = Arrays::objectsToString($this->article->tags, function ($tag) {
         return $tag->title;
     });
     $main->addMultiAutoComplete('tagsList', $this->label('article.form.tags', 'article.formHint.tags'), array_values($allTags))->setDefaultValue($filledTags);
     $main->addTexyArea('perex', 'article.form.perex')->getControlPrototype()->rows(5);
     $main->addTexyArea('content', 'article.form.content')->getControlPrototype()->rows(15);
     $pic = $f->addContainer('pic');
     $this->createImageUpload($pic, $this->article->image);
     if ($this->article->category->image !== NULL) {
         $pic->addCheckbox('useCategoryImage', $this->label('article.form.useCategoryImage', 'article.formHint.useCategoryImage'))->addCondition(Form::FILLED)->toggle($id . '-pic-customize');
     }
     $picConfig = $f->addContainer('picConfig');
     $contexts = ['list' => 'article.form.inLists', 'root' => 'article.form.inRoot', 'detail' => 'article.form.inArticleDetail'];
     $picConfig->addCheckboxList('displayImg', $this->label('article.form.displayImg', 'article.formHint.displayImg'), $contexts)->setValue(Arrays::boolToCbl($this->article->getImageConfig('visible')))->setOption('id', $id . '-pic-displayImg');
     $picConfig->addCheckboxList('displayImgOpen', $this->label('article.form.imgOpenOnClick', 'article.formHint.imgOpenOnClick'), $contexts)->setValue(Arrays::boolToCbl($this->article->getImageConfig('open')))->setOption('id', $id . '-pic-displayImgOpen');
     $picConfig->addStatic('displayStyleNote', 'article.form.imageStyles');
     $opts = ['article.form.floatLeft', 'article.form.floatLeftPerex', 'article.form.wide'];
     $configuredStyles = $this->article->getImageConfig('styles');
     foreach ($contexts as $context => $label) {
         $picConfig->addRadioList('displayImgStyle' . ucfirst($context), $label, $opts)->setValue($configuredStyles[$context]);
     }
     $options = $f->addContainer('options');
     $options->addCheckbox('isPublic', 'article.form.publish');
     $options->addCheckbox('isVisibleInRootCategory', 'article.form.setVisibleOnMain');
     $options->addCheckbox('isMain', 'article.form.setAsMain')->setOption('id', $id . '-style-isMain');
     // hide root-related stuff when category is not displayed in root
     $options['isVisibleInRootCategory']->addCondition(Form::EQUAL, TRUE)->toggle($id . '-style-isMain');
     $options->addCheckbox('hideAuthors', 'article.form.hideAuthors');
     $sidebar = $f->addContainer('sidebar');
     $sidebar->addCheckbox('sidebarCategory', 'article.form.useCategorySidebar');
     $sidebar->addTexyArea('sidebarContent', 'common.form.sidebarContent')->setOption('id', $id . '-sidebar')->getControlPrototype()->rows(15);
     $sidebar['sidebarCategory']->addCondition($f::EQUAL, FALSE)->toggle($id . '-sidebar');
     $footer = $f->addContainer('footer');
     $footer->addButtonSubmit('saveArticle', 'common.button.save', 'ok');
     $footer->addLinkSubmit('cancel', '', 'remove', $this->link('cancel!'));
     $f->addProtection();
     $f->enableBootstrap(['success' => ['saveArticle'], 'default' => ['cancel']], TRUE, 3, 'sm', 'form-horizontal', 3);
     // fill the form from entity
     $this->binder->entityToForm($this->article, $main);
     $this->binder->entityToForm($this->article, $pic);
     $this->binder->entityToForm($this->article, $sidebar);
     $this->binder->entityToForm($this->article, $options);
     $f->autofocus('main-title');
     return $f;
 }