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 RolePresenter extends BasePresenter {
16
17
18
19 public $roleRepository;
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->roleRepository->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->roleRepository->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->roleRepository->findById($id);
67
68
69 if ($id != '' && $item === FALSE) {
70 $this->redirect('default');
71 }
72
73
74 if ($id != '') {
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->secrole)) {
87 $backlink = $session->secrole;
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 public function editFormSubmitted($form) {
101 $fdata = $form->getValues();
102 $id = $this->getParameter('id');
103
104
105 if ($id) {
106 $this->roleRepository->updateById($id, $fdata);
107 $this->flashMessage("Záznam byl upraven.", "success");
108 }
109
110
111
112
113
114 $session = $this->getSession()->getSection('history');
115
116 if (isset($session->secrole)) {
117 $backlink = $session->secrole;
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