Skip to content

Commit

Permalink
Merge pull request #2911 from skaut/2908-protidoklad-z-akce-do-pokladny
Browse files Browse the repository at this point in the history
Switched the base class from BaseControl to Dialog.
  • Loading branch information
juradee authored Dec 6, 2024
2 parents 201067e + 7403e10 commit 870c05b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
24 changes: 10 additions & 14 deletions app/AccountancyModule/Components/Cashbook/InvertChitDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\AccountancyModule\Components\Cashbook;

use App\AccountancyModule\Components\BaseControl;
use App\AccountancyModule\Components\Dialog;
use App\Forms\BaseForm;
use Model\Cashbook\Cashbook\CashbookId;
use Model\Cashbook\Cashbook\CashbookType;
Expand All @@ -29,7 +29,7 @@
use function in_array;
use function sprintf;

class InvertChitDialog extends BaseControl
class InvertChitDialog extends Dialog
{
/**
* (string because persistent parameters aren't auto-casted)
Expand All @@ -46,30 +46,26 @@ public function __construct(private CashbookId $cashbookId, private CommandBus $
{
}

public function handleOpen(int $chitId): void
public function handleOpen(int|null $chitId = null): void
{
$this->chitId = $chitId;
$this->redrawControl();
}

public function render(): void
{
if ($this->chitId !== null && ! $this->isChitValid()) {
throw new BadRequestException(
sprintf('Chit %d doesn\'t exist or can\'t be inverted', $this->chitId),
IResponse::S404_NotFound,
);
}

$template = $this->template;
$this->show();
}

$template->setParameters([
public function beforeRender(): void
{
$this->template->setFile(__DIR__ . '/templates/InvertChitDialog.latte');
$this->template->setParameters([
'renderModal' => $this->chitId !== null,
'noCashbooks' => ! $this->isChitValid() || count($this->getCashbooks()) === 0,
]);

$template->setFile(__DIR__ . '/templates/InvertChitDialog.latte');
$template->render();
}

/** @return CashbookType[] */
Expand Down Expand Up @@ -177,6 +173,6 @@ private function getChit(): Chit|null
private function close(): void
{
$this->chitId = null;
$this->redrawControl();
$this->hide();
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<div n:snippet n:inner-if="$renderModal" class="modal {if $renderModal}rendered{/if}" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Vytvořit protidoklad <i class="fas fa-exchange-alt"></i></h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{if $noCashbooks}
Nemáte žádné pokladní knihy, ve kterých můžete vytvořit protidoklad.
{else}
<p>
Vyberte pokladní knihu, ve které má být protidoklad vytvořen:
</p>
{control form}
{/if}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Storno</button>
</div>
</div>
</div>
</div>
{layout $layout}

{define control $input, $extraClasses}
<input n:name="$input" n:class="$input->hasErrors() ? 'is-invalid', form-control, $extraClasses ?? ''">
{/define}

{define errors $input}
<div class="invalid-feedback d-block" n:foreach="$input->getErrors() as $error">{$error}</div>
{/define}

{block dialog-title}Vytvořit protidoklad{/block}

{block dialog-body}
{if $noCashbooks}
Nemáte žádné pokladní knihy, ve kterých můžete vytvořit protidoklad.
{else}
<p>
Vyberte pokladní knihu, ve které má být protidoklad vytvořen:
</p>
{control form}
{/if}

{/block}

0 comments on commit 870c05b

Please sign in to comment.