1: <?php
2: namespace Budovy;
3:
4: use Nette\Object;
5: use Nette\Utils\Paginator;
6: use Nette\Utils\Html;
7: use Nette\Application\UI;
8: use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
9:
10: class ScheduledTaskRealizationFactory extends Object {
11: 12: 13:
14: private $scheduledTaskRepository;
15:
16: 17: 18:
19: private $scheduledTaskRealizationRepository;
20:
21: 22: 23:
24: private $contactRepository;
25:
26: 27: 28:
29: protected $documenttypeRepository;
30:
31: function __construct(ScheduledTaskRepository $scheduledTaskRepository, ScheduledTaskRealizationRepository $scheduledTaskRealizationRepository, ContactRepository $contactRepository, DocumenttypeRepository $documenttypeRepository) {
32: $this->scheduledTaskRepository = $scheduledTaskRepository;
33: $this->scheduledTaskRealizationRepository = $scheduledTaskRealizationRepository;
34: $this->contactRepository = $contactRepository;
35: $this->documenttypeRepository = $documenttypeRepository;
36: }
37:
38: function createDataGrid() {
39: $grid = new \Nextras\Datagrid\Datagrid;
40:
41: $grid->addColumn('name', 'Název úkolu')->enableSort();
42: $grid->addColumn('price', 'Cena')->enableSort();
43: $grid->addColumn('date', 'Datum')->enableSort();
44: $grid->addColumn('contact', 'Kontakt')->enableSort();
45:
46: $grid->setRowPrimaryKey('id');
47:
48: $grid->setDatasourceCallback(function ($filter, $order, Paginator $paginator = null) {
49: return $this->scheduledTaskRealizationRepository->getGridSelection($filter, $order, $paginator->page, $paginator->itemsPerPage);
50: });
51:
52: $grid->setFilterFormFactory(function () {
53: $form = new \Nette\Forms\Container;
54:
55: $form->addText('price');
56: $form->addText('date')->setAttribute('data-dateinput-type', 'date');
57: $form->addSelect('name', 'Název úkolu', array('' => '') + $this->scheduledTaskRepository->getPairData());
58: $form->addSelect('contact', 'Kontakt', array('' => '') + $this->contactRepository->getPairData());
59:
60: $form->addSubmit('filter', 'Hledej');
61: $form->addSubmit('cancel', 'Zrušit');
62:
63: $pretyp = $form['filter']->getControlPrototype();
64: $pretyp->setName("button");
65: $pretyp->type = 'submit';
66: $pretyp->class = 'ico-btn';
67: $pretyp->create('i class="fa fa-search"');
68:
69: $pretyp = $form['cancel']->getControlPrototype();
70: $pretyp->setName("button");
71: $pretyp->type = 'submit';
72: $pretyp->class = 'ico-btn';
73: $pretyp->create('i class="fa fa-times-circle-o"');
74:
75: return $form;
76: });
77:
78: $grid->setPagination(20, function ($filter, $order) {
79: return $this->scheduledTaskRealizationRepository->getGridCount($filter);
80: });
81:
82: $grid->addCellsTemplate(__DIR__ . '/../templates/ScheduledTaskRealization/grid.latte');
83:
84: return $grid;
85: }
86:
87: function createEditForm($backlink) {
88: $form = new UI\Form;
89:
90: $form->setRenderer(new BootstrapRenderer());
91:
92: $form->getElementPrototype()->class = 'form-horizontal';
93:
94: $base = $form->addContainer('base');
95:
96: $base->addText('price', 'Cena opravy:')
97: ->addRule(UI\Form::FLOAT, 'Cena musí být číslo')
98: ->setAttribute('class', 'form-control');
99:
100: $base->addDate('date', 'Datum', \Vodacek\Forms\Controls\DateInput::TYPE_DATE)
101: ->addRule(UI\Form::VALID)
102: ->setAttribute('class', 'form-control');
103:
104: $base->addSelect('id_scheduledtask', 'Plánovaná úloha', $this->scheduledTaskRepository->getApprovedPairData());
105: $base->addSelect('id_contact', 'Kontakt', array(0 => '') + $this->contactRepository->getPairData());
106:
107: $base->addTextArea('description', 'Popis:')
108: ->setAttribute('class', 'form-control');
109:
110: $form->addSubmit('saving', 'Uložit a zpět')
111: ->setAttribute('class', 'btn btn-primary');
112:
113: $form->addSubmit('back')
114: ->setAttribute('class', 'btn btn-inverse')
115: ->getControlPrototype()
116: ->setName('a')
117: ->href($backlink)
118: ->add(Html::el('i')->class('fa fa-reply'))
119: ->add(Html::el('span', ' Zpět'));
120:
121: $document = $form->addContainer('document');
122:
123: $document->addSelect('id_documenttype', 'Typ', $this->documenttypeRepository->getPairData());
124: $document->addUpload('files', 'Soubor', true);
125:
126: return $form;
127: }
128: }