13
13
use Icinga \Module \Reporting \Report ;
14
14
use Icinga \Module \Reporting \Web \Flatpickr ;
15
15
use Icinga \Module \Reporting \Web \Forms \Decorator \CompatDecorator ;
16
+ use Icinga \Web \Notification ;
16
17
use ipl \Html \Contract \FormSubmitElement ;
17
18
use ipl \Html \Form ;
18
19
use ipl \Web \Compat \CompatForm ;
@@ -39,7 +40,6 @@ class ScheduleForm extends CompatForm
39
40
public static function fromReport (Report $ report ): self
40
41
{
41
42
$ form = new static ();
42
-
43
43
$ form ->report = $ report ;
44
44
45
45
$ schedule = $ report ->getSchedule ();
@@ -73,7 +73,11 @@ public function setId(int $id): ScheduleForm
73
73
74
74
public function hasBeenSubmitted (): bool
75
75
{
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
+ );
77
81
}
78
82
79
83
protected function assemble ()
@@ -136,6 +140,13 @@ protected function assemble()
136
140
]);
137
141
138
142
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
+
139
150
/** @var FormSubmitElement $removeButton */
140
151
$ removeButton = $ this ->createElement ('submit ' , 'remove ' , [
141
152
'label ' => $ this ->translate ('Remove Schedule ' ),
@@ -158,6 +169,14 @@ public function onSuccess()
158
169
}
159
170
160
171
$ 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
+ }
161
180
162
181
$ now = time () * 1000 ;
163
182
0 commit comments