1005 lines
42 KiB
JavaScript
1005 lines
42 KiB
JavaScript
$(document).ready(function() {
|
|
console.log("index page loaded");
|
|
send_data(JSON.stringify({request: "GET_CONTACT_SETUP"}));
|
|
|
|
let $c1Index = $('#c1Index');
|
|
let $c2Index = $('#c2Index');
|
|
let $c3Index = $('#c3Index');
|
|
let $c4Index = $('#c4Index');
|
|
let $c5Index = $('#c5Index');
|
|
let $c6Index = $('#c6Index');
|
|
let $c7Index = $('#c7Index');
|
|
let $c8Index = $('#c8Index');
|
|
|
|
// Events for Contact Description clicks
|
|
// for changing contact Description
|
|
let $c1Description = $('#c1Description');
|
|
$c1Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 1:", $c1Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription!== $c1Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c1", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c1", description: newDescription}}));
|
|
$c1Description.text(newDescription);
|
|
}
|
|
|
|
}
|
|
});
|
|
let $c2Description = $('#c2Description');
|
|
$c2Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 2:", $c2Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription !== $c2Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c2", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c2", description: newDescription}}));
|
|
$c2Description.text(newDescription);
|
|
}
|
|
}
|
|
});
|
|
let $c3Description = $('#c3Description');
|
|
$c3Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 3:", $c3Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription !== $c3Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c3", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c3", description: newDescription}}));
|
|
$c3Description.text(newDescription);
|
|
}
|
|
}
|
|
});
|
|
let $c4Description = $('#c4Description');
|
|
$c4Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 4:", $c4Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription !== $c4Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c4", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c4", description: newDescription}}));
|
|
$c4Description.text(newDescription);
|
|
}
|
|
}
|
|
});
|
|
let $c5Description = $('#c5Description');
|
|
$c5Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 5:", $c5Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription !== $c5Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c5", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c5", description: newDescription}}));
|
|
$c5Description.text(newDescription);
|
|
}
|
|
}
|
|
});
|
|
let $c6Description = $('#c6Description');
|
|
$c6Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 6:", $c6Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription !== $c6Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c6", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c6", description: newDescription}}));
|
|
$c6Description.text(newDescription);
|
|
}
|
|
}
|
|
});
|
|
|
|
let $c7Description = $('#c7Description');
|
|
$c7Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 7:", $c7Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription !== $c7Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c7", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c7", description: newDescription}}));
|
|
$c7Description.text(newDescription);
|
|
}
|
|
}
|
|
});
|
|
let $c8Description = $('#c8Description');
|
|
$c8Description.on('dblclick', () => {
|
|
let newDescription = prompt("Enter Description for Contact 8:", $c8Description.text());
|
|
if (ValidString(newDescription)) {
|
|
if (newDescription !== $c8Description.text()) {
|
|
// Send the new description to the server
|
|
// Example: send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", contact: "c8", description: newDescription}));
|
|
send_data(JSON.stringify({request: "SET_CONTACT_DESCRIPTION", args: {contact: "c8", description: newDescription}}));
|
|
$c8Description.text(newDescription);
|
|
}
|
|
}
|
|
});
|
|
|
|
let $c1Email = $('#c1Email');
|
|
$c1Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c1", email: result}}));
|
|
$c1Email.text(result);
|
|
})
|
|
});
|
|
let $c2Email = $('#c2Email');
|
|
$c2Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c2", email: result}}));
|
|
$c2Email.text(result);
|
|
})
|
|
});
|
|
let $c3Email = $('#c3Email');
|
|
$c3Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c3", email: result}}));
|
|
$c3Email.text(result);
|
|
})
|
|
});
|
|
let $c4Email = $('#c4Email');
|
|
$c4Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c4", email: result}}));
|
|
$c4Email.text(result);
|
|
})
|
|
});
|
|
let $c5Email = $('#c5Email');
|
|
$c5Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c5", email: result}}));
|
|
$c5Email.text(result);
|
|
})
|
|
});
|
|
let $c6Email = $('#c6Email');
|
|
$c6Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c6", email: result}}));
|
|
$c6Email.text(result);
|
|
})
|
|
});
|
|
let $c7Email = $('#c7Email');
|
|
$c7Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c7", email: result}}));
|
|
$c7Email.text(result);
|
|
})
|
|
});
|
|
let $c8Email = $('#c8Email');
|
|
$c8Email.on('dblclick', () => {
|
|
ShowModal('emailModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_EMAIL", args: {contact: "c8", email: result}}));
|
|
$c8Email.text(result);
|
|
})
|
|
});
|
|
|
|
let $c1Modbus = $('#c1Modbus');
|
|
$c1Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c1", modbus: result}}));
|
|
$c1Modbus.text(result);
|
|
})
|
|
});
|
|
let $c2Modbus = $('#c2Modbus');
|
|
$c2Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c2", modbus: result}}));
|
|
$c2Modbus.text(result);
|
|
})
|
|
});
|
|
let $c3Modbus = $('#c3Modbus');
|
|
$c3Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c3", modbus: result}}));
|
|
$c3Modbus.text(result);
|
|
})
|
|
});
|
|
let $c4Modbus = $('#c4Modbus');
|
|
$c4Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c4", modbus: result}}));
|
|
$c4Modbus.text(result);
|
|
})
|
|
});
|
|
let $c5Modbus = $('#c5Modbus');
|
|
$c5Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c5", modbus: result}}));
|
|
$c5Modbus.text(result);
|
|
})
|
|
});
|
|
let $c6Modbus = $('#c6Modbus');
|
|
$c6Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c6", modbus: result}}));
|
|
$c6Modbus.text(result);
|
|
})
|
|
});
|
|
let $c7Modbus = $('#c7Modbus');
|
|
$c7Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c7", modbus: result}}));
|
|
$c7Modbus.text(result);
|
|
})
|
|
});
|
|
let $c8Modbus = $('#c8Modbus');
|
|
$c8Modbus.on('dblclick', () => {
|
|
ShowModal('modbusModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MODBUS", args: {contact: "c8", modbus: result}}));
|
|
$c8Modbus.text(result);
|
|
})
|
|
});
|
|
|
|
let $c1VX3K = $('#c1VX3K');
|
|
$c1VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c1", vx3k: result}}));
|
|
$c1VX3K.text(result);
|
|
})
|
|
});
|
|
let $c2VX3K = $('#c2VX3K');
|
|
$c2VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c2", vx3k: result}}));
|
|
$c2VX3K.text(result);
|
|
})
|
|
});
|
|
let $c3VX3K = $('#c3VX3K');
|
|
$c3VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c3", vx3k: result}}));
|
|
$c3VX3K.text(result);
|
|
})
|
|
});
|
|
let $c4VX3K = $('#c4VX3K');
|
|
$c4VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c4", vx3k: result}}));
|
|
$c4VX3K.text(result);
|
|
})
|
|
});
|
|
let $c5VX3K = $('#c5VX3K');
|
|
$c5VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c5", vx3k: result}}));
|
|
$c5VX3K.text(result);
|
|
})
|
|
});
|
|
let $c6VX3K = $('#c6VX3K');
|
|
$c6VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c6", vx3k: result}}));
|
|
$c6VX3K.text(result);
|
|
})
|
|
});
|
|
let $c7VX3K = $('#c7VX3K');
|
|
$c7VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c7", vx3k: result}}));
|
|
$c7VX3K.text(result);
|
|
})
|
|
});
|
|
let $c8VX3K = $('#c8VX3K');
|
|
$c8VX3K.on('dblclick', () => {
|
|
ShowModal('vx3kModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_VX3K", args: {contact: "c8", vx3k: result}}));
|
|
$c8VX3K.text(result);
|
|
})
|
|
});
|
|
|
|
let $c1Mqtt = $('#c1Mqtt');
|
|
$c1Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c1", mqtt: result}}));
|
|
$c1Mqtt.text(result);
|
|
})
|
|
});
|
|
let $c2Mqtt = $('#c2Mqtt');
|
|
$c2Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c2", mqtt: result}}));
|
|
$c2Mqtt.text(result);
|
|
})
|
|
});
|
|
let $c3Mqtt = $('#c3Mqtt');
|
|
$c3Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c3", mqtt: result}}));
|
|
$c3Mqtt.text(result);
|
|
})
|
|
});
|
|
let $c4Mqtt = $('#c4Mqtt');
|
|
$c4Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c4", mqtt: result}}));
|
|
$c4Mqtt.text(result);
|
|
})
|
|
});
|
|
let $c5Mqtt = $('#c5Mqtt');
|
|
$c5Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c5", mqtt: result}}));
|
|
$c5Mqtt.text(result);
|
|
})
|
|
});
|
|
let $c6Mqtt = $('#c6Mqtt');
|
|
$c6Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c6", mqtt: result}}));
|
|
$c6Mqtt.text(result);
|
|
})
|
|
});
|
|
let $c7Mqtt = $('#c7Mqtt');
|
|
$c7Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c7", mqtt: result}}));
|
|
$c7Mqtt.text(result);
|
|
})
|
|
});
|
|
let $c8Mqtt = $('#c8Mqtt');
|
|
$c8Mqtt.on('dblclick', () => {
|
|
ShowModal('mqttModal')
|
|
.then((result) => {
|
|
send_data(JSON.stringify({request: "SET_CONTACT_MQTT", args: {contact: "c8", mqtt: result}}));
|
|
$c8Mqtt.text(result);
|
|
})
|
|
});
|
|
|
|
|
|
|
|
socket.onmessage = (event) => {
|
|
const data = JSON.parse(event.data);
|
|
console.log("Received from server:", data);
|
|
switch (data.response) {
|
|
case "GET_CONTACT_SETUP":
|
|
// Update the contact setup display
|
|
// Example: $('#contactSetup').text(data.args.contactSetup);
|
|
$c1Description.text(GetContactInputData_Description(data, 'c1'));
|
|
$c2Description.text(GetContactInputData_Description(data, 'c2'));
|
|
$c3Description.text(GetContactInputData_Description(data, 'c3'));
|
|
$c4Description.text(GetContactInputData_Description(data, 'c4'));
|
|
$c5Description.text(GetContactInputData_Description(data, 'c5'));
|
|
$c6Description.text(GetContactInputData_Description(data, 'c6'));
|
|
$c7Description.text(GetContactInputData_Description(data, 'c7'));
|
|
$c8Description.text(GetContactInputData_Description(data, 'c8'));
|
|
if (GetContactInputData_EnableEmail(data, 'c1')) {
|
|
$c1Email.text(GetContactInputData_EmailRecipient(data, 'c1'));
|
|
} else $c1Email.text("N/A");
|
|
if (GetContactInputData_EnableEmail(data, 'c2')) {
|
|
$c2Email.text(GetContactInputData_EmailRecipient(data, 'c2'));
|
|
} else $c2Email.text("N/A");
|
|
if (GetContactInputData_EnableEmail(data, 'c3')) {
|
|
$c3Email.text(GetContactInputData_EmailRecipient(data, 'c3'));
|
|
} else $c3Email.text("N/A");
|
|
if (GetContactInputData_EnableEmail(data, 'c4')) {
|
|
$c4Email.text(GetContactInputData_EmailRecipient(data, 'c4'));
|
|
} else $c4Email.text("N/A");
|
|
if (GetContactInputData_EnableEmail(data, 'c5')) {
|
|
$c5Email.text(GetContactInputData_EmailRecipient(data, 'c5'));
|
|
} else $c5Email.text("N/A");
|
|
if (GetContactInputData_EnableEmail(data, 'c6')) {
|
|
$c6Email.text(GetContactInputData_EmailRecipient(data, 'c6'));
|
|
} else $c6Email.text("N/A");
|
|
if (GetContactInputData_EnableEmail(data, 'c7')) {
|
|
$c7Email.text(GetContactInputData_EmailRecipient(data, 'c7'));
|
|
} else $c7Email.text("N/A");
|
|
if (GetContactInputData_EnableEmail(data, 'c8')) {
|
|
$c8Email.text(GetContactInputData_EmailRecipient(data, 'c8'));
|
|
} else $c8Email.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c1')) {
|
|
$c1Modbus.text(GetContactInputData_ModbusRegister(data, 'c1'));
|
|
} else $c1Modbus.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c2')) {
|
|
$c2Modbus.text(GetContactInputData_ModbusRegister(data, 'c2'));
|
|
} else $c2Modbus.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c3')) {
|
|
$c3Modbus.text(GetContactInputData_ModbusRegister(data, 'c3'));
|
|
} else $c3Modbus.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c4')) {
|
|
$c4Modbus.text(GetContactInputData_ModbusRegister(data, 'c4'));
|
|
} else $c4Modbus.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c5')) {
|
|
$c5Modbus.text(GetContactInputData_ModbusRegister(data, 'c5'));
|
|
} else $c5Modbus.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c6')) {
|
|
$c6Modbus.text(GetContactInputData_ModbusRegister(data, 'c6'));
|
|
} else $c6Modbus.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c7')) {
|
|
$c7Modbus.text(GetContactInputData_ModbusRegister(data, 'c7'));
|
|
} else $c7Modbus.text("N/A");
|
|
if (GetContactInputData_EnableModbus(data, 'c8')) {
|
|
$c8Modbus.text(GetContactInputData_ModbusRegister(data, 'c8'));
|
|
} else $c8Modbus.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c1')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c1');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c1');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c1VX3K.text(_f + ":" + _c);
|
|
} else $c1VX3K.text("N/A");
|
|
$c1VX3K.text(GetContactInputData_VX3KFrameID(data, 'c1') + " / " + GetContactInputData_VX3KContactID(data, 'c1'));
|
|
} else $c1VX3K.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c2')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c2');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c2');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c2VX3K.text(_f + ":" + _c);
|
|
} else $c2VX3K.text("N/A");
|
|
} else $c2VX3K.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c3')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c3');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c3');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c3VX3K.text(_f + ":" + _c);
|
|
} else $c3VX3K.text("N/A");
|
|
} else $c3VX3K.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c4')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c4');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c4');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c4VX3K.text(_f + ":" + _c);
|
|
} else $c4VX3K.text("N/A");
|
|
} else $c4VX3K.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c5')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c5');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c5');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c5VX3K.text(_f + ":" + _c);
|
|
} else $c5VX3K.text("N/A");
|
|
} else $c5VX3K.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c6')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c6');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c6');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c6VX3K.text(_f + ":" + _c);
|
|
} else $c6VX3K.text("N/A");
|
|
} else $c6VX3K.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c7')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c7');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c7');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c7VX3K.text(_f + ":" + _c);
|
|
} else $c7VX3K.text("N/A");
|
|
} else $c7VX3K.text("N/A");
|
|
if (GetContactInputData_EnableVX3K(data, 'c8')) {
|
|
let _f = GetContactInputData_VX3KFrameID(data, 'c8');
|
|
let _c = GetContactInputData_VX3KContactID(data, 'c8');
|
|
if (ValidVX3KFrameID(_f) && ValidVX3KContactID(_c)) {
|
|
$c8VX3K.text(_f + ":" + _c);
|
|
} else $c8VX3K.text("N/A");
|
|
} else $c8VX3K.text("N/A");
|
|
if (GetContactInputData_EnableMQTT(data, 'c1')) {
|
|
$c1Mqtt.text("Enabled");
|
|
} else $c1Mqtt.text("Disabled");
|
|
if (GetContactInputData_EnableMQTT(data, 'c2')) {
|
|
$c2Mqtt.text("Enabled");
|
|
} else $c2Mqtt.text("Disabled");
|
|
if (GetContactInputData_EnableMQTT(data, 'c3')) {
|
|
$c3Mqtt.text("Enabled");
|
|
} else $c3Mqtt.text("Disabled");
|
|
if (GetContactInputData_EnableMQTT(data, 'c4')) {
|
|
$c4Mqtt.text("Enabled");
|
|
} else $c4Mqtt.text("Disabled");
|
|
if (GetContactInputData_EnableMQTT(data, 'c5')) {
|
|
$c5Mqtt.text("Enabled");
|
|
} else $c5Mqtt.text("Disabled");
|
|
if (GetContactInputData_EnableMQTT(data, 'c6')) {
|
|
$c6Mqtt.text("Enabled");
|
|
} else $c6Mqtt.text("Disabled");
|
|
if (GetContactInputData_EnableMQTT(data, 'c7')) {
|
|
$c7Mqtt.text("Enabled");
|
|
} else $c7Mqtt.text("Disabled");
|
|
if (GetContactInputData_EnableMQTT(data, 'c8')) {
|
|
$c8Mqtt.text("Enabled");
|
|
} else $c8Mqtt.text("Disabled");
|
|
|
|
setInterval(() => {
|
|
// requesting update every second
|
|
send_data(JSON.stringify({request: "GET_CONTACT_STATUS"}));
|
|
}, 1000);
|
|
break;
|
|
case "GET_CONTACT_STATUS":
|
|
// Update the contact status display
|
|
// Example: $('#contactStatus').text(data.args.contactStatus);
|
|
if (GetContactStatus(data,'c1') == 1) {
|
|
$c1Index.css('background-color', 'green');
|
|
$c1Description.css('background-color', 'green');
|
|
} else {
|
|
$c1Index.css('background-color', '');
|
|
$c1Description.css('background-color', '');
|
|
|
|
}
|
|
if (GetContactStatus(data, 'c2') == 1) {
|
|
$c2Index.css('background-color', 'green');
|
|
$c2Description.css('background-color', 'green');
|
|
} else {
|
|
$c2Index.css('background-color', '');
|
|
$c2Description.css('background-color', '');
|
|
}
|
|
if (GetContactStatus(data,'c3') == 1) {
|
|
$c3Index.css('background-color', 'green');
|
|
$c3Description.css('background-color', 'green');
|
|
} else {
|
|
$c3Index.css('background-color', '');
|
|
$c3Description.css('background-color', '');
|
|
}
|
|
if (GetContactStatus(data, 'c4') == 1) {
|
|
$c4Index.css('background-color', 'green');
|
|
$c4Description.css('background-color', 'green');
|
|
} else {
|
|
$c4Index.css('background-color', '');
|
|
$c4Description.css('background-color', '');
|
|
}
|
|
if (GetContactStatus(data, 'c5') == 1) {
|
|
$c5Index.css('background-color', 'green');
|
|
$c5Description.css('background-color', 'green');
|
|
} else {
|
|
$c5Index.css('background-color', '');
|
|
$c5Description.css('background-color', '');
|
|
}
|
|
if (GetContactStatus(data, 'c6') == 1) {
|
|
$c6Index.css('background-color', 'green');
|
|
$c6Description.css('background-color', 'green');
|
|
} else {
|
|
$c6Index.css('background-color', '');
|
|
$c6Description.css('background-color', '');
|
|
}
|
|
if (GetContactStatus(data, 'c7') == 1) {
|
|
$c7Index.css('background-color', 'green');
|
|
$c7Description.css('background-color', 'green');
|
|
} else {
|
|
$c7Index.css('background-color', '');
|
|
$c7Description.css('background-color', '');
|
|
}
|
|
if (GetContactStatus(data, 'c8') == 1) {
|
|
$c8Index.css('background-color', 'green');
|
|
$c8Description.css('background-color', 'green');
|
|
} else {
|
|
$c8Index.css('background-color', '');
|
|
$c8Description.css('background-color', '');
|
|
}
|
|
break;
|
|
default:
|
|
console.error("Unknown response:", data);
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
/**
|
|
* Show a modal dialog and return a promise that resolves when the save button is clicked or rejects when the close button is clicked.
|
|
* @param {string} modalId Modal ID to show
|
|
* @param {string} prevData Previous data to pre-fill the modal (if needed)
|
|
* @returns {Promise} Promise that resolves or rejects based on user action
|
|
*/
|
|
function ShowModal(modalId, prevData) {
|
|
return new Promise((resolve) => {
|
|
const $modal = $('#' + modalId);
|
|
const $btnSave = $modal.find('#btnSave');
|
|
const btnClose = $modal.find('#btnClose');
|
|
|
|
function cleanup(){
|
|
$btnSave.off('click', onSave);
|
|
btnClose.off('click', onClose);
|
|
}
|
|
|
|
function onSave() {
|
|
console.log("Save button clicked in modal: " + modalId);
|
|
switch (modalId) {
|
|
case 'emailModal':
|
|
$disableEmail = $modal.find('#disableEmail');
|
|
$enableEmail = $modal.find('#enableEmail');
|
|
$emailInput = $modal.find('#emailInput');
|
|
|
|
if ($disableEmail.is(':checked')) {
|
|
// Handle disabling email
|
|
resolve("Disabled");
|
|
} else if ($enableEmail.is(':checked')) {
|
|
// Handle enabling email
|
|
if (ValidEmail($emailInput.val())) {
|
|
resolve($emailInput.val());
|
|
} else {
|
|
alert("Please enter a valid email address.");
|
|
return;
|
|
}
|
|
}
|
|
break;
|
|
case 'mqttModal':
|
|
$disableMqtt = $modal.find('#disableMqtt');
|
|
$enableMqtt = $modal.find('#enableMqtt');
|
|
if ($disableMqtt.is(':checked')) {
|
|
// Handle disabling MQTT
|
|
resolve("Disabled");
|
|
} else if ($enableMqtt.is(':checked')) {
|
|
// Handle enabling MQTT
|
|
resolve("Enabled");
|
|
}
|
|
break;
|
|
case 'modbusModal':
|
|
$disableModbus = $modal.find('#disableModbus');
|
|
$enableModbus = $modal.find('#enableModbus');
|
|
$modbusRegister = $modal.find('#modbusRegister');
|
|
if ($disableModbus.is(':checked')) {
|
|
// Handle disabling Modbus
|
|
resolve("Disabled");
|
|
} else if ($enableModbus.is(':checked')) {
|
|
// Handle enabling Modbus
|
|
if (ValidModbusRegister($modbusRegister.val())) {
|
|
resolve($modbusRegister.val());
|
|
} else {
|
|
alert("Please enter a valid Modbus register.");
|
|
return;
|
|
}
|
|
}
|
|
break;
|
|
case 'vx3kModal':
|
|
$disableVX3K = $modal.find('#disableVX3K');
|
|
$enableVX3K = $modal.find('#enableVX3K');
|
|
$VX3KFrameID = $modal.find('#VX3KFrameID');
|
|
$VX3KContactID = $modal.find('#VX3KContactID');
|
|
if ($disableVX3K.is(':checked')) {
|
|
// Handle disabling VX3K
|
|
resolve("Disabled");
|
|
} else if ($enableVX3K.is(':checked')) {
|
|
// Handle enabling VX3K
|
|
if (ValidVX3KFrameID($VX3KFrameID.val()) && ValidVX3KContactID($VX3KContactID.val())) {
|
|
resolve($VX3KFrameID.val() + ":" + $VX3KContactID.val());
|
|
} else {
|
|
alert("Please enter a valid VX3K Frame ID (0-39) and Contact ID (0-15).");
|
|
return;
|
|
}
|
|
}
|
|
break;
|
|
|
|
}
|
|
|
|
cleanup();
|
|
$modal.modal('hide');
|
|
}
|
|
|
|
function onClose() {
|
|
console.log("Close button clicked in modal: " + modalId);
|
|
cleanup();
|
|
$modal.modal('hide');
|
|
}
|
|
|
|
$btnSave.on('click', onSave);
|
|
btnClose.on('click', onClose);
|
|
|
|
|
|
|
|
$modal.on('shown.bs.modal', () => {
|
|
console.log("Modal shown: " + modalId);
|
|
switch (modalId) {
|
|
case 'emailModal':
|
|
$disableEmail = $modal.find('#disableEmail');
|
|
$enableEmail = $modal.find('#enableEmail');
|
|
$emailInput = $modal.find('#emailInput');
|
|
if (ValidEmail(prevData)) {
|
|
$disableEmail.prop('checked', false);
|
|
$enableEmail.prop('checked', true);
|
|
$emailInput.val(prevData);
|
|
$emailInput.prop('disabled', false);
|
|
} else {
|
|
$disableEmail.prop('checked', true);
|
|
$enableEmail.prop('checked', false);
|
|
$emailInput.val('');
|
|
$emailInput.prop('disabled', true);
|
|
}
|
|
$disableEmail.on('change', () => {
|
|
$emailInput.prop('disabled', $disableEmail.is(':checked'));
|
|
});
|
|
|
|
$enableEmail.on('change', () => {
|
|
$emailInput.prop('disabled', !$enableEmail.is(':checked'));
|
|
});
|
|
|
|
break;
|
|
case 'mqttModal':
|
|
$disableMqtt = $modal.find('#disableMqtt');
|
|
$enableMqtt = $modal.find('#enableMqtt');
|
|
if ("Enabled" === prevData) {
|
|
$disableMqtt.prop('checked', false);
|
|
$enableMqtt.prop('checked', true);
|
|
} else {
|
|
$disableMqtt.prop('checked', true);
|
|
$enableMqtt.prop('checked', false);
|
|
}
|
|
|
|
break;
|
|
case 'modbusModal':
|
|
$disableModbus = $modal.find('#disableModbus');
|
|
$enableModbus = $modal.find('#enableModbus');
|
|
$modbusRegister = $modal.find('#modbusRegister');
|
|
if (ValidModbusRegister(prevData)) {
|
|
$disableModbus.prop('checked', false);
|
|
$enableModbus.prop('checked', true);
|
|
$modbusRegister.val(prevData);
|
|
$modbusRegister.prop('disabled', false);
|
|
} else {
|
|
$disableModbus.prop('checked', true);
|
|
$enableModbus.prop('checked', false);
|
|
$modbusRegister.val('');
|
|
$modbusRegister.prop('disabled', true);
|
|
}
|
|
$disableModbus.on('change', () => {
|
|
$modbusRegister.prop('disabled', $disableModbus.is(':checked'));
|
|
});
|
|
$enableModbus.on('change', () => {
|
|
$modbusRegister.prop('disabled', !$enableModbus.is(':checked'));
|
|
});
|
|
break;
|
|
case 'vx3kModal':
|
|
$disableVX3K = $modal.find('#disableVX3K');
|
|
$enableVX3K = $modal.find('#enableVX3K');
|
|
$VX3KFrameID = $modal.find('#VX3KFrameID');
|
|
$VX3KContactID = $modal.find('#VX3KContactID');
|
|
|
|
|
|
if (ValidVX3KData(prevData)) {
|
|
const parts = prevData.split(':');
|
|
$disableVX3K.prop('checked', false);
|
|
$enableVX3K.prop('checked', true);
|
|
$VX3KFrameID.val(parts[0]);
|
|
$VX3KContactID.val(parts[1]);
|
|
$VX3KFrameID.prop('disabled', false);
|
|
$VX3KContactID.prop('disabled', false);
|
|
|
|
} else {
|
|
$disableVX3K.prop('checked', true);
|
|
$enableVX3K.prop('checked', false);
|
|
$VX3KFrameID.val('');
|
|
$VX3KContactID.val('');
|
|
$VX3KFrameID.prop('disabled', true);
|
|
$VX3KContactID.prop('disabled', true);
|
|
}
|
|
|
|
$disableVX3K.on('change', () => {
|
|
$VX3KFrameID.prop('disabled', $disableVX3K.is(':checked'));
|
|
$VX3KContactID.prop('disabled', $disableVX3K.is(':checked'));
|
|
});
|
|
$enableVX3K.on('change', () => {
|
|
$VX3KFrameID.prop('disabled', !$enableVX3K.is(':checked'));
|
|
$VX3KContactID.prop('disabled', !$enableVX3K.is(':checked'));
|
|
});
|
|
break;
|
|
}
|
|
|
|
});
|
|
$modal.modal('show');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Check if a string is valid (not empty or whitespace)
|
|
* @param {string} str String to validate
|
|
* @returns {boolean} true if valid, false otherwise
|
|
*/
|
|
function ValidString(str) {
|
|
return str && str.trim() !== '';
|
|
}
|
|
|
|
/**
|
|
* Validate an email address.
|
|
* @param {String} email Email address to validate
|
|
* @returns {boolean} true if valid, false otherwise
|
|
*/
|
|
function ValidEmail(email) {
|
|
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
return emailPattern.test(email);
|
|
}
|
|
|
|
/**
|
|
* Validate a Modbus register.
|
|
* @param {string} register Modbus register to validate
|
|
* @returns {boolean} true if valid, false otherwise
|
|
*/
|
|
function ValidModbusRegister(register) {
|
|
// Assuming Modbus register is a valid number or a valid string representation of a register
|
|
const registerPattern = /^\d+$/; // Only digits allowed for simplicity
|
|
return registerPattern.test(register);
|
|
}
|
|
|
|
/**
|
|
* Validate VX3K data format.
|
|
* @param {string} data data to validate, expected format is "frameID:contactID"
|
|
* @returns {boolean} true if valid, false otherwise
|
|
*/
|
|
function ValidVX3KData(data){
|
|
if (ValidString(data) && data.includes(':')) {
|
|
const parts = data.split(':');
|
|
if (parts.length === 2) {
|
|
return ValidVX3KFrameID(parts[0]) && ValidVX3KContactID(parts[1]);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Check if a VX3K Frame ID is valid. A valid VX3K Frame ID is actually number between 0 and 39.
|
|
* @param {string} frameID
|
|
* @returns {boolean} true if frameID is valid, false otherwise
|
|
*/
|
|
function ValidVX3KFrameID(frameID){
|
|
const id = parseInt(frameID, 10);
|
|
return !isNaN(id) && id >= 0 && id <= 39;
|
|
}
|
|
|
|
/**
|
|
* Check if a VX3K Contact ID is valid. A valid VX3K Contact ID is actually number between 0 and 15.
|
|
* @param {string} contactID
|
|
* @returns {boolean} true if contactID is valid, false otherwise
|
|
*/
|
|
function ValidVX3KContactID(contactID){
|
|
const id = parseInt(contactID, 10);
|
|
return !isNaN(id) && id >= 0 && id <= 15;
|
|
}
|
|
|
|
/**
|
|
* Get the contact status from the object. Object structure is expected to be:
|
|
* {
|
|
* args: {
|
|
* contactkey: {
|
|
* Status: 1 or 0
|
|
* }
|
|
* }
|
|
* @param {object} obj Object containing contact data
|
|
* @param {string} contactkey Contact key to check status for
|
|
* @returns {number} 1 if contact is active, 0 if not
|
|
*/
|
|
function GetContactStatus(obj, contactkey){
|
|
return obj?.args?.[contactkey]?.Status === 1 ? 1 : 0;
|
|
}
|
|
|
|
/**
|
|
* Get the ContactID from the object. Object structure is expected to be:
|
|
* {
|
|
* args: {
|
|
* contactkey: {
|
|
* ContactID: "some_id"
|
|
* }
|
|
* }
|
|
* @param {object} obj Object containing contact data
|
|
* @param {string} contactkey Contact key to retrieve ContactID for
|
|
* @returns {string} ContactID or N/A if not found
|
|
*/
|
|
function GetContactInputData_ContactID(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.ContactID || "N/A";
|
|
}
|
|
|
|
/**
|
|
* Get the Description from the object. Object structure is expected to be:
|
|
* {
|
|
* args: {
|
|
* contactkey: {
|
|
* Description: "some description"
|
|
* }
|
|
* }
|
|
* @param {object} obj Object containing contact data
|
|
* @param {string} contactkey Contact key to retrieve Description for
|
|
* @returns {string} Description or "N/A" if not found
|
|
*/
|
|
function GetContactInputData_Description(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.Description || "N/A";
|
|
}
|
|
|
|
/**
|
|
* Get the EnableEmail flag from the object. Object structure is expected to be:
|
|
* {
|
|
* args: {
|
|
* contactkey: {
|
|
* EnableEmail: true or false
|
|
* }
|
|
* }
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {boolean} true if EnableEmail is set, false otherwise
|
|
*/
|
|
function GetContactInputData_EnableEmail(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.EnableEmail || false;
|
|
}
|
|
|
|
/**
|
|
* Get the EmailRecipient from the object. Object structure is expected to be:
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {string} EmailRecipient or "N/A" if not found
|
|
*/
|
|
function GetContactInputData_EmailRecipient(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.EmailRecipient || "N/A";
|
|
}
|
|
|
|
/**
|
|
* Get the EnableMQTT flag from the object. Object structure is expected to be:
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {boolean} true if EnableMQTT is set, false otherwise
|
|
*/
|
|
function GetContactInputData_EnableMQTT(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.EnableMQTT || false;
|
|
}
|
|
|
|
/**
|
|
* Get the EnableModbus flag from the object. Object structure is expected to be:
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {boolean} true if EnableModbus is set, false otherwise
|
|
*/
|
|
function GetContactInputData_EnableModbus(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.EnableModbus || false;
|
|
}
|
|
|
|
/**
|
|
* Get the ModbusRegister from the object. Object structure is expected to be:
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {string} ModbusRegister or "N/A" if not found
|
|
*/
|
|
function GetContactInputData_ModbusRegister(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.ModbusRegister || "N/A";
|
|
}
|
|
|
|
/**
|
|
* Get the EnableVX3K flag from the object. Object structure is expected to be:
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {boolean} true if EnableVX3K is set, false otherwise
|
|
*/
|
|
function GetContactInputData_EnableVX3K(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.EnableVX3K || false;
|
|
}
|
|
|
|
/**
|
|
* Get the VX3KFrameID from the object. Object structure is expected to be:
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {string} VX3KFrameID or "N/A" if not found
|
|
*/
|
|
function GetContactInputData_VX3KFrameID(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.VX3KFrameID || "N/A";
|
|
}
|
|
|
|
/**
|
|
* Get the VX3KContactID from the object. Object structure is expected to be:
|
|
* @param {object} obj
|
|
* @param {string} contactkey
|
|
* @returns {string} VX3KContactID or "N/A" if not found
|
|
*/
|
|
function GetContactInputData_VX3KContactID(obj, contactkey) {
|
|
return obj?.args?.[contactkey]?.VX3KContactID || "N/A";
|
|
}
|