fixed data fetching error
This commit is contained in:
@@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const modal = document.getElementById('reboot-modal');
|
||||
const rebootButton = document.getElementById('rebootModem');
|
||||
const cancelButtons = modal.querySelectorAll('.cancel, .modal-background');
|
||||
const restartConnectionBtn = document.querySelector('a.button.is-link.is-outlined');
|
||||
const powerButton = document.querySelector('div.button.is-warning.is-outlined.reboot-modal');
|
||||
const modalMessage = document.getElementById('modal-message');
|
||||
const loadingContent = document.getElementById('loading-content');
|
||||
const modalButtons = document.getElementById('modal-buttons');
|
||||
@@ -46,7 +46,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
|
||||
// Show modal when restart connection button is clicked
|
||||
restartConnectionBtn.addEventListener('click', function(e) {
|
||||
powerButton.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
toggleModal(true);
|
||||
});
|
||||
|
||||
69
www/js/utils/restart-connection.js
Normal file
69
www/js/utils/restart-connection.js
Normal file
@@ -0,0 +1,69 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const restartBtn = document.getElementById('restartConnectionBtn');
|
||||
|
||||
// Function to send AT commands
|
||||
async function sendRestartCommands() {
|
||||
try {
|
||||
// Disable the restart button and show loading state
|
||||
restartBtn.classList.add('is-loading');
|
||||
restartBtn.disabled = true;
|
||||
|
||||
// Send AT+CFUN=0
|
||||
const response1 = await fetch('/cgi-bin/atinout_handler.sh', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'command=' + encodeURIComponent('AT+CFUN=0')
|
||||
});
|
||||
|
||||
if (!response1.ok) {
|
||||
throw new Error(`HTTP error! status: ${response1.status}`);
|
||||
}
|
||||
|
||||
// Wait for 2 seconds
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
// Send AT+CFUN=1
|
||||
const response2 = await fetch('/cgi-bin/atinout_handler.sh', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'command=' + encodeURIComponent('AT+CFUN=1')
|
||||
});
|
||||
|
||||
if (!response2.ok) {
|
||||
throw new Error(`HTTP error! status: ${response2.status}`);
|
||||
}
|
||||
|
||||
const data1 = await response1.json();
|
||||
const data2 = await response2.json();
|
||||
|
||||
if (data1.output.includes('OK') && data2.output.includes('OK')) {
|
||||
alert('Connection restarted successfully');
|
||||
// Optionally reload the page after a short delay
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
} else {
|
||||
throw new Error('Restart command failed');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
alert('Failed to restart connection. Please try again.');
|
||||
} finally {
|
||||
// Re-enable the restart button and remove loading state
|
||||
restartBtn.classList.remove('is-loading');
|
||||
restartBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add click event listener to the restart button
|
||||
if (restartBtn) {
|
||||
restartBtn.addEventListener('click', sendRestartCommands);
|
||||
} else {
|
||||
console.warn('Restart Connection button not found in the DOM');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user