102 lines
3.1 KiB
PHP
102 lines
3.1 KiB
PHP
<div class="flex hmax">
|
|
<form class="center card" method="POST">
|
|
<h3 id="title"></h3>
|
|
<div id="config"></div>
|
|
<br>
|
|
<div class="flex">
|
|
<button onclick="event.preventDefault();
|
|
window.history.back()" class="btn"
|
|
><i class="fa fa-arrow-left fa-fw"></i> Cancel</button>
|
|
<div style="width:1em"></div>
|
|
<button class="btn"
|
|
><i class="fa fa-save fa-fw"></i> Save configuration</button>
|
|
</div>
|
|
</form>
|
|
<div id="config-item">
|
|
<label for="{field}">{placeholder}:</label>
|
|
<input id="config_{field}" name="{field}" class="w100"
|
|
placeholder="{field}" type="text"/>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
window.view.instance_config = {
|
|
autofill_fields: {
|
|
mastodon: function(hargs, config) {
|
|
E.element('#window-instance_config form').setAttribute('action',
|
|
`api/v1/config/put/?software=mastodon&instance=${hargs['instance']}`);
|
|
const fields = window.consts['instance_config']['mastodon']['musthave'];
|
|
for (var i = 0; i < fields.length; i++) {
|
|
if (config[fields[i]] !== undefined)
|
|
E.elemid(`config_${fields[i]}`).value = config[fields[i]];
|
|
}
|
|
if (config['instance_url'] === undefined) {
|
|
http.get('api/v1/network/resolve-instance?hostname='+hargs['instance'],
|
|
{}, function(js) {
|
|
if (js['instance'] !== undefined)
|
|
E.elemid('config_instance_url').value = js['instance'];
|
|
});
|
|
}
|
|
},
|
|
},
|
|
}
|
|
function title__instance_config() {}
|
|
function load__instance_config(args) {
|
|
const hargs = get_hash_arguments();
|
|
|
|
const _error400 = function(msg) {
|
|
msg = msg || 'Parameters are not correct';
|
|
console.log('TODO: handle error correctly');
|
|
};
|
|
|
|
const _paint = function() {
|
|
E.template('#window-instance_config #title',
|
|
capitalize(hargs['software']) + ` (${hargs['instance']})`);
|
|
E.template('config', function(TPL) {
|
|
var html = '';
|
|
const fields = window.consts['instance_config'][hargs['software']]['musthave'];
|
|
for (var i = 0; i < fields.length; i++) {
|
|
var tpl = TPL;
|
|
tpl = tpl.replaceAll('{field}', fields[i]);
|
|
tpl = tpl.replaceAll('{placeholder}', human_field_name(fields[i]));
|
|
html += tpl;
|
|
}
|
|
return html;
|
|
});
|
|
const config = parse_ini_config(window.vars['current_instance']['config']);
|
|
window.view.instance_config.autofill_fields[hargs['software']](hargs, config);
|
|
};
|
|
|
|
const _main = function() {
|
|
if (hargs['software'] === undefined ||
|
|
!window.vars['instance_config']['supported_ap_software']
|
|
.includes(hargs['software']))
|
|
return _error400();
|
|
if (hargs['instance'] === undefined)
|
|
return _error400();
|
|
var found = false;
|
|
for (var i = 0; i < window.vars['instance_config']['hosts'][hargs['software']].length; i++)
|
|
{
|
|
const item = window.vars['instance_config']['hosts'][hargs['software']][i];
|
|
if (item['instance'] === hargs['instance']) {
|
|
window.vars['current_instance'] = item;
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!found)
|
|
return _error400();
|
|
|
|
apcontrol_title(`Config (${hargs['instance']})`);
|
|
return _paint();
|
|
};
|
|
|
|
if (window.vars['instance_config'] === undefined) {
|
|
http.get('api/v1/config/get',{},function(data) {
|
|
window.vars['instance_config'] = JSON.parse(data);
|
|
_main();
|
|
});
|
|
} else { _main() }
|
|
}
|
|
</script>
|