Overview

Namespaces

  • App
    • Components
    • Interfaces
    • Lib
      • Files
      • Forms
        • Controls
      • Html
      • Repair
      • Statics
    • Model
    • Modules
      • BaseModule
        • Presenters
      • PartnersModule
        • Presenters
      • ProductModule
        • Presenters
      • SaleModule
        • Model
        • Presenters
      • SettingsModule
        • Model
        • Presenters
      • StoreModule
        • Model
        • Presenters
    • Presenters
    • Router
  • PHP

Classes

  • DateTime
  • SplFileInfo

Interfaces

  • ArrayAccess
  • Countable
  • Exception
  • Iterator
  • Traversable
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Download
  1: <?php
  2: 
  3: /**
  4:  * Project sberp
  5:  *
  6:  * @file Form 
  7:  * @author Jaromír Polášek
  8:  * @version 0.7.1.FORM
  9:  * Encoding UTF-8
 10:  */
 11: 
 12: namespace App\Components;
 13: 
 14: use App\Lib\Forms\FormFactory,
 15:     Nette\Application\UI\Form;
 16: 
 17: 
 18: /**
 19:  * Komponenta pro generování formuláře
 20:  */
 21: class FormControl extends Component {
 22:     private $form ;
 23:     
 24:     public function create() {
 25:     $form = New FormFactory($this->action->table);//, $this, 'show');
 26:     $form->addButons($this->form, $this->param);
 27:     $form->addState();
 28:     $form->create();
 29:     
 30:     //$form->addProtection();
 31:     //if (!$form->isSubmitted()) {
 32:     $row = $this->action->data; 
 33:     if (!$row) {
 34:         $this->error('Záznam nenalezen');
 35:     } else if ($row instanceof \Nette\Database\Table\ActiveRow) {
 36:         $form['form']->setDefaults($row);
 37:     }
 38:     //$this->form->onSubmit[] = callback($this,'formCancel');//(Nette\Forms\Controls\Button $button);//(Nette\Forms\Controls\Button $button)
 39:     //$this->form->addText('test');
 40:     //$this->form->addSubmit('send','odeslat');
 41:     //$this->form->onSubmit[] = callback($this,'formCancel');
 42:     
 43:     
 44:     return $form;
 45:     }
 46:        
 47:         
 48:     /**
 49:      * Render nastaví vlastní šablonu a zavolá rodiče
 50:      */
 51:     public function render() {
 52:     $this->controlTemplate = __DIR__ . '/templates/FormControl.latte';
 53:     $this->template->foot = $this->action->jidash;
 54:     parent::render();
 55:     }
 56: 
 57:     /**
 58:      * V připadě úspěšné validace zapíše data do Databáze
 59:      * @param type $button
 60:      */
 61:     public function formSend($button) {
 62:     $this->updateData($button->form->values, (int) $this->getParameter('id'));
 63:     }
 64: 
 65:     public function editform() {
 66:     dump('edit');
 67:     }
 68: 
 69:     /**
 70:      * V případě úspěšného smazání
 71:      */
 72:     public function deleteFormSucceeded() {
 73:     $this->action->data->delete($this->getParameter('id'));
 74:     $this->flashMessage('Záznam byl smazán');
 75:     $this->redirectDefault();
 76:     }
 77: 
 78:     /**
 79:      * V případě zrušení úprav
 80:      */
 81:     public function formCancel(\Nette\Forms\Controls\SubmitButton $button) {
 82:     dump($button);
 83:     $this->redirectDefault();
 84:     }
 85: 
 86:     /**
 87:      * Upraví nebo přidá data do tabulky
 88:      * @param integer $values
 89:      * @param array $id
 90:      */
 91:     protected function updateData($values, $id = NULL) {
 92:     if ($id) {
 93:         $this->data->update($id, $values);
 94:         $this->flashMessage('Záznam byl upraven.');
 95:     } else {
 96:         $this->data->insert($values);
 97:         $this->flashMessage('Záznam byl přidán.');
 98:     }
 99:     $this->redirectDefault();
100:     }
101: 
102:     /**
103:      * provede přesměrování na výchozí zobtrazení
104:      */
105:     private function redirectDefault() {
106:     $this->presenter->redirect('default', $this->action->source);
107:     }   
108: }
109: 
sberp API API documentation generated by ApiGen