You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
361 lines
11 KiB
361 lines
11 KiB
//
|
|
//
|
|
//
|
|
|
|
|
|
var locomotives = [];
|
|
|
|
|
|
//
|
|
// update or add a new element
|
|
//
|
|
function locomotive_Update(data) {
|
|
for (var i = 0; i < locomotives.length; i++) {
|
|
if (data.name == locomotives[i].name) {
|
|
debug ("Update Locomotive:" + locomotives[i].name + " with Locomotive:" + data.name);
|
|
locomotives[i].name = data.name;
|
|
locomotives[i].ifname = data.ifname;
|
|
locomotives[i].addr = data.addr;
|
|
locomotives[i].steps = data.steps;
|
|
locomotives[i].speed = data.speed;
|
|
locomotives[i].vmin = data.vmin;
|
|
locomotives[i].vslow = data.vslow;
|
|
locomotives[i].vmid = data.vmid;
|
|
locomotives[i].vfast = data.vfast;
|
|
locomotives[i].vmax = data.vmax;
|
|
locomotives[i].flags = data.flags;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// not found add element
|
|
debug ("Add Locomotive:" + data.name);
|
|
locomotives.push ({
|
|
name: data.name,
|
|
ifname: data.ifname,
|
|
addr: data.addr,
|
|
steps: data.steps,
|
|
vmin: data.vmin,
|
|
vslow: data.vslow,
|
|
speed: data.speed,
|
|
vmid: data.vmid,
|
|
vfast: data.vfast,
|
|
vmax: data.vmax,
|
|
flags: data.flags
|
|
});
|
|
};
|
|
|
|
|
|
//
|
|
// delete element from the list
|
|
// in arrays we can not delete just an element, so we create a new one
|
|
// and replace this one.
|
|
//
|
|
function locomotive_Delete(name) {
|
|
var l = new Array();
|
|
|
|
for (var i = 0; i < locomotives.length; i++) {
|
|
if (name != locomotives[i].name) {
|
|
l.push (locomotives[i]);
|
|
}
|
|
}
|
|
|
|
// clear list and replace list with new data.
|
|
locomotives.lenght = 0;
|
|
locomotives = l;
|
|
};
|
|
|
|
|
|
//
|
|
// send new element to server
|
|
//
|
|
function locomotive_server_Add(elm) {
|
|
var request = { command: "addlocomotive", locomotive: elm };
|
|
serverinout (request, serverinout_defaultCallback);
|
|
};
|
|
|
|
|
|
//
|
|
// send delete element to server
|
|
//
|
|
function locomotive_server_Del(elm) {
|
|
var request = { command: "dellocomotive", locomotive: elm };
|
|
serverinout (request, serverinout_defaultCallback);
|
|
};
|
|
|
|
|
|
//
|
|
// send delete element to server
|
|
//
|
|
function locomotive_server_Set(elm) {
|
|
var request = { command: "setlocomotive", locomotive: elm };
|
|
serverinout (request, serverinout_defaultCallback);
|
|
};
|
|
|
|
|
|
|
|
function locodetail_show(loconame) {
|
|
var win = document.getElementById("locodetail");
|
|
|
|
debug ("locodetail_show");
|
|
|
|
if (!win) {
|
|
debug ("loco_showdetail create window");
|
|
win = gWindowCreate("locodetail", "Locomotive", 400, 500, " \
|
|
<div style=\"float: left\"> \
|
|
Name: <input id=\"locodet_name\" style=\"width: 100\"> \
|
|
</div> <div style=\"float: right\"> \
|
|
<button id=\"locodet_PREV\"><</button> \
|
|
<button id=\"locodet_NEXT\">></button> \
|
|
</div> <br> <hr>\
|
|
<div> \
|
|
Interface: <input id=\"locodet_ifname\" style=\"width: 50\"> \
|
|
Adress: <input id=\"locodet_addr\" style=\"width: 50\"> \
|
|
Flags: <input id=\"locodet_flags\" style=\"width: 50\"> \
|
|
</div> <hr>\
|
|
<div> <table><tr><td> \
|
|
<fieldset><legend>Speed</legend> <table>\
|
|
<tr><td></td><td>Stop</td><td><button id=\"locodet_btnvstop\" type=\"button\" value=\"vstop\">X</button> </td></tr>\
|
|
<tr><td>Vmin:</td><td><input id=\"locodet_vmin\" style=\"width: 50\"></td><td><button id=\"locodet_btnvmin\" type=\"button\" value=\"vmin\">X</button> </td></tr>\
|
|
<tr><td>Vslow:</td><td><input id=\"locodet_vslow\" style=\"width: 50\"></td><td><button id=\"locodet_btnvslow\" type=\"button\" value=\"vslow\">X</button> </td></tr> \
|
|
<tr><td>Vmid:</td><td><input id=\"locodet_vmid\" style=\"width: 50\"></td><td><button id=\"locodet_btnvmid\" type=\"button\" value=\"vmid\">X</button> </td></tr> \
|
|
<tr><td>Vfast:</td><td><input id=\"locodet_vfast\" style=\"width: 50\"></td><td><button id=\"locodet_btnvfast\" type=\"button\" value=\"vfast\">X</button> </td></tr> \
|
|
<tr><td>Vmax:</td><td><input id=\"locodet_vmax\" style=\"width: 50\"></td><td><button id=\"locodet_btnvmax\" type=\"button\" value=\"vmax\">X</button> </td></tr> \
|
|
</table></td></fieldset> \
|
|
<td> \
|
|
Steps: <input id=\"locodet_steps\" style=\"width: 50\"><br> \
|
|
Speed: <input id=\"locodet_speed\" style=\"width: 50\"><br> \
|
|
<label><input id=\"locodet_reverse\" type=\"checkbox\" value=\"\"> Reverse</label> \
|
|
</td></tr></table></div> <hr>\
|
|
<div align=right> \
|
|
<button id=\"locodet_SAVE\" type=\"button\">Save</button> \
|
|
<button id=\"locodet_DELETE\" type=\"button\">Delete</button> \
|
|
<button id=\"locodet_CLOSE\" type=\"button\">Close</button> \
|
|
</div> \
|
|
\
|
|
");
|
|
|
|
gAddEventListener("locodet_btnvstop", 'click', locodetail_cb_btnmove);
|
|
gAddEventListener("locodet_btnvmin", 'click', locodetail_cb_btnmove);
|
|
gAddEventListener("locodet_btnvslow", 'click', locodetail_cb_btnmove);
|
|
gAddEventListener("locodet_btnvmid", 'click', locodetail_cb_btnmove);
|
|
gAddEventListener("locodet_btnvfast", 'click', locodetail_cb_btnmove);
|
|
gAddEventListener("locodet_btnvmax", 'click', locodetail_cb_btnmove);
|
|
gAddEventListener("locodet_reverse", 'click', locodetail_cb_reverse);
|
|
|
|
gAddEventListener("locodet_CLOSE", 'click', locodetail_cb_close);
|
|
gAddEventListener("locodet_DELETE", 'click', locodetail_cb_delete);
|
|
gAddEventListener("locodet_SAVE", 'click', locodetail_cb_save);
|
|
|
|
gAddEventListener("locodet_NEXT", 'click', locodetail_cb_next);
|
|
gAddEventListener("locodet_PREV", 'click', locodetail_cb_prev);
|
|
}
|
|
|
|
//
|
|
// load default values
|
|
var res = { name: "", ifname: "", addr: "", flags: 0, steps: "",
|
|
vmin: "20", vslow: "40", vmid:"60", vfast:"80", vmax:"100" };
|
|
locodetail_setData(res);
|
|
|
|
if (loconame) {
|
|
for (var i = 0; i < locomotives.length; i++) {
|
|
if (loconame == locomotives[i].name) locodetail_setData(locomotives[i]);
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
|
|
//
|
|
// reverse selected, setup flags
|
|
function locodetail_cb_reverse () {
|
|
var cbreverse = document.getElementById("locodet_reverse");
|
|
var flags = document.getElementById("locodet_flags");
|
|
|
|
if (cbreverse.checked) {
|
|
flags.value = Number(flags.value) | 1;
|
|
}
|
|
|
|
else {
|
|
flags.value = Number(flags.value) & (0xFFFF-1);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
function locodetail_cb_btnmove () {
|
|
var win = document.getElementById("locodetail");
|
|
var loco_name = document.getElementById("locodet_name");
|
|
var loco_vmin = document.getElementById("locodet_vmin");
|
|
var loco_vslow = document.getElementById("locodet_vslow");
|
|
var loco_vmid = document.getElementById("locodet_vmid");
|
|
var loco_vfast = document.getElementById("locodet_vfast");
|
|
var loco_vmax = document.getElementById("locodet_vmax");
|
|
var loco_reverse = document.getElementById("locodet_reverse");
|
|
|
|
var speed = 0;
|
|
|
|
if (this.value == "vmin") speed = Number(loco_vmin.value);
|
|
if (this.value == "vslow") speed = Number(loco_vslow.value);
|
|
if (this.value == "vmid") speed = Number(loco_vmid.value);
|
|
if (this.value == "vfast") speed = Number(loco_vfast.value);
|
|
if (this.value == "vmax") speed = Number(loco_vmax.value);
|
|
|
|
if (loco_reverse.checked) {
|
|
speed = 0 - speed;
|
|
}
|
|
|
|
locomotive_server_Set ({name: loco_name.value, speed: speed});
|
|
debug ("Locomotive: '" + loco_name.value +"' Speed: " + speed);
|
|
};
|
|
|
|
|
|
function locodetail_cb_close () {
|
|
var win = document.getElementById("locodetail");
|
|
|
|
if (win) document.body.removeChild(win);
|
|
};
|
|
|
|
//
|
|
// Callback: Delete Button
|
|
//
|
|
function locodetail_cb_delete () {
|
|
var elm = {};
|
|
|
|
elm = locodetail_getData();
|
|
locomotive_Delete(elm.name);
|
|
locomotive_server_Del(elm);
|
|
};
|
|
|
|
|
|
//
|
|
// Callback: Save Button
|
|
//
|
|
function locodetail_cb_save () {
|
|
var elm = {};
|
|
|
|
elm = locodetail_getData();
|
|
locomotive_Update(elm);
|
|
locomotive_server_Add(elm);
|
|
};
|
|
|
|
|
|
//
|
|
// Callback: Next Button
|
|
//
|
|
function locodetail_cb_next () {
|
|
var cursel = -1;
|
|
var loconame = document.getElementById("locodet_name");
|
|
|
|
for (var i = 0; i < locomotives.length; i++) {
|
|
if (loconame.value == locomotives[i].name) cursel = i;
|
|
}
|
|
|
|
cursel = cursel + 1;
|
|
if (cursel >= locomotives.length) cursel = 0;
|
|
if (cursel < 0) cursel = 0;
|
|
|
|
for (var i = 0; i < locomotives.length; i++) {
|
|
if (i == cursel) locodetail_setData(locomotives[i]);
|
|
}
|
|
|
|
debug ("Cursel: " + cursel + " locomotives.lenght:" + locomotives.length);
|
|
};
|
|
|
|
|
|
//
|
|
// Callback: Prev Button
|
|
//
|
|
function locodetail_cb_prev () {
|
|
var cursel = -1;
|
|
var loconame = document.getElementById("locodet_name");
|
|
|
|
|
|
for (var i = 0; i < locomotives.length; i++) {
|
|
if (loconame.value == locomotives[i].name) cursel = i;
|
|
}
|
|
|
|
cursel = cursel - 1;
|
|
if (cursel < 0 || cursel >= locomotives.length) cursel = locomotives.length - 1;
|
|
|
|
for (var i = 0; i < locomotives.length; i++) {
|
|
if (i == cursel) locodetail_setData(locomotives[i]);
|
|
}
|
|
|
|
debug ("Cursel: " + cursel + " locomotives.lenght:" + locomotives.length);
|
|
};
|
|
|
|
|
|
//
|
|
// fill out all the elements on the dialogbox
|
|
//
|
|
function locodetail_setData(elm) {
|
|
var loco_name = document.getElementById("locodet_name");
|
|
var loco_ifname = document.getElementById("locodet_ifname");
|
|
var loco_addr = document.getElementById("locodet_addr");
|
|
var loco_speed = document.getElementById("locodet_speed");
|
|
var loco_flags = document.getElementById("locodet_flags");
|
|
var loco_steps = document.getElementById("locodet_steps");
|
|
var loco_vmin = document.getElementById("locodet_vmin");
|
|
var loco_vslow = document.getElementById("locodet_vslow");
|
|
var loco_vmid = document.getElementById("locodet_vmid");
|
|
var loco_vfast = document.getElementById("locodet_vfast");
|
|
var loco_vmax = document.getElementById("locodet_vmax");
|
|
var loco_reverse = document.getElementById("locodet_reverse");
|
|
|
|
if (elm) {
|
|
if (loco_name) loco_name.value = elm.name;
|
|
if (loco_ifname) loco_ifname.value = elm.ifname;
|
|
if (loco_flags) loco_flags.value = elm.flags;
|
|
if (loco_addr) loco_addr.value = elm.addr;
|
|
if (loco_speed) loco_speed.value = elm.speed;
|
|
if (loco_steps) loco_steps.value = elm.steps;
|
|
if (loco_vmin) loco_vmin.value = elm.vmin;
|
|
if (loco_vslow) loco_vslow.value = elm.vslow;
|
|
if (loco_vmid) loco_vmid.value = elm.vmid;
|
|
if (loco_vfast) loco_vfast.value = elm.vfast;
|
|
if (loco_vmax) loco_vmax.value = elm.vmax;
|
|
if (loco_reverse) {
|
|
if (Number(elm.flags) & 1) loco_reverse.checked = true;
|
|
else loco_reverse.checked = false;
|
|
}
|
|
|
|
}
|
|
};
|
|
|
|
|
|
|
|
//
|
|
// return all elements from the dialogbox
|
|
//
|
|
function locodetail_getData() {
|
|
var res = { name: "", ifname: "", addr: "", flags: 0, steps: "",
|
|
vmin: "20", vslow: "40", vmid:"60", vfast:"80", vmax:"100" };
|
|
|
|
var loco_name = document.getElementById("locodet_name");
|
|
var loco_ifname = document.getElementById("locodet_ifname");
|
|
var loco_flags = document.getElementById("locodet_flags");
|
|
var loco_addr = document.getElementById("locodet_addr");
|
|
var loco_steps = document.getElementById("locodet_steps");
|
|
var loco_vmin = document.getElementById("locodet_vmin");
|
|
var loco_vslow = document.getElementById("locodet_vslow");
|
|
var loco_vmid = document.getElementById("locodet_vmid");
|
|
var loco_vfast = document.getElementById("locodet_vfast");
|
|
var loco_vmax = document.getElementById("locodet_vmax");
|
|
|
|
if (loco_name) res.name = loco_name.value;
|
|
if (loco_ifname) res.ifname = loco_ifname.value;
|
|
if (loco_flags) res.flags = loco_flags.value;
|
|
if (loco_addr) res.addr = loco_addr.value;
|
|
if (loco_steps) res.steps = loco_steps.value;
|
|
if (loco_vmin) res.vmin = loco_vmin.value;
|
|
if (loco_vslow) res.vslow = loco_vslow.value;
|
|
if (loco_vmid) res.vmid = loco_vmid.value;
|
|
if (loco_vfast) res.vfast = loco_vfast.value;
|
|
if (loco_vmax) res.vmax = loco_vmax.value;
|
|
|
|
return res;
|
|
};
|
|
|