mirror of
https://github.com/pretix/pretix.git
synced 2026-08-19 12:16:26 +00:00
* initial implementation * factor out _resolve_base_date * add js to prevent illegal inputs * fix tests * Update src/pretix/base/reldate.py Co-authored-by: Raphael Michel <michel@pretix.eu> * Apply suggestions from code review Co-authored-by: Raphael Michel <mail@raphaelmichel.de> * move js includes of to fragment_js.html * add type annotations * moves logic from RelativeDateWrapper into RelativeDate and adds BaseChoice for configuring which models attributes support which relationship * fix tests * test upgrade behaviour * Apply suggestions from code review Co-authored-by: Raphael Michel <mail@raphaelmichel.de> * move reldate.js include in correct file * add OptionAttrsSelect to allow select options with their own attributes per value * add a little bit of information to the tests for future reference * rewrite reldate.js use data-attributes * general cleanup * add test for order.subevents cases * use correct choice format * remove order.subevent variants * various cleanup * Apply suggestions from code review Co-authored-by: Raphael Michel <mail@raphaelmichel.de> * remove empty docstrings * add depreciation warning * change event listener to pretix:bind-forms --------- Co-authored-by: Raphael Michel <michel@pretix.eu> Co-authored-by: Raphael Michel <mail@raphaelmichel.de>
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
$(document).on('pretix:bind-forms', () => {
|
|
document.querySelectorAll('.reldatetime, .reldate').forEach(container => {
|
|
const groups = container.querySelectorAll('.radio')
|
|
|
|
groups.forEach(group => {
|
|
const referenceSelect = group.querySelector('select[data-relative-choice]')
|
|
const beforeAfterSelect = group.querySelector('select[data-relation-choice]')
|
|
if (!referenceSelect || !beforeAfterSelect) return
|
|
|
|
const beforeOption = beforeAfterSelect.querySelector('option[value="before"]')
|
|
const afterOption = beforeAfterSelect.querySelector('option[value="after"]')
|
|
|
|
const updateBeforeOption = () => {
|
|
let supportsBefore = referenceSelect.selectedOptions[0].hasAttribute('data-supports-before')
|
|
if (beforeOption) {
|
|
beforeOption.disabled = !beforeOption.disabled && !supportsBefore
|
|
}
|
|
|
|
let supportsAfter = referenceSelect.selectedOptions[0].hasAttribute('data-supports-after')
|
|
if (afterOption) {
|
|
afterOption.disabled = !afterOption.disabled && !supportsAfter
|
|
}
|
|
|
|
let dirty = false
|
|
if (beforeOption.disabled && beforeAfterSelect.value === 'before') {
|
|
beforeAfterSelect.value = 'after'
|
|
dirty = true
|
|
}
|
|
if (afterOption.disabled && beforeAfterSelect.value === 'after') {
|
|
beforeAfterSelect.value = 'before'
|
|
dirty = true
|
|
}
|
|
|
|
if (dirty) {
|
|
beforeAfterSelect.dispatchEvent(new Event('change', {bubbles: true}))
|
|
}
|
|
}
|
|
referenceSelect.addEventListener('change', updateBeforeOption)
|
|
updateBeforeOption()
|
|
})
|
|
})
|
|
})
|