1 line
7.2 KiB
JavaScript
1 line
7.2 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const e=exports.los,t=document.querySelector("#lot--lotId").value,o=""===t;let l=!1,s=o;const n=()=>{l||(l=!0,cityssm.enableNavBlocker())},a=document.querySelector("#form--lot");a.addEventListener("submit",t=>{t.preventDefault(),cityssm.postJSON(e.urlPrefix+"/lots/"+(o?"doCreateLot":"doUpdateLot"),a,t=>{t.success?(l=!1,cityssm.disableNavBlocker(),o||s?window.location.href=e.urlPrefix+"/lots/"+t.lotId+"/edit?t="+Date.now():bulmaJS.alert({message:exports.aliases.lot+" Updated Successfully",contextualColorName:"success"})):bulmaJS.alert({title:"Error Updating "+exports.aliases.lot,message:t.errorMessage||"",contextualColorName:"danger"})})});const r=a.querySelectorAll("input, select");for(const e of r)e.addEventListener("change",n);e.initializeUnlockFieldButtons(a),o||document.querySelector("#button--deleteLot").addEventListener("click",o=>{o.preventDefault();bulmaJS.confirm({title:"Delete "+exports.aliases.lot,message:"Are you sure you want to delete this "+exports.aliases.lot.toLowerCase()+"?",contextualColorName:"warning",okButton:{text:"Yes, Delete "+exports.aliases.lot,callbackFunction:()=>{cityssm.postJSON(e.urlPrefix+"/lots/doDeleteLot",{lotId:t},t=>{t.success?(cityssm.disableNavBlocker(),window.location.href=e.urlPrefix+"/lots/?t="+Date.now()):bulmaJS.alert({title:"Error Deleting "+exports.aliases.lot,message:t.errorMessage||"",contextualColorName:"danger"})})}}})});const i=document.querySelector("#lot--lotTypeId");if(o){const t=document.querySelector("#container--lotFields");i.addEventListener("change",()=>{""!==i.value?cityssm.postJSON(e.urlPrefix+"/lots/doGetLotTypeFields",{lotTypeId:i.value},e=>{if(0===e.lotTypeFields.length)return void(t.innerHTML='<div class="message is-info"><p class="message-body">There are no additional fields for this '+exports.aliases.lot.toLowerCase()+" type.</p></div>");t.innerHTML="";let o="";for(const l of e.lotTypeFields){o+=","+l.lotTypeFieldId;const e="lotFieldValue_"+l.lotTypeFieldId,s="lot--"+e,n=document.createElement("div");if(n.className="field",n.innerHTML='<label class="label" for="'+s+'"></label><div class="control"></div>',n.querySelector("label").textContent=l.lotTypeField,""===l.lotTypeFieldValues){const t=document.createElement("input");t.className="input",t.id=s,t.name=e,t.type="text",t.required=l.isRequired,t.minLength=l.minimumLength,t.maxLength=l.maximumLength,l.pattern&&""!==l.pattern&&(t.pattern=l.pattern),n.querySelector(".control").append(t)}else{n.querySelector(".control").innerHTML='<div class="select is-fullwidth"><select id="'+s+'" name="'+e+'"><option value="">(Not Set)</option></select></div>';const t=n.querySelector("select");t.required=l.isRequired;const o=l.lotTypeFieldValues.split("\n");for(const e of o){const o=document.createElement("option");o.value=e,o.textContent=e,t.append(o)}}t.append(n)}t.insertAdjacentHTML("beforeend",'<input name="lotTypeFieldIds" type="hidden" value="'+o.slice(1)+'" />')}):t.innerHTML='<div class="message is-info"><p class="message-body">Select the '+exports.aliases.lot.toLowerCase()+" type to load the available fields.</p></div>"})}else{const e=i.value;i.addEventListener("change",()=>{i.value!==e&&bulmaJS.confirm({title:"Confirm Change",message:"Are you sure you want to change the "+exports.aliases.lot.toLowerCase()+" type?\nThis change affects the additional fields associated with this record.",contextualColorName:"warning",okButton:{text:"Yes, Keep the Change",callbackFunction:()=>{s=!0}},cancelButton:{text:"Revert the Change",callbackFunction:()=>{i.value=e}}})})}let m=exports.lotComments;delete exports.lotComments;const d=o=>{const l=Number.parseInt(o.currentTarget.closest("tr").dataset.lotCommentId,10),s=m.find(e=>e.lotCommentId===l);let n,a;const r=t=>{t.preventDefault(),cityssm.postJSON(e.urlPrefix+"/lots/doUpdateLotComment",n,e=>{e.success?(m=e.lotComments,a(),u()):bulmaJS.alert({title:"Error Updating Comment",message:e.errorMessage||"",contextualColorName:"danger"})})};cityssm.openHtmlModal("lot-editComment",{onshow:o=>{e.populateAliases(o),o.querySelector("#lotCommentEdit--lotId").value=t,o.querySelector("#lotCommentEdit--lotCommentId").value=l.toString(),o.querySelector("#lotCommentEdit--lotComment").value=s.lotComment;const n=o.querySelector("#lotCommentEdit--lotCommentDateString");n.value=s.lotCommentDateString;const a=cityssm.dateToString(new Date);n.max=s.lotCommentDateString<=a?a:s.lotCommentDateString,o.querySelector("#lotCommentEdit--lotCommentTimeString").value=s.lotCommentTimeString},onshown:(t,o)=>{bulmaJS.toggleHtmlClipped(),e.initializeDatePickers(t),t.querySelector("#lotCommentEdit--lotComment").focus(),(n=t.querySelector("form")).addEventListener("submit",r),a=o},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},c=o=>{const l=Number.parseInt(o.currentTarget.closest("tr").dataset.lotCommentId,10);bulmaJS.confirm({title:"Remove Comment?",message:"Are you sure you want to remove this comment?",okButton:{text:"Yes, Remove Comment",callbackFunction:()=>{cityssm.postJSON(e.urlPrefix+"/lots/doDeleteLotComment",{lotId:t,lotCommentId:l},e=>{e.success?(m=e.lotComments,u()):bulmaJS.alert({title:"Error Removing Comment",message:e.errorMessage||"",contextualColorName:"danger"})})}},contextualColorName:"warning"})},u=()=>{const e=document.querySelector("#container--lotComments");if(0===m.length)return void(e.innerHTML='<div class="message is-info"><p class="message-body">There are no comments to display.</p></div>');const t=document.createElement("table");t.className="table is-fullwidth is-striped is-hoverable",t.innerHTML='<thead><tr><th>Commentor</th><th>Comment Date</th><th>Comment</th><th class="is-hidden-print"><span class="is-sr-only">Options</span></th></tr></thead><tbody></tbody>';for(const e of m){const o=document.createElement("tr");o.dataset.lotCommentId=e.lotCommentId.toString(),o.innerHTML="<td>"+cityssm.escapeHTML(e.recordCreate_userName||"")+"</td><td>"+e.lotCommentDateString+(0===e.lotCommentTime?"":" "+e.lotCommentTimeString)+"</td><td>"+cityssm.escapeHTML(e.lotComment||"")+'</td><td class="is-hidden-print"><div class="buttons are-small is-justify-content-end"><button class="button is-primary button--edit" 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-light is-danger button--delete" data-tooltip="Delete Comment" type="button" aria-label="Delete"><i class="fas fa-trash" aria-hidden="true"></i></button></div></td>',o.querySelector(".button--edit").addEventListener("click",d),o.querySelector(".button--delete").addEventListener("click",c),t.querySelector("tbody").append(o)}e.innerHTML="",e.append(t)},p=()=>{let o;const l=t=>{t.preventDefault(),cityssm.postJSON(e.urlPrefix+"/lots/doAddLotComment",t.currentTarget,e=>{e.success&&(m=e.lotComments,u(),o())})};cityssm.openHtmlModal("lot-addComment",{onshow(o){e.populateAliases(o),o.querySelector("#lotCommentAdd--lotId").value=t,o.querySelector("form").addEventListener("submit",l)},onshown(e,t){bulmaJS.toggleHtmlClipped(),o=t,e.querySelector("#lotCommentAdd--lotComment").focus()},onremoved(){bulmaJS.toggleHtmlClipped(),document.querySelector("#lotComments--add").focus()}})};o||(document.querySelector("#lotComments--add").addEventListener("click",p),u())})(); |