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\Logger;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\StyleSheet;
|
||||
|
||||
/**
|
||||
* Configuration form for theming options
|
||||
|
@ -29,13 +30,17 @@ class ThemingConfigForm extends Form
|
|||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$themes = Icinga::app()->getThemes();
|
||||
$themes[''] = $themes[StyleSheet::DEFAULT_THEME] . ' (' . $this->translate('default') . ')';
|
||||
unset($themes[StyleSheet::DEFAULT_THEME]);
|
||||
$this->addElement(
|
||||
'select',
|
||||
'themes_default',
|
||||
array(
|
||||
'description' => $this->translate('The default theme', 'Form element description'),
|
||||
'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',
|
||||
'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)
|
||||
{
|
||||
$values = parent::getValues($suppressArrayNotation);
|
||||
if ($values['themes_default'] === 'Icinga') {
|
||||
if ($values['themes_default'] === '') {
|
||||
$values['themes_default'] = null;
|
||||
}
|
||||
if (! $values['themes_disabled']) {
|
||||
|
|
|
@ -17,6 +17,7 @@ use Icinga\Web\Cookie;
|
|||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Web\StyleSheet;
|
||||
|
||||
/**
|
||||
* Form class to adjust user preferences
|
||||
|
@ -91,9 +92,11 @@ class PreferenceForm extends Form
|
|||
{
|
||||
$this->preferences = new Preferences($this->store ? $this->store->load() : array());
|
||||
|
||||
$oldTheme = $this->preferences->getValue('icingaweb', 'theme');
|
||||
|
||||
$webPreferences = $this->preferences->get('icingaweb', array());
|
||||
foreach ($this->getValues() as $key => $value) {
|
||||
if ($value === null || $value === 'autodetect') {
|
||||
if ($value === '' || $value === 'autodetect') {
|
||||
if (isset($webPreferences[$key])) {
|
||||
unset($webPreferences[$key]);
|
||||
}
|
||||
|
@ -106,11 +109,9 @@ class PreferenceForm extends Form
|
|||
Session::getSession()->user->setPreferences($this->preferences);
|
||||
|
||||
if (($theme = $this->getElement('theme')) !== null
|
||||
&& ($theme = $theme->getValue()) !== $this->getRequest()->getCookie('theme')
|
||||
&& ($theme = $theme->getValue()) !== $oldTheme
|
||||
) {
|
||||
$this->getResponse()
|
||||
->setCookie(new Cookie('theme', $theme))
|
||||
->setReloadCss(true);
|
||||
$this->getResponse()->setReloadCss(true);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -154,13 +155,21 @@ class PreferenceForm extends Form
|
|||
{
|
||||
if (! (bool) Config::app()->get('themes', 'disabled', false)) {
|
||||
$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) {
|
||||
$this->addElement(
|
||||
'select',
|
||||
'theme',
|
||||
array(
|
||||
'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 Icinga\Application\Icinga;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
/**
|
||||
|
@ -112,18 +113,22 @@ class StyleSheet
|
|||
}
|
||||
|
||||
$themingConfig = $this->app->getConfig()->getSection('themes');
|
||||
$defaultTheme = $themingConfig->get('default', self::DEFAULT_THEME);
|
||||
$defaultTheme = $themingConfig->get('default');
|
||||
$theme = null;
|
||||
|
||||
if ((bool) $themingConfig->get('disabled', false)) {
|
||||
if ($defaultTheme !== self::DEFAULT_THEME) {
|
||||
if ($defaultTheme !== null && $defaultTheme !== self::DEFAULT_THEME) {
|
||||
$theme = $defaultTheme;
|
||||
}
|
||||
} else {
|
||||
if (($userTheme = $this->app->getRequest()->getCookie('theme', $defaultTheme))
|
||||
&& $userTheme !== $defaultTheme
|
||||
) {
|
||||
$auth = Auth::getInstance();
|
||||
if ($auth->isAuthenticated()) {
|
||||
$userTheme = $auth->getUser()->getPreferences()->getValue('icingaweb', 'theme');
|
||||
if ($userTheme !== null) {
|
||||
$theme = $userTheme;
|
||||
} elseif ($defaultTheme !== null && $defaultTheme !== self::DEFAULT_THEME) {
|
||||
$theme = $defaultTheme;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue