From 2112676594f67ddfdee81c6a9615b8a350659321 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Fri, 13 Feb 2015 14:34:29 +0100 Subject: [PATCH] Implement hidden accessible control for auto refresh on the page refs #7945 --- application/forms/AutoRefreshForm.php | 79 +++++++++++++++++++ application/layouts/scripts/body.phtml | 5 ++ .../Web/Controller/ActionController.php | 11 +++ public/css/icinga/menu.less | 19 +++++ 4 files changed, 114 insertions(+) create mode 100644 application/forms/AutoRefreshForm.php diff --git a/application/forms/AutoRefreshForm.php b/application/forms/AutoRefreshForm.php new file mode 100644 index 000000000..85992af27 --- /dev/null +++ b/application/forms/AutoRefreshForm.php @@ -0,0 +1,79 @@ +setName('form_auto_refresh'); + } + + /** + * 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'); + } + + /** + * @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' + ) + ) + )); + } +} diff --git a/application/layouts/scripts/body.phtml b/application/layouts/scripts/body.phtml index 9f0b78ce9..abf823750 100644 --- a/application/layouts/scripts/body.phtml +++ b/application/layouts/scripts/body.phtml @@ -23,6 +23,11 @@ if (Auth::getInstance()->isAuthenticated()): ?> + +
+ layout()->autoRefreshForm ?> +
+