diff --git a/server/public/css/settings.css b/server/public/css/settings.css index e2531a2..0487cf7 100644 --- a/server/public/css/settings.css +++ b/server/public/css/settings.css @@ -32,4 +32,12 @@ button { border-radius: 30px; padding: 5px 20px; cursor: pointer; +} + +.mac-address { + border: 1px solid rgba(255, 255, 255, 0.2); + border-radius: 10px; + display: flex; + width: -moz-fit-content; + width: fit-content; } \ No newline at end of file diff --git a/server/public/js/settings.js b/server/public/js/settings.js index 6f2bbda..ea05fb1 100644 --- a/server/public/js/settings.js +++ b/server/public/js/settings.js @@ -7,24 +7,71 @@ document.addEventListener('DOMContentLoaded', () => { }) .catch(error => console.error('Error fetching config:', error)); - var form = document.querySelector('form'); - form.addEventListener('submit', function (e) { - e.preventDefault(); + const addApButton = document.getElementById('add-ap'); + addApButton.addEventListener('click', () => { + const input = addApButton.parentElement.querySelector('input').value; + fetch('/add-config-item', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ key: 'TARGET_AP_MAC_ADDRESSES', value: input }) + }) + .then(response => response.json()) + .then(content => { + document.getElementById('target_ap_mac_addresses').value = content.TARGET_AP_MAC_ADDRESSES; + }) + .catch(error => console.error('Error adding config item:', error)); + }); + + const removeApButton = document.getElementById('remove-ap'); + removeApButton.addEventListener('click', () => { + const input = removeApButton.parentElement.querySelector('input').value; + fetch('/remove-config-item', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ key: 'TARGET_AP_MAC_ADDRESSES', value: input }) + }) + .then(response => response.json()) + .then(content => { + document.getElementById('target_ap_mac_addresses').value = content.TARGET_AP_MAC_ADDRESSES; + }) + .catch(error => console.error('Error removing config item:', error)); + }); - // Create a FormData object, passing in the form - var formData = new FormData(form); + const addBtButton = document.getElementById('add-bt'); + addBtButton.addEventListener('click', () => { + const input = addBtButton.parentElement.querySelector('input').value; + fetch('/add-config-item', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ key: 'TARGET_BT_ADDRESSES', value: input }) + }) + .then(response => response.json()) + .then(content => { + document.getElementById('target_bt_addresses').value = content.TARGET_BT_ADDRESSES; + }) + .catch(error => console.error('Error adding config item:', error)); + }); - fetch('/update-config', { + const removeBtButton = document.getElementById('remove-bt'); + removeBtButton.addEventListener('click', () => { + const input = removeBtButton.parentElement.querySelector('input').value; + fetch('/remove-config-item', { method: 'POST', - body: formData + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ key: 'TARGET_BT_ADDRESSES', value: input }) }) .then(response => response.json()) - .then(data => { - window.alert("Success"); - console.log('Success:', data); + .then(content => { + document.getElementById('target_bt_addresses').value = content.TARGET_BT_ADDRESSES; }) - .catch((error) => { - console.error('Error:', error); - }); + .catch(error => console.error('Error removing config item:', error)); }); }); diff --git a/server/public/settings.html b/server/public/settings.html index 0be2ae3..5923ae9 100644 --- a/server/public/settings.html +++ b/server/public/settings.html @@ -56,13 +56,34 @@