fgcommand.js: better reference to jQuery and property get/set
This commit is contained in:
parent
2f0dc41bc9
commit
32cbf424f1
1 changed files with 31 additions and 6 deletions
|
@ -4,12 +4,12 @@
|
||||||
(function(factory) {
|
(function(factory) {
|
||||||
if (typeof define === "function" && define.amd) {
|
if (typeof define === "function" && define.amd) {
|
||||||
// AMD. Register as an anonymous module.
|
// AMD. Register as an anonymous module.
|
||||||
define([], factory);
|
define(['jquery'], factory);
|
||||||
} else {
|
} else {
|
||||||
// Browser globals
|
// Browser globals
|
||||||
factory(jQuery);
|
factory(jquery);
|
||||||
}
|
}
|
||||||
}(function(arg) {
|
}(function(jquery) {
|
||||||
|
|
||||||
fgCommand = {
|
fgCommand = {
|
||||||
oneArg : function(t1, p1) {
|
oneArg : function(t1, p1) {
|
||||||
|
@ -51,10 +51,9 @@
|
||||||
|
|
||||||
sendCommand : function(name, args) {
|
sendCommand : function(name, args) {
|
||||||
if (typeof (args) == 'undefined ')
|
if (typeof (args) == 'undefined ')
|
||||||
$.post("/run.cgi?value=" + name);
|
jquery.post("/run.cgi?value=" + name);
|
||||||
else
|
else
|
||||||
$.post("/run.cgi?value=" + name, JSON.stringify(args));
|
jquery$.post("/run.cgi?value=" + name, JSON.stringify(args));
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
propertySwap : function(p1, p2) {
|
propertySwap : function(p1, p2) {
|
||||||
|
@ -92,6 +91,32 @@
|
||||||
switchAircraft : function(id) {
|
switchAircraft : function(id) {
|
||||||
this.sendCommand("switch-aircraft", this.oneArg("aircraft", 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;
|
return fgCommand;
|
||||||
|
|
Loading…
Add table
Reference in a new issue