{"version":3,"file":"reports-gEYC1s5Y.js","sources":["../../../app/frontend/entrypoints/controllers/ticket/overview/show/reports.ts"],"sourcesContent":["import jQuery from 'jquery/dist/jquery';\nimport * as bootstrap from 'bootstrap'\nimport Utils from '../../../../utils'\nimport ReportEntity from \"../../../report/entity\";\nimport Quill from 'quill'\n\n\nexport default class TicketShowReports {\n private parent: any;\n private toastr: any;\n private accord: HTMLElement;\n private commentEditor: any;\n\n constructor(parent: any) {\n this.parent = parent\n this.toastr = parent.toastr\n this.accord = document.querySelector(\"#ticketReportsAccordionChilds\") as HTMLElement;\n if (this.accord) {\n this.bindListeners();\n }\n }\n\n bindListeners() {\n this.commentEditor = new Quill('#report_description', {\n bounds: '#report_description',\n placeholder: Utils.translate(\"ticket.chat.placeholder\"),\n modules: {\n toolbar: '#snow-report-toolbar'\n },\n theme: 'snow'\n });\n this.accord.addEventListener(\"click\", async (e) => {\n const target = e.target as HTMLElement;\n if (target && target.classList.contains(\"ticketReportsAccordionEditEnable\")) {\n const uuid = (target.closest(\".accordion-collapse\") as HTMLElement).getAttribute(\"data-uuid\");\n await Utils.entity.destroy(uuid, 'reports');\n await this.parent.getEntity();\n }\n });\n\n (document.querySelector(\"#addNewTicketReport\") as HTMLFormElement).addEventListener(\"submit\", async (e) => {\n e.preventDefault();\n const form = document.querySelector(\"#addNewTicketReport\") as HTMLFormElement;\n if (form.checkValidity()) {\n const desc = this.commentEditor.root.innerHTML\n\n const arrivalFrom = (form.querySelector(\"#report_arrival_from\") as HTMLInputElement).value\n const arrivalTo = (form.querySelector(\"#report_arrival_to\") as HTMLInputElement).value\n\n const arrivalResourceId = (form.querySelector(\"#report_arrival_resource_id option:checked\") as HTMLInputElement) ? (form.querySelector(\"#report_arrival_resource_id option:checked\") as HTMLInputElement).value : null\n const arrivalDistance = (form.querySelector(\"#report_arrival_distance\") as HTMLInputElement).value\n\n const returnFrom = (form.querySelector(\"#report_return_from\") as HTMLInputElement).value\n const returnTo = (form.querySelector(\"#report_return_to\") as HTMLInputElement).value\n const returnResourceId = (form.querySelector(\"#report_return_resource_id option:checked\") as HTMLInputElement) ? (form.querySelector(\"#report_return_resource_id option:checked\") as HTMLInputElement).value : null\n const returnDistance = (form.querySelector(\"#report_return_distance\") as HTMLInputElement).value\n\n const spentFrom = (form.querySelector(\"#report_spent_from\") as HTMLInputElement).value\n const spentTo = (form.querySelector(\"#report_spent_to\") as HTMLInputElement).value\n\n\n const calendarAppointmentId = (form.querySelector(\"#report_calendar_appointment_id option:checked\") as HTMLInputElement).value\n const files = (form.querySelector(\"#report_attachments\") as HTMLInputElement).files\n const fileNames = []\n if (desc) {\n const fileData = []\n if (files) {\n for (let x = 0; x < files.length; x++) {\n fileData.push(await Utils.getBase64(files[x]))\n fileNames.push(files[x].name)\n }\n }\n const btn = (form.querySelector(\"button.btn-primary\")) as HTMLButtonElement;\n btn.setAttribute(\"disabled\", \"disabled\");\n const r = await Utils.entity.upsert({\n ticket_id: this.parent.id,\n calendar_appointment_id: calendarAppointmentId,\n description: desc,\n arrival_from: arrivalFrom,\n arrival_to: arrivalTo,\n arrival_resource_id: arrivalResourceId,\n arrival_distance: arrivalDistance,\n return_from: returnFrom,\n return_to: returnTo,\n return_resource_id: returnResourceId,\n return_distance: returnDistance,\n spent_from: spentFrom,\n spent_to: spentTo,\n files: fileData,\n file_names: fileNames\n }, 'reports')\n form.reset();\n await this.parent.getEntity();\n }\n }\n })\n\n //@ts-ignore\n jQuery(\"#report_calendar_appointment_id\").on(\"select2:select\", async (e: any) => {\n const target = (e.target as HTMLElement).querySelector(\"option:checked\") as HTMLOptionElement;\n //@ts-ignore\n const from = new Date(target.getAttribute(\"data-from\"));\n const fromValue = new Date(from.getTime() + new Date().getTimezoneOffset() * -60 * 1000).toISOString().slice(0, 19);\n\n //@ts-ignore\n const to = new Date(target.getAttribute(\"data-to\"));\n const toValue = new Date(to.getTime() + new Date().getTimezoneOffset() * -60 * 1000).toISOString().slice(0, 19);\n\n const d = new Date(from.getTime() + new Date().getTimezoneOffset() * -60 * 1000).toISOString().slice(0, 11);\n (document.querySelector(\"#report_arrival_from\") as HTMLInputElement).value= `${d}00:00:00`;\n (document.querySelector(\"#report_return_to\") as HTMLInputElement).value= `${d}00:00:00`;\n\n (document.querySelector(\"#report_spent_from\") as HTMLInputElement).value= fromValue;\n (document.querySelector(\"#report_arrival_to\") as HTMLInputElement).value= fromValue;\n (document.querySelector(\"#report_spent_to\") as HTMLInputElement).value= toValue;\n (document.querySelector(\"#report_return_from\") as HTMLInputElement).value= toValue;\n console.log(target, from, to)\n })\n }\n\n update(data: any) {\n const calendarAppointmentSelect = document.querySelector(\"#report_calendar_appointment_id\") as HTMLSelectElement;\n if (calendarAppointmentSelect) {\n calendarAppointmentSelect.innerHTML = \"\";\n\n data.calendar_appointments.forEach((calendarAppointment: any, i: number) => {\n const html = ``\n calendarAppointmentSelect.innerHTML = calendarAppointmentSelect.innerHTML + html;\n });\n }\n if (this.accord) {\n this.accord.innerHTML = \"\"\n //@ts-ignore\n data.reports.forEach((report: any, i: number) => {\n let attachmentHtml = 'No attachments available.'\n if (report.attachments.length > 0) {\n attachmentHtml = ''\n report.attachments.forEach((attachment: any) => {\n attachmentHtml += `${attachment.name}`\n });\n }\n // @ts-ignore\n const arrivalDiff = Math.abs(new Date(Date.parse(report.arrival_to)) - new Date(Date.parse(report.arrival_from)))\n // @ts-ignore\n const workDiff = Math.abs(new Date(Date.parse(report.spent_to)) - new Date(Date.parse(report.spent_from)))\n // @ts-ignore\n const returnDiff = Math.abs(new Date(Date.parse(report.return_to)) - new Date(Date.parse(report.return_from)))\n const html = `