commit f1da904b67b78e1dcd05f627dcb888be0b3727c6
Author: Filip Jani <jsem@filek.cz>
Date:   Mon Apr 22 22:33:30 2019 +0200

    Re #7338 správa místa původu

diff --git a/app/AdminModule/component/Origin/OriginEditForm.latte b/app/AdminModule/component/Origin/OriginEditForm.latte
new file mode 100644
index 0000000..b6a732f
--- /dev/null
+++ b/app/AdminModule/component/Origin/OriginEditForm.latte
@@ -0,0 +1,5 @@
+<div class="row">
+    <div class="col-4">
+        {control form}
+    </div>
+</div>
\ No newline at end of file
diff --git a/app/AdminModule/component/Origin/OriginEditForm.php b/app/AdminModule/component/Origin/OriginEditForm.php
new file mode 100644
index 0000000..ae4c19e
--- /dev/null
+++ b/app/AdminModule/component/Origin/OriginEditForm.php
@@ -0,0 +1,109 @@
+<?php
+
+
+namespace App\AdminModule\Components;
+
+
+use App\Enum\EFlashMessage;
+use App\Model\Repository\OriginRepository;
+use App\Utils\Form;
+use Nette\Application\UI\Control;
+
+class OriginEditForm extends Control
+{
+    private $originId;
+
+    /**
+     * @var Form
+     */
+    private $form;
+    /**
+     * @var OriginRepository
+     */
+    private $originRepository;
+
+    public function __construct(OriginRepository $originRepository)
+    {
+        parent::__construct();
+
+        $this->form = new Form;
+        $this->originId = NULL;
+        $this->originRepository = $originRepository;
+    }
+
+    public function render()
+    {
+        $this->template->setFile(__DIR__ . '/OriginEditForm.latte');
+        $this->template->render();
+    }
+
+    public function createComponentForm()
+    {
+        $this->form->addText(OriginRepository::COLUMN_ORIGIN, 'Origin')
+            ->addRule(Form::REQUIRED, 'Pole %label je povinné', TRUE);
+        $this->form->addText(OriginRepository::COLUMN_OLD_NAME, 'Old Name')
+            ->addRule(Form::REQUIRED, 'Pole %label je povinné', TRUE);
+
+        $this->form->setDefaults($this->getDefaults());
+
+        $this->form->addSubmit('submit', 'Save');
+
+        $this->form->onSuccess[] = [$this, 'formSuccess'];
+
+        return $this->form;
+    }
+
+    public function formSuccess(Form $form)
+    {
+        $result = $this->originRepository->save($form->getValues(TRUE), $this->originId);
+
+        if ($result)
+        {
+            $this->presenter->flashMessage('Origin was added successfully.', EFlashMessage::SUCCESS);
+            $this->presenter->redirect('Origin:edit', ['id' => $result->{OriginRepository::COLUMN_ID}]);
+        } else
+        {
+            $form->addError('Origin couldn\'t be added. Please try it again later.');
+        }
+    }
+
+    /**
+     * Nastavení ID původu při editaci
+     *
+     * @param int $originId
+     */
+    public function setOrigin(int $originId)
+    {
+        $this->originId = $originId;
+    }
+
+    /**
+     * Vrací hodnoty z databáze při upravování existujícího místa původu
+     *
+     * @return array
+     */
+    public function getDefaults()
+    {
+        $defaultValues = array();
+
+        if (!empty($this->originId))
+        {
+            $originRow = $this->originRepository->findRow($this->originId);
+
+            if ($originRow)
+            {
+                $defaultValues = $originRow->toArray();
+            }
+        }
+
+        return $defaultValues;
+    }
+}
+
+interface IOriginEditFormFactory
+{
+    /**
+     * @return OriginEditForm
+     */
+    public function create();
+}
\ No newline at end of file
diff --git a/app/AdminModule/component/Origin/OriginGrid.php b/app/AdminModule/component/Origin/OriginGrid.php
new file mode 100644
index 0000000..218e17e
--- /dev/null
+++ b/app/AdminModule/component/Origin/OriginGrid.php
@@ -0,0 +1,71 @@
+<?php
+
+
+namespace App\AdminModule\Components;
+
+
+use App\Model\Repository\OriginRepository;
+use App\Utils\DataGrid\DataGrid;
+use Ublaboo\DataGrid\Exception\DataGridException;
+
+class OriginGrid extends DataGrid
+{
+    /**
+     * @var OriginRepository
+     */
+    private $originRepository;
+
+    public function __construct(OriginRepository $originRepository)
+    {
+        $this->originRepository = $originRepository;
+
+        parent::__construct();
+    }
+
+    /**
+     * Abstraktní metoda, slouží k nastavení primárního klíče a nastavení datasource
+     *  1. $this->setPrimaryKey();
+     *  2. $this->setDataSource();
+     *
+     * @throws DataGridException
+     */
+    public function init()
+    {
+        $this->setPrimaryKey(OriginRepository::COLUMN_ID);
+        $this->setDataSource($this->originRepository->findAll());
+    }
+
+    /**
+     * Definice sloupečků, akcí, vyhledávácích filtrů gridu
+     *
+     * @throws DataGridException
+     */
+    public function define()
+    {
+        // Definice sloupečků
+        $this->addColumnNumber(OriginRepository::COLUMN_ID, 'ID')->setDefaultHide(TRUE);
+        $this->addColumnText(OriginRepository::COLUMN_ORIGIN, 'Origin');
+        $this->addColumnText(OriginRepository::COLUMN_OLD_NAME, 'Old Name');
+
+        // Definice filtrů
+        $this->addFilterText(OriginRepository::COLUMN_ORIGIN, 'Origin');
+        $this->addFilterText(OriginRepository::COLUMN_OLD_NAME, 'Old Name');
+
+        // Definice akcí
+        $this->addAction('edit', 'edit', 'Origin:edit', ['id' => OriginRepository::COLUMN_ID])
+            ->setTitle('Edit');
+
+        $this->addAction('delete', 'delete', 'deleteOrigin!', ['id' => OriginRepository::COLUMN_ID])
+            ->setConfirm('Do you really want to delete origin %s.', OriginRepository::COLUMN_ORIGIN)
+            ->setTitle('Delete')
+            ->setClass('btn btn-xs btn-danger ajax');
+    }
+}
+
+interface IOriginGridFactory
+{
+    /**
+     * @return OriginGrid
+     */
+    public function create();
+}
\ No newline at end of file
diff --git a/app/AdminModule/presenters/OriginPresenter.php b/app/AdminModule/presenters/OriginPresenter.php
new file mode 100644
index 0000000..210a2b5
--- /dev/null
+++ b/app/AdminModule/presenters/OriginPresenter.php
@@ -0,0 +1,87 @@
+<?php
+
+
+namespace App\AdminModule\Presenters;
+
+
+use App\AdminModule\Components\IOriginEditFormFactory;
+use App\AdminModule\Components\IOriginGridFactory;
+use App\Enum\EFlashMessage;
+use App\Model\Repository\OriginRepository;
+
+class OriginPresenter extends BaseUserPresenter
+{
+    /**
+     * @var IOriginGridFactory
+     */
+    private $originGridFactory;
+    /**
+     * @var IOriginEditFormFactory
+     */
+    private $originEditFormFactory;
+    /**
+     * @var OriginRepository
+     */
+    private $originRepository;
+
+    public function __construct(IOriginGridFactory $originGridFactory,
+                                IOriginEditFormFactory $originEditFormFactory,
+                                OriginRepository $originRepository)
+    {
+        parent::__construct();
+
+        $this->originGridFactory = $originGridFactory;
+        $this->originEditFormFactory = $originEditFormFactory;
+        $this->originRepository = $originRepository;
+    }
+
+    public function actionEdit(int $id)
+    {
+        $this->template->id = $id;
+        $this['originEditForm']->setOrigin($id);
+    }
+
+    /**
+     * Akce pro odstranění místa původu
+     *
+     * @param int $id
+     * @throws \Nette\Application\AbortException
+     */
+    public function actionDelete(int $id)
+    {
+        $result = $this->originRepository->findRow($id)->delete();
+        if ($result)
+        {
+            $this->flashMessage('Origin was successfully deleted.', EFlashMessage::SUCCESS);
+        } else
+        {
+            $this->flashMessage('Origin wasn\'t deleted.', EFlashMessage::ERROR);
+        }
+
+        $this->redirect('Origin:default');
+    }
+
+    /**
+     * Handle používaný v OriginGrid pro smazání místa původu
+     *
+     * @param int $id : ID mazaného místa původu
+     */
+    public function handleDeleteOrigin(int $id)
+    {
+        if ($this->isAjax())
+        {
+            $this->originRepository->findRow($id)->delete();
+            $this['originGrid']->reload();
+        }
+    }
+
+    public function createComponentOriginGrid()
+    {
+        return $this->originGridFactory->create();
+    }
+
+    public function createComponentOriginEditForm()
+    {
+        return $this->originEditFormFactory->create();
+    }
+}
\ No newline at end of file
diff --git a/app/AdminModule/templates/@layout.latte b/app/AdminModule/templates/@layout.latte
index e8b4e07..00fe271 100644
--- a/app/AdminModule/templates/@layout.latte
+++ b/app/AdminModule/templates/@layout.latte
@@ -116,7 +116,7 @@
 
     <li class="nav-item"><a n:href="Museum:default" n:class="nav-link, $presenter->isLinkCurrent('Museum:*') ? active" title="Museum">
             Museum </a></li>
