-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schedule: Update detail to reflect the new redesign
- Loading branch information
Showing
4 changed files
with
210 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* Icinga Notifications Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Notifications\Widget\Schedule; | ||
|
||
use DateTime; | ||
use ipl\Html\Attributes; | ||
use ipl\Html\Form; | ||
use ipl\Html\HtmlElement; | ||
use ipl\Html\Text; | ||
use ipl\I18n\Translation; | ||
|
||
class Controls extends Form | ||
{ | ||
use Translation; | ||
|
||
protected $method = 'GET'; | ||
|
||
protected $defaultAttributes = ['class' => 'schedule-controls']; | ||
|
||
/** | ||
* Get the number of days the user wants to see | ||
* | ||
* @return int | ||
*/ | ||
public function getNumberOfDays(): int | ||
{ | ||
return (int) $this->getPopulatedValue('days', '7'); | ||
} | ||
|
||
/** | ||
* Get the start date where the user wants the schedule to begin | ||
* | ||
* @return DateTime | ||
*/ | ||
public function getStartDate(): DateTime | ||
{ | ||
return (new DateTime())->setTime(0, 0); | ||
} | ||
|
||
protected function assemble() | ||
{ | ||
$param = 'days'; | ||
$options = [ | ||
1 => $this->translate('Day'), | ||
7 => $this->translate('Week'), | ||
14 => $this->translate('2 Weeks'), | ||
31 => $this->translate('Month') | ||
]; | ||
|
||
$viewModeSwitcher = HtmlElement::create('fieldset', ['class' => 'view-mode-switcher']); | ||
foreach ($options as $value => $label) { | ||
$input = $this->createElement('input', $param, [ | ||
'class' => 'autosubmit', | ||
'type' => 'radio', | ||
'id' => $param . '-' . $value, | ||
'value' => $value | ||
]); | ||
|
||
$input->getAttributes()->registerAttributeCallback('checked', function () use ($value) { | ||
return $value === $this->getNumberOfDays(); | ||
}); | ||
|
||
$viewModeSwitcher->addHtml( | ||
$input, | ||
new HtmlElement('label', Attributes::create(['for' => $param . '-' . $value]), Text::create($label)) | ||
); | ||
} | ||
|
||
$this->addHtml($viewModeSwitcher); | ||
} | ||
} |
Oops, something went wrong.