1313use Icinga \Module \Reporting \Report ;
1414use Icinga \Module \Reporting \Web \Flatpickr ;
1515use Icinga \Module \Reporting \Web \Forms \Decorator \CompatDecorator ;
16+ use Icinga \Web \Notification ;
1617use ipl \Html \Contract \FormSubmitElement ;
1718use ipl \Html \Form ;
1819use 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,12 @@ 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 (t ('Report sent successfully ' ));
177+ }
161178
162179 $ now = time () * 1000 ;
163180
0 commit comments