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 Fields 
  7:  * @author Jaromír Polášek
  8:  * @version 0.7.1.FORM
  9:  * Encoding UTF-8
 10:  */
 11: 
 12: namespace App\Lib\Forms;
 13: 
 14: use Nette\Application\UI\Form,
 15:     App\Lib\Statics\Cons,
 16:     Nette\Forms\Container as FormContainer;
 17: 
 18: /**
 19:  * Knohovna Rozšířených a přednastavených prvků formuláře
 20:  */
 21: class Controls extends Form {
 22: 
 23:     /**
 24:      * Názvy skupin prvků
 25:      */
 26:     const BUTTONS = 'buttons', STATE = 'state', FORM = 'form';
 27: 
 28:     /**
 29:      * Pokud je ve formuláři zastoupeno speciální pole state
 30:      * @var array 
 31:      */
 32:     protected $state;
 33: 
 34:     /**
 35:      * Pokud je ve formuláři zastoupeno speciální pole desc
 36:      * @var array 
 37:      */
 38:     protected $desc;
 39: 
 40:     /**
 41:      * Pole definic elementů formuláře
 42:      * @var \App\Model\Action\Table
 43:      */
 44:     protected $fields;
 45: 
 46:     /**
 47:      * Zásobník polí
 48:      * @var array
 49:      */
 50:     protected $query;
 51: 
 52:     /**
 53:      * Přístup ke službě Action
 54:      * @var \App\Model\Action 
 55:      */
 56:     protected $action;
 57: 
 58:     /**
 59:      * Ovládací prvky actionbaru
 60:      * @var \Nette\Form\Container 
 61:      */
 62:     private $bar;
 63: 
 64:     public function __construct(\Nette\ComponentModel\IContainer $parent = NULL, $name = NULL) {
 65:     parent::__construct($parent, $name);
 66:     $this->registerExtensions();
 67:     }
 68: 
 69:     /**
 70:      * Vytvoří skupinu ovládacích prvků formuláře
 71:      * @param type $edit
 72:      */
 73:     public function addButons($parent, $edit = TRUE) {
 74:     $this->bar = $this->addContainer(self::BUTTONS);
 75:     if ($edit === TRUE) {
 76:         $this->bar = $this->addSave($parent);
 77:     }
 78:     $this->bar = $this->addCancel($parent);
 79:     }
 80: 
 81:     /**
 82:      * Přidá pole stavů
 83:      */
 84:     public function addState($disabled = FALSE) {
 85:     if (isset($this->fields[Cons::COLUMN_STATE])) {
 86:         $state = $this->fields[Cons::COLUMN_STATE];
 87:         $array = explode(',', $state[Cons::COLUMN_RELATION]);
 88:         $this->bar = $this->addStateRadioList($state[Cons::COLUMN_FIELD])
 89:                 ->setItems($array, FALSE)
 90:                 ->getSeparatorPrototype()->setName(NULL);
 91:         ($disabled) ? : $this[$state[Cons::COLUMN_FIELD]]->setDisabled(TRUE);
 92:     }
 93:     }
 94: 
 95:     /**
 96:      * Přidá pole poznámka
 97:      */
 98:     public function adddesc($disabled = FALSE) {
 99:     if (isset($this->fields[Cons::COLUMN_DESC])) {
100:         $desc = $this->fields[Cons::COLUMN_DESC];
101:         $this->bar = $this->addTextArea($desc[Cons::COLUMN_FIELD], $desc[Cons::COLUMN_NAME])
102:             ->addRule(Form::MAX_LENGTH, 'Poznámka je příliš dlouhá', $desc[Cons::COLUMN_LENGHT])
103:             ->setAttribute('class', 'desc');
104:         ($disabled) ? : $this[$desc[Cons::COLUMN_FIELD]]->setDisabled(TRUE);
105:     }
106:     }
107: 
108:     /**
109:      * Adds set of radio button controls to the form.
110:      * @param  string  control name
111:      * @param  string  label
112:      * @param  array   options from which to choose
113:      * @return Nette\Forms\Controls\RadioList
114:      */
115:     public function addStateRadioList($name, $label = NULL, array $items = NULL) {
116:     return $this[$name] = new Controls\StateRadioList($label, $items);
117:     }
118: 
119:     /**
120:      * Přidá tlačítko Uložit
121:      * @param Nette\Application\UI\Presenter $parent Presenter obsahující vykonávanou metodu
122:      */
123:     protected function addSave($parent) {
124:     $this->addSubmit('save', 'Uložit')
125:             ->setAttribute('class', 'default button')
126:         ->onClick[] = array($parent, 'formSend');
127:     }
128: 
129:     /**
130:      * Přidá tlačítko Zrušit
131:      * @param Nette\Application\UI\Presenter $parent Presenter obsahující vykonávanou metodu
132:      */
133:     protected function addCancel($parent) {
134:     $this->addSubmit('cancel', 'Zpět')
135:             ->setAttribute('class', 'button')
136:             ->setValidationScope(array())
137:         ->onClick[] = array($parent, 'formCancel');
138:     }
139: 
140:     /**
141:      * Zaregistruje vlastní prvky jako ExtensionsMethod
142:      * 
143:      */
144:     private function registerExtensions() {
145:     /**
146:      * Rozšíření selectboxu o načítání dat z Action
147:      */
148:     FormContainer::extensionMethod('addSelector', function (FormContainer $container, $name, $label, $lenght) {
149:         $items = $this->action->getRelation($this->query[Cons::COLUMN_FIELD], $this->query[Cons::COLUMN_RELATION]);
150:         $control = new \Nette\Forms\Controls\SelectBox($label, $items);
151:         if ($lenght > 1) {
152:         $control->setAttribute('size', (int) $lenght);
153:         }
154:         return $container[$name] = $control;
155:     });
156: 
157:     /**
158:      * Plugin Datepicker
159:      */
160:     FormContainer::extensionMethod('addDatePicker', function (FormContainer $container, $name, $label = NULL) {
161:         return $container[$name] = new \App\Lib\Forms\Controls\DatePicker($label);
162:     });
163: 
164:     /**
165:      * Přidá ovladač Check box Text do Formuláře
166:      * @param type $name
167:      * @param type $caption
168:      * @return type
169:      */
170:     FormContainer::extensionMethod('addCheckboxText', function (FormContainer $container, $name, $caption = NULL) {
171:         return $container[$name] = new \App\Lib\Forms\Controls\CheckboxText($caption);
172:     });
173: 
174:     /**
175:      * Upravuje kompatibilitu Dadiolistu
176:      * @param  string  control name
177:      * @param  string  label
178:      * @param  array   options from which to choose
179:      * @return Nette\Forms\Controls\RadioList
180:      */
181:     FormContainer::extensionMethod('addRadio', function (FormContainer $container, $name, $label) {
182:         $items = explode(',', $this->query[Cons::COLUMN_RELATION]);
183:         $container[$name] = new \App\Lib\Forms\Controls\StateRadioList($label, $items);
184:         return $container[$name]->setItems($items, FALSE)
185:                 ->getSeparatorPrototype()->setName(NULL);
186:     });
187:     }
188: 
189: }
190: 
sberp API API documentation generated by ApiGen