diff --git a/iforte/base.js b/iforte/base.js index d95c956..0343ac3 100644 --- a/iforte/base.js +++ b/iforte/base.js @@ -1,4 +1,10 @@ $(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; @@ -9,7 +15,7 @@ $(document).ready(function() { 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(''); @@ -37,62 +43,11 @@ $(document).ready(function() { }); }); }); - //periodicly get status - var bsy = false; - var ebli = 0; - var eblio = 255; + + // handle RDM ident var idntb = $('#idnt img'); - function sta() { - do_ajax('/serr',{},function (json) { -// console.log(json); - dmxsnf = ''; - if (json ) { - if (json['err'] == 1) ebli = 0x80; - else ebli = 0; - if (json['dmxsnf'] == 1) dmxsnf = ' [sniffing DMX]'; - if (json['idnt'] == 1) idntb.addClass('a'); - else idntb.removeClass('a'); - if (json['dls'] && json['dls'] == 1) { - $('.snz').show(); - } - } else if (json == undefined) { - ebli = 0x40; - } else ebli = 0; - bsy = false; - }); - } - setInterval(function() { - if (!bsy) { - bsy = true; - sta(); - } - },3000); - sta(); - setInterval(function() { - if (ebli == eblio) return; - var opre = pre; - if (ebli & 0x80) { - ebli ^= 0x01; - if (ebli & 0x01) pre = '(!) '; - $('#pth').removeClass('stou'); - $('#pth').addClass('serr'); - } else if (ebli & 0x40) { - ebli ^= 0x01; - if (ebli & 0x01) pre = '(?) '; - $('#pth').removeClass('serr'); - $('#pth').addClass('stou'); - } else { - ebli = 0; - $('#pth').removeClass('serr stou'); - pre = ''; - } - //$('#pt_v').html(pre + $('#pth').data('title') + dmxsnf); - if (opre != pre) ptit(''); - eblio = ebli; - },1000); $('#idnt').click(function() { idntb.toggleClass('a'); - do_ajax('/rdmi',{s:idntb.hasClass('a') ? 1:0},function(json) {}); }); }); @@ -115,38 +70,26 @@ function get_cookie(n,d,ti=false) { } function mhdr_status(c) { - + if (c.length == 0) $('#cfg-modal .modal-header').removeClass('suc err'); else $('#cfg-modal .modal-header').addClass(c); } -function loader(a) { - - if (a) $('#cfg-modal .modal-header img').addClass('loader'); +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) { - - $.ajax({ - url: p_url, - type: 'POST', - data: p_data, - dataType: 'json', - async: a, - success: function (json) { - f(json,i); - }, - error: function () { -// console.log('do_ajax error'); - f(); - }, - timeout:2000 - }); + 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) { +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()); @@ -170,7 +113,7 @@ function copy_form_values(dir) { } else { if ($(this).is(':checked')) $('#' + id + '_v').html(label); } - + }); if (dir == 1) { $('#m-b div.form-group').each(function() { @@ -183,14 +126,14 @@ function copy_form_values(dir) { } 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'); @@ -207,9 +150,9 @@ function close_modal() { } function pv(p) { - + var s = ''; - + for (var i in p) { var o = p[i]; if (i == 0) s += o + '='; @@ -217,12 +160,12 @@ function pv(p) { 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 += ''; @@ -233,12 +176,12 @@ function c_txt(n,t,e,c = '',it = 'text') { } 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 += '' + t + ''; for (i = 0; i < r.length; i++) { @@ -268,12 +211,12 @@ function c_rad(n,t,r,e,c) { } html += e.length > 0 ? '
' + e + '
' : ''; html += '
'; - + return html; } function box(t,id,p,su = '',vid = '',bc = '') { - + var s = ''; s += '
'; @@ -310,7 +253,7 @@ function box(t,id,p,su = '',vid = '',bc = '') { function generateNavBar() { var o = '
'; o += ''; - - o += '
'; - - o += '
'; - o += '

