switches almost ready

This commit is contained in:
richonguzman 2024-09-30 14:43:08 -03:00
parent f35b652260
commit fb6c4ba2d4
7 changed files with 110 additions and 50 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -146,62 +146,99 @@ const bmeCheckbox = document.querySelector("input[name='bme.active']");
const stationModeSelect = document.querySelector("select[name='stationMode']"); const stationModeSelect = document.querySelector("select[name='stationMode']");
function toggleFields() { function toggleFields() {
/*const sendExternalVoltageCheckbox = document.querySelector( /*
'input[name="battery.sendExternalVoltage"]' // Display - timeout box enable
); const ecoModeCheckbox = document.querySelector('input[name="display.ecoMode"]');
const externalVoltagePinInput = document.querySelector( const timeoutInput = document.querySelector('input[name="display.timeout"]');
'input[name="battery.externalVoltagePin"]' ecoModeCheckbox.addEventListener("change", function () {
); timeoutInput.disabled = !this.checked;
});
externalVoltagePinInput.disabled = !sendExternalVoltageCheckbox.checked; // pttTrigger boxes enable
voltageDividerR1.disabled = !sendExternalVoltageCheckbox.checked; const pttTriggerCheckbox = document.querySelector('input[name="ptt.active"]');
voltageDividerR2.disabled = !sendExternalVoltageCheckbox.checked; const pttPinInput = document.querySelector('input[name="ptt.io_pin"]');
const pttPreDelayInput = document.querySelector('input[name="ptt.preDelay"]');
const pttPostDelayInput = document.querySelector('input[name="ptt.postDelay"]');
pttTriggerCheckbox.addEventListener("change", function () {
pttPinInput.disabled = !this.checked;
pttPreDelayInput.disabled = !this.checked;
pttPostDelayInput.disabled = !this.checked;
});
const WebadminCheckbox = document.querySelector( // notifications boxes enable
'input[name="webadmin.active"]' const ledTxCheckbox = document.querySelector('input[name="notification.ledTx"]');
); const letTxPinInput = document.querySelector('input[name="notification.ledTxPin"]');
ledTxCheckbox.addEventListener("change", function () {
letTxPinInput.disabled = !this.checked;
});
const WebadminUsername = document.querySelector( const ledMessageCheckbox = document.querySelector('input[name="notification.ledMessage"]');
'input[name="webadmin.username"]' const ledMessagePinInput = document.querySelector('input[name="notification.ledMessagePin"]');
);*/ ledMessageCheckbox.addEventListener("change", function () {
ledMessagePinInput.disabled = !this.checked;
});
const ledFlashlightCheckbox = document.querySelector('input[name="notification.ledFlashlight"]');
const ledFlashlightPinInput = document.querySelector('input[name="notification.ledFlashlightPin"]');
ledFlashlightCheckbox.addEventListener("change", function () {
ledFlashlightPinInput.disabled = !this.checked;
});
const buzzerActiveCheckbox = document.querySelector('input[name="notification.buzzerActive"]');
const buzzerPinToneInput = document.querySelector('input[name="notification.buzzerPinTone"]');
const buzzerPinVccInput = document.querySelector('input[name="notification.buzzerPinVcc"]');
buzzerActiveCheckbox.addEventListener("change", function () {
buzzerPinToneInput.disabled = !this.checked;
buzzerPinVccInput.disabled = !this.checked;
});*/
} }
/*const sendExternalVoltageCheckbox = document.querySelector( /*
'input[name="battery.sendExternalVoltage"]' // Display - timeout box enable
); const ecoModeCheckbox = document.querySelector('input[name="display.ecoMode"]');
const externalVoltagePinInput = document.querySelector( const timeoutInput = document.querySelector('input[name="display.timeout"]');
'input[name="battery.externalVoltagePin"]' ecoModeCheckbox.addEventListener("change", function () {
); timeoutInput.disabled = !this.checked;
const voltageDividerR1 = document.querySelector(
'input[name="battery.voltageDividerR1"]'
);
const voltageDividerR2 = document.querySelector(
'input[name="battery.voltageDividerR2"]'
);
sendExternalVoltageCheckbox.addEventListener("change", function () {
externalVoltagePinInput.disabled = !this.checked;
voltageDividerR1.disabled = !this.checked;
voltageDividerR2.disabled = !this.checked;
}); });
const WebadminCheckbox = document.querySelector( // pttTrigger boxes enable
'input[name="webadmin.active"]' const pttTriggerCheckbox = document.querySelector('input[name="ptt.active"]');
); const pttPinInput = document.querySelector('input[name="ptt.io_pin"]');
const pttPreDelayInput = document.querySelector('input[name="ptt.preDelay"]');
const pttPostDelayInput = document.querySelector('input[name="ptt.postDelay"]');
pttTriggerCheckbox.addEventListener("change", function () {
pttPinInput.disabled = !this.checked;
pttPreDelayInput.disabled = !this.checked;
pttPostDelayInput.disabled = !this.checked;
});
const WebadminUsername = document.querySelector( // notifications boxes enable
'input[name="webadmin.username"]' const ledTxCheckbox = document.querySelector('input[name="notification.ledTx"]');
); const letTxPinInput = document.querySelector('input[name="notification.ledTxPin"]');
ledTxCheckbox.addEventListener("change", function () {
letTxPinInput.disabled = !this.checked;
});
const WebadminPassword = document.querySelector( const ledMessageCheckbox = document.querySelector('input[name="notification.ledMessage"]');
'input[name="webadmin.password"]' const ledMessagePinInput = document.querySelector('input[name="notification.ledMessagePin"]');
); ledMessageCheckbox.addEventListener("change", function () {
WebadminCheckbox.addEventListener("change", function () { ledMessagePinInput.disabled = !this.checked;
WebadminUsername.disabled = !this.checked; });
WebadminPassword.disabled = !this.checked;
});*/ const ledFlashlightCheckbox = document.querySelector('input[name="notification.ledFlashlight"]');
const ledFlashlightPinInput = document.querySelector('input[name="notification.ledFlashlightPin"]');
ledFlashlightCheckbox.addEventListener("change", function () {
ledFlashlightPinInput.disabled = !this.checked;
});
const buzzerActiveCheckbox = document.querySelector('input[name="notification.buzzerActive"]');
const buzzerPinToneInput = document.querySelector('input[name="notification.buzzerPinTone"]');
const buzzerPinVccInput = document.querySelector('input[name="notification.buzzerPinVcc"]');
buzzerActiveCheckbox.addEventListener("change", function () {
buzzerPinToneInput.disabled = !this.checked;
buzzerPinVccInput.disabled = !this.checked;
});
*/
/*document.querySelector(".new button").addEventListener("click", function () { /*document.querySelector(".new button").addEventListener("click", function () {
const trackersContainer = document.querySelector(".list-tracker"); const trackersContainer = document.querySelector(".list-tracker");
@ -336,7 +373,7 @@ function checkConnection() {
}); });
} }
form.addEventListener("submit", async (event) => { /*form.addEventListener("submit", async (event) => {
event.preventDefault(); event.preventDefault();
//document.getElementById("beacons").value = document.querySelectorAll(".beacons").length; //document.getElementById("beacons").value = document.querySelectorAll(".beacons").length;
@ -345,12 +382,35 @@ form.addEventListener("submit", async (event) => {
method: form.method, method: form.method,
body: new FormData(form), body: new FormData(form),
}); });
saveModal.show(); saveModal.show();
setTimeout(checkConnection, 2000); setTimeout(checkConnection, 2000);
});*/
form.addEventListener("submit", async (event) => {
event.preventDefault();
// Optional: update the beacons count
// document.getElementById("beacons").value = document.querySelectorAll(".beacons").length;
try {
const response = await fetch(form.action, {
method: form.method,
body: new FormData(form),
});
if (!response.ok) {
throw new Error('Form submission failed');
}
saveModal.show();
setTimeout(checkConnection, 2000);
} catch (error) {
console.error(error);
// Optionally handle errors (e.g., show error modal/message)
}
}); });
fetchSettings(); fetchSettings();
function loadReceivedPackets(packets) { function loadReceivedPackets(packets) {

Binary file not shown.

Binary file not shown.