messages
This commit is contained in:
Witkopawel
2025-06-02 13:34:32 +02:00
parent a4cea4eeb3
commit fd6c4dfb11
16 changed files with 563 additions and 76 deletions

View File

@@ -39,7 +39,6 @@ function getEvents(titleOrDescription, fDate, tDate) {
titleOrDescription = searchbar.value;
}
if (optionsVisibility) {
// Opcje widoczne
var payload_visible = {
titleOrDescription,
eventDateFrom,
@@ -69,6 +68,32 @@ function getEvents(titleOrDescription, fDate, tDate) {
return events;
});
}
function sendMessageForEvent(eventId) {
return __awaiter(this, void 0, void 0, function* () {
const messageContent = `Help me with <a href="/view.html?event=${eventId}">this event</a>`;
try {
const response = yield fetch('/api/messages/sendFromOrgToVolunteers', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ eventId, content: messageContent })
});
if (response.ok) {
alert('Message sent successfully to all volunteers!');
}
else {
let error = yield response.text();
if (!error)
error = `Status code: ${response.status}`;
alert('Failed to send message: ' + error);
console.error('Send message failed', response.status, error);
}
}
catch (error) {
alert('Error sending message: ' + error);
console.error('Fetch error:', error);
}
});
}
function loadEvents(org_id, evs) {
return __awaiter(this, void 0, void 0, function* () {
const container = document.getElementById("eventList");
@@ -86,10 +111,7 @@ function loadEvents(org_id, evs) {
container.innerHTML = "<p class='text-muted'>No events to display at this moment.</p>";
return;
}
// Wyczyść kontener przed dodaniem nowych
container.innerHTML = '';
const styleDefault = "color: #2898BD";
const styleHighlighted = "#2393BD";
for (const ev of events) {
const card = document.createElement("div");
card.className = "event-card filled";
@@ -97,23 +119,39 @@ function loadEvents(org_id, evs) {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric' // "1"
day: 'numeric'
}).format(new Date(ev.eventDate));
card.innerHTML = `
<span>
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
<p style="margin: 0">👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}</p>
</span>`;
const eventInfoSpan = document.createElement("span");
eventInfoSpan.innerHTML = `
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
<p style="margin: 0">👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}</p>
`;
card.appendChild(eventInfoSpan);
if (org_id == ev.organisationId) {
card.innerHTML += `
<div>
<button class="edit-btn mod-btn" data-id="${ev.eventId}" id="edit-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>
</button>
<button class="remove-btn mod-btn" data-id="${ev.eventId}" id="remove-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
</button>
</div>`;
const buttonsDiv = document.createElement("div");
buttonsDiv.className = "d-flex gap-2 mt-2";
const editBtn = document.createElement("button");
editBtn.className = "edit-btn mod-btn";
editBtn.setAttribute("data-id", ev.eventId);
editBtn.title = "Edit event";
editBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>`;
const removeBtn = document.createElement("button");
removeBtn.className = "remove-btn mod-btn";
removeBtn.setAttribute("data-id", ev.eventId);
removeBtn.title = "Remove event";
removeBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>`;
const sendMsgBtn = document.createElement("button");
sendMsgBtn.className = "btn btn-sm btn-info";
sendMsgBtn.textContent = "Send Message";
sendMsgBtn.setAttribute("data-id", ev.eventId);
sendMsgBtn.title = "Send message about this event";
sendMsgBtn.addEventListener("click", () => __awaiter(this, void 0, void 0, function* () {
yield sendMessageForEvent(ev.eventId);
}));
buttonsDiv.appendChild(editBtn);
buttonsDiv.appendChild(removeBtn);
buttonsDiv.appendChild(sendMsgBtn);
card.appendChild(buttonsDiv);
}
container.appendChild(card);
}
@@ -138,12 +176,10 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
}
}
catch (_a) {
// console.log("User not signed in. Failing gracefully.");
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
loadEvents(org_id);
// listen for clicks
const listSortToggleButton = document.getElementById("list-sort-btn");
if (listSortToggleButton) {
listSortToggleButton.addEventListener("click", () => toggleListSortOrder(org_id));
@@ -152,11 +188,9 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
if (optionsToggleButton) {
optionsToggleButton.addEventListener("click", () => toggleOptionsVisibility());
}
// and for enter in search bar
const searchBar = document.getElementById('searchbar');
searchBar.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
// console.log('Enter key pressed!');
var searchResults = getEvents(searchBar.value);
loadEvents(org_id, searchResults);
}