Beispiel #1
0
 /**
  * Component factory.
  * @see Nette/ComponentContainer#createComponent()
  */
 protected function createComponentForm($name)
 {
     // NOTE: signal-submit on form disregard component's state
     //		because form is created directly by Presenter in signal handling phase
     //		and this principle is used to detect submit signal
     if (!$this->wasRendered) {
         $this->receivedSignal = 'submit';
     }
     $form = new Nette\Application\UI\Form($this, $name);
     $form->setTranslator($this->getTranslator());
     Nette\Forms\Controls\BaseControl::$idMask = 'frm-datagrid-' . $this->getUniqueId() . '-%s';
     $form->onSuccess[] = array($this, 'formSubmitHandler');
     $form->addSubmit('resetSubmit', 'Reset state');
     $form->addSubmit('filterSubmit', 'Apply filters');
     $form->addSelect('operations', 'Selected:', $this->operations);
     $form->addSubmit('operationSubmit', 'Send')->onClick = $this->onOperationSubmit;
     // page input
     $form->addText('page', 'Page', 1);
     $form['page']->setDefaultValue($this->page);
     $form->addSubmit('pageSubmit', 'Change page');
     // items per page selector
     $form->addSelect('items', 'Items per page', array_combine($this->displayedItems, $this->displayedItems));
     $form['items']->setDefaultValue($this->itemsPerPage);
     $form->addSubmit('itemsSubmit', 'Change');
     // generate filters FormControls
     if ($this->hasFilters()) {
         $defaults = array();
         $sub = $form->addContainer('filters');
         foreach ($this->getFilters() as $filter) {
             $sub->addComponent($filter->getFormControl(), $filter->getName());
             // NOTE: must be setted after is FormControl conntected to the form
             $defaults[$filter->getName()] = $filter->value;
         }
         $sub->setDefaults($defaults);
     }
     // checker
     if ($this->hasOperations()) {
         $sub = $form->addContainer('checker');
         if ($this->isSignalReceiver('submit')) {
             // NOTE: important!
             $ds = clone $this->dataSource;
             $this->filterItems();
         }
         foreach ($this->getRows() as $row) {
             $sub->addCheckbox($row[$this->keyName], $row[$this->keyName]);
         }
         if (isset($ds)) {
             $this->dataSource = $ds;
         }
     }
     $renderer = $form->getRenderer();
     $renderer->wrappers['controls']['container'] = NULL;
     $renderer->wrappers['label']['container'] = NULL;
     $renderer->wrappers['control']['container'] = NULL;
     $form->setRenderer($renderer);
     return;
 }