commit 80b17f46b423b9178ecf7fdee1c0b2c6f4b8af8b
Author: Jan Šedivý <honza.seeda@gmail.com>
Date:   Mon Apr 22 22:32:44 2019 +0200

    Re #7335 Formulář pro správu typu objektů v administraci

diff --git a/app/AdminModule/component/Object/ObjectTypeEditForm.latte b/app/AdminModule/component/Object/ObjectTypeEditForm.latte
new file mode 100644
index 0000000..83bec91
--- /dev/null
+++ b/app/AdminModule/component/Object/ObjectTypeEditForm.latte
@@ -0,0 +1,5 @@
+<div class="row">
+    <div class="col-4">
+        {control form}
+    </div>
+</div>
diff --git a/app/AdminModule/component/Object/ObjectTypeEditForm.php b/app/AdminModule/component/Object/ObjectTypeEditForm.php
new file mode 100644
index 0000000..7860fbb
--- /dev/null
+++ b/app/AdminModule/component/Object/ObjectTypeEditForm.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace App\AdminModule\Components;
+
+
+use App\Enum\EFlashMessage;
+use App\Model\Repository\ObjectTypeRepository;
+use App\Utils\Form;
+use Nette\Application\UI\Control;
+
+class ObjectTypeEditForm extends Control
+{
+    /** @var ObjectTypeRepository */
+    private $objectTypeRepository;
+
+    private $typeId;
+
+    /**
+     * ObjectTypeEditForm constructor.
+     * @param ObjectTypeRepository $objectTypeRepository
+     * @param $typeId null|int
+     */
+    public function __construct($typeId, ObjectTypeRepository $objectTypeRepository)
+    {
+        $this->objectTypeRepository = $objectTypeRepository;
+        $this->typeId = $typeId;
+
+        parent::__construct();
+    }
+
+    public function render()
+    {
+        $this->template->setFile(__DIR__ . '/ObjectTypeEditForm.latte');
+        $this->template->render();
+    }
+
+    public function createComponentForm()
+    {
+        $form = new Form();
+
+        $form->addText(ObjectTypeRepository::COLUMN_OBJECT_TYPE, 'Object Tyoe')
+            ->addRule(Form::REQUIRED, 'Field %label is required.');
+
+        $form->addSubmit('save', 'Save');
+
+        if($this->typeId)
+        {
+            $form->setDefaults($this->objectTypeRepository->findRow($this->typeId));
+        }
+
+        $form->onSuccess[] = [$this, 'formSuccess'];
+
+        return $form;
+    }
+
+    public function formSuccess(Form $form)
+    {
+        $result = $this->objectTypeRepository->save($form->getValues(true), $this->typeId);
+
+        if ($result)
+        {
+            $this->presenter->flashMessage('Object type was successfully saved.', EFlashMessage::SUCCESS);
+            $this->presenter->redirect('Object:');
+        } else
+        {
+            $this->presenter->flashMessage('Object Type could not be saved.', EFlashMessage::ERROR);
+        }
+    }
+}
+
+interface IObjectTypeEditFormFactory
+{
+    /**
+     * @param $typeId null|int
+     * @return ObjectTypeEditForm
+     */
+    public function create($typeId);
+}
\ No newline at end of file
diff --git a/app/AdminModule/presenters/ObjectPresenter.php b/app/AdminModule/presenters/ObjectPresenter.php
index ac19b70..0ed8702 100644
--- a/app/AdminModule/presenters/ObjectPresenter.php
+++ b/app/AdminModule/presenters/ObjectPresenter.php
@@ -3,7 +3,9 @@
 namespace App\AdminModule\Presenters;
 
 
+use App\AdminModule\Components\IObjectTypeEditFormFactory;
 use App\AdminModule\Components\IObjectTypeGridFactory;
+use App\Enum\EFlashMessage;
 use App\Model\Repository\ObjectTypeRepository;
 
 class ObjectPresenter extends BaseUserPresenter
@@ -14,17 +16,26 @@ class ObjectPresenter extends BaseUserPresenter
     /** @var IObjectTypeGridFactory */
     private $objectTypeGridFactory;
 
+    /** @var IObjectTypeEditFormFactory */
+    private $objectTypeEditFormFactory;
+
+    private $typeId;
+
     /**
      * ObjectPresenter constructor.
      * @param ObjectTypeRepository $objectTypeRepository
+     * @param IObjectTypeGridFactory $objectTypeGridFactory
+     * @param IObjectTypeEditFormFactory $objectTypeEditFormFactory
      */
     public function __construct(
         ObjectTypeRepository $objectTypeRepository,
-        IObjectTypeGridFactory $objectTypeGridFactory
+        IObjectTypeGridFactory $objectTypeGridFactory,
+        IObjectTypeEditFormFactory $objectTypeEditFormFactory
     )
     {
         $this->objectTypeRepository = $objectTypeRepository;
         $this->objectTypeGridFactory = $objectTypeGridFactory;
+        $this->objectTypeEditFormFactory = $objectTypeEditFormFactory;
 
         parent::__construct();
     }
