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.
274 lines
6.9 KiB
274 lines
6.9 KiB
//
|
|
//
|
|
//
|
|
|
|
var interfaces = [];
|
|
|
|
//
|
|
// update or add a new element
|
|
//
|
|
function interface_Update(intdata) {
|
|
for (var i = 0; i < interfaces.length; i++) {
|
|
if (intdata.name == interfaces[i].name) {
|
|
//debug ("Update Interface:" + interfaces[i].name + "(" + interfaces[i].host + ") with Interface:" + intdata.name + "(" + intdata.host + ")");
|
|
|
|
if (!(intdata.flags & 0x0001)) sideBtnOnOffMode (3); // not connected
|
|
else if ((intdata.flags & 0x0010)) sideBtnOnOffMode (3); // programming mode
|
|
else if ((intdata.flags & 0x0008)) sideBtnOnOffMode (3); // short circuit
|
|
else if ((intdata.flags & 0x0004)) sideBtnOnOffMode (2); // stop
|
|
else if (!(intdata.flags & 0x0002)) sideBtnOnOffMode (1); // power on
|
|
else sideBtnOnOffMode (0);
|
|
|
|
interfaces[i].name = intdata.name;
|
|
interfaces[i].host = intdata.host;
|
|
interfaces[i].flags = intdata.flags;
|
|
interfaces[i].type = intdata.type;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// not found add element
|
|
//debug ("Add Interface:" + intdata.name + "(" + intdata.host + ")");
|
|
interfaces.push ({
|
|
name: intdata.name,
|
|
host: intdata.host,
|
|
flags: intdata.flags,
|
|
type: intdata.type
|
|
});
|
|
};
|
|
|
|
|
|
//
|
|
// 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 interface_Delete(name) {
|
|
var l = new Array();
|
|
|
|
for (var i = 0; i < interfaces.length; i++) {
|
|
if (name != interfaces[i].name) {
|
|
l.push (interfaces[i]);
|
|
}
|
|
}
|
|
|
|
// clear list and replace list with new data.
|
|
interfaces.lenght = 0;
|
|
interfaces = l;
|
|
};
|
|
|
|
|
|
//
|
|
// send new element to server
|
|
//
|
|
function interface_server_Add(elm) {
|
|
var request = { command: "addinterface", interface: elm };
|
|
serverinout (request, serverinout_defaultCallback);
|
|
};
|
|
|
|
|
|
//
|
|
// send delete element to server
|
|
//
|
|
function interface_server_Del(elm) {
|
|
var request = { command: "delinterface", interface: elm };
|
|
serverinout (request, serverinout_defaultCallback);
|
|
};
|
|
|
|
|
|
|
|
function intdetail_show(intname) {
|
|
var win = document.getElementById("intdetail");
|
|
|
|
debug ("intdetail_show");
|
|
|
|
if (!win) {
|
|
debug ("intdetail_show create window");
|
|
win = gWindowCreate("intdetail", "Interface", 400, 300, " \
|
|
<div style=\"float: left\"> \
|
|
Interface Name: <input id=\"intdet_name\" style=\"width: 100\"> \
|
|
</div> <div style=\"float: right\"> \
|
|
<button id=\"intdet_PREV\"><</button> \
|
|
<button id=\"intdet_NEXT\">></button> \
|
|
</div> <br> <hr>\
|
|
<div> \
|
|
<table><tr><td><table>\
|
|
<tr><td>Host:</td><td><input id=\"intdet_host\" style=\"width: 200\"></td></tr> \
|
|
<tr><td>Flags:</td><td><input id=\"intdet_flags\" style=\"width: 50\"></td></tr> \
|
|
</table></td><td> \
|
|
<fieldset><legend>Type</legend> \
|
|
Type: <input id=\"intdet_type\" style=\"width: 25\"><br> \
|
|
<label><input type=\"radio\" id=\"intdet_typeunknown\" name=\"Type\" value=\"0\">Unkown</label><br> \
|
|
<label><input type=\"radio\" id=\"intdet_typez21\" name=\"Type\" value=\"1\">Z21</label><br> \
|
|
</fieldset> \
|
|
</td></tr></table> </div> <hr>\
|
|
<div align=right> \
|
|
<button id=\"intdet_SAVE\" type=\"button\">Save</button> \
|
|
<button id=\"intdet_DELETE\" type=\"button\">Delete</button> \
|
|
<button id=\"intdet_CLOSE\">Close</button> \
|
|
</div> \
|
|
\
|
|
");
|
|
|
|
gAddEventListener("intdet_type", 'change', intdetail_cb_typechange);
|
|
gAddEventListener("intdet_typeunknown", 'click', intdetail_cb_typeselector);
|
|
gAddEventListener("intdet_typez21", 'click', intdetail_cb_typeselector);
|
|
|
|
|
|
gAddEventListener("intdet_CLOSE", 'click', intdetail_cb_close);
|
|
gAddEventListener("intdet_DELETE", 'click', intdetail_cb_delete);
|
|
gAddEventListener("intdet_SAVE", 'click', intdetail_cb_save);
|
|
|
|
gAddEventListener("intdet_NEXT", 'click', intdetail_cb_next);
|
|
gAddEventListener("intdet_PREV", 'click', intdetail_cb_prev);
|
|
}
|
|
|
|
if (intname) {
|
|
for (var i = 0; i < interfaces.length; i++) {
|
|
if (intname == interfaces[i].name) intdetail_setData(interfaces[i]);
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
function intdetail_cb_close () {
|
|
var win = document.getElementById("intdetail");
|
|
|
|
if (win) document.body.removeChild(win);
|
|
};
|
|
|
|
|
|
//
|
|
// Callback: Delete Button
|
|
//
|
|
function intdetail_cb_delete () {
|
|
var elm = {};
|
|
|
|
elm = intdetail_getData();
|
|
interface_Delete(elm.name);
|
|
interface_server_Del(elm);
|
|
};
|
|
|
|
|
|
//
|
|
// Callback: Save Button
|
|
//
|
|
function intdetail_cb_save () {
|
|
var elm = {};
|
|
|
|
elm = intdetail_getData();
|
|
interface_Update(elm);
|
|
interface_server_Add(elm);
|
|
};
|
|
|
|
|
|
//
|
|
// Callback: Next Button
|
|
//
|
|
function intdetail_cb_next () {
|
|
var cursel = -1;
|
|
var if_name = document.getElementById("intdet_name");
|
|
|
|
for (var i = 0; i < interfaces.length; i++) {
|
|
if (if_name.value == interfaces[i].name) cursel = i;
|
|
}
|
|
|
|
cursel = cursel + 1;
|
|
if (cursel >= interfaces.length) cursel = 0;
|
|
if (cursel < 0) cursel = 0;
|
|
|
|
for (var i = 0; i < interfaces.length; i++) {
|
|
if (i == cursel) intdetail_setData(interfaces[i]);
|
|
}
|
|
|
|
// debug ("Cursel: " + cursel + " interfaces.lenght:" + interfaces.length);
|
|
};
|
|
|
|
|
|
//
|
|
// Callback: Prev Button
|
|
//
|
|
function intdetail_cb_prev () {
|
|
var cursel = -1;
|
|
var if_name = document.getElementById("intdet_name");
|
|
|
|
|
|
for (var i = 0; i < interfaces.length; i++) {
|
|
if (if_name.value == interfaces[i].name) cursel = i;
|
|
}
|
|
|
|
cursel = cursel - 1;
|
|
if (cursel < 0 || cursel >= interfaces.length) cursel = interfaces.length - 1;
|
|
|
|
for (var i = 0; i < interfaces.length; i++) {
|
|
if (i == cursel) intdetail_setData(interfaces[i]);
|
|
}
|
|
|
|
// debug ("Cursel: " + cursel + " interfaces.lenght:" + interfaces.length);
|
|
};
|
|
|
|
|
|
//
|
|
// fill out all the elements on the dialogbox
|
|
//
|
|
function intdetail_setData(elm) {
|
|
var if_name = document.getElementById("intdet_name");
|
|
var if_host = document.getElementById("intdet_host");
|
|
var if_flags = document.getElementById("intdet_flags");
|
|
var if_type = document.getElementById("intdet_type");
|
|
|
|
if (elm) {
|
|
if (if_name) if_name.value = elm.name;
|
|
if (if_host) if_host.value = elm.host;
|
|
if (if_flags) if_flags.value = elm.flags;
|
|
if (if_flags) if_type.value = elm.type;
|
|
}
|
|
|
|
intdetail_cb_typechange();
|
|
};
|
|
|
|
|
|
function intdetail_cb_typechange () {
|
|
var type = document.getElementById("intdet_type");
|
|
var typez21 = document.getElementById("intdet_typez21");
|
|
var typeunknown = document.getElementById("intdet_typeunknown");
|
|
|
|
switch(Number(type.value)) {
|
|
case 0: typeunknown.checked = true; break;
|
|
case 1: typez21.checked = true; break;
|
|
default:
|
|
type.value = 0;
|
|
typeunknown.checked = true;
|
|
break;
|
|
}
|
|
};
|
|
|
|
|
|
function intdetail_cb_typeselector () {
|
|
var type = document.getElementById("intdet_type");
|
|
|
|
type.value = this.value;
|
|
};
|
|
|
|
|
|
|
|
|
|
//
|
|
// return all elements from the dialogbox
|
|
//
|
|
function intdetail_getData() {
|
|
var res = { name: "", host: "", flags:0, type:0 };
|
|
var if_name = document.getElementById("intdet_name");
|
|
var if_host = document.getElementById("intdet_host");
|
|
var if_flags = document.getElementById("intdet_flags");
|
|
var if_type = document.getElementById("intdet_type");
|
|
|
|
if (if_name) res.name = if_name.value;
|
|
if (if_host) res.host = if_host.value;
|
|
if (if_flags) res.flags = if_flags.value;
|
|
if (if_type) res.type = if_type.value;
|
|
|
|
return res;
|
|
};
|
|
|