2014-03-12 21:45:35 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-02-04 20:03:16 +00:00
|
|
|
(function(factory) {
|
|
|
|
if (typeof define === "function" && define.amd) {
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-03-10 19:38:16 +00:00
|
|
|
define(['jquery'], factory);
|
2015-02-04 20:03:16 +00:00
|
|
|
} else {
|
|
|
|
// Browser globals
|
2015-03-10 19:38:16 +00:00
|
|
|
factory(jquery);
|
2015-02-04 20:03:16 +00:00
|
|
|
}
|
2015-03-10 19:38:16 +00:00
|
|
|
}(function(jquery) {
|
2014-03-12 21:45:35 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
fgCommand = {
|
|
|
|
oneArg : function(t1, p1) {
|
|
|
|
return {
|
|
|
|
name : '',
|
|
|
|
children : [
|
|
|
|
{
|
|
|
|
name : t1,
|
|
|
|
index : 0,
|
|
|
|
value : p1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
|
|
|
twoArgs : function(t1, p1, t2, p2) {
|
|
|
|
return {
|
|
|
|
name : '',
|
|
|
|
children : [
|
|
|
|
{
|
|
|
|
name : t1,
|
|
|
|
index : 0,
|
|
|
|
value : p1
|
|
|
|
}, {
|
|
|
|
name : t2,
|
|
|
|
index : (t1 == t2 ? 1 : 0),
|
|
|
|
value : p2
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
2014-03-12 21:45:35 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
twoPropsArgs : function(p1, p2) {
|
|
|
|
return this.twoArgs("property", p1, "property", p2);
|
|
|
|
},
|
2014-03-12 21:45:35 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
propValueArgs : function(p, v) {
|
|
|
|
return this.twoArgs("property", p, "value", v);
|
|
|
|
},
|
2014-03-12 21:45:35 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
sendCommand : function(name, args) {
|
|
|
|
if (typeof (args) == 'undefined ')
|
2015-03-10 19:38:16 +00:00
|
|
|
jquery.post("/run.cgi?value=" + name);
|
2015-02-04 20:03:16 +00:00
|
|
|
else
|
2015-03-10 19:38:16 +00:00
|
|
|
jquery$.post("/run.cgi?value=" + name, JSON.stringify(args));
|
2015-02-04 20:03:16 +00:00
|
|
|
},
|
2014-03-12 21:45:35 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
propertySwap : function(p1, p2) {
|
|
|
|
this.sendCommand("property-swap", this.twoPropsArgs(p1, p2));
|
|
|
|
},
|
2014-03-12 21:45:35 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
propertyAssign : function(p1, value) {
|
|
|
|
this.sendCommand("property-assign", this.propValueArgs(p1, value));
|
|
|
|
},
|
2014-11-10 09:52:10 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
pause : function() {
|
|
|
|
$.post("/run.cgi?value=pause");
|
|
|
|
},
|
|
|
|
|
|
|
|
reset : function() {
|
|
|
|
$.post("/run.cgi?value=reset");
|
|
|
|
},
|
|
|
|
|
|
|
|
exit : function() {
|
|
|
|
$.post("/run.cgi?value=exit");
|
|
|
|
},
|
|
|
|
|
|
|
|
dialogShow : function(dlg) {
|
|
|
|
this.sendCommand("dialog-show", this.oneArg("dialog-name", dlg));
|
|
|
|
},
|
|
|
|
dialogClose : function(dlg) {
|
|
|
|
this.sendCommand("dialog-close", this.oneArg("dialog-name", dlg));
|
|
|
|
},
|
|
|
|
reposition : function() {
|
|
|
|
$.post("/run.cgi?value=reposition");
|
|
|
|
},
|
|
|
|
timeofday : function(type, offset) {
|
|
|
|
this.sendCommand("timeofday", this.twoArgs("timeofday", type, "offset", null != offset ? offset : 0));
|
2015-02-17 11:05:02 +00:00
|
|
|
},
|
|
|
|
switchAircraft : function(id) {
|
|
|
|
this.sendCommand("switch-aircraft", this.oneArg("aircraft", id));
|
|
|
|
},
|
2015-03-10 19:38:16 +00:00
|
|
|
requestMetar : function(id,path) {
|
|
|
|
this.sendCommand("request-metar", this.twoArgs("station", id, "path", path ));
|
|
|
|
},
|
|
|
|
clearMetar : function(path) {
|
|
|
|
this.sendCommand("clear-metar", this.oneArg( "path", path ));
|
|
|
|
},
|
|
|
|
|
|
|
|
// not really commands, but very useful to get/set a single properties value
|
|
|
|
getPropertyValue: function(path,callback,context) {
|
|
|
|
var url = "/json/" + path;
|
|
|
|
|
|
|
|
jquery.get(url).done(function(data) {
|
|
|
|
if( context ) callback.call( context, data.value );
|
2015-03-10 21:44:20 +00:00
|
|
|
else callback(data.value);
|
2015-03-10 19:38:16 +00:00
|
|
|
}).fail(function(a,b) {
|
|
|
|
console.log("failed to getPropertyValue(): ", a, b );
|
|
|
|
}).always(function() {
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setPropertyValue: function(path,value) {
|
|
|
|
var url = "/json/" + path;
|
|
|
|
jquery.post(url, JSON.stringify({
|
|
|
|
'value' : value
|
|
|
|
}));
|
|
|
|
},
|
2015-02-04 20:03:16 +00:00
|
|
|
};
|
2014-03-12 21:45:35 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
return fgCommand;
|
|
|
|
}));
|