-    <li class="nav-item"><a href="#" class="nav-link" title="Origin">
+    <li class="nav-item"><a n:href="Origin:default" n:class="nav-link, $presenter->isLinkCurrent('Origin:*') ? active" title="Origin">
             Origin </a></li>
     <li class="nav-item"><a href="#" class="nav-link" title="Upload">
             Upload&nbsp;texts </a></li>
diff --git a/app/AdminModule/templates/Origin/add.latte b/app/AdminModule/templates/Origin/add.latte
new file mode 100644
index 0000000..66e9524
--- /dev/null
+++ b/app/AdminModule/templates/Origin/add.latte
@@ -0,0 +1,10 @@
+{block content}
+<div class="row">
+    <div class="col-11">
+        <div class="display-5">New Origin</div>
+    </div>
+    <div class="col-1">
+        <a n:href="Origin:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Origin list</a>
+    </div>
+</div>
+{control originEditForm}
\ No newline at end of file
diff --git a/app/AdminModule/templates/Origin/default.latte b/app/AdminModule/templates/Origin/default.latte
new file mode 100644
index 0000000..246753a
--- /dev/null
+++ b/app/AdminModule/templates/Origin/default.latte
@@ -0,0 +1,14 @@
+{block content}
+<div class="row">
+    <div class="col-11">
+        <div class="display-5">Origin List</div>
+    </div>
+    <div class="col-1">
+        <a n:href="Origin:add" class="btn btn-sm btn-success"><span class="fa fa-fw fa-plus"></span> New Origin</a>
+    </div>
+</div>
+<div class="row">
+    <div class="col-10 offset-1">
+        {control originGrid}
+    </div>
+</div>
\ No newline at end of file
diff --git a/app/AdminModule/templates/Origin/edit.latte b/app/AdminModule/templates/Origin/edit.latte
new file mode 100644
index 0000000..145c6a3
--- /dev/null
+++ b/app/AdminModule/templates/Origin/edit.latte
@@ -0,0 +1,11 @@
+{block content}
+<div class="row">
+    <div class="col-10">
+        <div class="display-5">Edit Origin</div>
+    </div>
+    <div class="col-2 text-right">
+        <a n:href="Origin:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Origin list</a>
+        <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>
+    </div>
+</div>
+{control originEditForm}
\ No newline at end of file
diff --git a/app/config/components.neon b/app/config/components.neon
index 9ea5ac5..31807b2 100644
--- a/app/config/components.neon
+++ b/app/config/components.neon
@@ -3,9 +3,11 @@ services:
     - App\FrontModule\Components\IExampleGirdFactory
     - App\AdminModule\Components\IUserGridFactory
     - App\AdminModule\Components\IMuseumGridFactory
+    - App\AdminModule\Components\IOriginGridFactory
 
     # Formuláře
     - App\FrontModule\Components\ILoginFormFactory
     - App\AdminModule\Components\IUserEditFormFactory
     - App\FrontModule\Components\ITransliterationSearchFormFactory
-    - App\AdminModule\Components\IMuseumEditFormFactory
\ No newline at end of file
+    - App\AdminModule\Components\IMuseumEditFormFactory
+    - App\AdminModule\Components\IOriginEditFormFactory
\ No newline at end of file
