cityssm/lottery-licence-manager

View on GitHub
public/javascripts/organization-cleanup.min.js

Summary

Maintainability
A
0 mins
Test Coverage
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const e=document.querySelector("main").dataset.urlPrefix,t=cityssm.escapeHTML(e),a="true"===document.querySelector("main").dataset.canUpdate,s=document.querySelector("#filter--inactiveYears"),n=document.querySelector("#container--searchResults"),r=t=>{const a=t.currentTarget,s=a.getAttribute("data-organization-name");cityssm.confirmModal("Delete Organization?","Are you sure you want delete "+cityssm.escapeHTML(s)+"?","Yes, Delete","danger",()=>{const t=a.getAttribute("data-organization-id");cityssm.postJSON(e+"/organizations/doDelete",{organizationID:t},e=>{e.success?(cityssm.alertModal(e.message,"","OK","success"),a.closest("tr").remove()):cityssm.alertModal(e.message,"","OK","danger")})})},i=()=>{n.innerHTML='<p class="has-text-centered has-text-grey-lighter"><i class="fas fa-3x fa-circle-notch fa-spin" aria-hidden="true"></i><br /><em>Loading organizations...</em></p>',cityssm.postJSON(e+"/organizations/doGetInactive",{inactiveYears:s.value},e=>{if(0===e.length)return void(n.innerHTML='<div class="message is-info"><p class="message-body">There are no inactive organizations to report.</p></div>');const s=document.createElement("table");s.className="table is-fullwidth is-striped is-hoverable has-sticky-header",s.innerHTML='<thead><tr><th>Organization</th><th class="has-text-centered">Last Licence End Date</th><th class="has-text-centered">Created</th><th class="has-text-centered">Last Updated</th>'+(a?'<th><span class="sr-only">Delete</span></th>':"")+"</tr></thead>";const i=document.createElement("tbody");for(const s of e){const e=document.createElement("tr"),n=cityssm.escapeHTML(s.organizationName);e.innerHTML='<td><a data-tooltip="View Organization" href="'+t+"/organizations/"+s.organizationID.toString()+'">'+n+'</a></td><td class="has-text-centered">'+(s.licences_endDateMax?s.licences_endDateMaxString:'<span class="tag is-light is-danger">No Licences</span>')+'</td><td class="has-text-centered"><span data-tooltip="Created by '+s.recordCreate_userName+'">'+s.recordCreate_dateString+'</span></td><td class="has-text-centered"><span data-tooltip="Updated by '+s.recordUpdate_userName+'">'+s.recordUpdate_dateString+"</span></td>",a&&(e.insertAdjacentHTML("beforeend",'<td class="has-text-right"><button class="button is-small is-danger" data-tooltip="Delete Organization" data-organization-id="'+s.organizationID.toString()+'" data-organization-name="'+n+'" type="button"><span class="icon"><i class="fas fa-trash" aria-hidden="true"></i></span> <span>Delete</span></button></td>'),e.querySelector("button").addEventListener("click",r)),i.append(e)}s.append(i),cityssm.clearElement(n),n.append(s)})};s.addEventListener("change",i),i()})();