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 DimenzionPresenter extends BasePresenter {
16
17
18
19 public $dimenzionRepository;
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->dimenzionRepository->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('catalog', '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->dimenzionRepository->findById($id);
56 if (!$item) {
57 $this->redirect('default');
58 }
59
60 $this->template->item = $item;
61 }
62
63
64 public function actionEdit($id){
65
66 $item = $this->dimenzionRepository->findById($id);
67
68
69 if ($id > 0 && $item === FALSE) {
70 $this->redirect('default');
71 }
72
73
74 if ($id > 0) {
75 $this['editForm']->setDefaults($item);
76
77 }
78
79
80 $this->template->id = $id;
81 }
82
83 protected function createComponentEditForm() {
84 $session = $this->getSession()->getSection('history');
85
86 if (isset($session->secdimenzion)) {
87 $backlink = $session->secdimenzion;
88 } else {
89 $backlink = $this->link('default');
90 }
91
92
93 $form = $this->createEditForm($backlink);
94 $form->onSuccess[] = $this->editFormSubmitted;
95
96 return $form;
97 }
98
99
100 protected function createComponentCreateForm() {
101
102 $session = $this->getSession()->getSection('history');
103
104 if (isset($session->secdimenzion)) {
105 $backlink = $session->secdimenzion;
106 } else {
107 $backlink = $this->link('default');
108 }
109
110
111 $form = $this->createEditForm($backlink);
112 $form->onSuccess[] = $this->editFormSubmitted;
113
114 return $form;
115 }
116
117
118 public function editFormSubmitted($form) {
119 $fdata = $form->getValues();
120 $id = $this->getParameter('id');
121
122
123 if ($id) {
124 $this->dimenzionRepository->updateById($id, $fdata);
125 $this->flashMessage("Záznam byl upraven.", "success");
126 } else {
127 $this->dimenzionRepository->insertData($fdata);
128 $this->flashMessage("Záznam byl vložen.", "success");
129 }
130
131 $session = $this->getSession()->getSection('history');
132
133 if (isset($session->secdimenzion)) {
134 $backlink = $session->secdimenzion;
135 } else {
136 $backlink = $this->link('default');
137 }
138
139 $this->redirectUrl($backlink);
140 }
141
142
143
144
145 function createEditForm($backlink){
146
147 $user = $this->getUser();
148 $form = new UI\Form;
149 $form->setRenderer(new BootstrapRenderer());
150
151 $form->getElementPrototype()->class = 'form-horizontal';
152
153
154 $form->addText('name', 'Název:')
155 ->setRequired('Zadejte prosím název')
156 ->setAttribute('class', 'form-control');
157
158
159 $form->addSubmit('saving', 'Uložit a zpět')
160 ->setAttribute('class', 'btn btn-danger');
161
162
163 $form->addSubmit('back')
164 ->setAttribute('class', 'btn btn-outline btn-danger')
165 ->getControlPrototype()
166 ->setName('a')
167 ->href($backlink)
168 ->add(Html::el('i')->class('fa fa-reply'))
169 ->add(Html::el('span', ' Zpět'));
170
171 return $form;
172 }
173
174
175 }
176