@@ -36,12 +47,27 @@ class ObjectPresenter extends BaseUserPresenter
 
     public function actionEditType(int $id)
     {
+        if(!$this->objectTypeRepository->findRow($id))
+        {
+            $this->flashMessage('Object type was not found.', EFlashMessage::ERROR);
+            $this->redirect('Object:');
+        }
 
+        $this->typeId = $id;
+        $this->template->id = $id;
     }
 
     public function actionDeleteType(int $id)
     {
-
+        if($this->objectTypeRepository->delete($id))
+        {
+            $this->flashMessage('Object type was deleted.', EFlashMessage::SUCCESS);
+        }
+        else
+        {
+            $this->flashMessage('Object type was not found.', EFlashMessage::ERROR);
+        }
+        $this->redirect('Object:');
     }
 
     public function createComponentObjectTypeGrid()
@@ -49,4 +75,8 @@ class ObjectPresenter extends BaseUserPresenter
         return $this->objectTypeGridFactory->create();
     }
 
+    public function createComponentObjectTypeEditForm()
+    {
+        return $this->objectTypeEditFormFactory->create($this->typeId);
+    }
 }
\ No newline at end of file
diff --git a/app/AdminModule/templates/Object/addType.latte b/app/AdminModule/templates/Object/addType.latte
new file mode 100644
index 0000000..fda3bc9
--- /dev/null
+++ b/app/AdminModule/templates/Object/addType.latte
@@ -0,0 +1,11 @@
+{block content}
+    <div class="row">
+        <div class="col-10">
+            <div class="display-5">New Object Type</div>
+        </div>
+        <div class="col-2 text-right">
+            <a n:href="Object:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Object Types</a>
+        </div>
+    </div>
+    {control objectTypeEditForm}
+{/block}
\ No newline at end of file
diff --git a/app/AdminModule/templates/Object/default.latte b/app/AdminModule/templates/Object/default.latte
index 1e9db32..471e2fa 100644
--- a/app/AdminModule/templates/Object/default.latte
+++ b/app/AdminModule/templates/Object/default.latte
@@ -4,7 +4,7 @@
             <div class="display-5">Object Type List</div>
         </div>
         <div class="col-1">
-            <a n:href="User:add" class="btn btn-sm btn-success"><span class="fa fa-fw fa-plus"></span> New Object Type</a>
+            <a n:href="Object:addType" class="btn btn-sm btn-success"><span class="fa fa-fw fa-plus"></span> New Object Type</a>
         </div>
     </div>
     <div class="row">
diff --git a/app/AdminModule/templates/Object/editType.latte b/app/AdminModule/templates/Object/editType.latte
new file mode 100644
index 0000000..7082d13
--- /dev/null
+++ b/app/AdminModule/templates/Object/editType.latte
@@ -0,0 +1,12 @@
+{block content}
+    <div class="row">
+        <div class="col-10">
+            <div class="display-5">Edit Object Type</div>
+        </div>
+        <div class="col-2 text-right">
+            <a n:href="Object:deleteType $id" class="btn btn-sm btn-danger" onclick="return confirm('Do you really want to delete this type?')"><span class="fa fa-fw fa-trash"></span> Delete Type</a>
+            <a n:href="Object:default" class="btn btn-sm btn-success"><span class="fa fa-fw fa-list"></span> Object Types</a>
+        </div>
+    </div>
+    {control objectTypeEditForm}
+{/block}
\ No newline at end of file
diff --git a/app/config/components.neon b/app/config/components.neon
index 7b5703c..0700c0a 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\IMuseumEditFormFactory
\ No newline at end of file
+    - App\AdminModule\Components\IMuseumEditFormFactory
+    - App\AdminModule\Components\IObjectTypeEditFormFactory
\ No newline at end of file
diff --git a/www/css/admin/style.css b/www/css/admin/style.css
index 828fd12..1ae5318 100644
--- a/www/css/admin/style.css
+++ b/www/css/admin/style.css
@@ -30,6 +30,7 @@
     font-size: 2rem;
     font-weight: 300;
     line-height: 1.2;
+    margin-bottom: 1rem;
 }
 
 .content {
