commit 22d93eb3ba421beeafc0a69a819db82057762ecc
Author: hard456 <janpalcut@seznam.cz>
Date:   Mon Jun 3 16:49:05 2019 +0200

    Re #7507 vytvoření šablony pro vkládání nové iterace

diff --git a/app/AdminModule/component/Book/BookEditForm.php b/app/AdminModule/component/Book/BookEditForm.php
index b416102..04b62ed 100644
--- a/app/AdminModule/component/Book/BookEditForm.php
+++ b/app/AdminModule/component/Book/BookEditForm.php
@@ -16,11 +16,11 @@ class BookEditForm extends Control
     /**
      * @var Form
      */
-    private $form;
+    protected $form;
     /**
      * @var BookRepository
      */
-    private $bookRepository;
+    protected $bookRepository;
 
     public function __construct(BookRepository $bookRepository)
     {
diff --git a/app/AdminModule/component/Book/BookOptionForm.latte b/app/AdminModule/component/Book/BookOptionForm.latte
new file mode 100644
index 0000000..200681d
--- /dev/null
+++ b/app/AdminModule/component/Book/BookOptionForm.latte
@@ -0,0 +1,97 @@
+{form form}
+<div class="row">
+    <div class="col-12">
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_ID}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_ID}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_BOOK_ABREV}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_BOOK_ABREV}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_BOOK_AUTHOR}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_BOOK_AUTHOR}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_BOOK_NAME}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_BOOK_NAME}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_BOOK_DESCRIPTION}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_BOOK_DESCRIPTION}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_PLACE_OF_PUB}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_PLACE_OF_PUB}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_DATE_OF_PUB}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_DATE_OF_PUB}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_PAGES}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_PAGES}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_VOLUME}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_VOLUME}
+            </div>
+        </div>
+
+        <div class="row mb-2">
+            <div class="col-4">
+                {label \App\Model\Repository\BookRepository::COLUMN_VOLUME_NO}
+            </div>
+            <div class="col-8">
+                {input \App\Model\Repository\BookRepository::COLUMN_VOLUME_NO}
+            </div>
+        </div>
+
+    </div>
+</div>
+{/form}
\ No newline at end of file
diff --git a/app/AdminModule/component/Book/BookOptionForm.php b/app/AdminModule/component/Book/BookOptionForm.php
new file mode 100644
index 0000000..a01e6cd
--- /dev/null
+++ b/app/AdminModule/component/Book/BookOptionForm.php
@@ -0,0 +1,93 @@
+<?php
+
+
+namespace App\AdminModule\Components;
+
+
+use App\Model\Repository\BookRepository;
+use App\Model\Repository\TransliterationRepository;
+use App\Utils\Form;
+
+class BookOptionForm extends BookEditForm
+{
+
+    public function render()
+    {
+        parent::render();
+        $this->template->setFile(__DIR__ . '/BookOptionForm.latte');
+        $this->template->render();
+    }
+
+    public function createComponentForm()
+    {
+
+        $this->form->addRadioList('book', 'Book option', [0 => 'Existing book', 1 => 'New book'])
+            ->addCondition($this->form::EQUAL, 0)
+            ->toggle(TransliterationRepository::COLUMN_BOOK_ID)
+            ->elseCondition($this->form::EQUAL, 1)
+            ->toggle(BookRepository::COLUMN_BOOK_ABREV)
+            ->toggle(BookRepository::COLUMN_BOOK_AUTHOR)
+            ->toggle(BookRepository::COLUMN_BOOK_NAME)
+            ->toggle(BookRepository::COLUMN_BOOK_SUBTITLE)
+            ->toggle(BookRepository::COLUMN_BOOK_DESCRIPTION)
+            ->toggle(BookRepository::COLUMN_PLACE_OF_PUB)
+            ->toggle(BookRepository::COLUMN_DATE_OF_PUB)
+            ->toggle(BookRepository::COLUMN_PAGES)
+            ->toggle(BookRepository::COLUMN_VOLUME)
+            ->toggle(BookRepository::COLUMN_VOLUME_NO)
+            ->endCondition();
+
+        $this->form->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect())
+            ->setOption('id', TransliterationRepository::COLUMN_BOOK_ID);
+
+        $this->form->addText(BookRepository::COLUMN_BOOK_ABREV, 'Abbreviation')
+            ->addRule(Form::REQUIRED, 'Field %label is required', TRUE)
+            ->setOption('id', BookRepository::COLUMN_BOOK_ABREV);
+
+        $this->form->addText(BookRepository::COLUMN_BOOK_AUTHOR, 'Author')
+            ->setOption('id', BookRepository::COLUMN_BOOK_AUTHOR);
+
+        $this->form->addText(BookRepository::COLUMN_BOOK_NAME, 'Name')
+            ->addRule(Form::REQUIRED, 'Field %label is required', TRUE)
+            ->setOption('id', BookRepository::COLUMN_BOOK_NAME);
+
+        $this->form->addText(BookRepository::COLUMN_BOOK_SUBTITLE, 'Alternate name')
+            ->setOption('id', BookRepository::COLUMN_BOOK_SUBTITLE);
+
+        $this->form->addTextArea(BookRepository::COLUMN_BOOK_DESCRIPTION, 'Description')
+            ->setOption('id', BookRepository::COLUMN_BOOK_DESCRIPTION);
+
+        $this->form->addText(BookRepository::COLUMN_PLACE_OF_PUB, 'Publication place')
+            ->setOption('id', BookRepository::COLUMN_PLACE_OF_PUB);
+
+        $this->form->addText(BookRepository::COLUMN_DATE_OF_PUB, 'Publication date')
+            ->setOption('id', BookRepository::COLUMN_DATE_OF_PUB);
+
+        $this->form->addText(BookRepository::COLUMN_PAGES, 'Pages')
+            ->setOption('id', BookRepository::COLUMN_PAGES);
+
+        $this->form->addText(BookRepository::COLUMN_VOLUME, 'Volume')
+            ->setOption('id', BookRepository::COLUMN_VOLUME);
+
+        $this->form->addText(BookRepository::COLUMN_VOLUME_NO, 'Volume No.')
+            ;
+
+        $this->form->setDefaults($this->getDefaults());
+        $this->form->setDefaults(['book' => '1']);
+
+        $this->form->addSubmit('submit', 'Save');
+
+        $this->form->onSuccess[] = [$this, 'formSuccess'];
+
+        return $this->form;
+    }
+
+}
+
+interface IBookOptionFormFactory
+{
+    /**
+     * @return BookOptionForm
+     */
+    public function create();
+}
\ No newline at end of file
diff --git a/app/AdminModule/component/Transliteration/TransliterationEditForm.latte b/app/AdminModule/component/Transliteration/TransliterationEditForm.latte
index d730db5..53ca69b 100644
--- a/app/AdminModule/component/Transliteration/TransliterationEditForm.latte
+++ b/app/AdminModule/component/Transliteration/TransliterationEditForm.latte
@@ -2,6 +2,7 @@
     {form form}
         <div class="row">
             <div class="col-12">
