2014-03-12 21:45:35 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-02-04 20:03:16 +00:00
|
|
|
(function(factory) {
|
2015-03-12 08:50:16 +00:00
|
|
|
if (typeof define === "function" && define.amd)// AMD. Register as an
|
|
|
|
// anonymous module.
|
|
|
|
define([
|
|
|
|
'jquery'
|
|
|
|
], factory);
|
|
|
|
else
|
|
|
|
// Browser globals
|
|
|
|
factory(jQuery);
|
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-11 21:30:56 +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() {
|
2015-03-11 21:30:56 +00:00
|
|
|
jquery.post("/run.cgi?value=pause");
|
2015-02-04 20:03:16 +00:00
|
|
|
},
|
2015-03-11 21:30:56 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
reset : function() {
|
2015-03-11 21:30:56 +00:00
|
|
|
jquery.post("/run.cgi?value=reset");
|
2015-02-04 20:03:16 +00:00
|
|
|
},
|
2015-03-11 21:30:56 +00:00
|
|
|
|
2015-02-04 20:03:16 +00:00
|
|
|
exit : function() {
|
2015-03-11 21:30:56 +00:00
|
|
|
jquery.post("/run.cgi?value=exit");
|
|
|
|
},
|
|
|
|
|
|
|
|
reinit : function(subsys) {
|
|
|
|
var arg = {
|
|
|
|
name : '',
|
|
|
|
children : []
|
|
|
|
};
|
2015-03-12 08:50:16 +00:00
|
|
|
if (typeof (subsys) === 'string')
|
|
|
|
arg.children.push({
|
|
|
|
name : 'subsystem',
|
|
|
|
index : 0,
|
|
|
|
value : subsys
|
|
|
|
});
|
|
|
|
else
|
2015-03-11 21:30:56 +00:00
|
|
|
subsys.forEach(function(s, i) {
|
|
|
|
arg.children.push({
|
|
|
|
name : 'subsystem',
|
|
|
|
index : i,
|
|
|
|
value : s
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.sendCommand("reinit", arg);
|
2015-02-04 20:03:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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() {
|
2015-03-11 21:30:56 +00:00
|
|
|
jquery.post("/run.cgi?value=reposition");
|
2015-02-04 20:03:16 +00:00
|
|
|
},
|
|
|
|
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-11 21:30:56 +00:00
|
|
|
|
|
|
|
requestMetar : function(id, path) {
|
|
|
|
this.sendCommand("request-metar", this.twoArgs("station", id, "path", path));
|
2015-03-10 19:38:16 +00:00
|
|
|
},
|
2015-03-11 21:30:56 +00:00
|
|
|
|
2015-03-14 21:31:31 +00:00
|
|
|
togglepause : function() {
|
|
|
|
this.sendCommand("pause");
|
|
|
|
},
|
|
|
|
|
|
|
|
unpause : function() {
|
|
|
|
this.sendCommand("pause", this.oneArg("force-play", true));
|
|
|
|
},
|
|
|
|
|
|
|
|
pause : function() {
|
|
|
|
this.sendCommand("pause", this.oneArg("force-pause", true));
|
|
|
|
},
|
|
|
|
|
2015-03-12 08:50:16 +00:00
|
|
|
multiplayerConnect : function(cmd) {
|
2015-03-11 21:30:56 +00:00
|
|
|
cmd = cmd || {};
|
|
|
|
var arg = {
|
|
|
|
'name' : '',
|
2015-03-12 08:50:16 +00:00
|
|
|
'children' : [],
|
2015-03-11 21:30:56 +00:00
|
|
|
};
|
2015-03-12 08:50:16 +00:00
|
|
|
arg.children.push({
|
|
|
|
'name' : 'servername',
|
|
|
|
'value' : cmd.servername
|
|
|
|
});
|
|
|
|
if (cmd.rxport)
|
2015-03-11 21:30:56 +00:00
|
|
|
arg.children.push({
|
|
|
|
'name' : 'rxport',
|
2015-03-12 08:50:16 +00:00
|
|
|
'value' : Number(cmd.rxport)
|
2015-03-11 21:30:56 +00:00
|
|
|
});
|
2015-03-12 08:50:16 +00:00
|
|
|
if (cmd.txport)
|
|
|
|
arg.children.push({
|
2015-03-11 21:30:56 +00:00
|
|
|
'name' : 'txport',
|
2015-03-12 08:50:16 +00:00
|
|
|
'value' : Number(cmd.txport)
|
2015-03-11 21:30:56 +00:00
|
|
|
});
|
2015-03-12 08:50:16 +00:00
|
|
|
this.sendCommand("multiplayer-connect", arg);
|
|
|
|
},
|
|
|
|
|
|
|
|
multiplayerDisconnect : function() {
|
|
|
|
var arg = {
|
|
|
|
'name' : '',
|
|
|
|
'children' : [],
|
|
|
|
};
|
|
|
|
this.sendCommand("multiplayer-disconnect");
|
|
|
|
},
|
|
|
|
|
|
|
|
multiplayerRefreshserverlist : function() {
|
|
|
|
this.sendCommand('multiplayer-refreshserverlist');
|
2015-03-11 21:30:56 +00:00
|
|
|
},
|
|
|
|
|
2015-03-10 19:38:16 +00:00
|
|
|
clearMetar : function(path) {
|
2015-03-11 21:30:56 +00:00
|
|
|
this.sendCommand("clear-metar", this.oneArg("path", path));
|
2015-03-10 19:38:16 +00:00
|
|
|
},
|
|
|
|
|
2015-03-11 21:30:56 +00:00
|
|
|
// not really commands, but very useful to get/set a single properties
|
|
|
|
// value
|
|
|
|
getPropertyValue : function(path, callback, context) {
|
|
|
|
var url = "/json/" + path;
|
2015-03-10 19:38:16 +00:00
|
|
|
|
2015-03-11 21:30:56 +00:00
|
|
|
jquery.get(url).done(function(data) {
|
|
|
|
if (context)
|
|
|
|
callback.call(context, data.value);
|
|
|
|
else
|
|
|
|
callback(data.value);
|
|
|
|
}).fail(function(a, b) {
|
|
|
|
console.log("failed to getPropertyValue(): ", a, b);
|
2015-03-10 19:38:16 +00:00
|
|
|
}).always(function() {
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-28 20:44:24 +00:00
|
|
|
setPropertyValue : function(path, value, callback, context) {
|
|
|
|
if( value == null )
|
|
|
|
return;
|
|
|
|
|
2015-03-11 21:30:56 +00:00
|
|
|
var url = "/json/" + path;
|
2015-03-28 20:44:24 +00:00
|
|
|
switch( typeof(value) ) {
|
|
|
|
case 'number':
|
|
|
|
case 'string':
|
|
|
|
case 'boolean':
|
|
|
|
jquery.post(url, JSON.stringify({
|
|
|
|
'value' : value
|
|
|
|
})).done(function(data){
|
|
|
|
if( !callback ) return;
|
|
|
|
if (context) callback.call(context, data.value);
|
|
|
|
else callback(data.value);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'object':
|
|
|
|
jquery.post(url, JSON.stringify(value)).done(function(data){
|
|
|
|
if( !callback ) return;
|
|
|
|
if (context) callback.call(context, data.value);
|
|
|
|
else callback(data.value);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2015-03-10 19:38:16 +00:00
|
|
|
},
|
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;
|
|
|
|
}));
|