'; - o += '
'; - o += '
'; - + o += ''; - + return o; } @@ -381,21 +317,21 @@ var pre = ''; var dmxsnf = ''; function ptit(t) { -// console.log('setting title to ' + t); - + // console.log('setting title to ' + t); + if (t == $('#pth').data('title')) return; - -// console.log('set'); - + + // 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()); + + // console.log($('#pth').html()); } function c_dt(n,t,e,c,it) { - + var html = '
'; html += ''; html += '
'; @@ -407,7 +343,7 @@ function c_dt(n,t,e,c,it) { } function c_fsens(i,t,u) { - + var html = ''; html += '
'; html += '
'; @@ -418,6 +354,6 @@ function c_fsens(i,t,u) { html += '
'; html += '
'; html += '
'; - + return html; } \ No newline at end of file diff --git a/iforte/index.html b/iforte/index.html index 42eff57..24e47f2 100644 --- a/iforte/index.html +++ b/iforte/index.html @@ -12,7 +12,9 @@ -
iForte
+ +
+

Device status

@@ -245,66 +247,136 @@ } $('.sb').unbind(); $('#m-f').empty(); - $('#m-f').append(' < button type = "button" - class = "btn btn-primary sb" > Save < /button>');if(a_m==0) $('#m-f').show();else $('#m-f').hide();var h='';if(a_m==0){h+=c_txt('dmxa','DMX address','Please put DMX address from 1 to 512');h+=c_opt('dmxp','DMX preset',[1],'Mode ',0,1,'');h+=c_opt('dmxi','DMX input',['wired','wireless','wireless XLR out'],'',0,1,'Can not set wireless input now!');h+=c_txt('rdmn','RDM label','Please insert label,max 32 characters')} else if(a_m==1){h+=c_btn('Power on time reset',0,' rh')} else if(a_m==2){h+=c_btn('LEDs temperature reset',0,' rt');h+=c_btn('PSU temperature reset',3,' rt');h+=c_btn('Driver temperature reset',1,' rt');h+=c_btn('Base temperature reset',2,' rt')} else if(a_m==3){h+=c_btn('Unlink Wireless module',0,' lwu')}$('#m-b').html(h);copy_form_values(1);$('#cfg-modal').modal();$('.sb').bind('click',function(){loader(1);var par=['dmxa','dmxp','dmxi','rdmn'];do_ajax('/set_dmx - ',pv(par),function (json){if(json){if(json[' - status ']==0){mhdr_status(' - suc ');copy_form_values(0);if(a_m==0){console.log(json[' - dmxf ']);fill_values(json,[' - dmxf '])}ptit(json[' - pt ']);close_modal()}show_errors(json[' - status '],par);loader(0)}})});$('.rh ').bind(' - click ',function(){loader(1);do_ajax(' / reset_hours ',{index:$(this).attr(' - value ')},function (json){if(json){mhdr_status(' - suc ');fill_values(json,[' - hr0 ',' - hr1 ',' - hr2 ',' - hr3 '])}loader(0)})});$('.rt ').bind(' - click ',function(){loader(1);do_ajax(' / reset_temps ',{index:$(this).attr(' - value ')},function (json){if(json){mhdr_status(' - suc ');fill_values(json,[' - tmr0 ',' - tmr1 ',' - tmr2 '])}loader(0)})});$('.lwu ').bind(' - click ',function(){loader(1);do_ajax(' / lwm ',{unlink:1},function (json){if(json){fill_values(json,[' - lwc ',' - lws ']);mhdr_status(' - suc ');close_modal()}loader(0)})})}$(document).ready(function(){$(' - h1 ').html(' - Device status ');var boxes=' - ';boxes+=box(m_t[0],0,[[' - ',[' - DMX address; dmxa ',' - DMX preset; dmxp; < li > < div id = "dmxp_v" > - < /div> < small id = "dmxf_v" > < /small> < /li>','DMX input;dmxi',' < li class = "mt-2" > IP address < /li>;;; < li class = "mt-2" > < div id = "ip_v" > - < /div> < /li>','MAC address;mac',' < li class = "mt-2" > RDM UID < /li>;;; < li class = "mt-2" > < div id = "rdmu_v" > - < /div> < /li>','RDM label;rdmn',]],]);var lot_ta='';lot_ta=' < ul class = "group" > < li > LED on time total < /li> < li > LED on time adaptive < /li> < /ul>',lot_ta+=' < ul class = "group vals" > < li > < div id = "h1_v" > - < /div>h < /li> < li > < div id = "hr1_v" > - < /div>h < /li> < /ul>',boxes+=box('Device times',1,[['',[' < li > Power on time < /li>;;; < li > < div id = "h0_v" > - < /div>h / < div id = "hr0_v" > - < /div>h < /li>',]],],' < p > < small > total / resettable < /small> < /p>'+lot_ta);boxes+=box('Device temperatures',2,[['',[' < li > LEDs < /li>;;; < li > < div id = "t0_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tm0_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tmr0_v" > - < /div>&DG < div class = "tu" > < /div> < /li>',' < li > PSU < /li>;;; < li > < div id = "t3_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tm3_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tmr3_v" > - < /div>&DG < div class = "tu" > < /div> < /li>',' < li > Driver < /li>;;; < li > < div id = "t1_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tm1_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tmr1_v" > - < /div>&DG < div class = "tu" > < /div> < /li>',' < li > Base < /li>;;; < li > < div id = "t2_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tm2_v" > - < /div>&DG < div class = "tu" > < /div> / < div id = "tmr2_v" > - < /div>&DG < div class = "tu" > < /div> < /li>',]],],' < p > < small > current / maximum / resettable < /small> < /p>');boxes+=box('Wireless state',3,[['',['State;lwc','Signal strength;lws',]],]);boxes+=box('Software versions',-1,[['',['Display System','Module M','Module L1','Module L2','Module O','Module F-A','Module F-B','Module G1','Module G2','Module P','Module C1','Module C2','Module DL',]],],'','sw_vers');boxes+=box('Device state',-1,[['',['Device status;devs',]],],c_btn('',0,' esm dn')+' < div > Current RAINS status < /div> < div > < small class = "fl" > WET < /small> < small class = "fr" > DRY < /small> < /div> < div id = "rai" - class = "rains" > < div > < /div> < /div> < div > MAX WET / resettable < /div> < div > < small class = "fl" > WET < /small> < small class = "fr" > DRY < /small> < /div> < div id = "rair" - class = "rains" > < div > < /div> < /div>'+c_btn('MAX WET reset',0,' mwr')+' < p > < small id = "wrt" > < /small> < /p>');boxes+=' < div class = "col-12 box-c" > ';boxes+=' < h2 id = "sta_err" > Status messages < /h2>';boxes+=' < div class = "box" > ';boxes+=' < ul class = "group" - id = "err_v" > ';boxes+=' < /ul>';boxes+=' < /div>';boxes+=' < /div>';$('#boxes').html(boxes);var emb=$('button.esm');emb.addClass('btn-success');function ems_btn(v){if(v==0){emb.removeClass('sa btn-warning').html('Enter standby mode').show()} else {emb.addClass('sa btn-warning').html('Escape standby mode').show()}}emb.click(function(){var run=true;var s_v=(emb.hasClass('sa') ? 0:1);if((s_v==1)&&!confirm('Are you sure you want to enter standby mode?')) run=false;if(run){do_ajax('/sbm - ',{s:s_v},function (json){ems_btn(json[' - sm ']);fill_values(json,[' - devs '])})}});var bussy=0;function do_5s(){bussy|=(1< < 0); + $('#m-f').append(' '); + if(a_m==0) $('#m-f').show(); + else $('#m-f').hide(); + var h='';if(a_m==0){ + h+=c_txt('dmxa','DMX address','Please put DMX address from 1 to 512'); + h+=c_opt('dmxp','DMX preset',[1],'Mode ',0,1,''); + h+=c_opt('dmxi','DMX input',['wired','wireless','wireless XLR out'],'',0,1,'Can not set wireless input now!'); + h+=c_txt('rdmn','RDM label','Please insert label,max 32 characters') + } else if(a_m==1){ + h+=c_btn('Power on time reset',0,' rh') + } else if(a_m==2){ + h+=c_btn('LEDs temperature reset',0,' rt'); + h+=c_btn('PSU temperature reset',3,' rt'); + h+=c_btn('Driver temperature reset',1,' rt'); + h+=c_btn('Base temperature reset',2,' rt') + } else if(a_m==3){ + h+=c_btn('Unlink Wireless module',0,' lwu') + } + + $('#m-b').html(h); + copy_form_values(1); + $('#cfg-modal').modal(); + $('.sb').bind('click',function(){ + loader(1); + var par=['dmxa','dmxp','dmxi','rdmn']; + do_ajax('/set_dmx',pv(par),function (json){ + if(json){ + if(json['status']==0){ + mhdr_status('suc'); + copy_form_values(0); + if(a_m==0){ + console.log(json['dmxf']); + fill_values(json,['dmxf']) + } ptit(json['pt']); + close_modal() + } + show_errors(json['status'],par); + loader(0) + } + }) + }); + + $('.rh ').bind('click ',function(){ + loader(1); + do_ajax('/reset_hours',{ + index: $(this).attr('value') + },function (json){ + if(json){ + mhdr_status('suc'); + fill_values(json,['hr0','hr1','hr2','hr3']) + } + loader(0) + }) + }); + + $('.rt').bind('click',function(){ + loader(1); + do_ajax('/reset_temps',{ + index: $(this).attr('value') + },function (json){ + if(json){ + mhdr_status('suc'); + fill_values(json,['tmr0','tmr1','tmr2']) + } + loader(0) + }) + }); + + $('.lwu').bind('click',function(){ + loader(1); + do_ajax('/lwm',{ + unlink:1 + },function (json){ + if(json){ + fill_values(json,['lwc','lws']); + mhdr_status('suc'); + close_modal() + } + loader(0) + }) + }) + } + + $(document).ready(function(){ + var emb=$('button.esm'); + emb.addClass('btn-success'); + function ems_btn(v){ + if(v==0){ + emb.removeClass('sa btn-warning').html('Enter standby mode').show() + } else { + emb.addClass('sa btn-warning').html('Escape standby mode').show() + } + } + emb.click(function(){ + var run=true; + var s_v=(emb.hasClass('sa') ? 0:1); + if((s_v==1)&&!confirm('Are you sure you want to enter standby mode?')) run=false; + if(run){ + do_ajax('/sbm',{ + s:s_v + },function (json){ + ems_btn(json['sm']); + fill_values(json,['devs']) + }) + } + }); + var bussy=0; + function do_5s(){bussy|=(1 << 0); do_ajax('/lwm', {}, function(json) { if (json) { fill_values(json, ['lwc', 'lws']) } - bussy &= ~(1 < < 0) + bussy &= ~(1 << 0) }); - bussy |= (1 < < 1); + bussy |= (1 << 1); do_ajax('/reset_temps', {}, function(json) { if (json) { fill_values(json, ['t0', 't1', 't2', 't3', 'tm0', 'tm1', 'tm2', 'tm3', 'tmr0', 'tmr1', 'tmr2', 'tmr3']); $('.tu').html(json['tu']) } - bussy &= ~(1 < < 1) + bussy &= ~(1 << 1) }); - bussy |= (1 < < 3); + bussy |= (1 << 3); do_ajax('/reset_hours', {}, function(json) { if (json) { fill_values(json, ['h0', 'h1', 'h2', 'h3', 'hr0', 'hr1', 'hr2', 'hr3']) } - bussy &= ~(1 < < 3) + bussy &= ~(1 << 3) }); - bussy |= (1 < < 4); + bussy |= (1 << 4); do_ajax('/devsta', {}, function(json) { if (json) { fill_values(json, ['devs']); @@ -317,18 +389,20 @@ devs: 'disconnected' }, ['devs']) } - bussy &= ~(1 < < 4) + bussy &= ~(1 << 4) }); - bussy |= (1 < < 7); + bussy |= (1 << 7); do_ajax('/errors', {}, function(json) { if (json) { if (json['err']) { if (json['err'].length) $('#sta_err').addClass('err'); else $('#sta_err').removeClass('err'); var html = ''; - for (i = 0; i < json['err'].length; i++) html += ' < li > '+json[' - err '][i]+' < /li>';$('#err_v').html(html)}}bussy&=~(1< < 7) - }) + for (i = 0; i < json['err'].length; i++) html += '
  • ' + json['err'][i] + '
  • '; + $('#err_v').html(html) + } + } + bussy&=~(1 << 7)}) } do_ajax('/status_i', {}, function(json) { if (json) {