Fix that setting a default theme had not effect
This commit is contained in:
parent
887a688781
commit
9599b63a55
|
@ -6,6 +6,7 @@ namespace Icinga\Forms\Config\General;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\StyleSheet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration form for theming options
|
* Configuration form for theming options
|
||||||
|
@ -29,13 +30,17 @@ class ThemingConfigForm extends Form
|
||||||
*/
|
*/
|
||||||
public function createElements(array $formData)
|
public function createElements(array $formData)
|
||||||
{
|
{
|
||||||
|
$themes = Icinga::app()->getThemes();
|
||||||
|
$themes[''] = $themes[StyleSheet::DEFAULT_THEME] . ' (' . $this->translate('default') . ')';
|
||||||
|
unset($themes[StyleSheet::DEFAULT_THEME]);
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'select',
|
'select',
|
||||||
'themes_default',
|
'themes_default',
|
||||||
array(
|
array(
|
||||||
'description' => $this->translate('The default theme', 'Form element description'),
|
'description' => $this->translate('The default theme', 'Form element description'),
|
||||||
'label' => $this->translate('Default Theme', 'Form element label'),
|
'label' => $this->translate('Default Theme', 'Form element label'),
|
||||||
'multiOptions' => Icinga::app()->getThemes()
|
'multiOptions' => $themes,
|
||||||
|
'value' => ''
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -48,7 +53,7 @@ class ThemingConfigForm extends Form
|
||||||
. ' used nonetheless',
|
. ' used nonetheless',
|
||||||
'Form element description'
|
'Form element description'
|
||||||
),
|
),
|
||||||
'label' => $this->translate('Disable Themes', 'Form element label')
|
'label' => $this->translate('Users Can\'t Change Theme', 'Form element label')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -61,7 +66,7 @@ class ThemingConfigForm extends Form
|
||||||
public function getValues($suppressArrayNotation = false)
|
public function getValues($suppressArrayNotation = false)
|
||||||
{
|
{
|
||||||
$values = parent::getValues($suppressArrayNotation);
|
$values = parent::getValues($suppressArrayNotation);
|
||||||
if ($values['themes_default'] === 'Icinga') {
|
if ($values['themes_default'] === '') {
|
||||||
$values['themes_default'] = null;
|
$values['themes_default'] = null;
|
||||||
}
|
}
|
||||||
if (! $values['themes_disabled']) {
|
if (! $values['themes_disabled']) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ use Icinga\Web\Cookie;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Web\Session;
|
use Icinga\Web\Session;
|
||||||
|
use Icinga\Web\StyleSheet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form class to adjust user preferences
|
* Form class to adjust user preferences
|
||||||
|
@ -91,9 +92,11 @@ class PreferenceForm extends Form
|
||||||
{
|
{
|
||||||
$this->preferences = new Preferences($this->store ? $this->store->load() : array());
|
$this->preferences = new Preferences($this->store ? $this->store->load() : array());
|
||||||
|
|
||||||
|
$oldTheme = $this->preferences->getValue('icingaweb', 'theme');
|
||||||
|
|
||||||
$webPreferences = $this->preferences->get('icingaweb', array());
|
$webPreferences = $this->preferences->get('icingaweb', array());
|
||||||
foreach ($this->getValues() as $key => $value) {
|
foreach ($this->getValues() as $key => $value) {
|
||||||
if ($value === null || $value === 'autodetect') {
|
if ($value === '' || $value === 'autodetect') {
|
||||||
if (isset($webPreferences[$key])) {
|
if (isset($webPreferences[$key])) {
|
||||||
unset($webPreferences[$key]);
|
unset($webPreferences[$key]);
|
||||||
}
|
}
|
||||||
|
@ -106,11 +109,9 @@ class PreferenceForm extends Form
|
||||||
Session::getSession()->user->setPreferences($this->preferences);
|
Session::getSession()->user->setPreferences($this->preferences);
|
||||||
|
|
||||||
if (($theme = $this->getElement('theme')) !== null
|
if (($theme = $this->getElement('theme')) !== null
|
||||||
&& ($theme = $theme->getValue()) !== $this->getRequest()->getCookie('theme')
|
&& ($theme = $theme->getValue()) !== $oldTheme
|
||||||
) {
|
) {
|
||||||
$this->getResponse()
|
$this->getResponse()->setReloadCss(true);
|
||||||
->setCookie(new Cookie('theme', $theme))
|
|
||||||
->setReloadCss(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -154,13 +155,21 @@ class PreferenceForm extends Form
|
||||||
{
|
{
|
||||||
if (! (bool) Config::app()->get('themes', 'disabled', false)) {
|
if (! (bool) Config::app()->get('themes', 'disabled', false)) {
|
||||||
$themes = Icinga::app()->getThemes();
|
$themes = Icinga::app()->getThemes();
|
||||||
|
$defaultTheme = Config::app()->get('themes', 'default', StyleSheet::DEFAULT_THEME);
|
||||||
|
if (isset($themes[$defaultTheme])) {
|
||||||
|
$themes[''] = $themes[$defaultTheme] . ' (' . $this->translate('default') . ')';
|
||||||
|
unset($themes[$defaultTheme]);
|
||||||
|
}
|
||||||
if (count($themes) > 1) {
|
if (count($themes) > 1) {
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'select',
|
'select',
|
||||||
'theme',
|
'theme',
|
||||||
array(
|
array(
|
||||||
'label' => $this->translate('Theme', 'Form element label'),
|
'label' => $this->translate('Theme', 'Form element label'),
|
||||||
'multiOptions' => $themes
|
'multiOptions' => $themes,
|
||||||
|
'value' => $this->preferences->getValue(
|
||||||
|
'icingaweb', 'theme', ''
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace Icinga\Web;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
|
use Icinga\Authentication\Auth;
|
||||||
use Icinga\Exception\IcingaException;
|
use Icinga\Exception\IcingaException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,18 +113,22 @@ class StyleSheet
|
||||||
}
|
}
|
||||||
|
|
||||||
$themingConfig = $this->app->getConfig()->getSection('themes');
|
$themingConfig = $this->app->getConfig()->getSection('themes');
|
||||||
$defaultTheme = $themingConfig->get('default', self::DEFAULT_THEME);
|
$defaultTheme = $themingConfig->get('default');
|
||||||
$theme = null;
|
$theme = null;
|
||||||
|
|
||||||
if ((bool) $themingConfig->get('disabled', false)) {
|
if ((bool) $themingConfig->get('disabled', false)) {
|
||||||
if ($defaultTheme !== self::DEFAULT_THEME) {
|
if ($defaultTheme !== null && $defaultTheme !== self::DEFAULT_THEME) {
|
||||||
$theme = $defaultTheme;
|
$theme = $defaultTheme;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (($userTheme = $this->app->getRequest()->getCookie('theme', $defaultTheme))
|
$auth = Auth::getInstance();
|
||||||
&& $userTheme !== $defaultTheme
|
if ($auth->isAuthenticated()) {
|
||||||
) {
|
$userTheme = $auth->getUser()->getPreferences()->getValue('icingaweb', 'theme');
|
||||||
$theme = $userTheme;
|
if ($userTheme !== null) {
|
||||||
|
$theme = $userTheme;
|
||||||
|
} elseif ($defaultTheme !== null && $defaultTheme !== self::DEFAULT_THEME) {
|
||||||
|
$theme = $defaultTheme;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue