V1.0 add email notifications

This commit is contained in:
ellite
2023-11-10 11:45:01 +01:00
parent 65786aa191
commit 7c2e7f00b9
22 changed files with 7161 additions and 23 deletions
+3
View File
@@ -61,6 +61,9 @@ function fillEditFormFields(subscription) {
const notes = document.querySelector("#notes");
notes.value = subscription.notes;
const notifications = document.querySelector("#notifications");
notifications.checked = subscription.notify;
const deleteButton = document.querySelector("#deletesub");
deleteButton.style = 'display: block';
deleteButton.setAttribute("onClick", `deleteSubscription(${subscription.id})`);
+80
View File
@@ -468,6 +468,86 @@ function addFixerKeyButton() {
});
}
function saveNotificationsButton() {
const button = document.getElementById("saveNotifications");
button.disabled = true;
const enabled = document.getElementById("notifications").checked ? 1 : 0;
const days = document.getElementById("days").value;
const smtpAddress = document.getElementById("smtpaddress").value;
const smtpPort = document.getElementById("smtpport").value;
const smtpUsername = document.getElementById("smtpusername").value;
const smtpPassword = document.getElementById("smtppassword").value;
const data = {
enabled: enabled,
days: days,
smtpaddress: smtpAddress,
smtpport: smtpPort,
smtpusername: smtpUsername,
smtppassword: smtpPassword
};
fetch('/endpoints/notifications/save.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
if (data.success) {
showSuccessMessage("Notification settings saved successfully.");
} else {
showErrorMessage(data.errorMessage);
}
button.disabled = false;
})
.catch(error => {
showErrorMessage("Error saving notification data");
button.disabled = false;
});
}
function testNotificationButton() {
const button = document.getElementById("testNotifications");
button.disabled = true;
const smtpAddress = document.getElementById("smtpaddress").value;
const smtpPort = document.getElementById("smtpport").value;
const smtpUsername = document.getElementById("smtpusername").value;
const smtpPassword = document.getElementById("smtppassword").value;
const data = {
smtpaddress: smtpAddress,
smtpport: smtpPort,
smtpusername: smtpUsername,
smtppassword: smtpPassword
};
fetch('/endpoints/notifications/sendtestmail.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
if (data.success) {
showSuccessMessage("Notification sent successfully.");
} else {
showErrorMessage(data.errorMessage);
}
button.disabled = false;
})
.catch(error => {
showErrorMessage("Error sending notification");
button.disabled = false;
});
}
function switchTheme() {
const darkThemeCss = document.querySelector("#dark-theme");
darkThemeCss.disabled = !darkThemeCss.disabled;