From 32cbf424f1ec73b56cd9b449f4f5e1f136507435 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Tue, 10 Mar 2015 20:38:16 +0100 Subject: [PATCH] fgcommand.js: better reference to jQuery and property get/set --- webgui/lib/fgcommand.js | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/webgui/lib/fgcommand.js b/webgui/lib/fgcommand.js index 892300122..6f65daaf2 100644 --- a/webgui/lib/fgcommand.js +++ b/webgui/lib/fgcommand.js @@ -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;