commit 8b71ca4d62aacff760dab4bd69f107ce8d06bef2
Author: Jan Šedivý <honza.seeda@gmail.com>
Date:   Sat Apr 20 12:34:27 2019 +0200

    Re #7336 Formuláře pro úpravu typů povrchu

diff --git a/app/AdminModule/component/Surface/SurfaceGrid.php b/app/AdminModule/component/Surface/SurfaceGrid.php
index b05d3e3..6599e65 100644
--- a/app/AdminModule/component/Surface/SurfaceGrid.php
+++ b/app/AdminModule/component/Surface/SurfaceGrid.php
@@ -42,9 +42,14 @@ class SurfaceTypeGrid extends DataGrid
         $this->addColumnText(SurfaceTypeRepository::COLUMN_SURFACE_TYPE, 'Surface Type');
         $this->addColumnText(SurfaceTypeRepository::COLUMN_SORTER, 'Sort Position');
 
-        $this->addAction('edit', 'upravit', 'Surface:editType', ['id' => SurfaceTypeRepository::COLUMN_ID])
+        $this->addAction('edit', 'edit', 'Surface:editType', ['id' => SurfaceTypeRepository::COLUMN_ID])
             ->setTitle('Edit');
 
+        $this->addAction('delete', 'smazat', 'Surface:deleteType', ['id' => SurfaceTypeRepository::COLUMN_ID])
+            ->setConfirm('Do you really want to delete surface type "%s"?', SurfaceTypeRepository::COLUMN_SURFACE_TYPE)
+            ->setTitle('Delete')
+            ->setClass('btn btn-xs btn-danger ajax');
+
         $this->setDefaultPerPage(20);
     }
 }
diff --git a/app/AdminModule/component/Surface/SurfaceTypeEditForm.latte b/app/AdminModule/component/Surface/SurfaceTypeEditForm.latte
new file mode 100644
index 0000000..83bec91
--- /dev/null
+++ b/app/AdminModule/component/Surface/SurfaceTypeEditForm.latte
@@ -0,0 +1,5 @@
+<div class="row">
+    <div class="col-4">
+        {control form}
+    </div>
+</div>
diff --git a/app/AdminModule/component/Surface/SurfaceTypeEditFormFactory.php b/app/AdminModule/component/Surface/SurfaceTypeEditFormFactory.php
new file mode 100644
index 0000000..a28d716
--- /dev/null
+++ b/app/AdminModule/component/Surface/SurfaceTypeEditFormFactory.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace App\AdminModule\Components;
+
+
+use App\Enum\EFlashMessage;
+use App\Model\Repository\SurfaceTypeRepository;
+use App\Utils\Form;
+use Nette\Application\UI\Control;
+
+class SurfaceTypeEditForm extends Control
+{
+    /** @var SurfaceTypeRepository */
+    private $surfaceTypeRepository;
+
+    private $typeId;
+
+    /**
+     * SurfaceTypeEditForm constructor.
+     * @param SurfaceTypeRepository $surfaceTypeRepository
+     * @param $typeId
+     */
+    public function __construct($typeId, SurfaceTypeRepository $surfaceTypeRepository)
+    {
+        $this->surfaceTypeRepository = $surfaceTypeRepository;
+        $this->typeId = $typeId;
+
+        parent::__construct();
+    }
+
+    public function render()
+    {
+        $this->template->setFile(__DIR__ . '/SurfaceTypeEditForm.latte');
+        $this->template->render();
+    }
+
+    public function createComponentForm()
+    {
+        $form = new Form();
+
+        $form->addText(SurfaceTypeRepository::COLUMN_SURFACE_TYPE, 'Surface Type');
+        $form->addText(SurfaceTypeRepository::COLUMN_SORTER, 'Sorter');
+
+        $form->addSubmit('submit', 'Save');
+
+        $form->onSuccess[] = [$this, 'formSuccess'];
+
+        if($this->typeId)
+        {
+            $form->setDefaults($this->surfaceTypeRepository->findRow($this->typeId));
+        }
+
+        return $form;
+    }
+
+    public function formSuccess(Form $form)
+    {
+        $result = $this->surfaceTypeRepository->save($form->getValues(true), $this->typeId);
+
+        if ($result)
+        {
+            $this->presenter->flashMessage('Surface type was successfully saved.', EFlashMessage::SUCCESS);
+            $this->presenter->redirect('Surface:');
+        } else
+        {
+            $this->presenter->flashMessage('Uživatele se nepodařilo upravit.', EFlashMessage::ERROR);
+        }
+    }
+}
+
+interface ISurfaceTypeEditFormFactory
+{
+    /**
+     * @param $typeId
+     * @return SurfaceTypeEditForm
+     */
+    public function create($typeId);
+}
\ No newline at end of file
diff --git a/app/AdminModule/presenters/SurfacePresenter.php b/app/AdminModule/presenters/SurfacePresenter.php
index efe5277..5212fd3 100644
--- a/app/AdminModule/presenters/SurfacePresenter.php
+++ b/app/AdminModule/presenters/SurfacePresenter.php
@@ -3,6 +3,7 @@
 namespace App\AdminModule\Presenters;
 
 
