util/window/form: add a theme selector

add a widget that implements a theme selector and sets a cookie to
load the appropriate theme.

Co-authored-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
Co-authored-by: Stefan Sterz <s.sterz@proxmox.com>
Signed-off-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
This commit is contained in:
Daniel Tschlatscher 2023-03-08 17:37:43 +01:00 committed by Thomas Lamprecht
parent c5559f82ea
commit 15fddc20d1
4 changed files with 82 additions and 0 deletions

View File

@ -44,6 +44,7 @@ JSSRC= \
form/TaskTypeSelector.js \ form/TaskTypeSelector.js \
form/ACME.js \ form/ACME.js \
form/UserSelector.js \ form/UserSelector.js \
form/ThemeSelector.js \
button/Button.js \ button/Button.js \
button/AltText.js \ button/AltText.js \
button/HelpButton.js \ button/HelpButton.js \
@ -90,6 +91,7 @@ JSSRC= \
window/AddYubico.js \ window/AddYubico.js \
window/TfaEdit.js \ window/TfaEdit.js \
window/NotesEdit.js \ window/NotesEdit.js \
window/ThemeEdit.js \
node/APT.js \ node/APT.js \
node/APTRepositories.js \ node/APTRepositories.js \
node/NetworkEdit.js \ node/NetworkEdit.js \

View File

@ -109,6 +109,31 @@ utilities: {
return data; return data;
}, },
theme_map: {
auto: 'auto',
"proxmox-dark": 'Proxmox Dark',
},
render_theme: function(value) {
if (!value || value === '__default__') {
return Proxmox.Utils.defaultText + ' (Light theme)';
}
let text = Proxmox.Utils.theme_map[value];
if (text) {
return text;
}
return value;
},
theme_array: function() {
let data = [['__default__', Proxmox.Utils.render_theme('')]];
Ext.Object.each(Proxmox.Utils.theme_map, function(key, value) {
data.push([key, Proxmox.Utils.render_theme(value)]);
});
return data;
},
bond_mode_gettext_map: { bond_mode_gettext_map: {
'802.3ad': 'LACP (802.3ad)', '802.3ad': 'LACP (802.3ad)',
'lacp-balance-slb': 'LACP (balance-slb)', 'lacp-balance-slb': 'LACP (balance-slb)',

View File

@ -0,0 +1,6 @@
Ext.define('Proxmox.form.ThemeSelector', {
extend: 'Proxmox.form.KVComboBox',
xtype: 'proxmoxThemeSelector',
comboItems: Proxmox.Utils.theme_array(),
});

49
src/window/ThemeEdit.js Normal file
View File

@ -0,0 +1,49 @@
Ext.define('Proxmox.window.ThemeEditWindow', {
extend: 'Ext.window.Window',
alias: 'widget.pmxThemeEditWindow',
viewModel: {
parent: null,
data: {
language: '__default__',
},
},
controller: {
xclass: 'Ext.app.ViewController',
init: function(view) {
let theme = Ext.util.Cookies.get(view.cookieName) || '__default__';
this.getViewModel().set('theme', theme);
},
applyTheme: function(button) {
let view = this.getView();
let vm = this.getViewModel();
let expire = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
Ext.util.Cookies.set(view.cookieName, vm.get('theme'), expire);
view.mask(gettext('Please wait...'), 'x-mask-loading');
window.location.reload();
},
},
cookieName: 'PVEThemeCookie',
title: gettext('Theme'),
modal: true,
bodyPadding: 10,
resizable: false,
items: [
{
xtype: 'proxmoxThemeSelector',
fieldLabel: gettext('Theme'),
bind: {
value: '{theme}',
},
},
],
buttons: [
{
text: gettext('Apply'),
handler: 'applyTheme',
},
],
});