🔔 User Notifications v0.5

This commit is contained in:
jokob-sk
2024-06-01 20:59:54 +10:00
parent cb3c0ecee7
commit d14fc6586a
4 changed files with 78 additions and 36 deletions

View File

@@ -10,6 +10,7 @@ require 'php/templates/header.php';
<script src="lib/AdminLTE/bower_components/datatables.net/js/dataTables.select.min.js"></script>
<div id="notifications" class="content-wrapper">
<div class="box-body table-responsive">
<table id="notificationsTable" class="table table-bordered table-hover table-striped display">
<thead>
<tr>
@@ -25,10 +26,12 @@ require 'php/templates/header.php';
</tbody>
</table>
</div>
<button id="clearNotificationsBtn" class="btn btn-danger">Clear All Notifications</button>
</div>
<script>
function fetchData(callback) {
$.ajax({
url: '/api/user_notifications.json',
url: '/api/user_notifications.json?nocache=' + Date.now(),
method: 'GET',
dataType: 'json',
success: function(response) {
@@ -62,7 +65,12 @@ require 'php/templates/header.php';
{
"data": "content",
"render": function(data, type, row) {
return `<span class="btn-show-message">${data}</span>`;
if (data.includes("Report:")) {
var guid = data.split(":")[1].trim();
return `<a href="/report.php?guid=${guid}">Click to see Sent Report</a>`;
} else {
return data;
}
}
}
],
@@ -77,6 +85,28 @@ require 'php/templates/header.php';
fetchData(function(data) {
table.clear().rows.add(data).draw();
});
const phpEndpoint = 'php/server/utilNotification.php';
// Function to clear all notifications
$('#clearNotificationsBtn').click(function() {
$.ajax({
url: phpEndpoint,
type: 'GET',
data: {
action: 'notifications_clear'
},
success: function(response) {
// Clear the table and reload data
table.clear().draw();
},
error: function(xhr, status, error) {
console.log("An error occurred while clearing notifications: " + error);
// You can display an error message here if needed
}
});
});
});
</script>