Make the new Admin => Config experimental editable #189

This commit is contained in:
the-djmaze 2022-09-29 15:06:23 +02:00
parent 1c542b33e7
commit 690656e4d1
3 changed files with 36 additions and 25 deletions

View file

@ -7,6 +7,7 @@ export class AdminSettingsConfig /*extends AbstractViewSettings*/ {
constructor() {
this.config = ko.observableArray();
this.saved = ko.observable(false).extend({ falseTimeout: 5000 });
}
beforeShow() {
@ -27,6 +28,7 @@ export class AdminSettingsConfig /*extends AbstractViewSettings*/ {
items: []
};
forEachObjectEntry(items, (skey, item) => {
'admin_password' === skey ||
section.items.push({
key: `config[${key}][${skey}]`,
name: skey,
@ -43,6 +45,27 @@ export class AdminSettingsConfig /*extends AbstractViewSettings*/ {
}
saveConfig(form) {
Remote.post('AdminSettingsSet', null, new FormData(form));
const data = new FormData(form),
config = {};
this.config.forEach(section => {
if (!config[section.name]) {
config[section.name] = {};
}
section.items.forEach(item => {
let value = data.get(item.key);
switch (typeof item.value) {
case 'boolean':
value = 'on' == value;
break;
case 'number':
value = parseInt(value, 10);
break;
}
config[section.name][item.name] = value;
})
});
Remote.post('AdminSettingsSet', null, {config:config}).then(result => {
result.Result && this.saved(true);
});
}
}

View file

@ -26,24 +26,13 @@ class ActionsAdmin extends Actions
public function DoAdminSettingsSet() : array
{
// TODO
$aConfig = $this->GetActionParam('config', []);
unset($aConfig['version']);
/* Sections:
[webmail] => Array
[interface] => Array
[contacts] => Array
[security] => Array
[ssl] => Array
[capa] => Array
[login] => Array
[plugins] => Array
[defaults] => Array
[logs] => Array
[cache] => Array
[labs] => Array
*/
return $this->TrueResponse(__FUNCTION__);
$oConfig = $this->Config();
foreach ($this->GetActionParam('config', []) as $sSection => $aItems) {
foreach ($aItems as $sKey => $mValue) {
$oConfig->Set($sSection, $sKey, $mValue);
}
}
return $this->DefaultResponse(__FUNCTION__, $oConfig->Save());
}
public function DoAdminSettingsUpdate() : array

View file

@ -1,5 +1,6 @@
<div class="legend">application.ini</div>
<form method="POST" data-bind="submit: saveConfig">
<p><strong>WARNING: experimental editor!</strong></p>
<form method="POST" data-bind="submit: saveConfig" spellcheck="false" autocomplete="off" autocapitalize="none">
<table class="table table-hover table-bordered">
<!-- ko foreach: config -->
<tbody>
@ -9,10 +10,10 @@
<td data-bind="text: name"></td>
<td>
<!-- ko if: 'checkbox' == type -->
<input type="checkbox" data-bind="attr: {name: key, checked: value}" readonly="">
<input type="checkbox" data-bind="attr: {name: key, checked: value}">
<!-- /ko -->
<!-- ko if: 'checkbox' != type -->
<input data-bind="attr: {name: key, type: type}, value: value" readonly="">
<input data-bind="attr: {name: key, type: type}, value: value" autocorrect="off">
<!-- /ko -->
<em data-bind="text: comment, visible: comment"></em>
</td>
@ -21,7 +22,5 @@
</tbody>
<!-- /ko -->
</table>
<!--
<button data-i18n="GLOBAL/SAVE"></button>
-->
<button class="btn" data-i18n="GLOBAL/SAVE" data-bind="css:{'btn-success':saved()},attr:{'data-icon':saved()?'✔':'💾'}"></button>
</form>