+                {if $addBook == true}
                 <div class="row mb-2">
                     <div class="col-4">
                         {label \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_ID}
@@ -10,7 +11,7 @@
                         {input \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_ID}
                     </div>
                 </div>
-
+                {/if}
                 <div class="row mb-2">
                     <div class="col-4">
                         {label \App\Model\Repository\TransliterationRepository::COLUMN_CHAPTER}
diff --git a/app/AdminModule/component/Transliteration/TransliterationEditForm.php b/app/AdminModule/component/Transliteration/TransliterationEditForm.php
index 7649039..611f122 100644
--- a/app/AdminModule/component/Transliteration/TransliterationEditForm.php
+++ b/app/AdminModule/component/Transliteration/TransliterationEditForm.php
@@ -93,12 +93,17 @@ class TransliterationEditForm extends Control
     public function render()
     {
         $this->template->setFile(__DIR__ . '/TransliterationEditForm.latte');
+
+        $this->template->addBook = true;
+        if($this->transliterationId == null){
+            $this->template->addBook = false;
+        }
+
         $this->template->render();
     }
 
     public function createComponentForm()
     {
-        $this->form->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect());
         $this->form->addText(TransliterationRepository::COLUMN_CHAPTER, 'Chapter');
         $this->form->addSelect(TransliterationRepository::COLUMN_MUSEUM_ID, 'Museum', $this->museumRepository->getMuseumNameForSelect());
         $this->form->addText(TransliterationRepository::COLUMN_MUSEUM_NO, 'Museum No');