+use App\AdminModule\Components\ISurfaceTypeEditFormFactory;
 use App\AdminModule\Components\ISurfaceTypeGridFactory;
 
 class SurfacePresenter extends BaseAdminPresenter
@@ -10,17 +11,25 @@ class SurfacePresenter extends BaseAdminPresenter
     /** @var ISurfaceTypeGridFactory */
     private $surfaceTypeGridFactory;
 
+    /** @var ISurfaceTypeEditFormFactory */
+    private $surfaceTypeEditFormFactory;
+
     private $typeId;
 
     /**
      * SurfacePresenter constructor.
      * @param ISurfaceTypeGridFactory $surfaceTypeGridFactory
+     * @param ISurfaceTypeEditFormFactory $surfaceTypeEditFormFactory
      */
-    public function __construct(ISurfaceTypeGridFactory $surfaceTypeGridFactory)
+    public function __construct(
+        ISurfaceTypeGridFactory $surfaceTypeGridFactory,
+        ISurfaceTypeEditFormFactory $surfaceTypeEditFormFactory
+    )
     {
         parent::__construct();
 
         $this->surfaceTypeGridFactory = $surfaceTypeGridFactory;
+        $this->surfaceTypeEditFormFactory = $surfaceTypeEditFormFactory;
     }
 
     public function actionAddType()
@@ -28,12 +37,12 @@ class SurfacePresenter extends BaseAdminPresenter
 
     }
 
-    public function actionEditType($id)
+    public function actionEditType(int $id)
     {
-
+        $this->typeId = $id;
     }
 
-    public function actionDeleteType($id)
+    public function actionDeleteType(int $id)
     {
 
     }
@@ -42,4 +51,9 @@ class SurfacePresenter extends BaseAdminPresenter
     {
         return $this->surfaceTypeGridFactory->create();
     }
+
+    public function createComponentSurfaceTypeEditForm()
+    {
+        return $this->surfaceTypeEditFormFactory->create($this->typeId);
+    }
 }
\ No newline at end of file
diff --git a/app/AdminModule/templates/Surface/addType.latte b/app/AdminModule/templates/Surface/addType.latte
new file mode 100644
index 0000000..cba1e89
--- /dev/null
+++ b/app/AdminModule/templates/Surface/addType.latte
@@ -0,0 +1,11 @@
+{block content}
+    <div class="row">
+        <div class="col-10">
+            <div class="display-5">New Surface Type</div>
+        </div>
+        <div class="col-2 text-right">
+            <a n:href="Surface:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Surface Types</a>
+        </div>
+    </div>
+    {control surfaceTypeEditForm}
+{/block}
\ No newline at end of file
diff --git a/app/AdminModule/templates/Surface/default.latte b/app/AdminModule/templates/Surface/default.latte
index 3a867f6..2a175a3 100644
--- a/app/AdminModule/templates/Surface/default.latte
+++ b/app/AdminModule/templates/Surface/default.latte
@@ -1,3 +1,16 @@
 {block content}
