behavior RetryPrintHandler
on Retry[event.detail.source==me.id] from body
if me matches
trigger click
exit
end
get @hx-trigger of me
if it contains 'PrintPdf'
trigger PrintPdf
exit
end
if it contains 'PrintSticker'
trigger PrintSticker
exit
end
end
end
behavior PrintStickerInProgressModalHandler(source)
on StickerPrinted from body
set $stickerPrinted to true
send Continue to me
end
on PrintFailed from body
set $stickerPrintError to event.detail.Message
send Continue to me
end
on shown.bs.modal from body
if event.target is not #PrintStickerInProgressModal
exit
end
if $stickerPrinted
call hidePrintStickerInProgressModal()
exit
end
if $stickerPrintError
call showPrintStickerRetryModal($stickerPrintError)
exit
end
wait for Continue or 5s
if result is 5s
call showPrintStickerRetryModal('Timed out.')
exit
end
if $stickerPrinted
call hidePrintStickerInProgressModal()
exit
end
call showPrintStickerRetryModal($stickerPrintError)
end
on ShowPrintStickerInProgress from body
set $stickerPrintError to undefined
set $stickerPrinted to undefined
htmx.ajax('GET', '/shared/components/printing/sticker/in-progress-modal', { target: '#page-modal', values: { source: source } })
end
on ShowSticker from body
htmx.ajax('POST', '/shared/components/printing/sticker/sticker-modal', { target: '#page-modal', values: { data: event.detail.Data } })
end
def hidePrintStickerInProgressModal()
bootstrap.Modal.getInstance(#PrintStickerInProgressModal).hide()
end
def showPrintStickerRetryModal(message)
set #printStickerError's innerText to message
call hidePrintStickerInProgressModal()
bootstrap.Modal.getOrCreateInstance(#PrintStickerRetryModal).show()
end
end
behavior PrintPdfInProgressModalHandler(source)
on PdfPrinted from body
set $pdfPrinted to true
send Continue to me
end
on PrintFailed from body
set $pdfPrintError to event.detail.Message
send Continue to me
end
on shown.bs.modal from body
if event.target is not #PrintPdfInProgressModal
exit
end
if $pdfPrinted
call hidePrintPdfInProgressModal()
exit
end
if $pdfPrintError
call showPrintPdfRetryModal($pdfPrintError)
exit
end
wait for Continue or 5s
if result is 5s
call showPrintPdfRetryModal('Timed out.')
exit
end
if $pdfPrinted
call hidePrintPdfInProgressModal()
exit
end
call showPrintPdfRetryModal($pdfPrintError)
end
on ShowPrintPdfInProgress from body
set $pdfPrintError to undefined
set $pdfPrinted to undefined
htmx.ajax('GET', '/shared/components/printing/pdf/in-progress-modal', { target: '#page-modal', values: { source: source } })
end
on ShowPdf from body
htmx.ajax('POST', '/shared/components/printing/pdf/pdf-modal', { target: '#page-modal', values: { documentUrl: event.detail.DocumentUrl, requestId: event.detail.RequestId } })
end
def hidePrintPdfInProgressModal()
js
const modals = document.querySelectorAll('.PrintPdfInProgressModal');
modals.forEach(modal => {
const instance = bootstrap.Modal.getInstance(modal);
if (instance) {
instance.hide();
modal.addEventListener('hidden.bs.modal', () => {
instance.dispose();
});
}
});
end
end
def showPrintPdfRetryModal(message)
set #printPdfError's innerText to message
call hidePrintPdfInProgressModal()
bootstrap.Modal.getOrCreateInstance(#PrintPdfRetryModal).show()
end
end
behavior ModalEscapeKeyHandler(closeButton)
on keydown[key is 'Escape']
if me matches .show
send click to closeButton
end
end
end
behavior PhoneNumberInput(hiddenInput, initialValue)
on load
set me.value to initialValue
set :phoneNumber to intlTelInput(me, {utilsScript: 'https://cdn.jsdelivr.net/npm/intl-tel-input@17.0.16/build/js/utils.js', allowDropdown : false, customPlaceholder: getCustomPhoneNumberPlaceholder})
end
on blur
if me.value === '' or :phoneNumber.isValidNumber() then
call :phoneNumber.setNumber(:phoneNumber.getNumber())
set #{hiddenInput}.value to :phoneNumber.getNumber()
send change to #{hiddenInput}
me.setCustomValidity('')
else
me.setCustomValidity('Invalid phone number')
me.reportValidity()
end
end
on keydown[key is 'Enter']
send blur to me
end
on keyup
if me.value ==='' then
call :phoneNumber.setCountry("us")
end
end
js
function getCustomPhoneNumberPlaceholder(selectedCountryPlaceholder, selectedCountryData) {
return "(___) ___-____";
}
end
end
def uppercaseOnGivenInput(inputId)
call uppercaseStringValue(inputId.value) then set inputId.value to it
end
def uppercaseStringValue(value)
js(value)
return value.toLocaleUpperCase()
end
return it
end
def removeSpecialCharactersOnGivenInput(inputId)
call removeSpecialCharacteresOnStringValue(inputId.value) then set inputId.value to it
end
def removeSpecialCharacteresOnStringValue(value)
js(value)
return value.replace(/[\W\s\._\-]+/g, '')
end
return it
end
behavior TitleCaseOnBlur
on blur from me
js(me)
if (me.value.toUpperCase() === me.value) return me.value;
return me.value.replace(/\b\w/g, s => s.toUpperCase());
end
set me.value to it
end
end
behavior TrimOnBlur
on blur from me
set me.value to me.value.trim()
end
end
behavior NumericInput(maxLength, customValidationMessage)
on keyup from me
set me.value to removeNonNumeric(me.value)
if maxLength is not empty then
get my value
if it's length is greater than maxLength then
set my value to it.substring(0, maxLength)
end
end
end
on blur
if customValidationMessage is not empty then
me.setCustomValidity('')
if me.checkValidity() is false then
if me.value is not empty then
me.setCustomValidity(customValidationMessage)
me.select()
end
me.reportValidity()
end
end
end
on focus
me.select()
end
end
behavior TextInput
on load
if I match .autoselect then
call moveCursorToEnd(me)
end
end
on focus
call moveCursorToEnd(me)
end
def moveCursorToEnd(focusElement)
set length to focusElement.value.length
focusElement.setSelectionRange(0, length)
end
end
behavior PinInput(invalidMessage)
on input
if event.target.validity.tooShort or event.target.validity.tooLong
me.setCustomValidity(invalidMessage)
else
me.setCustomValidity('')
end
end
end
behavior ConfirmPinInput(pinInput, invalidMessage, notMatchingMessage)
on input or change from pinInput
get pinInput's value
if it is not me.value then
me.setCustomValidity(notMatchingMessage)
else if event.target.validity.tooShort or event.target.validity.tooLong
me.setCustomValidity(invalidMessage)
else
me.setCustomValidity('')
end
end
end
behavior RadioButton
on keydown[key is 'Tab' and not shiftKey] from me
halt the event
set nextButton to (the next