2017-02-08 14:36:28 +01:00
|
|
|
$(document).ready( function() {
|
|
|
|
performTranslation();
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
var importedConf;
|
|
|
|
var confName;
|
|
|
|
var conf_editor = null;
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#conf_cont').append(createOptPanel('fa-wrench', $.i18n("edt_conf_gen_heading_title"), 'editor_container', 'btn_submit'));
|
2019-06-05 18:19:08 +02:00
|
|
|
if(window.showOptHelp)
|
2017-01-17 21:53:35 +01:00
|
|
|
{
|
2019-06-05 18:19:08 +02:00
|
|
|
$('#conf_cont').append(createHelpTable(window.schema.general.properties, $.i18n("edt_conf_gen_heading_title")));
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
$('#conf_imp').appendTo('#conf_cont');
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2016-12-23 19:37:35 +01:00
|
|
|
conf_editor = createJsonEditor('editor_container', {
|
2019-06-05 18:19:08 +02:00
|
|
|
general: window.schema.general
|
2017-01-04 10:55:10 +01:00
|
|
|
}, true, true);
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
conf_editor.on('change',function() {
|
|
|
|
conf_editor.validate().length ? $('#btn_submit').attr('disabled', true) : $('#btn_submit').attr('disabled', false);
|
|
|
|
});
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2016-12-23 19:37:35 +01:00
|
|
|
$('#btn_submit').off().on('click',function() {
|
|
|
|
requestWriteConfig(conf_editor.getValue());
|
|
|
|
});
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2019-07-12 16:54:26 +02:00
|
|
|
// Token handling
|
|
|
|
function buildTokenList()
|
|
|
|
{
|
|
|
|
$('.tktbody').html("");
|
|
|
|
for(var key in tokenList)
|
|
|
|
{
|
|
|
|
var lastUse = (tokenList[key].last_use) ? tokenList[key].last_use : "-";
|
|
|
|
var btn = '<button id="tok'+tokenList[key].id+'" type="button" class="btn btn-danger">'+$.i18n('general_btn_delete')+'</button>';
|
|
|
|
$('.tktbody').append(createTableRow([tokenList[key].comment, lastUse, btn], false, true));
|
|
|
|
$('#tok'+tokenList[key].id).off().on('click', handleDeleteToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createTable('tkthead', 'tktbody', 'tktable');
|
|
|
|
$('.tkthead').html(createTableRow([$.i18n('conf_general_tok_cidhead'), $.i18n('conf_general_tok_lastuse'), $.i18n('general_btn_delete')], true, true));
|
|
|
|
buildTokenList();
|
|
|
|
|
|
|
|
function handleDeleteToken(e)
|
|
|
|
{
|
|
|
|
var key = e.currentTarget.id.replace("tok","");
|
|
|
|
requestTokenDelete(key);
|
|
|
|
$('#tok'+key).parent().parent().remove();
|
|
|
|
// rm deleted token id
|
|
|
|
tokenList = tokenList.filter(function( obj ) {
|
|
|
|
return obj.id !== key;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#btn_create_tok').off().on('click',function() {
|
|
|
|
requestToken($('#tok_comment').val())
|
|
|
|
$('#tok_comment').val("")
|
|
|
|
$('#btn_create_tok').attr('disabled', true)
|
|
|
|
});
|
|
|
|
$('#tok_comment').off().on('input',function(e) {
|
|
|
|
(e.currentTarget.value.length >= 10) ? $('#btn_create_tok').attr('disabled', false) : $('#btn_create_tok').attr('disabled', true);
|
|
|
|
});
|
|
|
|
$(window.hyperion).off("cmd-authorize-createToken").on("cmd-authorize-createToken", function(event) {
|
|
|
|
var val = event.response.info;
|
|
|
|
showInfoDialog("newToken",$.i18n('conf_general_tok_diaTitle'),$.i18n('conf_general_tok_diaMsg')+'<br><div style="font-weight:bold">'+val.token+'</div>')
|
|
|
|
tokenList.push(val)
|
|
|
|
buildTokenList()
|
|
|
|
});
|
|
|
|
|
2019-07-14 22:43:22 +02:00
|
|
|
// Instance handling
|
|
|
|
function handleInstanceStartStop(e)
|
|
|
|
{
|
|
|
|
var inst = e.currentTarget.id.split("_")[1];
|
|
|
|
var start = (e.currentTarget.className == "btn btn-danger")
|
|
|
|
requestInstanceStartStop(inst, start)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleInstanceDelete(e)
|
|
|
|
{
|
|
|
|
var inst = e.currentTarget.id.split("_")[1];
|
|
|
|
showInfoDialog('delplug',$.i18n('conf_general_inst_delreq_h'),$.i18n('conf_general_inst_delreq_t',getInstanceNameByIndex(inst)));
|
|
|
|
$("#id_btn_yes").off().on('click', function(){
|
|
|
|
requestInstanceDelete(inst)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildInstanceList()
|
|
|
|
{
|
|
|
|
var inst = serverInfo.instance
|
|
|
|
$('.itbody').html("");
|
|
|
|
for(var key in inst)
|
|
|
|
{
|
|
|
|
var startBtnColor = inst[key].running ? "success" : "danger";
|
|
|
|
var startBtnText = inst[key].running ? $.i18n('general_btn_stop') : $.i18n('general_btn_start');
|
|
|
|
var startBtn = "-"
|
|
|
|
var delBtn = "-";
|
|
|
|
if(inst[key].instance > 0)
|
|
|
|
{
|
|
|
|
delBtn = '<button id="instdel_'+inst[key].instance+'" type="button" class="btn btn-danger">'+$.i18n('general_btn_delete')+'</button>';
|
|
|
|
startBtn = '<button id="inst_'+inst[key].instance+'" type="button" class="btn btn-'+startBtnColor+'">'+startBtnText+'</button>';
|
|
|
|
}
|
|
|
|
$('.itbody').append(createTableRow([inst[key].friendly_name, startBtn, delBtn], false, true));
|
|
|
|
$('#inst_'+inst[key].instance).off().on('click', handleInstanceStartStop);
|
|
|
|
$('#instdel_'+inst[key].instance).off().on('click', handleInstanceDelete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createTable('ithead', 'itbody', 'itable');
|
|
|
|
$('.ithead').html(createTableRow([$.i18n('conf_general_inst_namehead'), $.i18n('conf_general_inst_actionhead'), $.i18n('general_btn_delete')], true, true));
|
|
|
|
buildInstanceList();
|
|
|
|
|
|
|
|
$('#inst_name').off().on('input',function(e) {
|
|
|
|
(e.currentTarget.value.length >= 5) ? $('#btn_create_inst').attr('disabled', false) : $('#btn_create_inst').attr('disabled', true);
|
|
|
|
});
|
|
|
|
$('#btn_create_inst').off().on('click',function(e) {
|
|
|
|
requestInstanceCreate($('#inst_name').val());
|
|
|
|
});
|
|
|
|
|
|
|
|
$(hyperion).off("instance-updated").on("instance-updated", function(event) {
|
|
|
|
buildInstanceList()
|
|
|
|
});
|
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
//import
|
2017-01-17 21:53:35 +01:00
|
|
|
function dis_imp_btn(state)
|
|
|
|
{
|
|
|
|
state ? $('#btn_import_conf').attr('disabled', true) : $('#btn_import_conf').attr('disabled', false);
|
|
|
|
}
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
function readFile(evt)
|
|
|
|
{
|
|
|
|
var f = evt.target.files[0];
|
|
|
|
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
var r = new FileReader();
|
|
|
|
r.onload = function(e)
|
|
|
|
{
|
2017-07-30 13:32:10 +02:00
|
|
|
var content = e.target.result.replace(/[^:]?\/\/.*/g, ''); //remove Comments
|
2017-01-17 21:53:35 +01:00
|
|
|
|
|
|
|
//check file is json
|
|
|
|
var check = isJsonString(content);
|
|
|
|
if(check.length != 0)
|
|
|
|
{
|
|
|
|
showInfoDialog('error', "", $.i18n('infoDialog_import_jsonerror_text', f.name, JSON.stringify(check)));
|
|
|
|
dis_imp_btn(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
content = JSON.parse(content);
|
|
|
|
//check for hyperion json
|
|
|
|
if(typeof content.leds === 'undefined' || typeof content.general === 'undefined')
|
|
|
|
{
|
|
|
|
showInfoDialog('error', "", $.i18n('infoDialog_import_hyperror_text', f.name));
|
2017-07-30 13:32:10 +02:00
|
|
|
dis_imp_btn(true);
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-04 23:12:59 +02:00
|
|
|
dis_imp_btn(false);
|
|
|
|
importedConf = content;
|
|
|
|
confName = f.name;
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r.readAsText(f);
|
|
|
|
}
|
|
|
|
}
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#btn_import_conf').off().on('click', function(){
|
|
|
|
showInfoDialog('import', $.i18n('infoDialog_import_confirm_title'), $.i18n('infoDialog_import_confirm_text', confName));
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#id_btn_import').off().on('click', function(){
|
|
|
|
requestWriteConfig(importedConf, true);
|
|
|
|
setTimeout(initRestart, 100);
|
|
|
|
});
|
|
|
|
});
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#select_import_conf').off().on('change', function(e){
|
|
|
|
if (window.File && window.FileReader && window.FileList && window.Blob)
|
|
|
|
readFile(e);
|
|
|
|
else
|
|
|
|
showInfoDialog('error', "", $.i18n('infoDialog_import_comperror_text'));
|
|
|
|
});
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
//export
|
|
|
|
$('#btn_export_conf').off().on('click', function(){
|
2019-06-05 18:19:08 +02:00
|
|
|
var name = window.serverConfig.general.name;
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
var d = new Date();
|
|
|
|
var month = d.getMonth()+1;
|
|
|
|
var day = d.getDate();
|
|
|
|
|
|
|
|
var timestamp = d.getFullYear() + '.' +
|
|
|
|
(month<10 ? '0' : '') + month + '.' +
|
|
|
|
(day<10 ? '0' : '') + day;
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2019-06-05 18:19:08 +02:00
|
|
|
download(JSON.stringify(window.serverConfig, null, "\t"), 'Hyperion-'+window.currentVersion+'-Backup ('+name+') '+timestamp+'.json', "application/json");
|
2017-02-08 14:36:28 +01:00
|
|
|
});
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
//create introduction
|
2019-06-05 18:19:08 +02:00
|
|
|
if(window.showOptHelp)
|
2017-02-08 14:36:28 +01:00
|
|
|
createHint("intro", $.i18n('conf_general_intro'), "editor_container");
|
2019-07-12 16:54:26 +02:00
|
|
|
createHint("intro", $.i18n('conf_general_tok_desc'), "tok_desc_cont");
|
2019-07-14 22:43:22 +02:00
|
|
|
createHint("intro", $.i18n('conf_general_inst_desc'), "inst_desc_cont");
|
2017-09-04 23:12:59 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
removeOverlay();
|
2016-12-23 19:37:35 +01:00
|
|
|
});
|