/** * Get assambled form * @param Nette\Forms\Container $container * @return void */ public function addToFormContainer($container) { /** @var Nette\Application\UI\Form $form */ $form = $container->lookup('Nette\\Application\\UI\\Form'); $translator = $form->getTranslator(); $main_options = []; /** * First foreach for filling "main" select */ foreach ($this->group_actions as $id => $action) { $main_options[$id] = $action->getTitle(); } $container->addSelect('group_action', '', $main_options)->setPrompt('ublaboo_datagrid.choose'); /** * Second for creating select for each "sub"-action */ foreach ($this->group_actions as $id => $action) { $control = NULL; if ($action instanceof GroupSelectAction) { if ($action->hasOptions()) { $control = $container->addSelect($id, '', $action->getOptions()); $control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id); } } else { if ($action instanceof GroupTextAction) { $control = $container->addText($id, ''); $control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id)->addConditionOn($container['group_action'], Form::EQUAL, $id)->setRequired($translator->translate('ublaboo_datagrid.choose_input_required'))->endCondition(); } else { if ($action instanceof GroupTextareaAction) { $control = $container->addTextarea($id, ''); $control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id)->addConditionOn($container['group_action'], Form::EQUAL, $id)->setRequired($translator->translate('ublaboo_datagrid.choose_input_required')); } } } if ($control) { /** * User may set a class to the form control */ if ($class = $action->getClass()) { $control->setAttribute('class', $class); } /** * User may set additional attribtues to the form control */ foreach ($action->getAttributes() as $name => $value) { $control->setAttribute($name, $value); } } } foreach ($this->group_actions as $id => $action) { $container['group_action']->addCondition(Form::EQUAL, $id)->toggle(static::ID_ATTRIBUTE_PREFIX . $id); } $container['group_action']->addCondition(Form::FILLED)->toggle(strtolower($this->datagrid->getName()) . 'group_action_submit'); $container->addSubmit('submit', 'ublaboo_datagrid.execute')->setAttribute('id', strtolower($this->datagrid->getName()) . 'group_action_submit'); if ($form instanceof Nette\ComponentModel\IComponent) { $form->onSubmit[] = [$this, 'submitted']; } }
/** * Adds select box to filter form * @param Nette\Forms\Container $container */ public function addToFormContainer($container) { $form = $container->lookup('Nette\\Application\\UI\\Form'); $translator = $form->getTranslator(); $select = $container->addSelect($this->key, $translator->translate($this->name), $this->options); if (!$this->translateOptions) { $select->setTranslator(NULL); } }
/** * @param Nette\Forms\Container $container * @param string $key * @param string $name * @param array $options * @return Nette\Forms\Controls\SelectBox */ protected function addControl(Nette\Forms\Container $container, $key, $name, $options) { /** * Set some translated texts */ $form = $container->lookup('Nette\\Application\\UI\\Form'); $t = [$form->getTranslator(), 'translate']; $this->addAttribute('title', $t('ublaboo_datagrid.multiselect_choose')); $this->addAttribute('data-i18n-selected', $t('ublaboo_datagrid.multiselect_selected')); /** * Add input to container */ $input = $container->addMultiSelect($key, $name, $options); return $this->addAttributes($input); }