From 5285333756d4ef3090dff40f35eab88f4c1baec6 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Fri, 27 Sep 2024 11:00:48 -0500 Subject: [PATCH 1/5] Change behavior when changing dates in a datepicker group to be more intuitive. Previously when any of the dates were changed, the open, reduced scoring, close, and answer dates were ensured to be in the correct order by always changing the input later in the last to a later date if needed. This instead acts on the input that was modified. That input value is not changed from what the user just changed it to. Any earlier inputs in the list are set to the new date in the changed input if they are later than that date, and any later inputs in the list are set to the new date in the changed input if they are earlier than that date. This is to address issue #2581. --- htdocs/js/DatePicker/datepicker.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/htdocs/js/DatePicker/datepicker.js b/htdocs/js/DatePicker/datepicker.js index b2d9cfae6c..dca96fb2d8 100644 --- a/htdocs/js/DatePicker/datepicker.js +++ b/htdocs/js/DatePicker/datepicker.js @@ -48,15 +48,21 @@ rule.push(value ? parseInt(value) * 1000 - timezoneAdjustment : 0); } - const update = () => { + const update = (input) => { + const activeIndex = groupRules.findIndex((r) => r[0] === input); + if (activeIndex == -1) return; + const activeFieldDate = + groupRules[activeIndex][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || + groupRules[activeIndex][1]; + for (let i = 1; i < groupRules.length; ++i) { - const prevFieldDate = - groupRules[i - 1][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || groupRules[i - 1][1]; + if (i == activeFieldDate) continue; const thisFieldDate = groupRules[i][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || groupRules[i][1]; - if (prevFieldDate && thisFieldDate && prevFieldDate > thisFieldDate) { - groupRules[i][0].parentNode._flatpickr.setDate(prevFieldDate, true); - } + if (i < activeIndex && thisFieldDate > activeFieldDate) + groupRules[i][0].parentNode._flatpickr.setDate(activeFieldDate, true); + else if (i > activeIndex && thisFieldDate < activeFieldDate) + groupRules[i][0].parentNode._flatpickr.setDate(activeFieldDate, true); } }; @@ -115,7 +121,9 @@ if (this.input.value === orig_value) this.altInput.classList.remove('changed'); else this.altInput.classList.add('changed'); }, - onClose: update, + onClose() { + return update(this.input); + }, onReady() { // Flatpickr hides the original input and adds the alternate input after it. That messes up the // bootstrap input group styling. So move the now hidden original input after the created alternate @@ -133,7 +141,7 @@ // Make the alternate input left-to-right even for right-to-left languages. this.altInput.dir = 'ltr'; - this.altInput.addEventListener('blur', update); + this.altInput.addEventListener('blur', () => update(this.input)); }, parseDate(datestr, format) { // Deal with the case of a unix timestamp. The timezone needs to be adjusted back as this is for From 4c01001d0a8c17a421b549f861ef4f15d22dbf3f Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Sat, 28 Sep 2024 17:28:19 -0500 Subject: [PATCH 2/5] Update the start index of the for loop. Previously the open date was never acted on, and so the for loop started at one which skipped the open date. Now it needs to be acted on. --- htdocs/js/DatePicker/datepicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/js/DatePicker/datepicker.js b/htdocs/js/DatePicker/datepicker.js index dca96fb2d8..eb469bb30f 100644 --- a/htdocs/js/DatePicker/datepicker.js +++ b/htdocs/js/DatePicker/datepicker.js @@ -55,7 +55,7 @@ groupRules[activeIndex][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || groupRules[activeIndex][1]; - for (let i = 1; i < groupRules.length; ++i) { + for (let i = 0; i < groupRules.length; ++i) { if (i == activeFieldDate) continue; const thisFieldDate = groupRules[i][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || groupRules[i][1]; From cc31f274c140aeb1f7ef3789054d8f234a870302 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Thu, 10 Oct 2024 05:28:38 -0500 Subject: [PATCH 3/5] Fix an incorrect index comparison. --- htdocs/js/DatePicker/datepicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/js/DatePicker/datepicker.js b/htdocs/js/DatePicker/datepicker.js index eb469bb30f..04ba72cb46 100644 --- a/htdocs/js/DatePicker/datepicker.js +++ b/htdocs/js/DatePicker/datepicker.js @@ -56,7 +56,7 @@ groupRules[activeIndex][1]; for (let i = 0; i < groupRules.length; ++i) { - if (i == activeFieldDate) continue; + if (i == activeIndex) continue; const thisFieldDate = groupRules[i][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || groupRules[i][1]; if (i < activeIndex && thisFieldDate > activeFieldDate) From c02f04ae3c5ef9ce492b8d344312a07b59d0cf5a Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Thu, 10 Oct 2024 06:21:32 -0500 Subject: [PATCH 4/5] Fix another minor observed issue. When using the "Today" or "Now" buttons, the "changed" class is not being added to the input. When the handlers for those buttons are called, the "change" event needs to be triggered so that this happens. --- htdocs/js/DatePicker/datepicker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/js/DatePicker/datepicker.js b/htdocs/js/DatePicker/datepicker.js index 04ba72cb46..3690415b72 100644 --- a/htdocs/js/DatePicker/datepicker.js +++ b/htdocs/js/DatePicker/datepicker.js @@ -110,9 +110,9 @@ selectedDate.setFullYear(today.getFullYear()); selectedDate.setMonth(today.getMonth()); selectedDate.setDate(today.getDate()); - fp.setDate(selectedDate); + fp.setDate(selectedDate, true); } else if (index === 1) { - fp.setDate(new Date()); + fp.setDate(new Date(), true); } } }) From fc659e1ae67670978bcfbb1d380b2dec7c56bde0 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Tue, 12 Nov 2024 15:50:11 -0600 Subject: [PATCH 5/5] For overrides fallback to the class value when an override is deleted. --- htdocs/js/DatePicker/datepicker.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/htdocs/js/DatePicker/datepicker.js b/htdocs/js/DatePicker/datepicker.js index 3690415b72..e7d01f365a 100644 --- a/htdocs/js/DatePicker/datepicker.js +++ b/htdocs/js/DatePicker/datepicker.js @@ -43,9 +43,10 @@ ).getTime(); for (const rule of groupRules) { - const value = - rule[0].value || document.getElementsByName(`${rule[0].name}.class_value`)[0]?.dataset.classValue; + const classValue = document.getElementsByName(`${rule[0].name}.class_value`)[0]?.dataset.classValue; + const value = rule[0].value || classValue; rule.push(value ? parseInt(value) * 1000 - timezoneAdjustment : 0); + if (classValue) rule.push(parseInt(classValue) * 1000 - timezoneAdjustment); } const update = (input) => { @@ -53,16 +54,25 @@ if (activeIndex == -1) return; const activeFieldDate = groupRules[activeIndex][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || + groupRules[activeIndex][2] || groupRules[activeIndex][1]; for (let i = 0; i < groupRules.length; ++i) { if (i == activeIndex) continue; const thisFieldDate = - groupRules[i][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || groupRules[i][1]; + groupRules[i][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || + groupRules[i][2] || + groupRules[i][1]; if (i < activeIndex && thisFieldDate > activeFieldDate) - groupRules[i][0].parentNode._flatpickr.setDate(activeFieldDate, true); + groupRules[i][0].parentNode._flatpickr.setDate( + activeFieldDate === groupRules[i][2] ? undefined : activeFieldDate, + true + ); else if (i > activeIndex && thisFieldDate < activeFieldDate) - groupRules[i][0].parentNode._flatpickr.setDate(activeFieldDate, true); + groupRules[i][0].parentNode._flatpickr.setDate( + activeFieldDate === groupRules[i][2] ? undefined : activeFieldDate, + true + ); } };