Skip to content

Commit

Permalink
Lint and fix stats button
Browse files Browse the repository at this point in the history
  • Loading branch information
fblupi committed Jan 9, 2025
1 parent 19c740c commit 0d998c2
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions app/packs/src/decidim/direct_verifications/admin/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class VerificationUI {
}

addModal() {
// Create the modal HTML
const modalHtml = `
<div id="show-verifications-modal" data-dialog="show-verifications-modal" role="dialog" tabindex="-1"
aria-hidden="true" aria-modal="true" aria-labelledby="dialog-title-show-verifications-modal" aria-describedby="dialog-desc-show-verifications-modal">
Expand All @@ -31,19 +30,15 @@ class VerificationUI {
</div>
</div>`;

// Convert the string to a DOM element
const tempDiv = document.createElement("div");
tempDiv.innerHTML = modalHtml.trim();
this.modal = tempDiv.firstChild;

// Insert the modal after the table
this.table.parentNode.insertBefore(this.modal, this.table.nextSibling);

// Find modal components
this.modalBody = this.modal.querySelector(".modal-body");
this.closeButton = this.modal.querySelector(".close-button");

// Add event listeners
this.closeButton.addEventListener("click", () => this.hideModal());
this.modal.addEventListener("click", (event) => {
if (event.target === this.modal) {
Expand All @@ -54,34 +49,19 @@ class VerificationUI {

drawButtons() {
const rows = this.table.querySelectorAll("tbody tr");
console.log(rows);
rows.forEach((tr) => {
const lastTd = tr.querySelector("td:last-child");
if (lastTd) {
const buttonHtml = `<span><a class="action-icon show-verifications-modal" title="${this.config.buttonTitle}" href="#open-show-verifications-modal"><span class="has-tip ${this.getTrStatus(tr)}"><svg aria-label="${this.config.buttonTitle}" role="img" class="icon--ban icon"><title>${this.config.buttonTitle}</title><use href="${this.svgPath}#ri-key-2-line"></use></svg></span></a></span>`;
console.log(buttonHtml);
lastTd.innerHTML = buttonHtml + lastTd.innerHTML;
}
});
}

addStatsTitle() {
// Create a link element for verification stats
const a = document.createElement("a");
a.className = "button tiny button--title";
a.href = this.config.statsPath;
a.textContent = this.config.statsLabel;

// Add a click event listener to prevent default navigation and load URL
a.addEventListener("click", (event) => {
event.preventDefault();
this.loadUrl(a.href, true);
});

// Append the link to the title element
if (this.title) {
this.title.appendChild(a);
}
const element = document.querySelector(".item_show__header-title");
const button = `<a class="button button__sm button__secondary" href="/admin/direct_verifications/stats">${this.config.statsLabel}</a>`;
element.innerHTML += button;
}

getTrStatus(tr) {
Expand Down Expand Up @@ -121,17 +101,13 @@ class VerificationUI {
}

loadUrl(url, large = false) {
// Adjust modal size
if (large) {
this.modal.classList.add("large");
} else {
this.modal.classList.remove("large");
}

// Show loading spinner in the modal body
this.modalBody.innerHTML = '<span class="loading-spinner"></span>';

// Fetch and load the content into the modal body
fetch(url).
then((response) => response.text()).
then((html) => {
Expand All @@ -148,7 +124,6 @@ class VerificationUI {
document.addEventListener("DOMContentLoaded", () => {
// eslint-disable-next-line no-undef
const ui = new VerificationUI(document.querySelector("#user-groups table.table-list"), DirectVerificationsConfig);
// Draw the icon buttons for checking verification statuses
ui.drawButtons();
ui.addStatsTitle();
});

0 comments on commit 0d998c2

Please sign in to comment.