Skip to content

Commit

Permalink
Change what decides whether the email additional text container shoul…
Browse files Browse the repository at this point in the history
…d be open

It was a `class=hidden` on the container itself, checking form component's value to see if it should be added or not. Now it's `class=expanded` on an element defined by `data-class-target`, a textarea in this case, where `class=expanded` is added in the form factory if needed.

CSS `:has()` is currently not supported by Firefox (it's behind a flag) but guess that's ok by me.

Fixes
```
 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------
  Line   Compiled   Admin/Presenters/templates/Emails/default.latte rendered from MichalSpacekCz\Admin\Presenters\EmailsPresenter::default
         line       See compiled template: /tmp/phpstan-latte/app/Admin/Presenters/templates/Emails/default.latte.ffc5a80775bd006bd5dcca69684ee311.php
 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------
  63     364        Cannot access offset 'additional' on Nette\Forms\Controls\BaseControl.
 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------
```
  • Loading branch information
spaze committed Jul 17, 2023
1 parent b85ad94 commit c7eeb84
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion site/app/Admin/Presenters/templates/Emails/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<td></td>
<td colspan="5">{input feedbackRequest}</td>
</tr>
<tr n:class="expand-container, !$form[applications][$application->id][additional]->value ? hidden">
<tr class="expand-container" data-class-target="textarea">
<td></td>
<td></td>
<td colspan="5">
Expand Down
10 changes: 9 additions & 1 deletion site/app/Form/TrainingMailsOutboxFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function create(callable $onSuccess, array $applications): Form
$form = $this->factory->create();

$applicationsContainer = $form->addContainer('applications');
$additionalInputs = [];

foreach ($applications as $application) {
$applicationIdsContainer = $applicationsContainer->addContainer($application->id);
Expand Down Expand Up @@ -101,7 +102,7 @@ public function create(callable $onSuccess, array $applications): Form
if ($sendCheckboxTitle) {
$send->setHtmlAttribute('title', implode("\n", $sendCheckboxTitle));
}
$applicationIdsContainer->addTextArea('additional')
$additionalInputs[] = $applicationIdsContainer->addTextArea('additional')
->setHtmlAttribute('placeholder', 'Dodatečný text')
->setHtmlAttribute('cols', 80)
->setHtmlAttribute('rows', 3);
Expand Down Expand Up @@ -181,6 +182,13 @@ public function create(callable $onSuccess, array $applications): Form
}
$onSuccess($sent);
};
$form->onAnchor[] = function () use ($additionalInputs): void {
foreach ($additionalInputs as $additionalInput) {
if ($additionalInput->getValue()) {
$additionalInput->setHtmlAttribute('class', 'expanded');
}
}
};
return $form;
}

Expand Down
3 changes: 3 additions & 0 deletions site/public/www.michalspacek.cz/i/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ div.notice {
margin-left: 1.1em;
line-height: 0;
}
#frm-mails .expand-container:not(:has(.expanded)) {
display: none;
}
#frm-passwordsStorages #frm-passwordsStorages-algo-from { width: 200px; }
#pubkey {
background-color: #F7F7FF;
Expand Down
5 changes: 4 additions & 1 deletion site/public/www.michalspacek.cz/i/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ App.ready(document, function () {

App.onClick('#emails tbody .button', function () {
for (const item of this.parentElement.parentElement.querySelectorAll('.expand-container')) {
item.classList.toggle('hidden');
const classTarget = item.querySelector(item.dataset.classTarget);
if (classTarget) {
classTarget.classList.toggle('expanded');
}
}
});
App.onClick('#emails #checkAll', function (event) {
Expand Down

0 comments on commit c7eeb84

Please sign in to comment.