mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 16:54:04 +02:00
Implement hidden accessible control for auto refresh on the page
refs #7945
This commit is contained in:
parent
b9c9f564ec
commit
2112676594
79
application/forms/AutoRefreshForm.php
Normal file
79
application/forms/AutoRefreshForm.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013-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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form class to adjust user auto refresh preferences
|
||||||
|
*/
|
||||||
|
class AutoRefreshForm extends Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Initialize this form
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->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'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,11 @@ if (Auth::getInstance()->isAuthenticated()): ?>
|
|||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="auto-refresh-trigger">
|
||||||
|
<?= $this->layout()->autoRefreshForm ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ul id="notifications"><?php
|
<ul id="notifications"><?php
|
||||||
|
|
||||||
$moduleName = $this->layout()->moduleName;
|
$moduleName = $this->layout()->moduleName;
|
||||||
|
@ -10,6 +10,7 @@ use Icinga\Authentication\Manager;
|
|||||||
use Icinga\Exception\IcingaException;
|
use Icinga\Exception\IcingaException;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\File\Pdf;
|
use Icinga\File\Pdf;
|
||||||
|
use Icinga\Forms\AutoRefreshForm;
|
||||||
use Icinga\Security\SecurityException;
|
use Icinga\Security\SecurityException;
|
||||||
use Icinga\Util\Translator;
|
use Icinga\Util\Translator;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
@ -379,6 +380,16 @@ class ActionController extends Zend_Controller_Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Controller_Action::preDispatch()
|
||||||
|
*/
|
||||||
|
public function preDispatch()
|
||||||
|
{
|
||||||
|
$form = new AutoRefreshForm();
|
||||||
|
$form->handleRequest();
|
||||||
|
$this->_helper->layout()->autoRefreshForm = $form;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect whether the current request requires changes in the layout and apply them before rendering
|
* Detect whether the current request requires changes in the layout and apply them before rendering
|
||||||
*
|
*
|
||||||
|
@ -300,3 +300,22 @@ a:focus {
|
|||||||
.skip-links-inline {
|
.skip-links-inline {
|
||||||
margin-top: -3.5em;
|
margin-top: -3.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.auto-refresh-trigger {
|
||||||
|
position: absolute;
|
||||||
|
form {
|
||||||
|
button[type="submit"] {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
left: -999em;
|
||||||
|
width: 12em !important;
|
||||||
|
top: 0.4em;
|
||||||
|
padding: 0.8em 0.8em !important;
|
||||||
|
background-color: white !important;
|
||||||
|
text-align: left !important;
|
||||||
|
&:focus {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user