// `);
// });
},
error: function (xhr) {
alert("Failed to fetch applications.");
}
});
}
// UPDATE
$(document).on("click", ".editBtn", function () {
let id = $(this).data("id");
let updatedData = {
comment_body: prompt("Enter new comment:")
};
$.ajax({
url: `${baseUrl}/${id}`,
type: "PUT",
data: updatedData,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Accept": "application/json"
},
success: function (response) {
alert("Application Updated!");
console.log(response);
fetchPermitApplicationComments();
},
error: function (xhr) {
alert("Update failed: " + xhr.responseText);
}
});
});
// DELETE
$(document).on("click", ".deleteBtn", function () {
let id = $(this).data("id");
if (confirm("Are you sure you want to delete this application?")) {
$.ajax({
url: `${baseUrl}/${id}`,
type: "DELETE",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Accept": "application/json"
},
success: function (response) {
alert("Application Deleted!");
console.log(response);
fetchPermitApplicationComments();
},
error: function (xhr) {
alert("Delete failed: " + xhr.responseText);
}
});
}
});
// Example AJAX setup assuming your response is stored in a variable called 'response'
function populateCommentsTimeline(response) {
const $timeline = $('#commentsTimeline');
// Clear out any old data or loading spinners
$timeline.empty();
// Check if we have a successful response with data
if (response.success && response.count > 0) {
// Loop through each comment in the data array
$.each(response.data, function(index, item) {
// Format the date to look like "19 Jun 2026, 06:55 PM"
const dateObj = new Date(item.created_date);
const formattedDate = dateObj.toLocaleDateString('en-GB', {
day: 'numeric',
month: 'short',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: true
});
// Construct the Timeline Item HTML
const timelineHtml = `
${item.created_by}
${formattedDate}
${item.app_comments}
`;
// Append it to the container
$timeline.append(timelineHtml);
});
}
else {
// Fallback UI if there are no comments yet
$timeline.append(`
No history or comments found for this application.