$(document).ready(function() {
// Sets the proper fixture name in the header and title
var fixturename = "Robin iForte - Simulated";
$('#pth').html(fixturename)
$(document).prop('title', fixturename)
$('body').prepend(generateNavBar());
var am = 0;
var mip = 0;
mip = 1;
var href = $(location).attr('pathname');
if (href.indexOf('personality') != -1) am = 1;
if (href.indexOf('logs') != -1) am = 2;
if (href.indexOf('sensors') != -1) am = 3;
if (href.indexOf('discovery') != -1) am = (3 + mip);
$('#navbar ul li').eq(am).addClass('active');
//handle settings
$(document).on('click','#scfg',function() {
mhdr_status('');
$('#m-t').html('Site settings');
var h = '
Password settings
';
h += c_txt('opswd','Old password','Please put old password (four digits)','','password');
h += c_txt('npswd','New password','Please put new password (four digits)','','password');
h += c_txt('npsch','New password check','New passwords check failed','','password');
$('#m-b').html(h);
$('.sb').unbind();
$('#cfg-modal').modal();
$('.sb').bind('click',function() {
loader(1);
var par = ['opswd','npswd','npsch'];
do_ajax('/set_cfg',pv(par),function (json) {
if (json) {
if (json['status'] == 0) {
mhdr_status('suc');
close_modal();
location = '/';
}
show_errors(json['status'],par);
loader(0);
}
});
});
});
// handle RDM ident
var idntb = $('#idnt img');
$('#idnt').click(function() {
idntb.toggleClass('a');
});
});
function get_cookie(n,d,ti=false) {
var r = d;
var c = document.cookie.split(';');
c.forEach(function(v,i) {
v = v.split('=');
if (v[0].trim() == n) {
if (ti) {
const par = parseInt(v[1].trim());
if (!isNaN(par)) {
r = par;
}
} else r = v[1].trim();
}
});
return r;
}
function mhdr_status(c) {
if (c.length == 0) $('#cfg-modal .modal-header').removeClass('suc err');
else $('#cfg-modal .modal-header').addClass(c);
}
function loader(showheader) {
if (showheader) $('#cfg-modal .modal-header img').addClass('loader');
else $('#cfg-modal .modal-header img').removeClass('loader');
}
function do_ajax(p_url,p_data,f,i = -1,a = true) {
console.log("url : " + p_url);
console.log("data : " + p_data);
console.log("callback function : " + f);
console.log("callback params : " + i);
console.log("async : " + a);
}
function copy_form_values(dir) {
$('#m-b input:text, #m-b input[type=range]').each(function() {
var id = $(this).attr('id');
if (dir == 0) $('#' + id + '_v').html($('#' + id).val());
else $('#' + id).val($('#' + id + '_v').html());
});
$('#m-b select').each(function() {
var id = $(this).attr('id');
text = $('#' + id + '_v').html();
if (dir == 1) {
$(this).find('option').filter(function () { return $(this).html() == text; }).attr('selected', 'selected');
} else {
$('#' + id + '_v').html($(this).find('option:selected').html());
}
});
$('#m-b input:radio').each(function() {
var id = $(this).attr('name');
text = $('#' + id + '_v').html();
label = $(this).parent().find('label').html();
if (dir == 1) {
if (label == text) $(this).attr('checked','checked');
} else {
if ($(this).is(':checked')) $('#' + id + '_v').html(label);
}
});
if (dir == 1) {
$('#m-b div.form-group').each(function() {
var len = $(this).find('div.invalid-feedback').length;
if (len == 0) {
$(this).append('
Wrong value!
');
}
});
}
}
function fill_values(d,ids) {
for (i = 0; i < ids.length; i++) {
$('#' + ids[i] + '_v').html(d[ids[i]]);
}
}
function show_errors(s,ids) {
if (s) mhdr_status('err');
for (i = 0; i < ids.length; i++) {
if (s & (1 << i)) $('#' + ids[i]).addClass('is-invalid').removeClass('is-valid');
else $('#' + ids[i]).removeClass('is-invalid').addClass('is-valid');
}
}
function close_modal() {
setTimeout(function() {
$('#m-b').empty();
$('#cfg-modal').modal('hide');
},500);
}
function pv(p) {
var s = '';
for (var i in p) {
var o = p[i];
if (i == 0) s += o + '=';
else s += '&' + o + '=';
if ($('#' + o).val() != undefined) s += $('#' + o).val();
else if ($('input[name=' + o + ']:checked').val() != undefined) s += $('input[name=' + o + ']:checked').val();
}
return s;
}
function c_txt(n,t,e,c = '',it = 'text') {
var html = '
';
html += '';
html += '';
html += e.length > 0 ? '
' + e + '
' : '';
html += '
';
return html;
}
function c_btn(t,v,c) {
return '';
}
function c_opt(n,t,o,pl,vp,lp,e) {
var html = '
';
html += '';
html += '';
html += e.length > 0 ? '
' + e + '
' : '';
html += '
';
return html;
}
function c_rad(n,t,r,e,c) {
var html = '
';
html += '';
for (i = 0; i < r.length; i++) {
html += '
';
html += '';
html += '';
html += '
';
}
html += e.length > 0 ? '
' + e + '
' : '';
html += '
';
return html;
}
function box(t,id,p,su = '',vid = '',bc = '') {
var s = '';
s += '
';
if (id >= 0) s += '
' + t + '
';
else s += '
' + t + '
';
s += '
';
for (var j in p) {
if (p[j][0].length > 0) s += '
' + p[j][0] + '
';
s += '
';
for (var i in p[j][1]) {
l = p[j][1][i].split(";");
if (l.length == 4) s += l[0];
else s += '
' + l[0] + '
';
}
s += '
';
s += '
';
for (var i in p[j][1]) {
l = p[j][1][i].split(";");
if (l.length == 4) {
var t = l[3].replace(/&DG/gi,'°');
s += t;
} else if (l.length == 3) s += l[2];
else if (l.length == 2) s += '
-
';
else s += '
-
';
}
s += '
';
}
s += su;
s += '
';
s += '
';
return s;
}
function generateNavBar() {
var o = '';
o += '
';
o += '
';
o += '
';
o += '
';
o += '';
o += '';
o += '';
o += '
';
o += '
';
o += '
';
o += '';
o += '
';
o += '
';
o += '
';
return o;
}
var pre = '';
var dmxsnf = '';
function ptit(t) {
// console.log('setting title to ' + t);
if (t == $('#pth').data('title')) return;
// console.log('set');
if (t.length) $('#pth').data('title',t);
$('#pth').html($('#pth').data('title') + dmxsnf);
$('#pt_v').html(pre + $('#pth').html());
// console.log($('#pth').html());
}
function c_dt(n,t,e,c,it) {
var html = '
';
html += '';
html += '
';
html += '';
html += e.length > 0 ? '
' + e + '
' : '';
html += '
';
return html;
}
function c_fsens(i,t,u) {
var html = '';
html += '
';
html += '';
html += '';
html += '';
html += '';
html += '