-    {control surfaceTypeGrid}
+    <div class="row">
+        <div class="col-10">
+            <div class="display-5">Surface Types</div>
+        </div>
+        <div class="col-2 text-right">
+            <a n:href="Surface:addType" class="btn btn-sm btn-success"><span class="fa fa-fw fa-plus"></span> New Surface Type</a>
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-10 offset-1">
+            {control surfaceTypeGrid}
+        </div>
+    </div>
+
 {/block}
\ No newline at end of file
diff --git a/app/AdminModule/templates/Surface/editType.latte b/app/AdminModule/templates/Surface/editType.latte
new file mode 100644
index 0000000..abf5229
--- /dev/null
+++ b/app/AdminModule/templates/Surface/editType.latte
@@ -0,0 +1,11 @@
+{block content}
+    <div class="row">
+        <div class="col-10">
+            <div class="display-5">Edit Surface Type</div>
+        </div>
+        <div class="col-2 text-right">
+            <a n:href="Surface:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Surface Types</a>
+        </div>
+    </div>
+    {control surfaceTypeEditForm}
+{/block}
\ No newline at end of file
diff --git a/app/AdminModule/templates/User/add.latte b/app/AdminModule/templates/User/add.latte
index 5861aed..44d6948 100644
--- a/app/AdminModule/templates/User/add.latte
+++ b/app/AdminModule/templates/User/add.latte
@@ -1,9 +1,9 @@
 {block content}
 <div class="row">
-    <div class="col-11">
-        <h4>Administrace - Nový uživatel</h4>
+    <div class="col-10">
+        <div class="display-5">Administrace - Nový uživatel</div>
     </div>
-    <div class="col-1">
+    <div class="col-2 text-right">
         <a n:href="User:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Seznam uživatelů</a>
     </div>
 </div>
diff --git a/app/AdminModule/templates/User/default.latte b/app/AdminModule/templates/User/default.latte
index 078228d..c4c44bb 100644
--- a/app/AdminModule/templates/User/default.latte
+++ b/app/AdminModule/templates/User/default.latte
@@ -1,9 +1,9 @@
 {block content}
 <div class="row">
-    <div class="col-11">
-        <h4>Administrace - Seznam uživatelů</h4>
+    <div class="col-10">
+        <div class="display-5">Administrace - Seznam uživatelů</div>
     </div>
-    <div class="col-1">
+    <div class="col-2 text-right">
         <a n:href="User:add" class="btn btn-sm btn-success"><span class="fa fa-fw fa-plus"></span> Přidat uživatele</a>
     </div>
 </div>
diff --git a/app/AdminModule/templates/User/edit.latte b/app/AdminModule/templates/User/edit.latte
index ecbd821..cbe97e7 100644
--- a/app/AdminModule/templates/User/edit.latte
+++ b/app/AdminModule/templates/User/edit.latte
@@ -1,9 +1,9 @@
 {block content}
 <div class="row">
-    <div class="col-11">
-        <h4>Administrace - Editace uživatele</h4>
+    <div class="col-10">
+        <div class="display-5">Administrace - Editace uživatele</div>
     </div>
-    <div class="col-1">
+    <div class="col-2 text-right">
         <a n:href="User:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Seznam uživatelů</a>
     </div>
 </div>
diff --git a/app/config/components.neon b/app/config/components.neon
index 71ce30e..e6063d5 100644
--- a/app/config/components.neon
+++ b/app/config/components.neon
@@ -9,4 +9,5 @@ services:
     - App\FrontModule\Components\ILoginFormFactory
     - App\AdminModule\Components\IUserEditFormFactory
     - App\FrontModule\Components\ITransliterationSearchFormFactory
+    - App\AdminModule\Components\ISurfaceTypeEditFormFactory
     - App\AdminModule\Components\IMuseumEditFormFactory
\ No newline at end of file
