-
-
- {% endblock content %}
\ No newline at end of file
+
+
+
+{% endblock content %}
\ No newline at end of file
diff --git a/src/static/js/drive_dashboard.js b/src/static/js/drive_dashboard.js
index baa80b2..9c9db9a 100644
--- a/src/static/js/drive_dashboard.js
+++ b/src/static/js/drive_dashboard.js
@@ -3,7 +3,7 @@ document.addEventListener("DOMContentLoaded", () => {
const openModalBtns = document.querySelectorAll(".open-modal");
const closeModalBtns = document.querySelectorAll(".close-btn");
const contributeForm = document.getElementById("contribute-form");
- const contributionsTable = document.getElementById("contributions-table");
+ const contributionsTable = document.getElementById("contributions");
const orgDropdown = document.getElementById("donor_organization");
const mealsInput = document.getElementById("meals");
const volunteersInput = document.getElementById("volunteers");
@@ -42,7 +42,6 @@ document.addEventListener("DOMContentLoaded", () => {
// Fetch participation details dynamically when dropdown changes
orgDropdown.addEventListener("change", () => {
const selectedOrgId = orgDropdown.value;
- const driveId = contributeForm.dataset.driveId;
mealsInput.value = "";
volunteersInput.value = "";
@@ -76,6 +75,20 @@ document.addEventListener("DOMContentLoaded", () => {
deleteBtn.hidden = true; // Ensure the delete button stays hidden on error
});
});
+
+ fetch(`/community_drives/fetch-contributions/${driveId}/`)
+ .then(response => {
+ if (!response.ok) {
+ throw new Error("Network response was not ok");
+ }
+ return response.json();
+ })
+ .then(data => {
+ updateContributions(data);
+ })
+ .catch(error => {
+ console.error("Error fetching contributions:", error);
+ });
// Handle form submission
@@ -84,7 +97,6 @@ document.addEventListener("DOMContentLoaded", () => {
const meals = mealsInput.value;
const volunteers = volunteersInput.value;
const donorOrganization = orgDropdown.value;
- const driveId = contributeForm.dataset.driveId;
// Send data via AJAX (using Fetch API)
fetch(`/community_drives/drives/${driveId}/contribute/`, {
@@ -106,19 +118,10 @@ document.addEventListener("DOMContentLoaded", () => {
mealsInput.value = "";
volunteersInput.value = "";
if (data.success) {
+ contributionsTable.replaceChildren();
contributionsTable.innerHTML = "";
-
// Populate the table with the updated contributions
- data.contributions.forEach(contribution => {
- const row = document.createElement("tr");
- row.innerHTML = `
-
${contribution.organization_name} |
-
${contribution.meals_contributed} |
-
${contribution.volunteers_contributed} |
- `;
- contributionsTable.appendChild(row);
- });
-
+ updateContributions(data);
alert("Thank you for your contribution!");
} else {
alert("Failed to contribute." + data.error);
@@ -137,7 +140,6 @@ document.addEventListener("DOMContentLoaded", () => {
deleteBtn.addEventListener("click", (event) => {
event.preventDefault(); // Prevent form submission if delete button is clicked
const selectedOrgId = orgDropdown.value;
- const driveId = contributeForm.dataset.driveId;
// Make AJAX request to delete participation
fetch(`/community_drives/delete_participation/${selectedOrgId}/${driveId}/`, {
@@ -152,17 +154,7 @@ document.addEventListener("DOMContentLoaded", () => {
modal.classList.remove("is-active");
// Update the table or reset fields accordingly
contributionsTable.innerHTML = "";
-
- // Populate the table with the updated contributions
- data.contributions.forEach(contribution => {
- const row = document.createElement("tr");
- row.innerHTML = `
-
${contribution.organization_name} |
-
${contribution.meals_contributed} |
-
${contribution.volunteers_contributed} |
- `;
- contributionsTable.appendChild(row);
- });
+ updateContributions(data);
alert("Contribution successfully deleted!");
} else {
alert("Failed to delete contribution: " + data.error);
@@ -176,6 +168,67 @@ document.addEventListener("DOMContentLoaded", () => {
});
+function updateContributions(data) {
+ const contributionsTable = document.getElementById("contributions");
+ data.contributions.forEach(contribution => {
+ const row = document.createElement("article");
+ row.className = 'media is-align-items-center';
+ const iconContainer = document.createElement('figure');
+ iconContainer.className = 'media-left';
+ iconContainer.innerHTML = `
+
+
+
+
+
+
+ `;
+ row.appendChild(iconContainer);
+
+ const cardContainer = document.createElement('div');
+ cardContainer.className = 'media-content';
+ const formattedDate = new Date(contribution.created_at).toLocaleString('en-US', {
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric',
+ hour: '2-digit',
+ minute: '2-digit'
+ });
+ cardContainer.innerHTML = `
+
+
+
+
+
+ ${contribution.organization_name} contributed
+
+ ${formattedDate}
+
+
+
+
+ ${contribution.meals_contributed}
+
+ meals
+
+
+
+
+ ${contribution.volunteers_contributed}
+
+ volunteers
+
+
+
+
+
+ `;
+ row.appendChild(cardContainer);
+ contributionsTable.appendChild(row);
+ });
+}
+
+
function uploadDriveImage(inputElement) {
const driveId = inputElement.dataset.id;
const file = inputElement.files[0];
@@ -246,4 +299,4 @@ function deleteDriveImage(inputElement) {
alert("An error occurred while deleting the image.");
});
}
-}
\ No newline at end of file
+}
diff --git a/src/static/js/drive_list.js b/src/static/js/drive_list.js
index e0257f8..5e6885c 100644
--- a/src/static/js/drive_list.js
+++ b/src/static/js/drive_list.js
@@ -22,7 +22,7 @@ document.addEventListener('DOMContentLoaded', () => {
// If no matching tab was found, set 'pending-tab' as the default active tab and show its content
if (!activeTabExists) {
const defaultTab = document.getElementById('all-drives-tab');
- const defaultContent = document.getElementById('pending-orders');
+ const defaultContent = document.getElementById('all-drives');
if (defaultTab && defaultContent) {
defaultTab.classList.add('is-active');
@@ -85,6 +85,13 @@ document.addEventListener('DOMContentLoaded', () => {
closeAllModals();
}
});
+
+ document.querySelectorAll('.short-text').forEach(element => {
+ const maxChars = 300;
+ if (element.textContent.length > maxChars) {
+ element.textContent = element.textContent.slice(0, maxChars-3) + ' ...';
+ }
+ });
});
diff --git a/src/static/js/org_list_tabs.js b/src/static/js/org_list_tabs.js
index 7d6e954..4246770 100644
--- a/src/static/js/org_list_tabs.js
+++ b/src/static/js/org_list_tabs.js
@@ -48,7 +48,14 @@ document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.short-text').forEach(element => {
const maxChars = 20;
if (element.textContent.length > maxChars) {
- element.textContent = element.textContent.slice(0, maxChars) + '...';
+ element.textContent = element.textContent.slice(0, maxChars-3) + '...';
+ }
+ });
+
+ document.querySelectorAll('.short-addr').forEach(element => {
+ const maxChars = 35;
+ if (element.textContent.length > maxChars) {
+ element.textContent = element.textContent.slice(0, maxChars-3) + '...';
}
});
});
\ No newline at end of file