Revize b8fae4af
Přidáno uživatelem Filip Jani před téměř 6 roky(ů)
app/AdminModule/component/Book/BookEditForm.php | ||
---|---|---|
69 | 69 |
|
70 | 70 |
public function formSuccess(Form $form) |
71 | 71 |
{ |
72 |
|
|
73 | 72 |
$result = $this->bookFacade->saveBook($form, $this->bookId); |
74 | 73 |
|
75 | 74 |
if ($result != null) |
app/AdminModule/component/Book/BookOptionForm.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
namespace App\AdminModule\Components; |
|
5 |
|
|
6 |
|
|
7 |
use App\Enum\EFlashMessage; |
|
8 |
use App\Model\Repository\BookRepository; |
|
9 |
use App\Model\Repository\TransliterationRepository; |
|
10 |
use App\Utils\Form; |
|
11 |
|
|
12 |
class BookOptionForm extends BookEditForm |
|
13 |
{ |
|
14 |
public function createComponentForm() |
|
15 |
{ |
|
16 |
$this->form->addRadioList('book', 'Book option', [0 => 'Existing book', 1 => 'New book']) |
|
17 |
->addCondition(Form::EQUAL, 0) |
|
18 |
->toggle(TransliterationRepository::COLUMN_BOOK_ID) |
|
19 |
->elseCondition(Form::EQUAL, 1) |
|
20 |
->toggle(BookRepository::COLUMN_BOOK_ABREV) |
|
21 |
->toggle(BookRepository::COLUMN_BOOK_AUTHOR) |
|
22 |
->toggle(BookRepository::COLUMN_BOOK_NAME) |
|
23 |
->toggle(BookRepository::COLUMN_BOOK_SUBTITLE) |
|
24 |
->toggle(BookRepository::COLUMN_BOOK_DESCRIPTION) |
|
25 |
->toggle(BookRepository::COLUMN_PLACE_OF_PUB) |
|
26 |
->toggle(BookRepository::COLUMN_DATE_OF_PUB) |
|
27 |
->toggle(BookRepository::COLUMN_PAGES) |
|
28 |
->toggle(BookRepository::COLUMN_VOLUME) |
|
29 |
->toggle(BookRepository::COLUMN_VOLUME_NO) |
|
30 |
->endCondition(); |
|
31 |
|
|
32 |
$this->form->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect()) |
|
33 |
->setOption('id', TransliterationRepository::COLUMN_BOOK_ID); |
|
34 |
|
|
35 |
// Vytvoření všech prvků z rodiče |
|
36 |
parent::createComponentForm(); |
|
37 |
|
|
38 |
// Nastavení jejich ID jinak se neschovávají pomocí toggle |
|
39 |
foreach ($this->form->getControls() as $control) |
|
40 |
{ |
|
41 |
$this->form[$control->getName()]->setOption('id', $control->getName()); |
|
42 |
} |
|
43 |
|
|
44 |
$this->form->setDefaults(['book' => 0]); |
|
45 |
|
|
46 |
$this->form->onSuccess[] = [$this, 'formSuccess']; |
|
47 |
|
|
48 |
return $this->form; |
|
49 |
} |
|
50 |
|
|
51 |
public function formSuccess(Form $form) |
|
52 |
{ |
|
53 |
// $data = $form->getValues(); |
|
54 |
// if($data['book']) |
|
55 |
} |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
interface IBookOptionFormFactory |
|
60 |
{ |
|
61 |
/** |
|
62 |
* @return BookOptionForm |
|
63 |
*/ |
|
64 |
public function create(); |
|
65 |
} |
app/AdminModule/component/Transliteration/TransliterationDataEditForm.php | ||
---|---|---|
12 | 12 |
use App\Utils\Form; |
13 | 13 |
use Nette\Application\UI\Control; |
14 | 14 |
use Nette\Forms\Container; |
15 |
use Nette\Forms\Controls\SubmitButton; |
|
16 | 15 |
use WebChemistry\Forms\Controls\Multiplier; |
17 | 16 |
|
18 | 17 |
class TransliterationDataEditForm extends Control |
app/AdminModule/component/Transliteration/TransliterationEditForm.latte | ||
---|---|---|
1 | 1 |
{snippet informationSnippet} |
2 | 2 |
{form form} |
3 |
|
|
4 |
<div class="alert alert-danger" role="alert" n:if="$form->hasErrors()"> |
|
5 |
<div n:foreach="$form->errors as $error">{$error}</div> |
|
6 |
</div> |
|
7 |
|
|
3 | 8 |
<div class="row"> |
4 | 9 |
<div class="col-12"> |
5 | 10 |
{if $addBook == true} |
app/AdminModule/component/Transliteration/TransliterationEditForm.php | ||
---|---|---|
72 | 72 |
* @param MuseumRepository $museumRepository |
73 | 73 |
* @param OriginRepository $originRepository |
74 | 74 |
* @param BookTypeRepository $bookTypeRepository |
75 |
* @param TransliterationFacade $transliterationFacade |
|
75 | 76 |
* @param LitReferenceRepository $litReferenceRepository |
76 | 77 |
*/ |
77 | 78 |
public function __construct(TransliterationRepository $transliterationRepository, |
... | ... | |
88 | 89 |
$this->transliterationRepository = $transliterationRepository; |
89 | 90 |
$this->bookRepository = $bookRepository; |
90 | 91 |
$this->museumRepository = $museumRepository; |
91 |
|
|
92 |
$this->transliterationId = NULL; |
|
93 |
$this->form = new Form; |
|
94 | 92 |
$this->originRepository = $originRepository; |
95 | 93 |
$this->bookTypeRepository = $bookTypeRepository; |
96 | 94 |
$this->litReferenceRepository = $litReferenceRepository; |
97 | 95 |
$this->transliterationFacade = $transliterationFacade; |
96 |
|
|
97 |
$this->transliterationId = NULL; |
|
98 |
$this->form = new Form; |
|
98 | 99 |
} |
99 | 100 |
|
100 | 101 |
public function render() |
... | ... | |
146 | 147 |
|
147 | 148 |
$this->form->addSubmit('submit', 'Save'); |
148 | 149 |
|
150 |
$this->form->onValidate[] = [$this, 'formValidate']; |
|
149 | 151 |
$this->form->onSuccess[] = [$this, 'formSuccess']; |
150 | 152 |
|
151 | 153 |
return $this->form; |
152 | 154 |
} |
153 | 155 |
|
156 |
/** |
|
157 |
* Validace formuláře před odesláním |
|
158 |
* |
|
159 |
* @param Form $form |
|
160 |
*/ |
|
161 |
public function formValidate(Form $form) |
|
162 |
{ |
|
163 |
// Musí se kontrolovat jestli se jedná o AJAX, protože při každým přidáním dynamických prvků se volá form validate |
|
164 |
if (!$this->presenter->isAjax()) |
|
165 |
{ |
|
166 |
$values = $form->getValues(TRUE); |
|
167 |
|
|
168 |
if ($this->transliterationFacade->isAnyReferenceEmpty($values['references'])) |
|
169 |
{ |
|
170 |
$form->addError('There are some empty references in the transliteration info. Please fill or delete them.'); |
|
171 |
} |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
154 | 175 |
/** |
155 | 176 |
* Zpracování editace informací o transliteraci |
156 | 177 |
* |
... | ... | |
158 | 179 |
*/ |
159 | 180 |
public function formSuccess(Form $form) |
160 | 181 |
{ |
161 |
$result = $this->transliterationFacade->saveTransliterationInfo($this->transliterationId, $form->getValues(true));
|
|
182 |
$result = $this->transliterationFacade->saveTransliterationInfo($form, $this->transliterationId);
|
|
162 | 183 |
|
163 | 184 |
if ($result != null) |
164 | 185 |
{ |
app/AdminModule/component/Transliteration/TransliterationNewForm.latte | ||
---|---|---|
1 | 1 |
{snippet transliterationSnippet} |
2 | 2 |
{form form} |
3 | 3 |
|
4 |
<div class="alert alert-danger" role="alert" n:if="$form->hasErrors()"> |
|
5 |
<div n:foreach="$form->errors as $error">{$error}</div> |
|
6 |
</div> |
|
7 |
|
|
4 | 8 |
{* BOOK CONTAINER *} |
5 | 9 |
<div class="row mt-5"> |
6 | 10 |
<div class="col-5"> |
... | ... | |
13 | 17 |
<div class="col-4"> |
14 | 18 |
{label $form['bookContainer']['book']} |
15 | 19 |
</div> |
16 |
<div class="col-8 align-middle">
|
|
17 |
Existing book{input $form['bookContainer']['book']:0}New book{input $form['bookContainer']['book']:1}
|
|
20 |
<div class="col-8"> |
|
21 |
{input $form['bookContainer']['book']}
|
|
18 | 22 |
</div> |
19 | 23 |
</div> |
20 | 24 |
|
21 |
<div class="row mb-2"> |
|
25 |
<div class="row mb-2" |
|
26 |
id="{\App\AdminModule\Components\TransliterationNewForm::BOOK_EXISTING_ID}"> |
|
22 | 27 |
<div class="col-4"> |
23 | 28 |
{label $form['bookContainer'][\App\Model\Repository\TransliterationRepository::COLUMN_BOOK_ID]} |
24 | 29 |
</div> |
... | ... | |
27 | 32 |
</div> |
28 | 33 |
</div> |
29 | 34 |
|
30 |
<div class="row mb-2"> |
|
31 |
<div class="col-4"> |
|
32 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_ABREV]} |
|
33 |
</div> |
|
34 |
<div class="col-8"> |
|
35 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_ABREV]} |
|
35 |
<div id="{\App\AdminModule\Components\TransliterationNewForm::BOOK_NEW_ID}"> |
|
36 |
<div class="row mb-2"> |
|
37 |
<div class="col-4"> |
|
38 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_ABREV], class => 'required'} |
|
39 |
</div> |
|
40 |
<div class="col-8"> |
|
41 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_ABREV]} |
|
42 |
</div> |
|
36 | 43 |
</div> |
37 |
</div> |
|
38 | 44 |
|
39 |
<div class="row mb-2"> |
|
40 |
<div class="col-4"> |
|
41 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_AUTHOR]} |
|
42 |
</div> |
|
43 |
<div class="col-8"> |
|
44 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_AUTHOR]} |
|
45 |
<div class="row mb-2"> |
|
46 |
<div class="col-4"> |
|
47 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_AUTHOR]} |
|
48 |
</div> |
|
49 |
<div class="col-8"> |
|
50 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_AUTHOR]} |
|
51 |
</div> |
|
45 | 52 |
</div> |
46 |
</div> |
|
47 | 53 |
|
48 |
<div class="row mb-2"> |
|
49 |
<div class="col-4"> |
|
50 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_NAME]} |
|
51 |
</div> |
|
52 |
<div class="col-8"> |
|
53 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_NAME]} |
|
54 |
<div class="row mb-2"> |
|
55 |
<div class="col-4"> |
|
56 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_NAME], class => 'required'} |
|
57 |
</div> |
|
58 |
<div class="col-8"> |
|
59 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_NAME]} |
|
60 |
</div> |
|
54 | 61 |
</div> |
55 |
</div> |
|
56 | 62 |
|
57 |
<div class="row mb-2"> |
|
58 |
<div class="col-4"> |
|
59 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_SUBTITLE]} |
|
60 |
</div> |
|
61 |
<div class="col-8"> |
|
62 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_SUBTITLE]} |
|
63 |
<div class="row mb-2"> |
|
64 |
<div class="col-4"> |
|
65 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_SUBTITLE]} |
|
66 |
</div> |
|
67 |
<div class="col-8"> |
|
68 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_SUBTITLE]} |
|
69 |
</div> |
|
63 | 70 |
</div> |
64 |
</div> |
|
65 | 71 |
|
66 |
<div class="row mb-2"> |
|
67 |
<div class="col-4"> |
|
68 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_DESCRIPTION]} |
|
69 |
</div> |
|
70 |
<div class="col-8"> |
|
71 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_DESCRIPTION]} |
|
72 |
<div class="row mb-2"> |
|
73 |
<div class="col-4"> |
|
74 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_DESCRIPTION]} |
|
75 |
</div> |
|
76 |
<div class="col-8"> |
|
77 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_BOOK_DESCRIPTION]} |
|
78 |
</div> |
|
72 | 79 |
</div> |
73 |
</div> |
|
74 | 80 |
|
75 |
<div class="row mb-2"> |
|
76 |
<div class="col-4"> |
|
77 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PLACE_OF_PUB]} |
|
78 |
</div> |
|
79 |
<div class="col-8"> |
|
80 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PLACE_OF_PUB]} |
|
81 |
<div class="row mb-2"> |
|
82 |
<div class="col-4"> |
|
83 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PLACE_OF_PUB]} |
|
84 |
</div> |
|
85 |
<div class="col-8"> |
|
86 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PLACE_OF_PUB]} |
|
87 |
</div> |
|
81 | 88 |
</div> |
82 |
</div> |
|
83 | 89 |
|
84 |
<div class="row mb-2"> |
|
85 |
<div class="col-4"> |
|
86 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_DATE_OF_PUB]} |
|
87 |
</div> |
|
88 |
<div class="col-8"> |
|
89 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_DATE_OF_PUB]} |
|
90 |
<div class="row mb-2"> |
|
91 |
<div class="col-4"> |
|
92 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_DATE_OF_PUB]} |
|
93 |
</div> |
|
94 |
<div class="col-8"> |
|
95 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_DATE_OF_PUB]} |
|
96 |
</div> |
|
90 | 97 |
</div> |
91 |
</div> |
|
92 | 98 |
|
93 |
<div class="row mb-2"> |
|
94 |
<div class="col-4"> |
|
95 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PAGES]} |
|
96 |
</div> |
|
97 |
<div class="col-8"> |
|
98 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PAGES]} |
|
99 |
<div class="row mb-2"> |
|
100 |
<div class="col-4"> |
|
101 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PAGES]} |
|
102 |
</div> |
|
103 |
<div class="col-8"> |
|
104 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_PAGES]} |
|
105 |
</div> |
|
99 | 106 |
</div> |
100 |
</div> |
|
101 | 107 |
|
102 |
<div class="row mb-2"> |
|
103 |
<div class="col-4"> |
|
104 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME]} |
|
105 |
</div> |
|
106 |
<div class="col-8"> |
|
107 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME]} |
|
108 |
<div class="row mb-2"> |
|
109 |
<div class="col-4"> |
|
110 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME]} |
|
111 |
</div> |
|
112 |
<div class="col-8"> |
|
113 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME]} |
|
114 |
</div> |
|
108 | 115 |
</div> |
109 |
</div> |
|
110 | 116 |
|
111 |
<div class="row mb-2"> |
|
112 |
<div class="col-4"> |
|
113 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME_NO]} |
|
114 |
</div> |
|
115 |
<div class="col-8"> |
|
116 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME_NO]} |
|
117 |
<div class="row mb-2"> |
|
118 |
<div class="col-4"> |
|
119 |
{label $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME_NO]} |
|
120 |
</div> |
|
121 |
<div class="col-8"> |
|
122 |
{input $form['bookContainer'][\App\Model\Repository\BookRepository::COLUMN_VOLUME_NO]} |
|
123 |
</div> |
|
117 | 124 |
</div> |
118 | 125 |
</div> |
119 |
|
|
120 | 126 |
</div> |
121 | 127 |
</div> |
122 | 128 |
|
... | ... | |
231 | 237 |
{btnCreate $form['infoContainer']['references'] class => 'btn btn-info btn-sm ajax'} |
232 | 238 |
</div> |
233 | 239 |
</div> |
234 |
|
|
235 |
<div class="row mt-5"> |
|
236 |
<div class="col-4 offset-8 float-right"> |
|
237 |
{* {input submit}*} |
|
238 |
</div> |
|
239 |
</div> |
|
240 | 240 |
</fieldset> |
241 | 241 |
</div> |
242 | 242 |
</div> |
... | ... | |
288 | 288 |
|
289 | 289 |
<div class="card mb-1"> |
290 | 290 |
<h5 class="mb-0"> |
291 |
<a class="btn btn-link" data-toggle="collapse" data-target="#{$name}" |
|
291 |
<a class="btn btn-link" data-toggle="collapse" |
|
292 |
data-target="#{$name}" |
|
292 | 293 |
aria-expanded="{$expanded}"> |
293 | 294 |
<small> |
294 | 295 |
<span class="fa fa-fw fa-plus"></span> |
... | ... | |
318 | 319 |
|
319 | 320 |
</div> |
320 | 321 |
{/if} |
321 |
|
|
322 | 322 |
{/foreach} |
323 | 323 |
|
324 | 324 |
</div> |
app/AdminModule/component/Transliteration/TransliterationNewForm.php | ||
---|---|---|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
use App\Enum\EFlashMessage; |
8 |
use App\Model\Facade\BookFacade; |
|
9 | 8 |
use App\Model\Facade\TransliterationFacade; |
10 | 9 |
use App\Model\Repository\BookRepository; |
11 | 10 |
use App\Model\Repository\BookTypeRepository; |
... | ... | |
19 | 18 |
use App\Utils\Form; |
20 | 19 |
use Nette\Application\UI\Control; |
21 | 20 |
use Nette\Forms\Container; |
22 |
use Tracy\Debugger;
|
|
21 |
use Nette\Forms\Controls\RadioList;
|
|
23 | 22 |
use WebChemistry\Forms\Controls\Multiplier; |
24 | 23 |
|
25 | 24 |
class TransliterationNewForm extends Control |
26 | 25 |
{ |
26 |
// ID pro šablonu a skrývání prvků pomocí radio buttonu |
|
27 |
const BOOK_EXISTING_ID = 'book-existing'; |
|
28 |
const BOOK_NEW_ID = 'book-new'; |
|
29 |
|
|
27 | 30 |
/** |
28 | 31 |
* @var Form |
29 | 32 |
*/ |
... | ... | |
64 | 67 |
* @var TransliterationFacade |
65 | 68 |
*/ |
66 | 69 |
private $transliterationFacade; |
67 |
/** |
|
68 |
* @var BookFacade |
|
69 |
*/ |
|
70 |
private $bookFacade; |
|
71 | 70 |
|
72 | 71 |
|
73 | 72 |
/** |
74 | 73 |
* TransliterationNewForm constructor. |
74 |
* @param TransliterationRepository $transliterationRepository |
|
75 |
* @param BookRepository $bookRepository |
|
76 |
* @param OriginRepository $originRepository |
|
77 |
* @param MuseumRepository $museumRepository |
|
78 |
* @param BookTypeRepository $bookTypeRepository |
|
79 |
* @param ObjectTypeRepository $objectTypeRepository |
|
80 |
* @param TransliterationFacade $transliterationFacade |
|
81 |
* @param SurfaceTypeRepository $surfaceTypeRepository |
|
75 | 82 |
*/ |
76 | 83 |
public function __construct(TransliterationRepository $transliterationRepository, |
77 | 84 |
BookRepository $bookRepository, |
... | ... | |
80 | 87 |
BookTypeRepository $bookTypeRepository, |
81 | 88 |
ObjectTypeRepository $objectTypeRepository, |
82 | 89 |
TransliterationFacade $transliterationFacade, |
83 |
BookFacade $bookFacade, |
|
84 | 90 |
SurfaceTypeRepository $surfaceTypeRepository) |
85 | 91 |
{ |
86 | 92 |
parent::__construct(); |
... | ... | |
112 | 118 |
$this->containers = $containers; |
113 | 119 |
|
114 | 120 |
$this->transliterationFacade = $transliterationFacade; |
115 |
$this->bookFacade = $bookFacade; |
|
116 | 121 |
} |
117 | 122 |
|
118 | 123 |
public function render() |
... | ... | |
124 | 129 |
|
125 | 130 |
public function createComponentForm() |
126 | 131 |
{ |
127 |
|
|
128 | 132 |
//BOOK CONTAINER |
129 | 133 |
$redrawCallback = function () |
130 | 134 |
{ |
... | ... | |
133 | 137 |
|
134 | 138 |
$bookContainer = $this->form->addContainer('bookContainer'); |
135 | 139 |
|
136 |
$bookContainer->addRadioList('book', 'Book option', [0 => '', 1 => 'New book']) |
|
140 |
$bookContainer->addRadioList('book', 'Book option', [0 => 'Existing book', 1 => 'New book']) |
|
141 |
->setDefaultValue(0) |
|
137 | 142 |
->addCondition(Form::EQUAL, 0) |
138 |
->toggle(TransliterationRepository::COLUMN_BOOK_ID) |
|
139 |
->elseCondition(Form::EQUAL, 1) |
|
140 |
->toggle(BookRepository::COLUMN_BOOK_ABREV) |
|
141 |
->toggle(BookRepository::COLUMN_BOOK_AUTHOR) |
|
142 |
->toggle(BookRepository::COLUMN_BOOK_NAME) |
|
143 |
->toggle(BookRepository::COLUMN_BOOK_SUBTITLE) |
|
144 |
->toggle(BookRepository::COLUMN_BOOK_DESCRIPTION) |
|
145 |
->toggle(BookRepository::COLUMN_PLACE_OF_PUB) |
|
146 |
->toggle(BookRepository::COLUMN_DATE_OF_PUB) |
|
147 |
->toggle(BookRepository::COLUMN_PAGES) |
|
148 |
->toggle(BookRepository::COLUMN_VOLUME) |
|
149 |
->toggle(BookRepository::COLUMN_VOLUME_NO) |
|
143 |
->toggle(self::BOOK_EXISTING_ID) |
|
144 |
->elseCondition() |
|
145 |
->toggle(self::BOOK_NEW_ID) |
|
150 | 146 |
->endCondition(); |
151 | 147 |
|
152 | 148 |
$bookContainer->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect()) |
153 | 149 |
->setOption('id', TransliterationRepository::COLUMN_BOOK_ID); |
154 | 150 |
|
155 | 151 |
$bookContainer->addText(BookRepository::COLUMN_BOOK_ABREV, 'Abbreviation') |
152 |
->addConditionOn($this->form['bookContainer']['book'], Form::EQUAL, 1) |
|
156 | 153 |
->addRule(Form::REQUIRED, 'Field %label is required', TRUE); |
157 | 154 |
$bookContainer->addText(BookRepository::COLUMN_BOOK_AUTHOR, 'Author'); |
158 | 155 |
$bookContainer->addText(BookRepository::COLUMN_BOOK_NAME, 'Name') |
156 |
->addConditionOn($this->form['bookContainer']['book'], Form::EQUAL, 1) |
|
159 | 157 |
->addRule(Form::REQUIRED, 'Field %label is required', TRUE); |
160 | 158 |
$bookContainer->addText(BookRepository::COLUMN_BOOK_SUBTITLE, 'Alternate name'); |
161 | 159 |
$bookContainer->addTextArea(BookRepository::COLUMN_BOOK_DESCRIPTION, 'Description'); |
... | ... | |
165 | 163 |
$bookContainer->addText(BookRepository::COLUMN_VOLUME, 'Volume'); |
166 | 164 |
$bookContainer->addText(BookRepository::COLUMN_VOLUME_NO, 'Volume No.'); |
167 | 165 |
|
168 |
// Nastavení jejich ID jinak se neschovávají pomocí toggle |
|
169 |
foreach ($bookContainer->getControls() as $control) |
|
170 |
{ |
|
171 |
$bookContainer[$control->getName()]->setOption('id', $control->getName()); |
|
172 |
} |
|
173 |
|
|
174 |
$bookContainer->setDefaults(['book' => 0]); |
|
175 |
|
|
176 | 166 |
//INFO CONTAINER |
177 | 167 |
$infoContainer = $this->form->addContainer('infoContainer'); |
178 | 168 |
$infoContainer->addText(TransliterationRepository::COLUMN_CHAPTER, 'Chapter'); |
... | ... | |
185 | 175 |
$infoContainer->addText(TransliterationRepository::COLUMN_NOTE, 'Note'); |
186 | 176 |
|
187 | 177 |
// Definice dynamických prvků |
188 |
/** @var Multiplier $multiplier */
|
|
189 |
$multiplier = $infoContainer->addMultiplier('references', function (Container $container)
|
|
178 |
/** @var Multiplier $referenceMultiplier */
|
|
179 |
$referenceMultiplier = $infoContainer->addMultiplier('references', function (Container $container)
|
|
190 | 180 |
{ |
191 | 181 |
$container->addHidden(LitReferenceRepository::COLUMN_ID); |
192 | 182 |
$container->addText(LitReferenceRepository::COLUMN_SERIES, 'Series'); |
... | ... | |
195 | 185 |
}, 0); |
196 | 186 |
|
197 | 187 |
// Definice tlačítek pro přidání / odebrání řádku |
198 |
$multiplier->addCreateButton('Add', 1, $redrawCallback);
|
|
199 |
$multiplier->addRemoveButton('Remove', $redrawCallback);
|
|
188 |
$referenceMultiplier->addCreateButton('Add', 1, $redrawCallback);
|
|
189 |
$referenceMultiplier->addRemoveButton('Remove', $redrawCallback);
|
|
200 | 190 |
|
201 | 191 |
//DATA CONTAINER |
202 | 192 |
$dataContainer = $this->form->addContainer('dataContainer'); |
... | ... | |
226 | 216 |
|
227 | 217 |
foreach ($this->form->getControls() as $control) |
228 | 218 |
{ |
229 |
if (!$control instanceof Multiplier) |
|
219 |
// Nastavení třídy, aby se nemusela nastavovat ručně v šabloně |
|
220 |
if (!$control instanceof Multiplier && !$control instanceof RadioList) |
|
230 | 221 |
{ |
231 | 222 |
$control->setHtmlAttribute('class', 'form-control form-control-sm'); |
232 | 223 |
} |
233 | 224 |
} |
234 | 225 |
|
235 | 226 |
$this->form->addSubmit('submit', 'Save'); |
227 |
|
|
228 |
$this->form->onValidate[] = [$this, 'formValidate']; |
|
236 | 229 |
$this->form->onSuccess[] = [$this, 'formSuccess']; |
237 | 230 |
|
238 | 231 |
return $this->form; |
239 | 232 |
} |
240 | 233 |
|
241 |
public function formSuccess(Form $form) |
|
234 |
/** |
|
235 |
* Validace formuláře před odesláním |
|
236 |
* |
|
237 |
* @param Form $form |
|
238 |
*/ |
|
239 |
public function formValidate(Form $form) |
|
242 | 240 |
{ |
243 |
|
|
244 |
$data = $form->getValues(); |
|
245 |
$transliteration = $this->transliterationFacade->saveTransliterationInfo(null,$form); |
|
246 |
|
|
247 |
if ($data['bookContainer']['book'] == 0) |
|
241 |
// Musí se kontrolovat jestli se jedná o AJAX, protože při každým přidáním dynamických prvků se volá form validate |
|
242 |
if(!$this->presenter->isAjax()) |
|
248 | 243 |
{ |
249 |
$bookId = $data['bookContainer'][BookRepository::COLUMN_ID]; |
|
250 |
} |
|
251 |
else{ |
|
252 |
$book = $this->bookFacade->saveBook($form); |
|
253 |
$bookId = $book[BookRepository::COLUMN_ID]; |
|
254 |
} |
|
244 |
$values = $form->getValues(TRUE); |
|
255 | 245 |
|
256 |
$transliteration->update( |
|
257 |
[ |
|
258 |
TransliterationRepository::COLUMN_BOOK_ID => $bookId |
|
259 |
] |
|
260 |
); |
|
261 |
|
|
262 |
if($transliteration == null){ |
|
263 |
$this->presenter->flashMessage('Transliteration could not be saved.', EFlashMessage::ERROR); |
|
264 |
return; |
|
246 |
if ($this->transliterationFacade->isAnyReferenceEmpty($values['infoContainer']['references'])) |
|
247 |
{ |
|
248 |
$form->addError('There are some empty references in the transliteration info. Please fill or delete them.'); |
|
249 |
} |
|
265 | 250 |
} |
251 |
} |
|
266 | 252 |
|
267 |
$this->transliterationFacade->saveTransliterationData($transliteration[TransliterationRepository::COLUMN_ID], $form); |
|
253 |
/** |
|
254 |
* Zpracování formuláře po úspěšném odeslání |
|
255 |
* |
|
256 |
* @param Form $form |
|
257 |
* @throws \Nette\Application\AbortException |
|
258 |
*/ |
|
259 |
public function formSuccess(Form $form) |
|
260 |
{ |
|
261 |
$result = $this->transliterationFacade->saveNewTransliteration($form); |
|
268 | 262 |
|
263 |
if ($result) |
|
264 |
{ |
|
265 |
$this->presenter->flashMessage('Transliteration was added successfully.', EFlashMessage::SUCCESS); |
|
266 |
$this->presenter->redirect('Transliteration:Edit', ['id' => $result]); |
|
267 |
} else |
|
268 |
{ |
|
269 |
$this->presenter->flashMessage('Transliteration was not added.', EFlashMessage::ERROR); |
|
270 |
} |
|
269 | 271 |
} |
270 |
|
|
271 | 272 |
} |
272 | 273 |
|
273 | 274 |
interface ITransliterationNewFormFactory |
app/AdminModule/presenters/TransliterationPresenter.php | ||
---|---|---|
4 | 4 |
namespace App\AdminModule\Presenters; |
5 | 5 |
|
6 | 6 |
|
7 |
use App\AdminModule\Components\IBookEditFormFactory; |
|
8 |
use App\AdminModule\Components\IBookOptionFormFactory; |
|
9 | 7 |
use App\AdminModule\Components\ITransliterationDataEditFormFactory; |
10 | 8 |
use App\AdminModule\Components\ITransliterationGridFactory; |
11 | 9 |
use App\AdminModule\Components\ITransliterationEditFormFactory; |
12 | 10 |
use App\AdminModule\Components\ITransliterationNewFormFactory; |
11 |
use App\Enum\EFlashMessage; |
|
13 | 12 |
use App\FrontModule\Components\IKeyboard; |
14 | 13 |
use App\Model\Repository\TransliterationRepository; |
15 | 14 |
|
... | ... | |
38 | 37 |
* @var ITransliterationNewFormFactory |
39 | 38 |
*/ |
40 | 39 |
private $transliterationNewFormFactory; |
41 |
/** |
|
42 |
* @var IBookOptionFormFactory |
|
43 |
*/ |
|
44 |
private $bookOptionFormFactory; |
|
45 | 40 |
/** |
46 | 41 |
* @var IKeyboard |
47 | 42 |
*/ |
... | ... | |
52 | 47 |
TransliterationRepository $transliterationRepository, |
53 | 48 |
ITransliterationDataEditFormFactory $transliterationDataEditFormFactory, |
54 | 49 |
ITransliterationNewFormFactory $transliterationNewFormFactory, |
55 |
IBookOptionFormFactory $bookOptionFormFactory, |
|
56 | 50 |
IKeyboard $keyboard |
57 | 51 |
) |
58 | 52 |
{ |
... | ... | |
62 | 56 |
$this->transliterationRepository = $transliterationRepository; |
63 | 57 |
$this->transliterationDataEditFormFactory = $transliterationDataEditFormFactory; |
64 | 58 |
$this->transliterationNewFormFactory = $transliterationNewFormFactory; |
65 |
$this->bookOptionFormFactory = $bookOptionFormFactory; |
|
66 | 59 |
$this->keyboard = $keyboard; |
67 | 60 |
} |
68 | 61 |
|
... | ... | |
89 | 82 |
{ |
90 | 83 |
$this['transliterationEditForm']->setTransliteration($id); |
91 | 84 |
$this['transliterationDataEditForm']->setTransliteration($id); |
85 |
$this->template->id = $id; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Akce pro odstranění transliterace |
|
90 |
* |
|
91 |
* @param int $id |
|
92 |
* @throws \Nette\Application\AbortException |
|
93 |
*/ |
|
94 |
public function actionDeleteTransliteration(int $id){ |
|
95 |
$result = $this->transliterationRepository->findRow($id)->delete(); |
|
96 |
|
|
97 |
if ($result) |
|
98 |
{ |
|
99 |
$this->flashMessage('Transliteration was successfully deleted.', EFlashMessage::SUCCESS); |
|
100 |
} else |
|
101 |
{ |
|
102 |
$this->flashMessage('Transliteration wasn\'t deleted.', EFlashMessage::ERROR); |
|
103 |
} |
|
104 |
|
|
105 |
$this->redirect('Transliteration:default'); |
|
92 | 106 |
} |
93 | 107 |
|
108 |
/** |
|
109 |
* Komponenta gridu se seznamem transliterací |
|
110 |
* |
|
111 |
* @return \App\AdminModule\Components\TransliterationGrid |
|
112 |
*/ |
|
94 | 113 |
public function createComponentTransliterationGrid() |
95 | 114 |
{ |
96 | 115 |
return $this->transliterationGridFactory->create(); |
97 | 116 |
} |
98 | 117 |
|
118 |
/** |
|
119 |
* Komponenta pro editaci informací o transliteraci |
|
120 |
* |
|
121 |
* @return \App\AdminModule\Components\TransliterationEditForm |
|
122 |
*/ |
|
99 | 123 |
public function createComponentTransliterationEditForm() |
100 | 124 |
{ |
101 | 125 |
return $this->transliterationEditFormFactory->create(); |
102 | 126 |
} |
103 | 127 |
|
128 |
/** |
|
129 |
* Komponenta pro editaci dat transliterace |
|
130 |
* |
|
131 |
* @return \App\AdminModule\Components\TransliterationDataEditForm |
|
132 |
*/ |
|
104 | 133 |
public function createComponentTransliterationDataEditForm() |
105 | 134 |
{ |
106 | 135 |
return $this->transliterationDataEditFormFactory->create(); |
107 | 136 |
} |
108 | 137 |
|
138 |
/** |
|
139 |
* Komponenta pro přidávání nové transliterace |
|
140 |
* |
|
141 |
* @return \App\AdminModule\Components\TransliterationNewForm |
|
142 |
*/ |
|
109 | 143 |
public function createComponentTransliterationNewForm() |
110 | 144 |
{ |
111 | 145 |
return $this->transliterationNewFormFactory->create(); |
112 | 146 |
} |
113 | 147 |
|
114 |
public function createComponentBookOptionForm()
|
|
115 |
{
|
|
116 |
return $this->bookOptionFormFactory->create();
|
|
117 |
}
|
|
118 |
|
|
148 |
/**
|
|
149 |
* Komponenta s klávesnicí
|
|
150 |
*
|
|
151 |
* @return \App\FrontModule\Components\Keyboard
|
|
152 |
*/ |
|
119 | 153 |
public function createComponentKeyboard() |
120 | 154 |
{ |
121 | 155 |
return $this->keyboard->create(); |
app/AdminModule/templates/Transliteration/edit.latte | ||
---|---|---|
1 | 1 |
{block content} |
2 | 2 |
<div class="row"> |
3 |
<div class="col-5">
|
|
3 |
<div class="col-10">
|
|
4 | 4 |
<div class="display-5">Edit Transliteration</div> |
5 |
</div> |
|
6 |
<div class="col-2 text-right"> |
|
7 |
<a n:href="Transliteration:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Transliteration list</a> |
|
8 |
<a n:href="Transliteration:deleteTransliteration $id" class="btn btn-sm btn-danger" onclick="return confirm('Do you really want to delete this transliteration?')"><span class="fa fa-fw fa-trash"></span> Delete origin</a> |
|
9 |
</div> |
|
10 |
</div> |
|
5 | 11 |
|
12 |
<div class="row"> |
|
13 |
<div class="col-5"> |
|
6 | 14 |
<fieldset> |
7 | 15 |
<legend>Transliteration information</legend> |
8 | 16 |
|
app/config/components.neon | ||
---|---|---|
25 | 25 |
- App\AdminModule\Components\IImportFormFactory |
26 | 26 |
- App\AdminModule\Components\IExportFormFactory |
27 | 27 |
- App\AdminModule\Components\ITransliterationNewFormFactory |
28 |
- App\AdminModule\Components\IBookOptionFormFactory |
|
29 |
|
|
30 | 28 |
|
31 | 29 |
|
32 | 30 |
- App\FrontModule\Components\IKeyboard |
app/model/facade/BookFacade.php | ||
---|---|---|
17 | 17 |
|
18 | 18 |
/** |
19 | 19 |
* BookFacade constructor. |
20 |
* @param BookRepository $bookRepository |
|
20 | 21 |
*/ |
21 | 22 |
public function __construct(BookRepository $bookRepository) |
22 | 23 |
{ |
23 | 24 |
$this->bookRepository = $bookRepository; |
24 | 25 |
} |
25 | 26 |
|
26 |
public function saveBook(Form $form, int $id = null){ |
|
27 |
/** |
|
28 |
* Uložení knížky do databáze |
|
29 |
* |
|
30 |
* @param Form $form |
|
31 |
* @param int|null $id |
|
32 |
* @return \Nette\Database\Table\ActiveRow |
|
33 |
*/ |
|
34 |
public function saveBook(Form $form, int $id = null) |
|
35 |
{ |
|
27 | 36 |
$formValues = $form->getValues(); |
28 | 37 |
$formValues = isset($formValues['bookContainer']) ? $formValues['bookContainer'] : $formValues; |
38 |
|
|
29 | 39 |
unset($formValues['book']); |
40 |
|
|
30 | 41 |
return $this->bookRepository->save($formValues, $id); |
31 | 42 |
} |
32 | 43 |
|
app/model/facade/TransliterationFacade.php | ||
---|---|---|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
use App\Enum\EFlashMessage; |
8 |
use App\Model\Repository\BookRepository; |
|
8 | 9 |
use App\Model\Repository\LineRepository; |
9 | 10 |
use App\Model\Repository\LitReferenceRepository; |
10 | 11 |
use App\Model\Repository\ObjectTypeRepository; |
... | ... | |
47 | 48 |
* @var LitReferenceRepository |
48 | 49 |
*/ |
49 | 50 |
private $litReferenceRepository; |
51 |
/** |
|
52 |
* @var BookFacade |
|
53 |
*/ |
|
54 |
private $bookFacade; |
|
50 | 55 |
|
51 | 56 |
public function __construct(SurfaceRepository $surfaceRepository, |
52 | 57 |
LineRepository $lineRepository, |
... | ... | |
54 | 59 |
SurfaceTypeRepository $surfaceTypeRepository, |
55 | 60 |
TransliterationRepository $transliterationRepository, |
56 | 61 |
LitReferenceRepository $litReferenceRepository, |
57 |
Context $context |
|
62 |
Context $context, |
|
63 |
BookFacade $bookFacade |
|
58 | 64 |
) |
59 | 65 |
{ |
60 | 66 |
$this->surfaceRepository = $surfaceRepository; |
... | ... | |
64 | 70 |
$this->context = $context; |
65 | 71 |
$this->transliterationRepository = $transliterationRepository; |
66 | 72 |
$this->litReferenceRepository = $litReferenceRepository; |
73 |
$this->bookFacade = $bookFacade; |
|
67 | 74 |
} |
68 | 75 |
|
69 |
public function saveTransliterationInfo($id, Form $form) |
|
76 |
/** |
|
77 |
* Vložení nové transliterace do databáze |
|
78 |
* |
|
79 |
* @param \App\Utils\Form $form |
|
80 |
* @return bool|void |
|
81 |
*/ |
|
82 |
public function saveNewTransliteration(\App\Utils\Form $form) |
|
70 | 83 |
{ |
84 |
$data = $form->getValues(); |
|
85 |
$transliteration = $this->saveTransliterationInfo($form); |
|
71 | 86 |
|
72 |
$formValues = $form->getValues(); |
|
73 |
|
|
74 |
$formValues = isset($formValues['infoContainer']) ? $formValues['infoContainer'] : $formValues; |
|
87 |
if ($data['bookContainer']['book'] == 0) |
|
88 |
{ |
|
89 |
$bookId = $data['bookContainer'][BookRepository::COLUMN_ID]; |
|
90 |
} else |
|
91 |
{ |
|
92 |
$book = $this->bookFacade->saveBook($form); |
|
93 |
$bookId = $book[BookRepository::COLUMN_ID]; |
|
94 |
} |
|
75 | 95 |
|
76 |
$references = $formValues['references'];
|
|
96 |
$transliteration->update([TransliterationRepository::COLUMN_BOOK_ID => $bookId]);
|
|
77 | 97 |
|
78 |
if ($this->isAnyReferenceEmpty($references))
|
|
98 |
if ($transliteration == null)
|
|
79 | 99 |
{ |
80 |
return null;
|
|
100 |
return FALSE;
|
|
81 | 101 |
} |
82 | 102 |
|
103 |
$result = $this->saveTransliterationData($transliteration[TransliterationRepository::COLUMN_ID], $form); |
|
104 |
return $result; |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* Uložení informací o transliteraci do databáze |
|
109 |
* |
|
110 |
* @param Form $form |
|
111 |
* @param int|null $id |
|
112 |
* @return ActiveRow|null |
|
113 |
*/ |
|
114 |
public function saveTransliterationInfo(Form $form, int $id = null) |
|
115 |
{ |
|
116 |
$formValues = $form->getValues(); |
|
117 |
$formValues = isset($formValues['infoContainer']) ? $formValues['infoContainer'] : $formValues; |
|
118 |
|
|
119 |
$references = $formValues['references']; |
|
83 | 120 |
unset($formValues['references']); |
84 | 121 |
|
85 | 122 |
$newTransliteration = $this->transliterationRepository->save($formValues, $id); |
86 | 123 |
|
87 |
if($id != null){ |
|
124 |
if ($id != null) |
|
125 |
{ |
|
88 | 126 |
$this->deleteRemovedReferences($references, $id); |
89 |
} |
|
90 |
else{
|
|
127 |
} else
|
|
128 |
{ |
|
91 | 129 |
$id = $newTransliteration[TransliterationRepository::COLUMN_ID]; |
92 | 130 |
} |
93 | 131 |
|
... | ... | |
124 | 162 |
* |
125 | 163 |
* @param $newReferences array nových transliterací |
126 | 164 |
*/ |
127 |
public function deleteRemovedReferences($newReferences,$id) |
|
165 |
public function deleteRemovedReferences($newReferences, $id)
|
|
128 | 166 |
{ |
129 | 167 |
$references = $this->litReferenceRepository->findByTransliterationId($id); |
130 | 168 |
|
... | ... | |
162 | 200 |
* |
163 | 201 |
* @param int|null $id : ID transliterace |
164 | 202 |
* @param Form $form |
165 |
* @return bool
|
|
203 |
* @return int $id : Vrací ID transliterace
|
|
166 | 204 |
*/ |
167 |
public function saveTransliterationData(int $id, Form $form): bool
|
|
205 |
public function saveTransliterationData(int $id, Form $form): int
|
|
168 | 206 |
{ |
169 | 207 |
$formValues = $form->getValues(); |
170 |
|
|
171 | 208 |
$formValues = isset($formValues['dataContainer']) ? $formValues['dataContainer'] : $formValues; |
172 | 209 |
|
173 | 210 |
$this->removeDeletedLines($id, $formValues); |
... | ... | |
209 | 246 |
} catch (\Exception $exception) |
210 | 247 |
{ |
211 | 248 |
\Tracy\Debugger::log('Nepodařilo se uložit data transliterace. Chyba: ' . $exception->getMessage(), 'transliteration-facade'); |
212 |
return FALSE;
|
|
249 |
return 0;
|
|
213 | 250 |
} |
214 | 251 |
} |
215 | 252 |
} |
216 | 253 |
} |
217 | 254 |
|
218 |
return TRUE;
|
|
255 |
return $id;
|
|
219 | 256 |
} |
220 | 257 |
|
221 | 258 |
/** |
... | ... | |
305 | 342 |
|
306 | 343 |
return $deletedIds; |
307 | 344 |
} |
308 |
/** |
|
309 |
* Vrací název inputu pro formulář |
|
310 |
* |
|
311 |
* @param string|NULL $name |
|
312 |
* @return string |
|
313 |
*/ |
|
314 |
public function getInputName(string $name): string |
|
315 |
{ |
|
316 |
return str_replace(' ', '', $name); |
|
317 |
} |
|
318 | 345 |
} |
Také k dispozici: Unified diff
Re #7507 přidávání nových textů