"use strict"; /* eslint-disable @typescript-eslint/indent */ /* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ Object.defineProperty(exports, "__esModule", { value: true }); (() => { const los = exports.los; const containerElement = document.querySelector('#container--lotTypes'); let lotTypes = exports.lotTypes; delete exports.lotTypes; const expandedLotTypes = new Set(); function toggleLotTypeFields(clickEvent) { const toggleButtonElement = clickEvent.currentTarget; const lotTypeElement = toggleButtonElement.closest('.container--lotType'); const lotTypeId = Number.parseInt(lotTypeElement.dataset.lotTypeId, 10); if (expandedLotTypes.has(lotTypeId)) { expandedLotTypes.delete(lotTypeId); } else { expandedLotTypes.add(lotTypeId); } toggleButtonElement.innerHTML = expandedLotTypes.has(lotTypeId) ? '' : ''; const panelBlockElements = lotTypeElement.querySelectorAll('.panel-block'); for (const panelBlockElement of panelBlockElements) { panelBlockElement.classList.toggle('is-hidden'); } } function lotTypeResponseHandler(responseJSON) { var _a; if (responseJSON.success) { lotTypes = responseJSON.lotTypes; renderLotTypes(); } else { bulmaJS.alert({ title: `Error Updating ${los.escapedAliases.Lot} Type`, message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } } function deleteLotType(clickEvent) { const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId, 10); function doDelete() { cityssm.postJSON(los.urlPrefix + '/admin/doDeleteLotType', { lotTypeId }, lotTypeResponseHandler); } bulmaJS.confirm({ title: `Delete ${los.escapedAliases.Lot} Type`, message: `Are you sure you want to delete this ${los.escapedAliases.lot} type?`, contextualColorName: 'warning', okButton: { text: `Yes, Delete ${los.escapedAliases.Lot} Type`, callbackFunction: doDelete } }); } function openEditLotType(clickEvent) { const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId, 10); const lotType = lotTypes.find((currentLotType) => { return lotTypeId === currentLotType.lotTypeId; }); let editCloseModalFunction; function doEdit(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/admin/doUpdateLotType', submitEvent.currentTarget, (rawResponseJSON) => { const responseJSON = rawResponseJSON; lotTypeResponseHandler(responseJSON); if (responseJSON.success) { editCloseModalFunction(); } }); } cityssm.openHtmlModal('adminLotTypes-editLotType', { onshow(modalElement) { los.populateAliases(modalElement); modalElement.querySelector('#lotTypeEdit--lotTypeId').value = lotTypeId.toString(); modalElement.querySelector('#lotTypeEdit--lotType').value = lotType.lotType; }, onshown(modalElement, closeModalFunction) { editCloseModalFunction = closeModalFunction; modalElement.querySelector('#lotTypeEdit--lotType').focus(); modalElement.querySelector('form').addEventListener('submit', doEdit); bulmaJS.toggleHtmlClipped(); }, onremoved() { bulmaJS.toggleHtmlClipped(); } }); } function openAddLotTypeField(clickEvent) { const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId, 10); let addCloseModalFunction; function doAdd(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/admin/doAddLotTypeField', submitEvent.currentTarget, (rawResponseJSON) => { const responseJSON = rawResponseJSON; expandedLotTypes.add(lotTypeId); lotTypeResponseHandler(responseJSON); if (responseJSON.success) { addCloseModalFunction(); openEditLotTypeField(lotTypeId, responseJSON.lotTypeFieldId); } }); } cityssm.openHtmlModal('adminLotTypes-addLotTypeField', { onshow(modalElement) { los.populateAliases(modalElement); if (lotTypeId) { ; modalElement.querySelector('#lotTypeFieldAdd--lotTypeId').value = lotTypeId.toString(); } }, onshown(modalElement, closeModalFunction) { addCloseModalFunction = closeModalFunction; modalElement.querySelector('#lotTypeFieldAdd--lotTypeField').focus(); modalElement.querySelector('form').addEventListener('submit', doAdd); bulmaJS.toggleHtmlClipped(); }, onremoved() { bulmaJS.toggleHtmlClipped(); } }); } function moveLotType(clickEvent) { const buttonElement = clickEvent.currentTarget; const lotTypeId = buttonElement.closest('.container--lotType').dataset.lotTypeId; cityssm.postJSON(los.urlPrefix + '/admin/' + (buttonElement.dataset.direction === 'up' ? 'doMoveLotTypeUp' : 'doMoveLotTypeDown'), { lotTypeId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, lotTypeResponseHandler); } function openEditLotTypeField(lotTypeId, lotTypeFieldId) { const lotType = lotTypes.find((currentLotType) => { return currentLotType.lotTypeId === lotTypeId; }); const lotTypeField = lotType.lotTypeFields.find((currentLotTypeField) => { return currentLotTypeField.lotTypeFieldId === lotTypeFieldId; }); let minimumLengthElement; let maximumLengthElement; let patternElement; let lotTypeFieldValuesElement; let editCloseModalFunction; function updateMaximumLengthMin() { maximumLengthElement.min = minimumLengthElement.value; } function toggleInputFields() { if (lotTypeFieldValuesElement.value === '') { minimumLengthElement.disabled = false; maximumLengthElement.disabled = false; patternElement.disabled = false; } else { minimumLengthElement.disabled = true; maximumLengthElement.disabled = true; patternElement.disabled = true; } } function doUpdate(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/admin/doUpdateLotTypeField', submitEvent.currentTarget, (rawResponseJSON) => { const responseJSON = rawResponseJSON; lotTypeResponseHandler(responseJSON); if (responseJSON.success) { editCloseModalFunction(); } }); } function doDelete() { cityssm.postJSON(los.urlPrefix + '/admin/doDeleteLotTypeField', { lotTypeFieldId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON; lotTypeResponseHandler(responseJSON); if (responseJSON.success) { editCloseModalFunction(); } }); } function confirmDoDelete() { bulmaJS.confirm({ title: 'Delete Field', message: 'Are you sure you want to delete this field? Note that historical records that make use of this field will not be affected.', contextualColorName: 'warning', okButton: { text: 'Yes, Delete Field', callbackFunction: doDelete } }); } cityssm.openHtmlModal('adminLotTypes-editLotTypeField', { onshow(modalElement) { los.populateAliases(modalElement); modalElement.querySelector('#lotTypeFieldEdit--lotTypeFieldId').value = lotTypeField.lotTypeFieldId.toString(); modalElement.querySelector('#lotTypeFieldEdit--lotTypeField').value = lotTypeField.lotTypeField; modalElement.querySelector('#lotTypeFieldEdit--isRequired').value = lotTypeField.isRequired ? '1' : '0'; minimumLengthElement = modalElement.querySelector('#lotTypeFieldEdit--minimumLength'); minimumLengthElement.value = lotTypeField.minimumLength.toString(); maximumLengthElement = modalElement.querySelector('#lotTypeFieldEdit--maximumLength'); maximumLengthElement.value = lotTypeField.maximumLength.toString(); patternElement = modalElement.querySelector('#lotTypeFieldEdit--pattern'); patternElement.value = lotTypeField.pattern; lotTypeFieldValuesElement = modalElement.querySelector('#lotTypeFieldEdit--lotTypeFieldValues'); lotTypeFieldValuesElement.value = lotTypeField.lotTypeFieldValues; toggleInputFields(); }, onshown(modalElement, closeModalFunction) { editCloseModalFunction = closeModalFunction; bulmaJS.init(modalElement); bulmaJS.toggleHtmlClipped(); cityssm.enableNavBlocker(); modalElement.querySelector('form').addEventListener('submit', doUpdate); minimumLengthElement.addEventListener('keyup', updateMaximumLengthMin); updateMaximumLengthMin(); lotTypeFieldValuesElement.addEventListener('keyup', toggleInputFields); modalElement .querySelector('#button--deleteLotTypeField') .addEventListener('click', confirmDoDelete); }, onremoved() { bulmaJS.toggleHtmlClipped(); cityssm.disableNavBlocker(); } }); } function openEditLotTypeFieldByClick(clickEvent) { clickEvent.preventDefault(); const lotTypeFieldId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotTypeField').dataset.lotTypeFieldId, 10); const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId, 10); openEditLotTypeField(lotTypeId, lotTypeFieldId); } function moveLotTypeField(clickEvent) { const buttonElement = clickEvent.currentTarget; const lotTypeFieldId = buttonElement.closest('.container--lotTypeField').dataset.lotTypeFieldId; cityssm.postJSON(los.urlPrefix + '/admin/' + (buttonElement.dataset.direction === 'up' ? 'doMoveLotTypeFieldUp' : 'doMoveLotTypeFieldDown'), { lotTypeFieldId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, lotTypeResponseHandler); } function renderLotTypeFields(panelElement, lotTypeId, lotTypeFields) { var _a; if (lotTypeFields.length === 0) { panelElement.insertAdjacentHTML('beforeend', '
'); } else { for (const lotTypeField of lotTypeFields) { const panelBlockElement = document.createElement('div'); panelBlockElement.className = 'panel-block is-block container--lotTypeField'; if (!expandedLotTypes.has(lotTypeId)) { panelBlockElement.classList.add('is-hidden'); } panelBlockElement.dataset.lotTypeFieldId = lotTypeField.lotTypeFieldId.toString(); panelBlockElement.innerHTML = '