2016-09-03 15:54:33 +02:00
|
|
|
|
2016-12-18 19:00:14 +01:00
|
|
|
function debugMessage(msg)
|
|
|
|
{
|
|
|
|
if (debugMessagesActive)
|
|
|
|
{
|
|
|
|
console.log(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-04 16:27:48 +02:00
|
|
|
function bindNavToContent(containerId, fileName, loadNow)
|
2016-09-03 15:54:33 +02:00
|
|
|
{
|
2016-09-14 13:51:28 +02:00
|
|
|
$("#page-content").off();
|
2016-09-03 15:54:33 +02:00
|
|
|
$(containerId).on("click", function() {
|
2016-09-14 13:51:28 +02:00
|
|
|
$("#page-content").load("/content/"+fileName+".html");
|
2016-09-04 16:27:48 +02:00
|
|
|
});
|
2016-09-03 15:54:33 +02:00
|
|
|
if (loadNow)
|
|
|
|
{
|
2016-09-15 20:42:58 +02:00
|
|
|
$(containerId).trigger("click");
|
2016-09-03 15:54:33 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-05 17:26:29 +02:00
|
|
|
|
2016-09-06 10:14:54 +02:00
|
|
|
function loadContentTo(containerId, fileName)
|
|
|
|
{
|
|
|
|
$(containerId).load("/content/"+fileName+".html");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-05 17:26:29 +02:00
|
|
|
|
|
|
|
function toggleClass(obj,class1,class2)
|
|
|
|
{
|
|
|
|
if ( $(obj).hasClass(class1))
|
|
|
|
{
|
|
|
|
$(obj).removeClass(class1);
|
|
|
|
$(obj).addClass(class2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$(obj).removeClass(class2);
|
|
|
|
$(obj).addClass(class1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setClassByBool(obj,enable,class1,class2)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
$(obj).removeClass(class1);
|
|
|
|
$(obj).addClass(class2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$(obj).removeClass(class2);
|
|
|
|
$(obj).addClass(class1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-08 23:39:41 +01:00
|
|
|
function showInfoDialog(type,header,message,btnid)
|
2016-09-06 10:14:54 +02:00
|
|
|
{
|
2016-12-08 23:39:41 +01:00
|
|
|
if (type != 'select')
|
|
|
|
$('#modal_select').toggle(false);
|
|
|
|
else
|
|
|
|
$('#modal_select').toggle(true);
|
|
|
|
|
2016-10-27 23:42:24 +02:00
|
|
|
$('#modal_dialog .modal-bodytitle').html(header);
|
|
|
|
$('#modal_dialog .modal-bodycontent').html(message);
|
|
|
|
|
|
|
|
if (type=="success"){
|
|
|
|
$('#modal_dialog .modal-bodyicon').html('<i class="fa fa-check modal-icon-check">');
|
2016-12-08 23:39:41 +01:00
|
|
|
$('#modal_dialog .modal-footer-button').html('<button type="button" class="btn btn-success" data-dismiss="modal">'+$.i18n('general_btn_ok')+'</button>');
|
2016-10-27 23:42:24 +02:00
|
|
|
}
|
|
|
|
else if (type=="warning"){
|
|
|
|
$('#modal_dialog .modal-bodyicon').html('<i class="fa fa-warning modal-icon-warning">');
|
2016-12-08 23:39:41 +01:00
|
|
|
$('#modal_dialog .modal-footer-button').html('<button type="button" class="btn btn-warning" data-dismiss="modal">'+$.i18n('general_btn_ok')+'</button>');
|
2016-10-27 23:42:24 +02:00
|
|
|
}
|
|
|
|
else if (type=="error"){
|
|
|
|
$('#modal_dialog .modal-bodyicon').html('<i class="fa fa-warning modal-icon-error">');
|
2016-12-08 23:39:41 +01:00
|
|
|
$('#modal_dialog .modal-footer-button').html('<button type="button" class="btn btn-danger" data-dismiss="modal">'+$.i18n('general_btn_ok')+'</button>');
|
2016-10-27 23:42:24 +02:00
|
|
|
}
|
2016-12-08 23:39:41 +01:00
|
|
|
else if (type == "select"){
|
|
|
|
$('#modal_dialog .modal-bodyicon').html('<img src="img/hyperion/hyperionlogo.png" alt="Redefine ambient light!">');
|
|
|
|
$('#modal_dialog .modal-footer-button').html('<button type="button" id="'+btnid+'" class="btn btn-success" data-dismiss="modal">'+$.i18n('general_btn_save')+'</button>');
|
|
|
|
$('#modal_dialog .modal-footer-button').append('<button type="button" class="btn btn-danger" data-dismiss="modal">'+$.i18n('general_btn_abort')+'</button>');
|
|
|
|
}
|
2016-12-21 18:24:03 +01:00
|
|
|
else if (type == "uilock"){
|
|
|
|
$('#modal_dialog .modal-bodyicon').html('<img src="img/hyperion/hyperionlogo.png" alt="Redefine ambient light!">');
|
|
|
|
$('#modal_dialog .modal-footer-button').html('<b>'+$.i18n('InfoDialog_nowrite_foottext')+'</b>');
|
|
|
|
}
|
2016-10-27 23:42:24 +02:00
|
|
|
|
2016-12-08 23:39:41 +01:00
|
|
|
$("#modal_dialog").modal({
|
|
|
|
backdrop : "static",
|
|
|
|
keyboard: false,
|
|
|
|
show: true
|
|
|
|
});
|
2016-09-06 10:14:54 +02:00
|
|
|
}
|
|
|
|
|
2016-10-09 10:23:04 +02:00
|
|
|
function isJsonString(str)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-09-06 10:14:54 +02:00
|
|
|
JSON.parse(str);
|
2016-10-09 10:23:04 +02:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
2016-09-06 10:14:54 +02:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2016-10-09 10:23:04 +02:00
|
|
|
|
|
|
|
|
2016-12-21 18:24:03 +01:00
|
|
|
function createJsonEditor(container,schema,setconfig,usePanel)
|
2016-10-09 10:23:04 +02:00
|
|
|
{
|
|
|
|
$('#'+container).off();
|
|
|
|
$('#'+container).html("");
|
2016-12-21 18:24:03 +01:00
|
|
|
|
2016-10-10 23:15:50 +02:00
|
|
|
var editor = new JSONEditor(document.getElementById(container),
|
2016-10-09 10:23:04 +02:00
|
|
|
{
|
|
|
|
theme: 'bootstrap3',
|
|
|
|
iconlib: "fontawesome4",
|
|
|
|
disable_collapse: 'true',
|
|
|
|
form_name_root: 'sa',
|
|
|
|
disable_edit_json: 'true',
|
|
|
|
disable_properties: 'true',
|
2016-10-30 17:54:38 +01:00
|
|
|
disable_array_reorder: 'true',
|
2016-10-09 10:23:04 +02:00
|
|
|
no_additional_properties: 'true',
|
2016-10-10 23:15:50 +02:00
|
|
|
schema: {
|
|
|
|
title:'',
|
|
|
|
properties: schema
|
|
|
|
}
|
2016-10-09 10:23:04 +02:00
|
|
|
});
|
2016-12-21 18:24:03 +01:00
|
|
|
|
|
|
|
if(usePanel)
|
|
|
|
{
|
|
|
|
$('#'+container+' .well').first().removeClass('well well-sm');
|
|
|
|
$('#'+container+' h3').remove();
|
|
|
|
$('#'+container+' .well').first().removeClass('well well-sm');
|
|
|
|
}
|
2016-10-10 23:15:50 +02:00
|
|
|
|
|
|
|
if (setconfig)
|
|
|
|
{
|
|
|
|
for(var key in editor.root.editors)
|
|
|
|
{
|
|
|
|
editor.getEditor("root."+key).setValue( parsedConfJSON[key] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return editor;
|
2016-10-09 10:23:04 +02:00
|
|
|
}
|
2016-11-30 17:32:12 +01:00
|
|
|
|
2016-12-21 18:24:03 +01:00
|
|
|
function createTableTh(th1, th2){
|
|
|
|
var elth1 = document.createElement('th');
|
|
|
|
var elth2 = document.createElement('th');
|
|
|
|
var tr = document.createElement('tr');
|
|
|
|
|
|
|
|
elth1.innerHTML = th1;
|
|
|
|
elth2.innerHTML = th2;
|
|
|
|
tr.appendChild(elth1);
|
|
|
|
tr.appendChild(elth2);
|
|
|
|
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTableTd(td1, td2){
|
|
|
|
var eltd1 = document.createElement('td');
|
|
|
|
var eltd2 = document.createElement('td');
|
|
|
|
var tr = document.createElement('tr');
|
|
|
|
|
|
|
|
eltd1.innerHTML = td1;
|
|
|
|
eltd2.innerHTML = td2;
|
|
|
|
tr.appendChild(eltd1);
|
|
|
|
tr.appendChild(eltd2);
|
|
|
|
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createHelpTable(list, phead){
|
|
|
|
var table = document.createElement('table');
|
|
|
|
var thead = document.createElement('thead');
|
|
|
|
var tbody = document.createElement('tbody');
|
|
|
|
|
|
|
|
table.className = 'table table-hover borderless';
|
|
|
|
|
|
|
|
thead.appendChild(createTableTh($.i18n('conf_helptable_option'), $.i18n('conf_helptable_expl')));
|
|
|
|
for (key in list){
|
|
|
|
text = list[key].title.replace('title', 'expl');
|
|
|
|
tbody.appendChild(createTableTd($.i18n(list[key].title), $.i18n(text)));
|
|
|
|
}
|
|
|
|
table.appendChild(thead);
|
|
|
|
table.appendChild(tbody);
|
|
|
|
|
|
|
|
return createPanel(phead, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createPanel(head, body, footer, type){
|
|
|
|
var p = document.createElement('div');
|
|
|
|
var phead = document.createElement('div');
|
|
|
|
var pbody = document.createElement('div');
|
|
|
|
var pfooter = document.createElement('div');
|
|
|
|
|
|
|
|
if(typeof type == 'undefined')
|
|
|
|
type = 'panel-default';
|
|
|
|
|
|
|
|
p.className = 'panel '+type;
|
|
|
|
phead.className = 'panel-heading';
|
|
|
|
pbody.className = 'panel-body';
|
|
|
|
pfooter.className = 'panel-footer';
|
|
|
|
|
|
|
|
phead.innerHTML = head;
|
|
|
|
|
|
|
|
if(typeof body != 'undefined')
|
|
|
|
pbody.appendChild(body);
|
|
|
|
|
|
|
|
pfooter.innerHTML = footer;
|
|
|
|
|
|
|
|
p.appendChild(phead);
|
|
|
|
p.appendChild(pbody);
|
|
|
|
|
|
|
|
if(typeof footer != 'undefined')
|
|
|
|
p.appendChild(pfooter);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:10:44 +01:00
|
|
|
function createSelGroup(group)
|
|
|
|
{
|
2016-11-30 17:32:12 +01:00
|
|
|
var el = document.createElement('optgroup');
|
|
|
|
el.setAttribute('label', group);
|
2016-12-05 11:10:44 +01:00
|
|
|
return el;
|
2016-11-30 17:32:12 +01:00
|
|
|
}
|
|
|
|
|
2016-12-08 23:39:41 +01:00
|
|
|
function createSelOpt(opt, title)
|
2016-12-05 11:10:44 +01:00
|
|
|
{
|
2016-11-30 17:32:12 +01:00
|
|
|
var el = document.createElement('option');
|
|
|
|
el.setAttribute('value', opt);
|
2016-12-08 23:39:41 +01:00
|
|
|
if (typeof title == 'undefined')
|
|
|
|
el.innerHTML = opt;
|
|
|
|
else
|
|
|
|
el.innerHTML = title;
|
2016-12-05 11:10:44 +01:00
|
|
|
return el;
|
2016-11-30 17:32:12 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:10:44 +01:00
|
|
|
function createSel(array, group)
|
|
|
|
{
|
|
|
|
if (array.length != "0")
|
|
|
|
{
|
|
|
|
var el = createSelGroup(group);
|
|
|
|
for(var i=0; i<array.length; i++)
|
|
|
|
{
|
2016-11-30 17:32:12 +01:00
|
|
|
var opt = createSelOpt(array[i])
|
|
|
|
el.appendChild(opt);
|
|
|
|
}
|
2016-12-05 11:10:44 +01:00
|
|
|
return el;
|
2016-11-30 17:32:12 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-04 19:32:23 +01:00
|
|
|
|
2016-12-05 11:10:44 +01:00
|
|
|
function performTranslation()
|
|
|
|
{
|
2016-12-21 18:24:03 +01:00
|
|
|
$('[data-i18n]').i18n();
|
2016-12-04 19:32:23 +01:00
|
|
|
}
|
2016-12-05 11:10:44 +01:00
|
|
|
|
|
|
|
function encode_utf8(s)
|
|
|
|
{
|
|
|
|
return unescape(encodeURIComponent(s));
|
|
|
|
}
|