2014-03-08 14:01:50 +00:00
|
|
|
var props = {
|
|
|
|
load : function(path, callback, base) {
|
|
|
|
if (typeof (base) == 'undefined')
|
|
|
|
base = "/json/";
|
|
|
|
$.getJSON(base + path, function(data) {
|
|
|
|
callback(props.makeNode(data));
|
2014-03-07 11:07:13 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
save : function(node, url) {
|
|
|
|
alert("can't save yet :-(");
|
2014-03-07 11:07:13 +00:00
|
|
|
},
|
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
// convert a JSON node to a PropertyNode by adding
|
2014-03-07 21:22:01 +00:00
|
|
|
// the API Methods
|
2014-03-08 14:01:50 +00:00
|
|
|
makeNode : function(node) {
|
|
|
|
if (typeof (node) == 'undefined')
|
|
|
|
return node; // not an object
|
|
|
|
if (typeof (node.getNode) == 'function')
|
|
|
|
return node; // allready done
|
2014-03-07 21:22:01 +00:00
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
node.getNode = function(name, index) {
|
|
|
|
if (typeof (index) == 'undefined') {
|
|
|
|
index = 0;
|
|
|
|
}
|
2014-03-07 11:07:13 +00:00
|
|
|
var reply;
|
2014-03-08 14:01:50 +00:00
|
|
|
$.each(node.children, function(key, child) {
|
|
|
|
if (child.name == name && child.index == index) {
|
|
|
|
reply = props.makeNode(child);
|
2014-03-07 11:07:13 +00:00
|
|
|
}
|
|
|
|
});
|
2014-03-08 14:01:50 +00:00
|
|
|
|
|
|
|
// be a bit more graceful here...
|
|
|
|
if (typeof (reply) == 'undefined')
|
|
|
|
alert('unknown property: ' + name + ':' + index);
|
2014-03-07 11:07:13 +00:00
|
|
|
return reply;
|
2014-03-08 14:01:50 +00:00
|
|
|
};
|
2014-03-07 11:07:13 +00:00
|
|
|
return node;
|
|
|
|
}
|
2014-03-08 14:01:50 +00:00
|
|
|
};
|
2014-03-07 11:07:13 +00:00
|
|
|
|
|
|
|
var reloadProperties = function() {
|
2014-03-08 14:01:50 +00:00
|
|
|
props.load("instrumentation?d=3", function(n) {
|
|
|
|
$("#com1u").val(n.getNode("comm").getNode("frequencies").getNode("selected-mhz-fmt").value);
|
|
|
|
$("#com1s").val(n.getNode("comm").getNode("frequencies").getNode("standby-mhz-fmt").value);
|
|
|
|
$("#com2u").val(n.getNode("comm", 1).getNode("frequencies").getNode("selected-mhz-fmt").value);
|
|
|
|
$("#com2s").val(n.getNode("comm", 1).getNode("frequencies").getNode("standby-mhz-fmt").value);
|
|
|
|
$("#nav1u").val(n.getNode("nav").getNode("frequencies").getNode("selected-mhz-fmt").value);
|
|
|
|
$("#nav1s").val(n.getNode("nav").getNode("frequencies").getNode("standby-mhz-fmt").value);
|
|
|
|
$("#nav1rad").val(n.getNode("nav").getNode("radials").getNode("selected-deg").value);
|
|
|
|
$("#nav2u").val(n.getNode("nav", 1).getNode("frequencies").getNode("selected-mhz-fmt").value);
|
|
|
|
$("#nav2s").val(n.getNode("nav", 1).getNode("frequencies").getNode("standby-mhz-fmt").value);
|
|
|
|
$("#nav2rad").val(n.getNode("nav", 1).getNode("radials").getNode("selected-deg").value);
|
|
|
|
$("#adf1u").val(n.getNode("adf").getNode("frequencies").getNode("selected-khz").value);
|
|
|
|
$("#adf1s").val(n.getNode("adf").getNode("frequencies").getNode("standby-khz").value);
|
|
|
|
$("#adf1rad").val(n.getNode("adf").getNode("rotation-deg").value);
|
|
|
|
$("#dme1u").val(n.getNode("dme").getNode("frequencies").getNode("selected-mhz").value);
|
|
|
|
});
|
2014-03-07 11:07:13 +00:00
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
};
|
2014-03-07 11:07:13 +00:00
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
$("#com1swap").click(function() {
|
|
|
|
var v = $("#com1u").val();
|
|
|
|
$("#com1u").val($("#com1s").val());
|
|
|
|
$("#com1s").val(v);
|
2014-03-07 11:07:13 +00:00
|
|
|
});
|
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
$("#com2swap").click(function() {
|
|
|
|
var v = $("#com2u").val();
|
|
|
|
$("#com2u").val($("#com2s").val());
|
|
|
|
$("#com2s").val(v);
|
2014-03-07 11:07:13 +00:00
|
|
|
});
|
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
$("#nav1swap").click(function() {
|
|
|
|
var v = $("#nav1u").val();
|
|
|
|
$("#nav1u").val($("#nav1s").val());
|
|
|
|
$("#nav1s").val(v);
|
2014-03-07 11:07:13 +00:00
|
|
|
});
|
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
$("#nav2swap").click(function() {
|
|
|
|
var v = $("#nav2u").val();
|
|
|
|
$("#nav2u").val($("#nav2s").val());
|
|
|
|
$("#nav2s").val(v);
|
2014-03-07 11:07:13 +00:00
|
|
|
});
|
|
|
|
|
2014-03-08 14:01:50 +00:00
|
|
|
$("#adf1swap").click(function() {
|
|
|
|
var v = $("#adf1u").val();
|
|
|
|
$("#adf1u").val($("#adf1s").val());
|
|
|
|
$("#adf1s").val(v);
|
2014-03-07 11:07:13 +00:00
|
|
|
});
|
2014-03-08 14:01:50 +00:00
|
|
|
|
2014-03-07 11:07:13 +00:00
|
|
|
reloadProperties();
|
2014-03-08 14:01:50 +00:00
|
|
|
window.setInterval(reloadProperties, 5000);
|
2014-03-07 11:07:13 +00:00
|
|
|
});
|