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

1 line
4.9 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),l||document.querySelector("#button--deleteLot").addEventListener("click",t=>{t.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+"/lots/doDeleteLot",{lotId:o},t=>{t.success?(cityssm.disableNavBlocker(),window.location.href=e+"/lots/?t="+Date.now()):bulmaJS.alert({title:"Error Deleting "+exports.aliases.lot,message:t.errorMessage,contextualColorName:"danger"})})}}})});let n=exports.lotComments;delete exports.lotComments;const a=l=>{const s=Number.parseInt(l.currentTarget.closest("tr").dataset.lotCommentId,10),a=n.find(t=>t.lotCommentId===s);let r,i;const d=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doUpdateLotComment",r,t=>{t.success?(n=t.lotComments,i(),m()):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=a.lotComment;const l=e.querySelector("#lotCommentEdit--lotCommentDateString");l.value=a.lotCommentDateString;const n=cityssm.dateToString(new Date);l.max=a.lotCommentDateString<=n?n:a.lotCommentDateString,e.querySelector("#lotCommentEdit--lotCommentTimeString").value=a.lotCommentTimeString},onshown:(e,o)=>{bulmaJS.toggleHtmlClipped(),t.initializeDatePickers(e),t.initializeTimePickers(e),e.querySelector("#lotCommentEdit--lotComment").focus(),(r=e.querySelector("form")).addEventListener("submit",d),i=o},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,m()):bulmaJS.alert({title:"Error Removing Comment",message:t.errorMessage,contextualColorName:"danger"})})}},contextualColorName:"warning"})},m=()=>{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",a),o.querySelector(".button--delete").addEventListener("click",r),e.querySelector("tbody").append(o)}t.innerHTML="",t.append(e)},i=()=>{let l;const s=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doAddLotComment",t.currentTarget,t=>{t.success&&(n=t.lotComments,m(),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",i),m())})();