@@ -127,7 +132,10 @@ class TransliterationEditForm extends Control
         $multiplier->addCreateButton('Add', 1, $redrawCallback);
         $multiplier->addRemoveButton('Remove', $redrawCallback);
 
-        $this->form->setDefaults($this->getDefaults());
+        if($this->transliterationId != null){
+            $this->form->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect());
+            $this->form->setDefaults($this->getDefaults());
+        }
 
         $this->form->addSubmit('submit', 'Save');
 
@@ -243,15 +251,17 @@ class TransliterationEditForm extends Control
      */
     private function getDefaults()
     {
-        $array = $this->transliterationRepository->findRow($this->transliterationId)->toArray();
-        $references = $this->litReferenceRepository->findByTransliterationId($this->transliterationId)->fetchAll();
+        if($this->transliterationId != null){
+            $array = $this->transliterationRepository->findRow($this->transliterationId)->toArray();
+            $references = $this->litReferenceRepository->findByTransliterationId($this->transliterationId)->fetchAll();
 
-        foreach ($references as $activeRow)
-        {
-            $array['references'][] = $activeRow->toArray();
-        }
+            foreach ($references as $activeRow)
+            {
+                $array['references'][] = $activeRow->toArray();
+            }
 
-        return $array;
+            return $array;
+        }
     }
 
 }
diff --git a/app/AdminModule/component/Transliteration/TransliterationNewForm.latte b/app/AdminModule/component/Transliteration/TransliterationNewForm.latte
new file mode 100644
index 0000000..a7911a9
--- /dev/null
+++ b/app/AdminModule/component/Transliteration/TransliterationNewForm.latte
@@ -0,0 +1,5 @@
+<div class="row">
+    <div class="col-12">
+        {control form}
+    </div>
+</div>
\ No newline at end of file
diff --git a/app/AdminModule/component/Transliteration/TransliterationNewForm.php b/app/AdminModule/component/Transliteration/TransliterationNewForm.php
new file mode 100644
index 0000000..adaf382
--- /dev/null
+++ b/app/AdminModule/component/Transliteration/TransliterationNewForm.php
@@ -0,0 +1,37 @@
+<?php
+
+
+namespace App\AdminModule\Components;
+
+
+use Nette\Application\UI\Control;
+
+class TransliterationNewForm extends Control
+{
+
+
+    /**
+     * TransliterationNewForm constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function render()
+    {
+        $this->template->setFile(__DIR__ . '/TransliterationNewForm.latte');
+        $this->template->render();
+    }
+
+}
+
+interface ITransliterationNewFormFactory
+{
+
+    /**
+     * @return TransliterationNewForm
+     */
+    public function create();
+
+}
\ No newline at end of file
diff --git a/app/AdminModule/presenters/TransliterationPresenter.php b/app/AdminModule/presenters/TransliterationPresenter.php
index 3d6baa9..4c8ed6f 100644
--- a/app/AdminModule/presenters/TransliterationPresenter.php
+++ b/app/AdminModule/presenters/TransliterationPresenter.php
@@ -4,9 +4,13 @@
 namespace App\AdminModule\Presenters;
 
 
+use App\AdminModule\Components\IBookEditFormFactory;
+use App\AdminModule\Components\IBookOptionFormFactory;
 use App\AdminModule\Components\ITransliterationDataEditFormFactory;
 use App\AdminModule\Components\ITransliterationGridFactory;
 use App\AdminModule\Components\ITransliterationEditFormFactory;
+use App\AdminModule\Components\ITransliterationNewFormFactory;
+use App\FrontModule\Components\IKeyboard;
 use App\Model\Repository\TransliterationRepository;
 
 class TransliterationPresenter extends BaseUserPresenter
@@ -30,11 +34,26 @@ class TransliterationPresenter extends BaseUserPresenter
      * @var ITransliterationDataEditFormFactory
      */
     private $transliterationDataEditFormFactory;
