sunrise-cms/public/javascripts/lotEdit.min.js

1 line
7.6 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;const s=document.querySelector("#form--lot");s.addEventListener("submit",function(e){e.preventDefault(),cityssm.postJSON(t.urlPrefix+"/lots/"+(n?"doCreateLot":"doUpdateLot"),s,e=>{var o;e.success?(t.clearUnsavedChanges(),n||l?window.location.href=t.getLotURL(e.lotId,!0,!0):bulmaJS.alert({message:t.escapedAliases.Lot+" Updated Successfully",contextualColorName:"success"})):bulmaJS.alert({title:"Error Updating "+t.escapedAliases.Lot,message:null!==(o=e.errorMessage)&&void 0!==o?o:"",contextualColorName:"danger"})})});const a=s.querySelectorAll("input, select");for(const e of a)e.addEventListener("change",t.setUnsavedChanges);t.initializeUnlockFieldButtons(s),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;e.success?(cityssm.disableNavBlocker(),window.location.href=t.getLotURL()):bulmaJS.alert({title:`Error Deleting ${t.escapedAliases.Lot}`,message:null!==(o=e.errorMessage)&&void 0!==o?o:"",contextualColorName:"danger"})})}}})});const r=document.querySelector("#lot--lotTypeId");if(n){const e=document.querySelector("#container--lotFields");r.addEventListener("change",()=>{""!==r.value?cityssm.postJSON(t.urlPrefix+"/lots/doGetLotTypeFields",{lotTypeId:r.value},o=>{if(0===o.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 n="";for(const t of o.lotTypeFields){n+=","+t.lotTypeFieldId;const o="lotFieldValue_"+t.lotTypeFieldId,l="lot--"+o,s=document.createElement("div");if(s.className="field",s.innerHTML=`<label class="label" for="${l}"></label>\n <div class="control"></div>`,s.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,t.pattern&&""!==t.pattern&&(e.pattern=t.pattern),s.querySelector(".control").append(e)}else{s.querySelector(".control").innerHTML=`<div class="select is-fullwidth">\n <select id="${l}" name="${o}"><option value="">(Not Set)</option></select>\n </div>`;const e=s.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(s)}e.insertAdjacentHTML("beforeend",`<input name="lotTypeFieldIds" type="hidden"\n value="${n.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=r.value;r.addEventListener("change",()=>{r.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:()=>{r.value=e}}})})}let i=exports.lotComments;function d(e){const n=Number.parseInt(e.currentTarget.closest("tr").dataset.lotCommentId,10),l=i.find(e=>e.lotCommentId===n);let s,a;function r(e){e.preventDefault(),cityssm.postJSON(t.urlPrefix+"/lots/doUpdateLotComment",s,e=>{var t;e.success?(i=e.lotComments,a(),c()):bulmaJS.alert({title:"Error Updating Comment",message:null!==(t=e.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",r),a=o},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})}function m(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;e.success?(i=e.lotComments,c()):bulmaJS.alert({title:"Error Removing Comment",message:null!==(t=e.errorMessage)&&void 0!==t?t:"",contextualColorName:"danger"})})}},contextualColorName:"warning"})}function c(){var e,t;const o=document.querySelector("#container--lotComments");if(0===i.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 i){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.lotCommentTimeString)+"</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",d),l.querySelector(".button--delete").addEventListener("click",m),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=>{t.success&&(i=t.lotComments,c(),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()}})}),c())})();