weather.js 2.23 KB
 
var sync_weather = {
    set_data: function(data_) {
        //See data_: http://127.0.0.1:5030/eicdata/ajax/?&action=data_state&id=2016-12-01
        //if (data_.ACK) {
            var res = sync_weather.tuned_state(data_, ' ');
            //document.getElementById(divparam).innerHTML = '';
            document.getElementById('plc').innerHTML = res;
            var res = sync_weather.object_to_tree(data_, ' ');
            //document.getElementById(divparam).innerHTML = '';
            document.getElementById('refresh').innerHTML = res;
        //}
    },
    tuned_state: function(data) {
        data = data[0];
        res ='<h4>PLC</h4>'
        res +='<table>';
        if (data.is_safe == true) {
            res += sync_weather.get_success("is_safe", data.is_safe);
        } else {
            res += sync_weather.get_warning("is_safe", data.is_safe);
        }
        res += sync_weather.get_success("plc_mode", data.plc_mode);
        res += sync_weather.get_success("plc_timeout", data.plc_timeout);
        res += "</table>";
        return res
    },
    // alert alert-success
    get_success: function(name, value) {return '<tr class="alert alert-info"><th scope="row">'+name+':&nbsp;</th><td>'+value+'</td></tr>';},
    get_warning: function(name, value) {return '<tr class="alert alert-warning"><th scope="row">'+name+':&nbsp;</th><td>'+value+'</td></tr>';},
    setTimeout:function(){
        //alert("change");
        Async.status.timeout = document.getElementById('timer_select').value * 1000;
    },
    object_to_tree: function(argObject, level) {
      var msg = '';
      for (var propertyName in argObject) {
        if (typeof argObject[propertyName] == 'object'){
              msg += '<p>' + level + propertyName  + ': (' + typeof argObject[propertyName] + ')</p>';
              msg += this.object_to_tree(argObject[propertyName], level + '--&nbsp;');
        } else if (typeof argObject[propertyName] == 'function'){
              msg += '<p>' + level + propertyName  + ': (' + typeof argObject[propertyName] + ')</p>';
        } else {
              msg += '<p>' + level + propertyName  + ': (' + typeof argObject[propertyName] + ') <span class=\"fld\">' + argObject[propertyName] + '</span></p>';
        }
      }
      return msg
    }
}