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

1 line
4.1 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const t=exports.los,e=document.querySelector("main").dataset.urlPrefix,o=document.querySelector("#lot--lotId").value,l=""===o,s=document.querySelector("#form--lot");s.addEventListener("submit",t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/"+(l?"doCreateLot":"doUpdateLot"),s,t=>{t.success?l?window.location.href=e+"/lots/"+t.lotId+"/edit":bulmaJS.alert({message:exports.aliases.lot+" Updated Successfully",contextualColorName:"success"}):bulmaJS.alert({title:"Error Updating "+exports.aliases.lot,message:t.errorMessage,contextualColorName:"danger"})})}),t.initializeUnlockFieldButtons(s);let n=exports.lotComments;const m=l=>{const s=Number.parseInt(l.currentTarget.closest("tr").dataset.lotCommentId,10),m=n.find(t=>t.lotCommentId===s);let r,d;const i=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doUpdateLotComment",r,t=>{t.success?(n=t.lotComments,d(),a()):bulmaJS.alert({title:"Error Updating Comment",message:t.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("lot-editComment",{onshow:e=>{t.populateAliases(e),e.querySelector("#lotCommentEdit--lotId").value=o,e.querySelector("#lotCommentEdit--lotCommentId").value=s.toString(),e.querySelector("#lotCommentEdit--lotComment").value=m.lotComment,e.querySelector("#lotCommentEdit--lotCommentDateString").value=m.lotCommentDateString,e.querySelector("#lotCommentEdit--lotCommentTimeString").value=m.lotCommentTimeString},onshown:(t,e)=>{bulmaJS.toggleHtmlClipped(),t.querySelector("#lotCommentEdit--lotComment").focus(),(r=t.querySelector("form")).addEventListener("submit",i),d=e},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},r=t=>{const l=Number.parseInt(t.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+"/lots/doDeleteLotComment",{lotId:o,lotCommentId:l},t=>{t.success?(n=t.lotComments,a()):bulmaJS.alert({title:"Error Removing Comment",message:t.errorMessage,contextualColorName:"danger"})})}},contextualColorName:"warning"})},a=()=>{const t=document.querySelector("#container--lotComments");if(0===n.length)return void(t.innerHTML='<div class="message is-info"><p class="message-body">There are no comments to display.</p></div>');const e=document.createElement("table");e.className="table is-fullwidth is-striped is-hoverable",e.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 t of n){const o=document.createElement("tr");o.dataset.lotCommentId=t.lotCommentId.toString(),o.innerHTML="<td>"+cityssm.escapeHTML(t.recordCreate_userName)+"</td><td>"+t.lotCommentDateString+(0===t.lotCommentTime?"":" "+t.lotCommentTimeString)+"</td><td>"+cityssm.escapeHTML(t.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",m),o.querySelector(".button--delete").addEventListener("click",r),e.querySelector("tbody").append(o)}t.innerHTML="",t.append(e)},d=()=>{let l;const s=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doAddLotComment",t.currentTarget,t=>{t.success&&(n=t.lotComments,a(),l())})};cityssm.openHtmlModal("lot-addComment",{onshow(e){t.populateAliases(e),e.querySelector("#lotCommentAdd--lotId").value=o,e.querySelector("form").addEventListener("submit",s)},onshown(t,e){bulmaJS.toggleHtmlClipped(),l=e,t.querySelector("#lotCommentAdd--lotComment").focus()},onremoved(){bulmaJS.toggleHtmlClipped(),document.querySelector("#lotComments--add").focus()}})};l||(document.querySelector("#lotComments--add").addEventListener("click",d),a())})();