diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
commit | 8ca6cc32b2c789a3149861159ad258f2cb9491e3 (patch) | |
tree | 2492de6f1528dd44eaa169a5c1555026d9cb75ec /application/forms/AutoRefreshForm.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-upstream.tar.xz icingaweb2-upstream.zip |
Adding upstream version 2.11.4.upstream/2.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/forms/AutoRefreshForm.php')
-rw-r--r-- | application/forms/AutoRefreshForm.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/application/forms/AutoRefreshForm.php b/application/forms/AutoRefreshForm.php new file mode 100644 index 0000000..122f635 --- /dev/null +++ b/application/forms/AutoRefreshForm.php @@ -0,0 +1,83 @@ +<?php +/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Forms; + +use Icinga\Application\Logger; +use Icinga\User\Preferences; +use Icinga\Web\Form; +use Icinga\Web\Notification; +use Icinga\Web\Session; +use Icinga\Web\Url; + +/** + * Form class to adjust user auto refresh preferences + */ +class AutoRefreshForm extends Form +{ + /** + * Initialize this form + */ + public function init() + { + $this->setName('form_auto_refresh'); + // Post against the current location + $this->setAction(''); + } + + /** + * Adjust preferences and persist them + * + * @see Form::onSuccess() + */ + public function onSuccess() + { + /** @var Preferences $preferences */ + $preferences = $this->getRequest()->getUser()->getPreferences(); + $icingaweb = $preferences->get('icingaweb'); + + if ((bool) $preferences->getValue('icingaweb', 'auto_refresh', true) === false) { + $icingaweb['auto_refresh'] = '1'; + $notification = $this->translate('Auto refresh successfully enabled'); + } else { + $icingaweb['auto_refresh'] = '0'; + $notification = $this->translate('Auto refresh successfully disabled'); + } + $preferences->icingaweb = $icingaweb; + + Session::getSession()->user->setPreferences($preferences); + Notification::success($notification); + + $this->getResponse()->setHeader('X-Icinga-Rerender-Layout', 'yes'); + $this->setRedirectUrl(Url::fromRequest()->without('renderLayout')); + } + + /** + * @see Form::createElements() + */ + public function createElements(array $formData) + { + $preferences = $this->getRequest()->getUser()->getPreferences(); + + if ((bool) $preferences->getValue('icingaweb', 'auto_refresh', true) === false) { + $value = $this->translate('Enable auto refresh'); + } else { + $value = $this->translate('Disable auto refresh'); + } + + $this->addElements(array( + array( + 'button', + 'btn_submit', + array( + 'ignore' => true, + 'type' => 'submit', + 'value' => $value, + 'decorators' => array('ViewHelper'), + 'escape' => false, + 'class' => 'link-like' + ) + ) + )); + } +} |