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