Add confirmation to apply interface

This commit is contained in:
Daniel Öster 2025-03-04 20:13:02 +02:00
parent effd80cc58
commit 0398cda44b
2 changed files with 13 additions and 6 deletions

View file

@ -22,7 +22,7 @@ String can_replay_processor(void) {
".can-message { background-color: #404E57; margin-bottom: 5px; padding: 10px; border-radius: 5px; font-family: " ".can-message { background-color: #404E57; margin-bottom: 5px; padding: 10px; border-radius: 5px; font-family: "
"monospace; }"; "monospace; }";
content += "</style>"; content += "</style>";
content += "<button onclick='stopPlaybackAndGoToMainPage()'>Back to main page</button>"; content += "<button onclick='home()'>Back to main page</button>";
// Start a new block for the CAN messages // Start a new block for the CAN messages
content += "<div style='background-color: #303E47; padding: 20px; border-radius: 15px'>"; content += "<div style='background-color: #303E47; padding: 20px; border-radius: 15px'>";
@ -129,11 +129,18 @@ String can_replay_processor(void) {
content += " var selectedInterface = document.getElementById('canInterface').value;"; content += " var selectedInterface = document.getElementById('canInterface').value;";
content += " var xhr = new XMLHttpRequest();"; content += " var xhr = new XMLHttpRequest();";
content += " xhr.open('GET', '/setCANInterface?interface=' + selectedInterface, true);"; content += " xhr.open('GET', '/setCANInterface?interface=' + selectedInterface, true);";
content += " xhr.onreadystatechange = function() {";
content += " if (xhr.readyState === 4) {";
content += " if (xhr.status === 200) {";
content += " alert('Success: ' + xhr.responseText);";
content += " } else {";
content += " alert('Error: ' + xhr.responseText);";
content += " }";
content += " }";
content += " };";
content += " xhr.send();"; content += " xhr.send();";
content += "}"; content += "}";
content += "function stopPlaybackAndGoToMainPage() {"; content += "function home() { window.location.href = '/'; }";
content += " fetch('/stop_can_logging').then(() => window.location.href = '/');";
content += "}";
content += "</script>"; content += "</script>";
content += index_html_footer; content += index_html_footer;
return content; return content;

View file

@ -236,9 +236,9 @@ void init_webserver() {
datalayer.system.info.can_replay_interface = interfaceValue; datalayer.system.info.can_replay_interface = interfaceValue;
// Respond with success message // Respond with success message
request->send(200, "text/plain", "CAN Interface Updated to " + canInterface); request->send(200, "text/plain", "New interface selected");
} else { } else {
request->send(400, "text/plain", "Error: Missing parameter 'interface'"); request->send(400, "text/plain", "Error: updating interface failed");
} }
}); });