1
0
Fork 0

fgcommand.js: better reference to jQuery and property get/set

This commit is contained in:
Torsten Dreyer 2015-03-10 20:38:16 +01:00
parent 2f0dc41bc9
commit 32cbf424f1

View file

@ -4,12 +4,12 @@
(function(factory) {
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
factory(jquery);
}
}(function(arg) {
}(function(jquery) {
fgCommand = {
oneArg : function(t1, p1) {
@ -51,10 +51,9 @@
sendCommand : function(name, args) {
if (typeof (args) == 'undefined ')
$.post("/run.cgi?value=" + name);
jquery.post("/run.cgi?value=" + name);
else
$.post("/run.cgi?value=" + name, JSON.stringify(args));
jquery$.post("/run.cgi?value=" + name, JSON.stringify(args));
},
propertySwap : function(p1, p2) {
@ -92,6 +91,32 @@
switchAircraft : function(id) {
this.sendCommand("switch-aircraft", this.oneArg("aircraft", id));
},
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 );
else callback(value);
}).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
}));
},
};
return fgCommand;