Revize f1da904b
Přidáno uživatelem Filip Jani před více než 5 roky(ů)
app/AdminModule/component/Origin/OriginEditForm.latte | ||
---|---|---|
1 |
<div class="row"> |
|
2 |
<div class="col-4"> |
|
3 |
{control form} |
|
4 |
</div> |
|
5 |
</div> |
app/AdminModule/component/Origin/OriginEditForm.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
namespace App\AdminModule\Components; |
|
5 |
|
|
6 |
|
|
7 |
use App\Enum\EFlashMessage; |
|
8 |
use App\Model\Repository\OriginRepository; |
|
9 |
use App\Utils\Form; |
|
10 |
use Nette\Application\UI\Control; |
|
11 |
|
|
12 |
class OriginEditForm extends Control |
|
13 |
{ |
|
14 |
private $originId; |
|
15 |
|
|
16 |
/** |
|
17 |
* @var Form |
|
18 |
*/ |
|
19 |
private $form; |
|
20 |
/** |
|
21 |
* @var OriginRepository |
|
22 |
*/ |
|
23 |
private $originRepository; |
|
24 |
|
|
25 |
public function __construct(OriginRepository $originRepository) |
|
26 |
{ |
|
27 |
parent::__construct(); |
|
28 |
|
|
29 |
$this->form = new Form; |
|
30 |
$this->originId = NULL; |
|
31 |
$this->originRepository = $originRepository; |
|
32 |
} |
|
33 |
|
|
34 |
public function render() |
|
35 |
{ |
|
36 |
$this->template->setFile(__DIR__ . '/OriginEditForm.latte'); |
|
37 |
$this->template->render(); |
|
38 |
} |
|
39 |
|
|
40 |
public function createComponentForm() |
|
41 |
{ |
|
42 |
$this->form->addText(OriginRepository::COLUMN_ORIGIN, 'Origin') |
|
43 |
->addRule(Form::REQUIRED, 'Pole %label je povinné', TRUE); |
|
44 |
$this->form->addText(OriginRepository::COLUMN_OLD_NAME, 'Old Name') |
|
45 |
->addRule(Form::REQUIRED, 'Pole %label je povinné', TRUE); |
|
46 |
|
|
47 |
$this->form->setDefaults($this->getDefaults()); |
|
48 |
|
|
49 |
$this->form->addSubmit('submit', 'Save'); |
|
50 |
|
|
51 |
$this->form->onSuccess[] = [$this, 'formSuccess']; |
|
52 |
|
|
53 |
return $this->form; |
|
54 |
} |
|
55 |
|
|
56 |
public function formSuccess(Form $form) |
|
57 |
{ |
|
58 |
$result = $this->originRepository->save($form->getValues(TRUE), $this->originId); |
|
59 |
|
|
60 |
if ($result) |
|
61 |
{ |
|
62 |
$this->presenter->flashMessage('Origin was added successfully.', EFlashMessage::SUCCESS); |
|
63 |
$this->presenter->redirect('Origin:edit', ['id' => $result->{OriginRepository::COLUMN_ID}]); |
|
64 |
} else |
|
65 |
{ |
|
66 |
$form->addError('Origin couldn\'t be added. Please try it again later.'); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Nastavení ID původu při editaci |
|
72 |
* |
|
73 |
* @param int $originId |
|
74 |
*/ |
|
75 |
public function setOrigin(int $originId) |
|
76 |
{ |
|
77 |
$this->originId = $originId; |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Vrací hodnoty z databáze při upravování existujícího místa původu |
|
82 |
* |
|
83 |
* @return array |
|
84 |
*/ |
|
85 |
public function getDefaults() |
|
86 |
{ |
|
87 |
$defaultValues = array(); |
|
88 |
|
|
89 |
if (!empty($this->originId)) |
|
90 |
{ |
|
91 |
$originRow = $this->originRepository->findRow($this->originId); |
|
92 |
|
|
93 |
if ($originRow) |
|
94 |
{ |
|
95 |
$defaultValues = $originRow->toArray(); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
return $defaultValues; |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
interface IOriginEditFormFactory |
|
104 |
{ |
|
105 |
/** |
|
106 |
* @return OriginEditForm |
|
107 |
*/ |
|
108 |
public function create(); |
|
109 |
} |
app/AdminModule/component/Origin/OriginGrid.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
namespace App\AdminModule\Components; |
|
5 |
|
|
6 |
|
|
7 |
use App\Model\Repository\OriginRepository; |
|
8 |
use App\Utils\DataGrid\DataGrid; |
|
9 |
use Ublaboo\DataGrid\Exception\DataGridException; |
|
10 |
|
|
11 |
class OriginGrid extends DataGrid |
|
12 |
{ |
|
13 |
/** |
|
14 |
* @var OriginRepository |
|
15 |
*/ |
|
16 |
private $originRepository; |
|
17 |
|
|
18 |
public function __construct(OriginRepository $originRepository) |
|
19 |
{ |
|
20 |
$this->originRepository = $originRepository; |
|
21 |
|
|
22 |
parent::__construct(); |
|
23 |
} |
|
24 |
|
|
25 |
/** |
|
26 |
* Abstraktní metoda, slouží k nastavení primárního klíče a nastavení datasource |
|
27 |
* 1. $this->setPrimaryKey(); |
|
28 |
* 2. $this->setDataSource(); |
|
29 |
* |
|
30 |
* @throws DataGridException |
|
31 |
*/ |
|
32 |
public function init() |
|
33 |
{ |
|
34 |
$this->setPrimaryKey(OriginRepository::COLUMN_ID); |
|
35 |
$this->setDataSource($this->originRepository->findAll()); |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* Definice sloupečků, akcí, vyhledávácích filtrů gridu |
|
40 |
* |
|
41 |
* @throws DataGridException |
|
42 |
*/ |
|
43 |
public function define() |
|
44 |
{ |
|
45 |
// Definice sloupečků |
|
46 |
$this->addColumnNumber(OriginRepository::COLUMN_ID, 'ID')->setDefaultHide(TRUE); |
|
47 |
$this->addColumnText(OriginRepository::COLUMN_ORIGIN, 'Origin'); |
|
48 |
$this->addColumnText(OriginRepository::COLUMN_OLD_NAME, 'Old Name'); |
|
49 |
|
|
50 |
// Definice filtrů |
|
51 |
$this->addFilterText(OriginRepository::COLUMN_ORIGIN, 'Origin'); |
|
52 |
$this->addFilterText(OriginRepository::COLUMN_OLD_NAME, 'Old Name'); |
|
53 |
|
|
54 |
// Definice akcí |
|
55 |
$this->addAction('edit', 'edit', 'Origin:edit', ['id' => OriginRepository::COLUMN_ID]) |
|
56 |
->setTitle('Edit'); |
|
57 |
|
|
58 |
$this->addAction('delete', 'delete', 'deleteOrigin!', ['id' => OriginRepository::COLUMN_ID]) |
|
59 |
->setConfirm('Do you really want to delete origin %s.', OriginRepository::COLUMN_ORIGIN) |
|
60 |
->setTitle('Delete') |
|
61 |
->setClass('btn btn-xs btn-danger ajax'); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
interface IOriginGridFactory |
|
66 |
{ |
|
67 |
/** |
|
68 |
* @return OriginGrid |
|
69 |
*/ |
|
70 |
public function create(); |
|
71 |
} |
app/AdminModule/presenters/OriginPresenter.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
namespace App\AdminModule\Presenters; |
|
5 |
|
|
6 |
|
|
7 |
use App\AdminModule\Components\IOriginEditFormFactory; |
|
8 |
use App\AdminModule\Components\IOriginGridFactory; |
|
9 |
use App\Enum\EFlashMessage; |
|
10 |
use App\Model\Repository\OriginRepository; |
|
11 |
|
|
12 |
class OriginPresenter extends BaseUserPresenter |
|
13 |
{ |
|
14 |
/** |
|
15 |
* @var IOriginGridFactory |
|
16 |
*/ |
|
17 |
private $originGridFactory; |
|
18 |
/** |
|
19 |
* @var IOriginEditFormFactory |
|
20 |
*/ |
|
21 |
private $originEditFormFactory; |
|
22 |
/** |
|
23 |
* @var OriginRepository |
|
24 |
*/ |
|
25 |
private $originRepository; |
|
26 |
|
|
27 |
public function __construct(IOriginGridFactory $originGridFactory, |
|
28 |
IOriginEditFormFactory $originEditFormFactory, |
|
29 |
OriginRepository $originRepository) |
|
30 |
{ |
|
31 |
parent::__construct(); |
|
32 |
|
|
33 |
$this->originGridFactory = $originGridFactory; |
|
34 |
$this->originEditFormFactory = $originEditFormFactory; |
|
35 |
$this->originRepository = $originRepository; |
|
36 |
} |
|
37 |
|
|
38 |
public function actionEdit(int $id) |
|
39 |
{ |
|
40 |
$this->template->id = $id; |
|
41 |
$this['originEditForm']->setOrigin($id); |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Akce pro odstranění místa původu |
|
46 |
* |
|
47 |
* @param int $id |
|
48 |
* @throws \Nette\Application\AbortException |
|
49 |
*/ |
|
50 |
public function actionDelete(int $id) |
|
51 |
{ |
|
52 |
$result = $this->originRepository->findRow($id)->delete(); |
|
53 |
if ($result) |
|
54 |
{ |
|
55 |
$this->flashMessage('Origin was successfully deleted.', EFlashMessage::SUCCESS); |
|
56 |
} else |
|
57 |
{ |
|
58 |
$this->flashMessage('Origin wasn\'t deleted.', EFlashMessage::ERROR); |
|
59 |
} |
|
60 |
|
|
61 |
$this->redirect('Origin:default'); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Handle používaný v OriginGrid pro smazání místa původu |
|
66 |
* |
|
67 |
* @param int $id : ID mazaného místa původu |
|
68 |
*/ |
|
69 |
public function handleDeleteOrigin(int $id) |
|
70 |
{ |
|
71 |
if ($this->isAjax()) |
|
72 |
{ |
|
73 |
$this->originRepository->findRow($id)->delete(); |
|
74 |
$this['originGrid']->reload(); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
public function createComponentOriginGrid() |
|
79 |
{ |
|
80 |
return $this->originGridFactory->create(); |
|
81 |
} |
|
82 |
|
|
83 |
public function createComponentOriginEditForm() |
|
84 |
{ |
|
85 |
return $this->originEditFormFactory->create(); |
|
86 |
} |
|
87 |
} |
app/AdminModule/templates/@layout.latte | ||
---|---|---|
116 | 116 |
|
117 | 117 |
<li class="nav-item"><a n:href="Museum:default" n:class="nav-link, $presenter->isLinkCurrent('Museum:*') ? active" title="Museum"> |
118 | 118 |
Museum </a></li> |
119 |
<li class="nav-item"><a href="#" class="nav-link" title="Origin">
|
|
119 |
<li class="nav-item"><a n:href="Origin:default" n:class="nav-link, $presenter->isLinkCurrent('Origin:*') ? active" title="Origin">
|
|
120 | 120 |
Origin </a></li> |
121 | 121 |
<li class="nav-item"><a href="#" class="nav-link" title="Upload"> |
122 | 122 |
Upload texts </a></li> |
app/AdminModule/templates/Origin/add.latte | ||
---|---|---|
1 |
{block content} |
|
2 |
<div class="row"> |
|
3 |
<div class="col-11"> |
|
4 |
<div class="display-5">New Origin</div> |
|
5 |
</div> |
|
6 |
<div class="col-1"> |
|
7 |
<a n:href="Origin:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Origin list</a> |
|
8 |
</div> |
|
9 |
</div> |
|
10 |
{control originEditForm} |
app/AdminModule/templates/Origin/default.latte | ||
---|---|---|
1 |
{block content} |
|
2 |
<div class="row"> |
|
3 |
<div class="col-11"> |
|
4 |
<div class="display-5">Origin List</div> |
|
5 |
</div> |
|
6 |
<div class="col-1"> |
|
7 |
<a n:href="Origin:add" class="btn btn-sm btn-success"><span class="fa fa-fw fa-plus"></span> New Origin</a> |
|
8 |
</div> |
|
9 |
</div> |
|
10 |
<div class="row"> |
|
11 |
<div class="col-10 offset-1"> |
|
12 |
{control originGrid} |
|
13 |
</div> |
|
14 |
</div> |
app/AdminModule/templates/Origin/edit.latte | ||
---|---|---|
1 |
{block content} |
|
2 |
<div class="row"> |
|
3 |
<div class="col-10"> |
|
4 |
<div class="display-5">Edit Origin</div> |
|
5 |
</div> |
|
6 |
<div class="col-2 text-right"> |
|
7 |
<a n:href="Origin:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Origin list</a> |
|
8 |
<a n:href="Origin:delete $id" class="btn btn-sm btn-danger" onclick="return confirm('Do you really want to delete this origin?')"><span class="fa fa-fw fa-trash"></span> Delete origin</a> |
|
9 |
</div> |
|
10 |
</div> |
|
11 |
{control originEditForm} |
app/config/components.neon | ||
---|---|---|
3 | 3 |
- App\FrontModule\Components\IExampleGirdFactory |
4 | 4 |
- App\AdminModule\Components\IUserGridFactory |
5 | 5 |
- App\AdminModule\Components\IMuseumGridFactory |
6 |
- App\AdminModule\Components\IOriginGridFactory |
|
6 | 7 |
|
7 | 8 |
# Formuláře |
8 | 9 |
- App\FrontModule\Components\ILoginFormFactory |
9 | 10 |
- App\AdminModule\Components\IUserEditFormFactory |
10 | 11 |
- App\FrontModule\Components\ITransliterationSearchFormFactory |
11 |
- App\AdminModule\Components\IMuseumEditFormFactory |
|
12 |
- App\AdminModule\Components\IMuseumEditFormFactory |
|
13 |
- App\AdminModule\Components\IOriginEditFormFactory |
Také k dispozici: Unified diff
Re #7338 správa místa původu