"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); (() => { const sunrise = exports.sunrise; const workOrderId = document.querySelector('#workOrderEdit--workOrderId').value; let workOrderComments = exports.workOrderComments; delete exports.workOrderComments; function openEditWorkOrderComment(clickEvent) { const workOrderCommentId = Number.parseInt(clickEvent.currentTarget.closest('tr')?.dataset .workOrderCommentId ?? '', 10); const workOrderComment = workOrderComments.find((currentComment) => currentComment.workOrderCommentId === workOrderCommentId); let editFormElement; let editCloseModalFunction; function editComment(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(`${sunrise.urlPrefix}/workOrders/doUpdateWorkOrderComment`, editFormElement, (rawResponseJSON) => { const responseJSON = rawResponseJSON; if (responseJSON.success) { workOrderComments = responseJSON.workOrderComments; editCloseModalFunction(); renderWorkOrderComments(); } else { bulmaJS.alert({ title: 'Error Updating Comment', message: responseJSON.errorMessage ?? '', contextualColorName: 'danger' }); } }); } cityssm.openHtmlModal('workOrder-editComment', { onshow(modalElement) { ; modalElement.querySelector('#workOrderCommentEdit--workOrderId').value = workOrderId; modalElement.querySelector('#workOrderCommentEdit--workOrderCommentId').value = workOrderCommentId.toString(); modalElement.querySelector('#workOrderCommentEdit--comment').value = workOrderComment.comment ?? ''; const workOrderCommentDateStringElement = modalElement.querySelector('#workOrderCommentEdit--commentDateString'); workOrderCommentDateStringElement.value = workOrderComment.commentDateString ?? ''; const currentDateString = cityssm.dateToString(new Date()); workOrderCommentDateStringElement.max = workOrderComment.commentDateString <= currentDateString ? currentDateString : workOrderComment.commentDateString ?? ''; modalElement.querySelector('#workOrderCommentEdit--commentTimeString').value = workOrderComment.commentTimeString ?? ''; }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); modalElement.querySelector('#workOrderCommentEdit--comment').focus(); editFormElement = modalElement.querySelector('form'); editFormElement.addEventListener('submit', editComment); editCloseModalFunction = closeModalFunction; }, onremoved() { bulmaJS.toggleHtmlClipped(); } }); } function deleteWorkOrderComment(clickEvent) { const workOrderCommentId = Number.parseInt(clickEvent.currentTarget.closest('tr')?.dataset .workOrderCommentId ?? '', 10); function doDelete() { cityssm.postJSON(`${sunrise.urlPrefix}/workOrders/doDeleteWorkOrderComment`, { workOrderId, workOrderCommentId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON; if (responseJSON.success) { workOrderComments = responseJSON.workOrderComments; renderWorkOrderComments(); } else { bulmaJS.alert({ title: 'Error Removing Comment', message: responseJSON.errorMessage ?? '', contextualColorName: 'danger' }); } }); } bulmaJS.confirm({ title: 'Remove Comment?', message: 'Are you sure you want to remove this comment?', okButton: { text: 'Yes, Remove Comment', callbackFunction: doDelete }, contextualColorName: 'warning' }); } function renderWorkOrderComments() { const containerElement = document.querySelector('#container--workOrderComments'); if (workOrderComments.length === 0) { containerElement.innerHTML = `
`; return; } const tableElement = document.createElement('table'); tableElement.className = 'table is-fullwidth is-striped is-hoverable'; tableElement.innerHTML = `