django-smartbase-admin 0.2.54__py3-none-any.whl → 1.0.42__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_smartbase_admin/actions/admin_action_list.py +79 -38
- django_smartbase_admin/actions/advanced_filters.py +24 -1
- django_smartbase_admin/admin/admin_base.py +402 -97
- django_smartbase_admin/admin/site.py +93 -35
- django_smartbase_admin/admin/widgets.py +636 -26
- django_smartbase_admin/apps.py +2 -0
- django_smartbase_admin/engine/actions.py +34 -16
- django_smartbase_admin/engine/admin_base_view.py +252 -115
- django_smartbase_admin/engine/configuration.py +186 -4
- django_smartbase_admin/engine/const.py +6 -0
- django_smartbase_admin/engine/dashboard.py +49 -24
- django_smartbase_admin/engine/fake_inline.py +15 -11
- django_smartbase_admin/engine/field.py +42 -12
- django_smartbase_admin/engine/field_formatter.py +38 -14
- django_smartbase_admin/engine/filter_widgets.py +348 -24
- django_smartbase_admin/engine/menu_item.py +8 -5
- django_smartbase_admin/engine/modal_view.py +12 -7
- django_smartbase_admin/engine/request.py +2 -0
- django_smartbase_admin/integration/__init__.py +0 -0
- django_smartbase_admin/integration/django_cms.py +43 -0
- django_smartbase_admin/locale/sk/LC_MESSAGES/django.mo +0 -0
- django_smartbase_admin/locale/sk/LC_MESSAGES/django.po +268 -37
- django_smartbase_admin/migrations/0005_sbadminuserconfiguration.py +26 -0
- django_smartbase_admin/migrations/0006_alter_sbadminuserconfiguration_color_scheme.py +18 -0
- django_smartbase_admin/models.py +22 -0
- django_smartbase_admin/monkeypatch/admin_readonly_field_monkeypatch.py +96 -0
- django_smartbase_admin/monkeypatch/fake_inline_monkeypatch.py +1 -1
- django_smartbase_admin/querysets.py +3 -0
- django_smartbase_admin/services/configuration.py +30 -0
- django_smartbase_admin/services/thread_local.py +6 -19
- django_smartbase_admin/services/views.py +80 -13
- django_smartbase_admin/services/xlsx_export.py +6 -0
- django_smartbase_admin/static/sb_admin/build/tailwind.config.js +1 -0
- django_smartbase_admin/static/sb_admin/build/tailwind_config_partials/colors.js +4 -0
- django_smartbase_admin/static/sb_admin/build/tailwind_config_partials/spacing.js +1 -0
- django_smartbase_admin/static/sb_admin/build/webpack.common.js +11 -8
- django_smartbase_admin/static/sb_admin/css/ckeditor/ckeditor_content_dark.css +208 -0
- django_smartbase_admin/static/sb_admin/css/coloris/coloris.min.css +1 -0
- django_smartbase_admin/static/sb_admin/dist/calendar.js +1 -0
- django_smartbase_admin/static/sb_admin/dist/calendar_style.css +1 -0
- django_smartbase_admin/static/sb_admin/dist/calendar_style.js +0 -0
- django_smartbase_admin/static/sb_admin/dist/chart.js +1 -1
- django_smartbase_admin/static/sb_admin/dist/main.js +1 -1
- django_smartbase_admin/static/sb_admin/dist/main_style.css +1 -1
- django_smartbase_admin/static/sb_admin/dist/table.js +1 -1
- django_smartbase_admin/static/sb_admin/dist/tree_widget.js +1 -0
- django_smartbase_admin/static/sb_admin/dist/tree_widget_style.css +1 -0
- django_smartbase_admin/static/sb_admin/dist/tree_widget_style.js +0 -0
- django_smartbase_admin/static/sb_admin/fancytree/jquery.fancytree-all-deps.min.js +1 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-csv.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-doc.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-docx.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-other.svg +13 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-pdf.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-ppt.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-xls.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-xlsx.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-zip.svg +18 -0
- django_smartbase_admin/static/sb_admin/images/flags/de-at.png +0 -0
- django_smartbase_admin/static/sb_admin/images/flags/de-ch.png +0 -0
- django_smartbase_admin/static/sb_admin/images/logo_light.svg +21 -0
- django_smartbase_admin/static/sb_admin/js/coloris/coloris.min.js +6 -0
- django_smartbase_admin/static/sb_admin/js/fullcalendar.min.js +14804 -0
- django_smartbase_admin/static/sb_admin/js/sbadmin_prepopulated_fields_init.js +25 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Bolt-one.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Calendar.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Caution.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Electric-drill.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Fire-extinguisher.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Gas.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Lightning-fill.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Moon.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Phone-telephone.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Printer.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Pull.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Sun-one.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Time.svg +3 -0
- django_smartbase_admin/static/sb_admin/src/css/_base.css +5 -1
- django_smartbase_admin/static/sb_admin/src/css/_colors.css +257 -82
- django_smartbase_admin/static/sb_admin/src/css/_components.css +61 -13
- django_smartbase_admin/static/sb_admin/src/css/_datepicker.css +8 -1
- django_smartbase_admin/static/sb_admin/src/css/_filer.css +60 -0
- django_smartbase_admin/static/sb_admin/src/css/_inlines.css +51 -10
- django_smartbase_admin/static/sb_admin/src/css/_tabulator.css +8 -2
- django_smartbase_admin/static/sb_admin/src/css/calendar.css +162 -0
- django_smartbase_admin/static/sb_admin/src/css/components/_button.css +41 -1
- django_smartbase_admin/static/sb_admin/src/css/components/_dropdown.css +31 -7
- django_smartbase_admin/static/sb_admin/src/css/components/_input.css +62 -20
- django_smartbase_admin/static/sb_admin/src/css/components/_modal.css +1 -1
- django_smartbase_admin/static/sb_admin/src/css/components/_query-builder.css +21 -2
- django_smartbase_admin/static/sb_admin/src/css/components/_toggle.css +12 -1
- django_smartbase_admin/static/sb_admin/src/css/components/_tooltip.css +8 -22
- django_smartbase_admin/static/sb_admin/src/css/style.css +17 -0
- django_smartbase_admin/static/sb_admin/src/css/tree_widget.css +411 -0
- django_smartbase_admin/static/sb_admin/src/js/autocomplete.js +69 -11
- django_smartbase_admin/static/sb_admin/src/js/calendar.js +56 -0
- django_smartbase_admin/static/sb_admin/src/js/chart.js +8 -22
- django_smartbase_admin/static/sb_admin/src/js/choices.js +18 -8
- django_smartbase_admin/static/sb_admin/src/js/datepicker.js +97 -336
- django_smartbase_admin/static/sb_admin/src/js/datepicker_plugins.js +357 -0
- django_smartbase_admin/static/sb_admin/src/js/main.js +306 -31
- django_smartbase_admin/static/sb_admin/src/js/multiselect.js +50 -41
- django_smartbase_admin/static/sb_admin/src/js/radio.js +31 -0
- django_smartbase_admin/static/sb_admin/src/js/range.js +3 -2
- django_smartbase_admin/static/sb_admin/src/js/table.js +34 -5
- django_smartbase_admin/static/sb_admin/src/js/table_modules/advanced_filter_module.js +43 -20
- django_smartbase_admin/static/sb_admin/src/js/table_modules/data_edit_module.js +8 -10
- django_smartbase_admin/static/sb_admin/src/js/table_modules/detail_view_module.js +50 -1
- django_smartbase_admin/static/sb_admin/src/js/table_modules/filter_module.js +10 -3
- django_smartbase_admin/static/sb_admin/src/js/table_modules/header_tabs_module.js +11 -11
- django_smartbase_admin/static/sb_admin/src/js/table_modules/selection_module.js +28 -8
- django_smartbase_admin/static/sb_admin/src/js/table_modules/table_params_module.js +6 -0
- django_smartbase_admin/static/sb_admin/src/js/table_modules/views_module.js +6 -0
- django_smartbase_admin/static/sb_admin/src/js/tree_widget.js +406 -0
- django_smartbase_admin/static/sb_admin/src/js/utils.js +56 -21
- django_smartbase_admin/templates/sb_admin/actions/change_form.html +176 -116
- django_smartbase_admin/templates/sb_admin/actions/dashboard.html +2 -2
- django_smartbase_admin/templates/sb_admin/actions/list.html +79 -39
- django_smartbase_admin/templates/sb_admin/actions/partials/action_link.html +14 -0
- django_smartbase_admin/templates/sb_admin/actions/partials/tabulator_header_v2.html +2 -2
- django_smartbase_admin/templates/sb_admin/actions/tree_list.html +63 -0
- django_smartbase_admin/templates/sb_admin/authentification/login_base.html +5 -1
- django_smartbase_admin/templates/sb_admin/components/columns.html +1 -1
- django_smartbase_admin/templates/sb_admin/components/filters.html +1 -0
- django_smartbase_admin/templates/sb_admin/components/filters_v2.html +99 -85
- django_smartbase_admin/templates/sb_admin/dashboard/calendar_widget.html +69 -0
- django_smartbase_admin/templates/sb_admin/dashboard/chart_widget.html +21 -2
- django_smartbase_admin/templates/sb_admin/dashboard/list_widget.html +6 -0
- django_smartbase_admin/templates/sb_admin/dashboard/widget_base.html +1 -1
- django_smartbase_admin/templates/sb_admin/filter_widgets/advanced_filters/date_field.html +18 -8
- django_smartbase_admin/templates/sb_admin/filter_widgets/advanced_filters/multiple_choice_field.html +1 -1
- django_smartbase_admin/templates/sb_admin/filter_widgets/advanced_filters/tree_select_filter.html +2 -0
- django_smartbase_admin/templates/sb_admin/filter_widgets/boolean_field.html +1 -14
- django_smartbase_admin/templates/sb_admin/filter_widgets/date_field.html +18 -4
- django_smartbase_admin/templates/sb_admin/filter_widgets/multiple_choice_field.html +14 -0
- django_smartbase_admin/templates/sb_admin/filter_widgets/partials/clear.html +12 -6
- django_smartbase_admin/templates/sb_admin/filter_widgets/radio_choice_field.html +5 -3
- django_smartbase_admin/templates/sb_admin/filter_widgets/tree_select_filter.html +16 -0
- django_smartbase_admin/templates/sb_admin/includes/change_form_title.html +3 -1
- django_smartbase_admin/templates/sb_admin/includes/inline_fieldset.html +48 -39
- django_smartbase_admin/templates/sb_admin/includes/notifications.html +2 -1
- django_smartbase_admin/templates/sb_admin/includes/readonly_boolean_field.html +9 -0
- django_smartbase_admin/templates/sb_admin/includes/readonly_field.html +12 -0
- django_smartbase_admin/templates/sb_admin/includes/table_inline_delete_button.html +4 -5
- django_smartbase_admin/templates/sb_admin/inlines/stacked_inline.html +68 -40
- django_smartbase_admin/templates/sb_admin/inlines/table_inline.html +76 -34
- django_smartbase_admin/templates/sb_admin/integrations/filer/folder_list.html +18 -0
- django_smartbase_admin/templates/sb_admin/navigation.html +166 -158
- django_smartbase_admin/templates/sb_admin/partials/modal/modal_content.html +2 -6
- django_smartbase_admin/templates/sb_admin/sb_admin_base.html +49 -4
- django_smartbase_admin/templates/sb_admin/sb_admin_base_no_sidebar.html +27 -11
- django_smartbase_admin/templates/sb_admin/sb_admin_js_trans.html +3 -0
- django_smartbase_admin/templates/sb_admin/sprites/sb_admin.svg +1 -1
- django_smartbase_admin/templates/sb_admin/tailwind_whitelist.html +6 -3
- django_smartbase_admin/templates/sb_admin/widgets/array.html +0 -1
- django_smartbase_admin/templates/sb_admin/widgets/attributes.html +68 -0
- django_smartbase_admin/templates/sb_admin/widgets/autocomplete.html +13 -2
- django_smartbase_admin/templates/sb_admin/widgets/{checkbox_select.html → checkbox_dropdown.html} +2 -2
- django_smartbase_admin/templates/sb_admin/widgets/clearable_file_input.html +2 -2
- django_smartbase_admin/templates/sb_admin/widgets/color_field.html +30 -0
- django_smartbase_admin/templates/sb_admin/widgets/date.html +8 -1
- django_smartbase_admin/templates/sb_admin/widgets/filer_file.html +84 -0
- django_smartbase_admin/templates/sb_admin/widgets/includes/related_item_buttons.html +38 -0
- django_smartbase_admin/templates/sb_admin/widgets/multiwidget.html +1 -1
- django_smartbase_admin/templates/sb_admin/widgets/radio.html +3 -2
- django_smartbase_admin/templates/sb_admin/widgets/radio_dropdown.html +30 -0
- django_smartbase_admin/templates/sb_admin/widgets/read_only_password_hash.html +3 -0
- django_smartbase_admin/templates/sb_admin/widgets/time.html +8 -1
- django_smartbase_admin/templates/sb_admin/widgets/toggle.html +1 -1
- django_smartbase_admin/templates/sb_admin/widgets/tree_base.html +59 -0
- django_smartbase_admin/templates/sb_admin/widgets/tree_select.html +24 -0
- django_smartbase_admin/templates/sb_admin/widgets/tree_select_inline.html +12 -0
- django_smartbase_admin/templatetags/sb_admin_tags.py +115 -4
- django_smartbase_admin/utils.py +22 -3
- django_smartbase_admin/views/dashboard_view.py +6 -0
- django_smartbase_admin/views/global_filter_view.py +8 -2
- django_smartbase_admin/views/translations_view.py +12 -5
- django_smartbase_admin/views/user_config_view.py +52 -0
- django_smartbase_admin-1.0.42.dist-info/METADATA +166 -0
- {django_smartbase_admin-0.2.54.dist-info → django_smartbase_admin-1.0.42.dist-info}/RECORD +182 -118
- {django_smartbase_admin-0.2.54.dist-info → django_smartbase_admin-1.0.42.dist-info}/WHEEL +1 -1
- django_smartbase_admin/templates/sb_admin/integrations/sorting/change_list.html +0 -401
- django_smartbase_admin-0.2.54.dist-info/METADATA +0 -25
- {django_smartbase_admin-0.2.54.dist-info → django_smartbase_admin-1.0.42.dist-info}/LICENSE.md +0 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import {monthToStr} from "flatpickr/dist/esm/utils/formatting"
|
|
2
|
+
import {createIcon} from "./utils"
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line no-unused-vars
|
|
5
|
+
export const monthYearViewsPlugin = (fp) => {
|
|
6
|
+
const customViewsWrapper = document.createElement('div')
|
|
7
|
+
customViewsWrapper.classList.add('flatpickr-custom-views-wrapper')
|
|
8
|
+
|
|
9
|
+
const customMonthsView = document.createElement('div')
|
|
10
|
+
customMonthsView.classList.add('flatpickr-custom-months-view', 'hidden')
|
|
11
|
+
|
|
12
|
+
const customYearsView = document.createElement('div')
|
|
13
|
+
customYearsView.classList.add('flatpickr-custom-years-view', 'hidden')
|
|
14
|
+
|
|
15
|
+
customViewsWrapper.append(customMonthsView)
|
|
16
|
+
customViewsWrapper.append(customYearsView)
|
|
17
|
+
|
|
18
|
+
const yearElHeight = 48
|
|
19
|
+
const yearScrollToElement = 106
|
|
20
|
+
|
|
21
|
+
let currentYearEl = null
|
|
22
|
+
|
|
23
|
+
const changeActiveView = (view) => {
|
|
24
|
+
switch (view) {
|
|
25
|
+
case 'months':
|
|
26
|
+
customMonthsView.classList.remove('hidden')
|
|
27
|
+
customYearsView.classList.add('hidden')
|
|
28
|
+
break
|
|
29
|
+
case 'years':
|
|
30
|
+
customMonthsView.classList.add('hidden')
|
|
31
|
+
customYearsView.classList.remove('hidden')
|
|
32
|
+
currentYearEl.parentNode.scrollTop = yearElHeight * yearScrollToElement
|
|
33
|
+
break
|
|
34
|
+
default:
|
|
35
|
+
customMonthsView.classList.add('hidden')
|
|
36
|
+
customYearsView.classList.add('hidden')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const selectMonth = (e) => {
|
|
41
|
+
fp.changeMonth(parseInt(e.target.dataset.month), false)
|
|
42
|
+
buildMonths()
|
|
43
|
+
buildYears()
|
|
44
|
+
changeActiveView()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const selectYear = (e) => {
|
|
48
|
+
fp.changeYear(parseInt(e.target.dataset.year), false)
|
|
49
|
+
buildMonths()
|
|
50
|
+
buildYears()
|
|
51
|
+
changeActiveView("months")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const yearInRange = (year, selectedYears) => {
|
|
55
|
+
if (selectedYears[0] && selectedYears[1]) {
|
|
56
|
+
return selectedYears[0] <= year && year <= selectedYears[1]
|
|
57
|
+
}
|
|
58
|
+
return selectedYears[0] === year
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const monthInRange = (monthIndex, selectedMonths, selectedYears) => {
|
|
62
|
+
//range
|
|
63
|
+
if (selectedYears[0] && selectedYears[1]) {
|
|
64
|
+
if (selectedYears[0] === selectedYears[1]) {
|
|
65
|
+
if (selectedYears[0] === fp.currentYear) {
|
|
66
|
+
return selectedMonths[0] <= monthIndex && monthIndex <= selectedMonths[1]
|
|
67
|
+
}
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
if (selectedYears[0] === fp.currentYear && monthIndex >= selectedMonths[0]) {
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
if (selectedYears[0] < fp.currentYear && fp.currentYear < selectedYears[1]) {
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
if (selectedYears[1] === fp.currentYear && monthIndex <= selectedMonths[1]) {
|
|
77
|
+
return true
|
|
78
|
+
}
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//single value
|
|
83
|
+
if (selectedYears[0] && !selectedYears[1]) {
|
|
84
|
+
if (selectedYears[0] === fp.currentYear && monthIndex === selectedMonths[0]) {
|
|
85
|
+
return true
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const buildBackButton = (backToView) => {
|
|
93
|
+
const back = document.createElement('div')
|
|
94
|
+
back.classList.add('flatpickr-back')
|
|
95
|
+
back.textContent = "Back"
|
|
96
|
+
fp._bind(back, 'click', (e) => {
|
|
97
|
+
e.preventDefault()
|
|
98
|
+
e.stopPropagation()
|
|
99
|
+
changeActiveView(backToView)
|
|
100
|
+
})
|
|
101
|
+
return back
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const buildMonths = () => {
|
|
105
|
+
customMonthsView.innerHTML = ''
|
|
106
|
+
const monthsHeader = fp.monthNav.cloneNode(true)
|
|
107
|
+
const yearEl = monthsHeader.querySelector('.flatpickr-current-month')
|
|
108
|
+
yearEl.innerHTML = fp.currentYear
|
|
109
|
+
fp._bind(yearEl, 'click', () => {
|
|
110
|
+
changeActiveView('years')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const prevYear = monthsHeader.querySelector('.flatpickr-prev-month')
|
|
114
|
+
const nextYear = monthsHeader.querySelector('.flatpickr-next-month')
|
|
115
|
+
|
|
116
|
+
prevYear.replaceChildren(createIcon('Left-small'))
|
|
117
|
+
nextYear.replaceChildren(createIcon('Right-small'))
|
|
118
|
+
|
|
119
|
+
fp._bind(prevYear, 'click', (e) => {
|
|
120
|
+
e.preventDefault()
|
|
121
|
+
e.stopPropagation()
|
|
122
|
+
fp.changeYear(fp.currentYear - 1)
|
|
123
|
+
buildMonths()
|
|
124
|
+
buildYears()
|
|
125
|
+
})
|
|
126
|
+
fp._bind(nextYear, 'click', (e) => {
|
|
127
|
+
e.preventDefault()
|
|
128
|
+
e.stopPropagation()
|
|
129
|
+
fp.changeYear(fp.currentYear + 1)
|
|
130
|
+
buildMonths()
|
|
131
|
+
buildYears()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const monthsContent = fp.innerContainer.cloneNode(true)
|
|
136
|
+
monthsContent.querySelector('.flatpickr-weekdays').remove()
|
|
137
|
+
const monthsContainer = monthsContent.querySelector('.dayContainer')
|
|
138
|
+
monthsContainer.innerHTML = ''
|
|
139
|
+
|
|
140
|
+
const selectedMonths = fp.selectedDates.map(date => {
|
|
141
|
+
return date.getMonth()
|
|
142
|
+
})
|
|
143
|
+
const selectedYears = fp.selectedDates.map(date => {
|
|
144
|
+
return date.getFullYear()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
for (let i = 0; i < 12; i++) {
|
|
148
|
+
const month = document.createElement('span')
|
|
149
|
+
month.classList.add('flatpickr-day', 'flatpickr-month')
|
|
150
|
+
if (i === fp.now.getMonth() && fp.currentYear === fp.now.getFullYear()) {
|
|
151
|
+
month.classList.add('today')
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (monthInRange(i, selectedMonths, selectedYears)) {
|
|
155
|
+
month.classList.add('selected')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
month.textContent = monthToStr(i, fp.shorthand, fp.l10n)
|
|
159
|
+
month.dataset.month = i.toString()
|
|
160
|
+
month.addEventListener("click", selectMonth)
|
|
161
|
+
monthsContainer.appendChild(month)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
customMonthsView.append(monthsHeader)
|
|
165
|
+
customMonthsView.append(monthsContent)
|
|
166
|
+
customMonthsView.append(buildBackButton())
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const buildYears = () => {
|
|
170
|
+
customYearsView.innerHTML = ''
|
|
171
|
+
const yearsHeader = fp.monthNav.cloneNode(true)
|
|
172
|
+
const yearEl = yearsHeader.querySelector('.flatpickr-current-month')
|
|
173
|
+
yearEl.innerHTML = fp.currentYear
|
|
174
|
+
|
|
175
|
+
yearsHeader.querySelector('.flatpickr-prev-month').remove()
|
|
176
|
+
yearsHeader.querySelector('.flatpickr-next-month').remove()
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
const yearsContent = fp.innerContainer.cloneNode(true)
|
|
180
|
+
yearsContent.querySelector('.flatpickr-weekdays').remove()
|
|
181
|
+
yearsContent.querySelector('.flatpickr-days').classList.add('h-full', '-mr-8')
|
|
182
|
+
|
|
183
|
+
const yearsContainer = yearsContent.querySelector('.dayContainer')
|
|
184
|
+
yearsContainer.classList.add('overflow-auto', 'custom-scrollbar')
|
|
185
|
+
yearsContainer.innerHTML = ''
|
|
186
|
+
|
|
187
|
+
const currentYear = fp.now.getFullYear()
|
|
188
|
+
const selectedYears = fp.selectedDates.map(date => {
|
|
189
|
+
return date.getFullYear()
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
for (let i = currentYear - 100; i <= currentYear + 100; i++) {
|
|
193
|
+
const year = document.createElement('span')
|
|
194
|
+
year.classList.add('flatpickr-day', 'flatpickr-year')
|
|
195
|
+
|
|
196
|
+
if (i === fp.now.getFullYear()) {
|
|
197
|
+
year.classList.add('today')
|
|
198
|
+
currentYearEl = year
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (yearInRange(i, selectedYears)) {
|
|
202
|
+
year.classList.add('selected')
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
year.textContent = i.toString()
|
|
206
|
+
year.dataset.year = i.toString()
|
|
207
|
+
year.addEventListener("click", selectYear)
|
|
208
|
+
yearsContainer.appendChild(year)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
customYearsView.append(yearsHeader)
|
|
212
|
+
customYearsView.append(yearsContent)
|
|
213
|
+
customYearsView.append(buildBackButton("months"))
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const replaceOriginalMonths = () => {
|
|
217
|
+
const currentMonth = fp.monthNav.querySelector('.flatpickr-current-month')
|
|
218
|
+
currentMonth.innerHTML = ''
|
|
219
|
+
currentMonth.textContent = `${monthToStr(fp.currentMonth, fp.shorthand, fp.l10n)} ${fp.currentYear}`
|
|
220
|
+
return currentMonth
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if(fp.config.noCalendar) {
|
|
224
|
+
return {}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const build = () => {
|
|
228
|
+
fp.monthNav.parentNode.insertBefore(customViewsWrapper, fp.monthNav)
|
|
229
|
+
|
|
230
|
+
fp._bind(replaceOriginalMonths(), "click", (e) => {
|
|
231
|
+
e.preventDefault()
|
|
232
|
+
e.stopPropagation()
|
|
233
|
+
changeActiveView('months')
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
buildMonths()
|
|
237
|
+
buildYears()
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
onReady: build,
|
|
242
|
+
onChange: [
|
|
243
|
+
replaceOriginalMonths,
|
|
244
|
+
buildMonths,
|
|
245
|
+
buildYears,
|
|
246
|
+
],
|
|
247
|
+
onMonthChange: replaceOriginalMonths,
|
|
248
|
+
onYearChange: replaceOriginalMonths
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export const createRadioInput = (id, name, value, label, checked, index) => {
|
|
253
|
+
const inputWrapperEl = document.createElement('label')
|
|
254
|
+
inputWrapperEl.classList.add('relative', 'block', 'px-12', 'py-8')
|
|
255
|
+
inputWrapperEl.setAttribute('for', id)
|
|
256
|
+
const labelEl = document.createElement('label')
|
|
257
|
+
labelEl.innerText = label
|
|
258
|
+
labelEl.setAttribute('for', id)
|
|
259
|
+
const inputEl = document.createElement('input')
|
|
260
|
+
inputEl.id = id
|
|
261
|
+
inputEl.name = name
|
|
262
|
+
inputEl.value = value
|
|
263
|
+
inputEl.type = 'radio'
|
|
264
|
+
inputEl.classList.add('radio', 'radio-list', 'flatpickr-shortcut')
|
|
265
|
+
inputEl.checked = checked
|
|
266
|
+
inputEl.dataset["index"] = index
|
|
267
|
+
inputWrapperEl.append(inputEl)
|
|
268
|
+
inputWrapperEl.append(labelEl)
|
|
269
|
+
return inputWrapperEl
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// eslint-disable-next-line no-unused-vars
|
|
273
|
+
export const customActionsPlugin = (fp) => {
|
|
274
|
+
const setInitialValueAndLabel = (realInput, shortcuts, baseId) => {
|
|
275
|
+
const shortcutValue = JSON.parse(realInput.value)
|
|
276
|
+
const from = new Date()
|
|
277
|
+
from.setDate(from.getDate() + shortcutValue[0])
|
|
278
|
+
|
|
279
|
+
const to = new Date()
|
|
280
|
+
to.setDate(to.getDate() + shortcutValue[1])
|
|
281
|
+
fp.setDate([from, to], false, fp.config.dateFormat)
|
|
282
|
+
|
|
283
|
+
shortcuts.forEach((shortcut, idx) => {
|
|
284
|
+
if(JSON.stringify(shortcut.value) === realInput.value) {
|
|
285
|
+
document.getElementById(`${baseId}_range${idx}`).checked = true
|
|
286
|
+
realInput.dataset['label'] = shortcut.label
|
|
287
|
+
}
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
const createShortcuts = () => {
|
|
293
|
+
const realInput = document.getElementById(fp.element.dataset.sbadminDatepickerRealInputId)
|
|
294
|
+
const baseId = realInput.id
|
|
295
|
+
const baseValue = realInput.value
|
|
296
|
+
const el = document.createElement('div')
|
|
297
|
+
const shortcuts = JSON.parse(fp.element.dataset.sbadminDatepickerShortcuts)
|
|
298
|
+
el.classList.add('flatpickr-shortcuts')
|
|
299
|
+
el.addEventListener('change', (e) => {
|
|
300
|
+
// on shortcut click/change set new value and label to real input element
|
|
301
|
+
const value = e.target.value
|
|
302
|
+
realInput.value = value
|
|
303
|
+
realInput.dataset['label'] = e.target.nextElementSibling.innerText
|
|
304
|
+
realInput.dispatchEvent(new Event('change'))
|
|
305
|
+
|
|
306
|
+
// parse new value and set it to flatpicker
|
|
307
|
+
const shortcutValue = shortcuts[e.target.dataset.index].value
|
|
308
|
+
const from = new Date()
|
|
309
|
+
from.setDate(from.getDate() + shortcutValue[0])
|
|
310
|
+
|
|
311
|
+
const to = new Date()
|
|
312
|
+
to.setDate(to.getDate() + shortcutValue[1])
|
|
313
|
+
|
|
314
|
+
fp.setDate([from, to], false, fp.config.dateFormat)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
shortcuts.forEach((shortcut, idx) => {
|
|
318
|
+
const checked = JSON.stringify(shortcut.value) === baseValue
|
|
319
|
+
if(checked) {
|
|
320
|
+
realInput.dataset['label'] = shortcut.label
|
|
321
|
+
}
|
|
322
|
+
el.append(createRadioInput(
|
|
323
|
+
`${baseId}_range${idx}`,
|
|
324
|
+
`${baseId}_shortcut`,
|
|
325
|
+
JSON.stringify(shortcut.value),
|
|
326
|
+
shortcut.label,
|
|
327
|
+
checked,
|
|
328
|
+
idx
|
|
329
|
+
))
|
|
330
|
+
})
|
|
331
|
+
fp.calendarContainer.prepend(el)
|
|
332
|
+
|
|
333
|
+
if(realInput.value){
|
|
334
|
+
setInitialValueAndLabel(realInput, shortcuts, baseId)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
realInput.addEventListener('SBTableFilterFormLoad', () => {
|
|
338
|
+
try {
|
|
339
|
+
setInitialValueAndLabel(realInput, shortcuts, baseId)
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
fp.setDate(realInput.value, false, fp.config.dateFormat)
|
|
343
|
+
}
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
onReady: createShortcuts,
|
|
350
|
+
onChange: (selectedDates, dateStr, instance) => {
|
|
351
|
+
const checkedShortcut = instance.element.parentElement.querySelector('input.flatpickr-shortcut:checked')
|
|
352
|
+
if(checkedShortcut){
|
|
353
|
+
checkedShortcut.checked = false
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|