Skip to content

Commit 3fc93d3

Browse files
authored
Merge pull request #137 from Icinga/feature/add-send-now-button-to-schedule-form-133
ScheduleForm: Add `Send Report Now` button
2 parents 449f1f5 + e4dc85e commit 3fc93d3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

library/Reporting/Web/Forms/ScheduleForm.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Icinga\Module\Reporting\Report;
1414
use Icinga\Module\Reporting\Web\Flatpickr;
1515
use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator;
16+
use Icinga\Web\Notification;
1617
use ipl\Html\Contract\FormSubmitElement;
1718
use ipl\Html\Form;
1819
use ipl\Web\Compat\CompatForm;
@@ -39,7 +40,6 @@ class ScheduleForm extends CompatForm
3940
public static function fromReport(Report $report): self
4041
{
4142
$form = new static();
42-
4343
$form->report = $report;
4444

4545
$schedule = $report->getSchedule();
@@ -73,7 +73,11 @@ public function setId(int $id): ScheduleForm
7373

7474
public function hasBeenSubmitted(): bool
7575
{
76-
return $this->hasBeenSent() && ($this->getPopulatedValue('submit') || $this->getPopulatedValue('remove'));
76+
return $this->hasBeenSent() && (
77+
$this->getPopulatedValue('submit')
78+
|| $this->getPopulatedValue('remove')
79+
|| $this->getPopulatedValue('send')
80+
);
7781
}
7882

7983
protected function assemble()
@@ -136,6 +140,13 @@ protected function assemble()
136140
]);
137141

138142
if ($this->id !== null) {
143+
$sendButton = $this->createElement('submit', 'send', [
144+
'label' => $this->translate('Send Report Now'),
145+
'formnovalidate' => true
146+
]);
147+
$this->registerElement($sendButton);
148+
$this->getElement('submit')->getWrapper()->prepend($sendButton);
149+
139150
/** @var FormSubmitElement $removeButton */
140151
$removeButton = $this->createElement('submit', 'remove', [
141152
'label' => $this->translate('Remove Schedule'),
@@ -158,6 +169,14 @@ public function onSuccess()
158169
}
159170

160171
$values = $this->getValues();
172+
if ($this->getPopulatedValue('send')) {
173+
$action = new $values['action']();
174+
$action->execute($this->report, $values);
175+
176+
Notification::success($this->translate('Report sent successfully'));
177+
178+
return;
179+
}
161180

162181
$now = time() * 1000;
163182

0 commit comments

Comments
 (0)