cityssm/lottery-licence-manager

View on GitHub
public/javascripts/organization-edit.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("#form--organization"),r=document.querySelector("#container--form-message"),n=document.querySelector("#organization--organizationID").value,a=""===n,s=""===n?void 0:Number.parseInt(n,10);if(t.addEventListener("submit",n=>{n.preventDefault(),r.innerHTML='Saving... <i class="fas fa-circle-notch fa-spin" aria-hidden="true"></i>',cityssm.postJSON(e+"/organizations/doSave",t,t=>{t.success&&cityssm.disableNavBlocker(),t.success&&a?window.location.href=e+"/organizations/"+t.organizationID.toString()+"/edit":(r.innerHTML="",cityssm.alertModal(t.message,"","OK",t.success?"success":"danger"))})}),!a){const r=()=>{cityssm.postJSON(e+"/organizations/doDelete",{organizationID:s},t=>{t.success&&(window.location.href=e+"/organizations")})};t.querySelector(".is-delete-button").addEventListener("click",()=>{cityssm.confirmModal("Delete Organization?","Are you sure you want to delete this organization?<br />Note that any active licences issued to this organization will remain active.","Yes, Delete Organization","warning",r)}),t.querySelector(".is-rollforward-button").addEventListener("click",()=>{let t,r,a=!1;const s=n=>{n.preventDefault(),a||(a=!0,cityssm.postJSON(e+"/organizations/doRollForward",r,e=>{e.success?window.location.reload():(a=!1,t(),cityssm.alertModal("Roll Forward Failed",e.message,"OK","danger"))}))};cityssm.openHtmlModal("organization-rollforward",{onshown:(e,a)=>{t=a,document.querySelector("#rollforward--organizationID").value=n,(r=document.querySelector("#form--rollforward")).addEventListener("submit",s)}})});const a=document.querySelector(".is-representative-table tbody"),i=()=>{0===a.querySelectorAll("tr").length&&(a.innerHTML='<tr class="has-background-warning is-empty-warning"><td class="has-text-centered" colspan="6"><strong>There are no representatives associated with this organization.</strong></td></tr>')};i();const o=t=>{const r=t.currentTarget.value;cityssm.postJSON(e+"/organizations/"+n+"/doSetDefaultRepresentative",{isDefaultRepresentativeIndex:r},()=>{})},d=a.querySelectorAll("input");for(const e of d)e.addEventListener("change",o);const c=t=>{t.preventDefault();const r=t.currentTarget.closest("tr"),a=r.getAttribute("data-representative-name");cityssm.confirmModal("Delete a Representative?",`<p>Are you sure you want to delete the representative "${cityssm.escapeHTML(a)}"?</p>`,"Yes, Delete","danger",()=>{cityssm.postJSON(e+"/organizations/"+n+"/doDeleteOrganizationRepresentative",{representativeIndex:r.getAttribute("data-representative-index")},e=>{e.success&&(r.remove(),i())})})},l=a.querySelectorAll(".is-delete-representative-button");for(const e of l)e.addEventListener("click",c);const u=document.querySelector(".is-edit-representative-modal"),p=u.querySelector("form");let m;const v=e=>{const t=(m=e.currentTarget.closest("tr")).dataset.representativeIndex;document.querySelector("#editOrganizationRepresentative--representativeIndex").value=t,document.querySelector("#editOrganizationRepresentative--representativeName").value=m.getAttribute("data-representative-name"),document.querySelector("#editOrganizationRepresentative--representativeTitle").value=m.getAttribute("data-representative-title"),document.querySelector("#editOrganizationRepresentative--representativeAddress1").value=m.getAttribute("data-representative-address-1"),document.querySelector("#editOrganizationRepresentative--representativeAddress2").value=m.getAttribute("data-representative-address-2"),document.querySelector("#editOrganizationRepresentative--representativeCity").value=m.getAttribute("data-representative-city"),document.querySelector("#editOrganizationRepresentative--representativeProvince").value=m.getAttribute("data-representative-province"),document.querySelector("#editOrganizationRepresentative--representativePostalCode").value=m.getAttribute("data-representative-postal-code"),document.querySelector("#editOrganizationRepresentative--representativePhoneNumber").value=m.getAttribute("data-representative-phone-number"),document.querySelector("#editOrganizationRepresentative--representativePhoneNumber2").value=m.getAttribute("data-representative-phone-number-2"),document.querySelector("#editOrganizationRepresentative--representativeEmailAddress").value=m.getAttribute("data-representative-email-address"),document.querySelector("#editOrganizationRepresentative--isDefault").value=document.querySelector("#representative-isDefault--"+t).checked?"1":"0",cityssm.showModal(u)},g=e=>{const t=document.createElement("tr");t.dataset.representativeIndex=e.representativeIndex.toString(),t.dataset.representativeName=e.representativeName,t.dataset.representativeTitle=e.representativeTitle,t.dataset["representativeAddress-1"]=e.representativeAddress1,t.dataset["representativeAddress-2"]=e.representativeAddress2,t.dataset.representativeCity=e.representativeCity,t.dataset.representativeProvince=e.representativeProvince,t.dataset.representativePostalCode=e.representativePostalCode,t.dataset.representativePhoneNumber=e.representativePhoneNumber,t.dataset["representativePhoneNumber-2"]=e.representativePhoneNumber2,t.dataset.representativeEmailAddress=e.representativeEmailAddress,t.insertAdjacentHTML("beforeend",'<td><div class="field"><input class="is-checkradio is-info" id="representative-isDefault--'+e.representativeIndex.toString()+'" name="representative-isDefault" type="radio"'+(e.isDefault?" checked":"")+' />&nbsp;<label for="representative-isDefault--'+e.representativeIndex.toString()+'"></label></div></td>'),t.querySelector("input").addEventListener("change",o);let r=document.createElement("td");r.innerHTML=cityssm.escapeHTML(e.representativeName)+"<br /><small>"+cityssm.escapeHTML(e.representativeTitle)+"</small>",t.append(r),(r=document.createElement("td")).innerHTML=cityssm.escapeHTML(e.representativeAddress1)+"<br /><small>"+(""===e.representativeAddress2?"":cityssm.escapeHTML(e.representativeAddress2)+"<br />")+cityssm.escapeHTML(e.representativeCity)+", "+cityssm.escapeHTML(e.representativeProvince)+"<br />"+cityssm.escapeHTML(e.representativePostalCode)+"</small>",t.append(r),(r=document.createElement("td")).innerHTML=cityssm.escapeHTML(e.representativePhoneNumber)+"<br />"+cityssm.escapeHTML(e.representativePhoneNumber2),t.append(r),(r=document.createElement("td")).innerHTML=cityssm.escapeHTML(e.representativeEmailAddress),t.append(r),t.insertAdjacentHTML("beforeend",'<td><div class="buttons is-right has-addons"><button class="button is-small is-edit-representative-button" data-tooltip="Edit Representative" type="button"><span class="icon"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span><span>Edit</span></button><button class="button is-small has-text-danger is-delete-representative-button" data-tooltip="Delete Representative" type="button"><i class="fas fa-trash" aria-hidden="true"></i><span class="sr-only">Delete</span></button></td>'),t.querySelector(".is-edit-representative-button").addEventListener("click",v),t.querySelector(".is-delete-representative-button").addEventListener("click",c),a.append(t)},y=a.querySelectorAll(".is-edit-representative-button");for(const e of y)e.addEventListener("click",v);let b=u.querySelectorAll(".is-cancel-button");for(const e of b)e.addEventListener("click",cityssm.hideModal);p.addEventListener("submit",t=>{t.preventDefault(),cityssm.postJSON(e+"/organizations/"+n+"/doEditOrganizationRepresentative",t.currentTarget,e=>{e.success&&(m.remove(),m=void 0,g(e.organizationRepresentative),cityssm.hideModal(u))})});const S=document.querySelector(".is-add-representative-modal"),f=S.querySelector("form");document.querySelector(".is-add-representative-button").addEventListener("click",()=>{f.reset(),cityssm.showModal(S),document.querySelector("#addOrganizationRepresentative--representativeName").focus()}),b=S.querySelectorAll(".is-cancel-button");for(const e of b)e.addEventListener("click",cityssm.hideModal);f.addEventListener("submit",t=>{t.preventDefault(),cityssm.postJSON(e+"/organizations/"+n+"/doAddOrganizationRepresentative",t.currentTarget,e=>{if(e.success){const t=a.querySelectorAll(".is-empty-warning");t.length>0&&t[0].remove(),g(e.organizationRepresentative),cityssm.hideModal(S)}})}),S.querySelector(".is-copy-organization-address-button").addEventListener("click",e=>{e.preventDefault(),document.querySelector("#addOrganizationRepresentative--representativeAddress1").value=document.querySelector("#organization--organizationAddress1").value,document.querySelector("#addOrganizationRepresentative--representativeAddress2").value=document.querySelector("#organization--organizationAddress2").value,document.querySelector("#addOrganizationRepresentative--representativeCity").value=document.querySelector("#organization--organizationCity").value,document.querySelector("#addOrganizationRepresentative--representativeProvince").value=document.querySelector("#organization--organizationProvince").value,document.querySelector("#addOrganizationRepresentative--representativePostalCode").value=document.querySelector("#organization--organizationPostalCode").value});const h=e=>{e.preventDefault();const t=e.currentTarget,r=Number.parseInt(t.dataset.reminderIndex,10);llm.organizationReminders.deleteReminder(s,r,!0,e=>{e.success&&t.closest("tr").remove()})},z=e=>{e.preventDefault();const t=e.currentTarget,r=Number.parseInt(t.dataset.reminderIndex,10);llm.organizationReminders.dismissReminder(s,r,!0,e=>{e.success&&llm.organizationReminders.loadReminderTypeCache(()=>{const r=t.closest("tr"),n=A(e.reminder);r.after(n),r.remove()})})},q=e=>{e.preventDefault();const t=e.currentTarget,r=Number.parseInt(t.dataset.reminderIndex,10);llm.organizationReminders.openEditReminderModal(s,r,e=>{const r=t.closest("tr"),n=A(e);r.after(n),r.remove()})},A=e=>{const t=llm.organizationReminders.getReminderType(e.reminderTypeKey),r=document.createElement("tr");let n="";return n=""===e.dueDateString?'<span class="has-text-grey">(No Due Date Set)</span>':""!==e.dismissedDateString?'<span class="has-text-grey is-linethrough">'+e.dueDateString+"</span>":e.dueDateString,r.innerHTML="<td>"+(t?t.reminderType+'<br /><span class="is-size-7">'+t.reminderCategory+"</span>":e.reminderTypeKey)+"</td><td>"+(e.reminderStatus||"")+'</td><td class="has-text-centered">'+(""===e.dismissedDateString?'<span class="has-text-grey">(Active)</span><br /><button class="button is-small is-light is-success is-dismiss-reminder-button mt-1" data-reminder-index="'+e.reminderIndex.toString()+'"><span class="icon is-small"><i class="fas fa-check" aria-hidden="true"></i></span><span>Dismiss</span></button>':e.dismissedDateString)+'</td><td class="has-text-centered">'+n+'</td><td class="is-hidden-print"><div class="buttons is-right has-addons is-hidden-status-view"><button class="button is-small is-edit-reminder-button" data-reminder-index="'+e.reminderIndex.toString()+'" data-tooltip="Edit Reminder" type="button"><span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span><span>Edit</span></button><button class="button is-small has-text-danger is-delete-reminder-button" data-reminder-index="'+e.reminderIndex.toString()+'" data-tooltip="Delete Reminder" type="button"><i class="fas fa-trash" aria-hidden="true"></i><span class="sr-only">Delete</span></button></div></td>',""===e.dismissedDateString&&r.querySelector(".is-dismiss-reminder-button").addEventListener("click",z),r.querySelector(".is-edit-reminder-button").addEventListener("click",q),r.querySelector(".is-delete-reminder-button").addEventListener("click",h),r};document.querySelector("#is-add-reminder-button").addEventListener("click",e=>{e.preventDefault(),llm.organizationReminders.openAddReminderModal(s,e=>{const t=A(e);document.querySelector("#container--reminders").prepend(t)})});const L=document.querySelectorAll(".is-dismiss-reminder-button");for(const e of L)e.addEventListener("click",z);const R=document.querySelectorAll(".is-edit-reminder-button");for(const e of R)e.addEventListener("click",q);const D=document.querySelectorAll(".is-delete-reminder-button");for(const e of D)e.addEventListener("click",h)}const i=()=>{cityssm.enableNavBlocker(),r.innerHTML='<span class="tag is-light is-info is-medium"><span class="icon"><i class="fas fa-exclamation-triangle" aria-hidden="true"></i></span> <span>Unsaved Changes</span></div>'},o=t.querySelectorAll("input, select, textarea");for(const e of o)e.addEventListener("change",i)})();