cityssm/lottery-licence-manager

View on GitHub
public/javascripts/location-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=document.querySelector("#filter--inactiveYears"),a=document.querySelector("#container--searchResults"),s=t=>{const a=t.currentTarget,s=cityssm.escapeHTML(a.dataset.locationDisplayName);cityssm.confirmModal("Delete Location?",`Are you sure you want delete ${cityssm.escapeHTML(s)}?`,"Yes, Delete","danger",()=>{const t=a.dataset.locationId;cityssm.postJSON(e+"/locations/doDelete",{locationID:t},e=>{e.success?(cityssm.alertModal(e.message,"","OK","success"),a.closest("tr").remove()):cityssm.alertModal(e.message,"","OK","danger")})})},n=()=>{a.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 locations...</em></p>',cityssm.postJSON(e+"/locations/doGetInactive",{inactiveYears:t.value},t=>{if(0===t.length)return void(a.innerHTML='<div class="message is-info"><p class="message-body">There are no inactive locations to report.</p></div>');const n=document.createElement("table");n.className="table is-fullwidth is-striped is-hoverable has-sticky-header",n.innerHTML='<thead><tr><th>Location</th><th class="has-text-centered">Last Licence End Date</th><th class="has-text-centered">Last Updated</th><th><span class="sr-only">Delete</span></th></tr></thead>';const c=document.createElement("tbody");for(const a of t){const t=document.createElement("tr"),n=cityssm.escapeHTML(a.locationDisplayName);t.insertAdjacentHTML("beforeend",'<td><a data-tooltip="View Location" href="'+cityssm.escapeHTML(e)+"/locations/"+a.locationID.toString()+'">'+n+"</a>"+(a.locationDisplayName===a.locationAddress1?"":"<br /><small>"+cityssm.escapeHTML(a.locationAddress1)+"</small>")+"</td>");let i=a.licences_endDateMax,o=a.licences_endDateMaxString,r="Licence Location";a.distributor_endDateMax&&(!i||i<a.distributor_endDateMax)&&(i=a.distributor_endDateMax,o=a.distributor_endDateMaxString,r="Distributor"),a.manufacturer_endDateMax&&(!i||i<a.manufacturer_endDateMax)&&(i=a.manufacturer_endDateMax,o=a.manufacturer_endDateMaxString,r="Manufacturer"),t.insertAdjacentHTML("beforeend",'<td class="has-text-centered">'+(i?o+'<br /><span class="tag is-light is-info">'+r+"</span>":'<span class="tag is-light is-danger">No Licences</span>')+"</td>"),t.insertAdjacentHTML("beforeend",'<td class="has-text-centered"><span data-tooltip="Updated by '+a.recordUpdate_userName+'">'+a.recordUpdate_dateString+"</span></td>"),t.insertAdjacentHTML("beforeend",'<td class="has-text-right"><button class="button is-small is-danger" data-tooltip="Delete Location" data-location-id="'+a.locationID.toString()+'" data-location-display-name="'+n+'" type="button"><span class="icon"><i class="fas fa-trash" aria-hidden="true"></i></span> <span>Delete</span></button></td>'),t.querySelector("button").addEventListener("click",s),c.append(t)}n.append(c),cityssm.clearElement(a),a.append(n)})};t.addEventListener("change",n),n()})();