Allow to choose a theme via preferences when there are themes

refs #10705
This commit is contained in:
Eric Lippmann 2015-11-27 15:39:19 +01:00
parent 271b5f9d5c
commit 958f8e5baf
1 changed files with 24 additions and 0 deletions

View File

@ -6,12 +6,14 @@ namespace Icinga\Forms;
use Exception;
use DateTimeZone;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Authentication\Auth;
use Icinga\User\Preferences;
use Icinga\User\Preferences\PreferencesStore;
use Icinga\Util\TimezoneDetect;
use Icinga\Util\Translator;
use Icinga\Web\Cookie;
use Icinga\Web\Form;
use Icinga\Web\Notification;
use Icinga\Web\Session;
@ -103,6 +105,14 @@ class PreferenceForm extends Form
Session::getSession()->user->setPreferences($this->preferences);
if (($theme = $this->getElement('theme')) !== null
&& ($theme = $theme->getValue()) !== $this->getRequest()->getCookie('theme')
) {
$this->getResponse()
->setCookie(new Cookie('theme', $theme))
->setReloadCss(true);
}
try {
if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) {
$this->save();
@ -142,6 +152,20 @@ class PreferenceForm extends Form
*/
public function createElements(array $formData)
{
if (! (bool) Config::app()->get('themes', 'disabled', false)) {
$themes = Icinga::app()->getThemes();
if (count($themes) > 1) {
$this->addElement(
'select',
'theme',
array(
'label' => $this->translate('Theme', 'Form element label'),
'multiOptions' => $themes
)
);
}
}
$languages = array();
$languages['autodetect'] = sprintf($this->translate('Browser (%s)', 'preferences.form'), $this->getLocale());
foreach (Translator::getAvailableLocaleCodes() as $language) {