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 DocumenttypePresenter extends BasePresenter {
16
17
18
19 public $documenttypeRepository;
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->documenttypeRepository->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->documenttypeRepository->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->documenttypeRepository->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->secdocumenttype)) {
87 $backlink = $session->secdocumenttype;
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->documenttypeRepository->updateById($id, $fdata);
107 $this->flashMessage("Záznam byl upraven.", "success");
108 } else {
109 $this->documenttypeRepository->insertData($fdata);
110 $this->flashMessage("Záznam byl vložen.", "success");
111 }
112
113 $session = $this->getSession()->getSection('history');
114
115 if (isset($session->secdocumenttype)) {
116 $backlink = $session->secdocumenttype;
117 } else {
118 $backlink = $this->link('default');
119 }
120
121 $this->redirectUrl($backlink);
122 }
123
124
125
126
127 function createEditForm($backlink){
128
129 $user = $this->getUser();
130 $form = new UI\Form;
131 $form->setRenderer(new BootstrapRenderer());
132
133 $form->getElementPrototype()->class = 'form-horizontal';
134
135
136 $form->addText('name', 'Název:')
137 ->setRequired('Zadejte prosím název')
138 ->setAttribute('class', 'form-control');
139
140
141 $form->addSubmit('saving', 'Uložit a zpět')
142 ->setAttribute('class', 'btn btn-danger');
143
144
145 $form->addSubmit('back')
146 ->setAttribute('class', 'btn btn-outline btn-danger')
147 ->getControlPrototype()
148 ->setName('a')
149 ->href($backlink)
150 ->add(Html::el('i')->class('fa fa-reply'))
151 ->add(Html::el('span', ' Zpět'));
152
153 return $form;
154 }
155 }
156