1window.customElements.define( 2 "schedule-select", 3 class ScheduleSelect extends HTMLElement { 4 #ruleSelect; 5 #customOptions; 6 7 connectedCallback() { 8 this.#ruleSelect = this.querySelector('.schedule-rule-select'); 9 this.#customOptions = this.querySelector('.custom-schedule-options'); 10 11 this.#ruleSelect.addEventListener('input', () => this.#ruleSelectChanged()); 12 const associatedForm = this.closest("form"); 13 associatedForm.addEventListener('reset', () => { 14 setTimeout(() => this.#ruleSelectChanged(), 1); 15 }); 16 17 this.computeFormValues(); 18 this.#updateCustomOptionsVisibility(); 19 } 20 21 computeFormValues() { 22 if (this.dataset.showExistingSchedule !== "true") return; 23 24 const interval = Number.parseInt(this.querySelector('[name="task[recurring_task_schedule][interval]"]').value, 10); 25 const period = this.querySelector('[name="task[recurring_task_schedule][period]"]').value; 26 const existingRule = {interval: interval, period: period} 27 const defaultRules = [].slice.call(this.#ruleSelect.options, 0, -1).map((option) => option.value); 28 29 for (const ruleJson of defaultRules) { 30 const rule = JSON.parse(ruleJson); 31 if (!_.isEqual(rule, existingRule)) continue; 32 33 this.#ruleSelect.value = ruleJson; 34 return; 35 } 36 this.#ruleSelect.value = "custom" 37 } 38 39 setFormValues() { 40 if (this.#ruleSelect.value === "custom") return; 41 42 const ruleJson = JSON.parse(this.#ruleSelect.value); 43 this.querySelector('[name="task[recurring_task_schedule][interval]"]').value = ruleJson.interval; 44 this.querySelector('[name="task[recurring_task_schedule][period]"]').value = ruleJson.period; 45 } 46 47 #ruleSelectChanged() { 48 const hasDateField = !!this.dataset.dateField; 49 this.#updateCustomOptionsVisibility(); 50 if (hasDateField) { 51 this.#updateDateFieldLabel(); 52 } 53 } 54 55 #updateCustomOptionsVisibility() { 56 const isVisible = this.#ruleSelect.value === "custom"; 57 this.#customOptions.style.display = isVisible ? '' : "none"; 58 } 59 60 #updateDateFieldLabel() { 61 const hasSchedule = this.#ruleSelect.value !== this.#ruleSelect.options[0].value; 62 const dateField = document.getElementById(this.dataset.dateField); 63 dateField.labels.forEach((label) => { 64 label.textContent = `${hasSchedule ? dateField.dataset.recurringLabel : dateField.dataset.notRecurringLabel}: `; 65 }); 66 } 67 } 68);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.