1 <?php
2
3 namespace Objednavky;
4
5 use Nette\Application\UI;
6 use Nette\Utils\Html;
7 use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
8 use PLus\Orders\Repositories;
9
10 11 12 13 14
15 class AreaPresenter extends BasePresenter {
16
17
18
19 public $areaRepository;
20
21
22
23 protected function createComponentGrid($name) {
24
25 $user = $this->getUser();
26
27 $grid = new \Grido\Grid($this, $name);
28 $grid->setmodel($this->areaRepository->getGridSelection());
29
30 $grid->translator->lang = 'cs';
31 $grid->defaultPerPage = 15;
32 $grid->filterRenderType = \Grido\Components\Filters\Filter::RENDER_INNER;
33 $grid->setRememberState(TRUE);
34
35 $grid->addColumnText('name', 'Název')
36 ->setFilterText()
37 ->setSuggestion();
38 $grid->getColumn('name')->headerPrototype->style['width'] = '50%';
39
40 $grid->addActionHref('view', 'Zobrazit')
41 ->setIcon('fa fa-eye fa-fw');
42
43 if ($user->isAllowed('setup', 'edit')) {
44 $grid->addActionHref('edit', 'Editovat')
45 ->setIcon('pencil fa-fw');
46 }
47
48
49 $grid->setExport();
50
51 }
52
53
54 public function renderView($id){
55 $item = $this->areaRepository->findById($id);
56 if (!$item) {
57 $this->redirect('default');
58 }
59
60 $this->template->item = $item;
61 $this->template->usersarea = $this->areaRepository->getUsersArea($id);
62 }
63
64
65 public function actionEdit($id){
66
67 $item = $this->areaRepository->findById($id);
68
69
70 if ($id > 0 && $item === FALSE) {
71 $this->redirect('default');
72 }
73
74
75 if ($id > 0) {
76 $this['editForm']->setDefaults($item);
77
78 }
79
80
81 $this->template->id = $id;
82 }
83
84 protected function createComponentEditForm() {
85 $session = $this->getSession()->getSection('history');
86
87 if (isset($session->secarea)) {
88 $backlink = $session->secarea;
89 } else {
90 $backlink = $this->link('default');
91 }
92
93
94 $form = $this->createEditForm($backlink);
95 $form->onSuccess[] = $this->editFormSubmitted;
96
97 return $form;
98 }
99
100
101 public function editFormSubmitted($form) {
102 $fdata = $form->getValues();
103 $id = $this->getParameter('id');
104
105
106 if ($id) {
107 $this->areaRepository->updateById($id, $fdata);
108 $this->flashMessage("Záznam byl upraven.", "success");
109 } else {
110 $this->areaRepository->insertData($fdata);
111 $this->flashMessage("Záznam byl vložen.", "success");
112 }
113
114 $session = $this->getSession()->getSection('history');
115
116 if (isset($session->secarea)) {
117 $backlink = $session->secarea;
118 } else {
119 $backlink = $this->link('default');
120 }
121
122 $this->redirectUrl($backlink);
123 }
124
125
126
127
128 function createEditForm($backlink){
129
130 $user = $this->getUser();
131 $form = new UI\Form;
132 $form->setRenderer(new BootstrapRenderer());
133
134 $form->getElementPrototype()->class = 'form-horizontal';
135
136
137 $form->addText('name', 'Název:')
138 ->setRequired('Zadejte prosím název')
139 ->setAttribute('class', 'form-control');
140
141
142 $form->addSubmit('saving', 'Uložit a zpět')
143 ->setAttribute('class', 'btn btn-danger');
144
145
146 $form->addSubmit('back')
147 ->setAttribute('class', 'btn btn-outline btn-danger')
148 ->getControlPrototype()
149 ->setName('a')
150 ->href($backlink)
151 ->add(Html::el('i')->class('fa fa-reply'))
152 ->add(Html::el('span', ' Zpět'));
153
154 return $form;
155 }
156
157
158 }
159