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() { constructor() {
this.config = ko.observableArray(); this.config = ko.observableArray();
this.saved = ko.observable(false).extend({ falseTimeout: 5000 });
} }
beforeShow() { beforeShow() {
@ -27,6 +28,7 @@ export class AdminSettingsConfig /*extends AbstractViewSettings*/ {
items: [] items: []
}; };
forEachObjectEntry(items, (skey, item) => { forEachObjectEntry(items, (skey, item) => {
'admin_password' === skey ||
section.items.push({ section.items.push({
key: `config[${key}][${skey}]`, key: `config[${key}][${skey}]`,
name: skey, name: skey,
@ -43,6 +45,27 @@ export class AdminSettingsConfig /*extends AbstractViewSettings*/ {
} }
saveConfig(form) { 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 public function DoAdminSettingsSet() : array
{ {
// TODO $oConfig = $this->Config();
$aConfig = $this->GetActionParam('config', []); foreach ($this->GetActionParam('config', []) as $sSection => $aItems) {
unset($aConfig['version']); foreach ($aItems as $sKey => $mValue) {
/* Sections: $oConfig->Set($sSection, $sKey, $mValue);
[webmail] => Array }
[interface] => Array }
[contacts] => Array return $this->DefaultResponse(__FUNCTION__, $oConfig->Save());
[security] => Array
[ssl] => Array
[capa] => Array
[login] => Array
[plugins] => Array
[defaults] => Array
[logs] => Array
[cache] => Array
[labs] => Array
*/
return $this->TrueResponse(__FUNCTION__);
} }
public function DoAdminSettingsUpdate() : array public function DoAdminSettingsUpdate() : array

View file

@ -1,5 +1,6 @@
<div class="legend">application.ini</div> <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"> <table class="table table-hover table-bordered">
<!-- ko foreach: config --> <!-- ko foreach: config -->
<tbody> <tbody>
@ -9,10 +10,10 @@
<td data-bind="text: name"></td> <td data-bind="text: name"></td>
<td> <td>
<!-- ko if: 'checkbox' == type --> <!-- 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 -->
<!-- ko if: 'checkbox' != type --> <!-- 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 --> <!-- /ko -->
<em data-bind="text: comment, visible: comment"></em> <em data-bind="text: comment, visible: comment"></em>
</td> </td>
@ -21,7 +22,5 @@
</tbody> </tbody>
<!-- /ko --> <!-- /ko -->
</table> </table>
<!-- <button class="btn" data-i18n="GLOBAL/SAVE" data-bind="css:{'btn-success':saved()},attr:{'data-icon':saved()?'✔':'💾'}"></button>
<button data-i18n="GLOBAL/SAVE"></button>
-->
</form> </form>