+    /**
+     * @var ITransliterationNewFormFactory
+     */
+    private $transliterationNewFormFactory;
+    /**
+     * @var IBookOptionFormFactory
+     */
+    private $bookOptionFormFactory;
+    /**
+     * @var IKeyboard
+     */
+    private $keyboard;
 
     public function __construct(ITransliterationGridFactory $transliterationGridFactory,
                                 ITransliterationEditFormFactory $transliterationEditFormFactory,
                                 TransliterationRepository $transliterationRepository,
-                                ITransliterationDataEditFormFactory $transliterationDataEditFormFactory
+                                ITransliterationDataEditFormFactory $transliterationDataEditFormFactory,
+                                ITransliterationNewFormFactory $transliterationNewFormFactory,
+                                IBookOptionFormFactory $bookOptionFormFactory,
+                                IKeyboard $keyboard
     )
     {
         parent::__construct();
@@ -42,6 +61,9 @@ class TransliterationPresenter extends BaseUserPresenter
         $this->transliterationGridFactory = $transliterationGridFactory;
         $this->transliterationRepository = $transliterationRepository;
         $this->transliterationDataEditFormFactory = $transliterationDataEditFormFactory;
+        $this->transliterationNewFormFactory = $transliterationNewFormFactory;
+        $this->bookOptionFormFactory = $bookOptionFormFactory;
+        $this->keyboard = $keyboard;
     }
 
     /**
@@ -84,4 +106,19 @@ class TransliterationPresenter extends BaseUserPresenter
         return  $this->transliterationDataEditFormFactory->create();
     }
 
+    public function createComponentTransliterationNewForm()
+    {
+        return $this->transliterationNewFormFactory->create();
+    }
+
+    public function createComponentBookOptionForm()
+    {
+        return $this->bookOptionFormFactory->create();
+    }
+
+    public function createComponentKeyboard()
+    {
+        return $this->keyboard->create();
+    }
+
 }
\ No newline at end of file
diff --git a/app/AdminModule/templates/Transliteration/new.latte b/app/AdminModule/templates/Transliteration/new.latte
new file mode 100644
index 0000000..e4fbfa5
--- /dev/null
+++ b/app/AdminModule/templates/Transliteration/new.latte
@@ -0,0 +1,49 @@
+{block content}
+
+    <div class="display-5">Enter New Transliteration</div>
+
+
+    <div class="row mt-5">
+        <div class="col-5">
+            <fieldset>
+                <legend>Book information</legend>
+
+                {control bookOptionForm}
+            </fieldset>
+        </div>
+    </div>
+
+    <div class="row mt-5">
+        <div class="col-5">
+            <fieldset>
+                <legend>Transliteration information</legend>
+
+                {control transliterationEditForm}
+            </fieldset>
+        </div>
+    </div>
+
+    <div class="row mt-5">
+        <div class="col-5">
+            <fieldset>
+                <legend>Transliteration data</legend>
+
+                {control transliterationDataEditForm}
+            </fieldset>
+        </div>
+    </div>
+
+    <div class="row mt-5">
+        <div class="col-5">
+            {control keyboard}
+        </div>
+    </div>
+
+{/block}
+
+{block scripts}
+<script>
+    $(function () {
+        $.nette.init();
+    });
+</script>
diff --git a/app/config/components.neon b/app/config/components.neon
index 02309d4..61563cc 100644
--- a/app/config/components.neon
+++ b/app/config/components.neon
@@ -22,6 +22,11 @@ services:
     - App\AdminModule\Components\IBookEditFormFactory
     - App\AdminModule\Components\ITransliterationEditFormFactory
     - App\AdminModule\Components\ITransliterationDataEditFormFactory
+    - App\AdminModule\Components\ITransliterationNewFormFactory
+    - App\AdminModule\Components\IBookOptionFormFactory
+
+
+
 
     - App\FrontModule\Components\IKeyboard
     - App\FrontModule\Components\ITransliterationSearchResultListFactory
\ No newline at end of file
diff --git a/app/templates/@menu.latte b/app/templates/@menu.latte
index d4b534b..ff55d90 100644
--- a/app/templates/@menu.latte
+++ b/app/templates/@menu.latte
@@ -16,7 +16,7 @@
             <a class="nav-link" href="#">Contact & members</a>
         </li>
         <li class="nav-item">
-            <a class="nav-link" href="#">Input new text</a>
+            <a class="nav-link" n:href=":Admin:Transliteration:new">Input new text</a>
         </li>
         {if $user->loggedIn && ($user->isInRole(\App\Enum\EUserRole::ADMIN) || $user->isInRole(\App\Enum\EUserRole::USER))}
             <li class="nav-item">
