Notes
![]() ![]() Notes - notes.io |
// Event listener for "Show Details" buttons
$(document).on('click', '.show-details', function () {
const announcementId = $(this).data('id');
// Fetch announcement details from your API
$.ajax({
url: `/api/announcements/${announcementId}`,
method: 'GET',
success: function (announcement) {
// Construct the announcement details HTML
const announcementHtml = `
<div class="announcement-card">
<div class="card">
<div class="card-body">
<p class="card-text">${announcement.content}</p>
</div>
</div>
</div>
`;
// Load the announcement details into the modal's body
$('#announcementDetailsBody').html(announcementHtml);
// Show the modal
$('#announcementDetailsModal').modal('show');
},
error: function (error) {
console.error('Error fetching announcement details:', error);
}
});
});
});
// Attach event listener for "View Comments & Follow Ups" buttons using event delegation
$('#announcementTable').on('click', '.view-comments-follow-ups', function () {
var announcementId = $(this).data('id');
fetchAndDisplayCombinedCommentsFollowUps(announcementId);
});
function fetchAndDisplayCombinedCommentsFollowUps(announcementId) {
Promise.all([
fetch(`/api/comments/ByAnnouncement/${announcementId}`).then(handleResponse),
fetch(`/api/Comments/ByAnnouncement/${announcementId}/follow-ups`).then(handleResponse)
]).then(([comments, followUps]) => {
// Add a 'type' property to each comment and follow-up
comments = comments.map(comment => ({ ...comment, type: 'comment' }));
followUps = followUps.map(followUp => ({ ...followUp, type: 'follow-up' }));
// Combine and sort the comments and follow-ups
const combinedItems = [...comments, ...followUps].sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
// Check if there are no comments and follow-ups
if (combinedItems.length === 0) {
document.getElementById('combinedTimeline').innerHTML = '<p>There are no comments nor follow-ups.</p>';
$('#combinedCommentsFollowUpsModal').modal('show');
return;
}
// Generate the HTML for the combined timeline
let timelineHtml = '<ul class="timeline">';
combinedItems.forEach(item => {
if (item.type === 'comment') {
timelineHtml += `<li>${item.author}: ${item.content}</li>`;
} else if (item.type === 'follow-up') {
timelineHtml += `<li><em>${item.requestedBy} requested a follow-up</em>: ${item.content}</li>`;
}
});
timelineHtml += '</ul>';
// Update the modal's content and display it
document.getElementById('combinedTimeline').innerHTML = timelineHtml;
$('#combinedCommentsFollowUpsModal').modal('show');
}).catch(error => {
console.error("Error fetching combined comments and follow-ups:", error);
document.getElementById('combinedTimeline').innerHTML = '<p>There are no comments nor follow-ups.</p>';
$('#combinedCommentsFollowUpsModal').modal('show');
});
}
// Helper function to handle fetch response
function handleResponse(response) {
if (!response.ok) {
// If the response status is 204 (No Content), treat it as an empty array
if (response.status === 204) {
return [];
}
throw new Error('Failed to fetch data');
}
return response.json();
}
// Attach event listener for pin/unpin buttons using event delegation
$('#announcementTable').on('click', '.toggle-pin', function () {
var announcementId = $(this).data('id'); // Ensure this correctly retrieves the announcementId
var isPinned = $(this).data('pinned') == true; // Use boolean comparison for clarity
var $this = $(this);
$.ajax({
url: `/api/announcements/${announcementId}/toggle-pin`, // Correctly use announcementId here
method: 'POST',
success: function (response) {
// Toggle the pin status based on the current state
$this.data('pinned', !isPinned); // Update the data-pinned attribute to the new state
// Update button classes and text to reflect the new state
if (isPinned) {
$this.removeClass('btn-danger').addClass('btn-success').text('Pin');
} else {
$this.removeClass('btn-success').addClass('btn-danger').text('Unpin');
}
},
error: function (error) {
console.error('Error toggling pin:', error);
// Optionally, alert the user about the error
alert('Failed to toggle pin status. Please try again.');
}
});
});
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team