@iamproperty/components 7.7.1--beta4 → 7.7.1--beta6
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.
- package/README.md +4 -4
- package/assets/bootstrap/README.md +247 -247
- package/assets/bootstrap/dist/css/bootstrap-grid.css +4124 -0
- package/assets/bootstrap/dist/css/bootstrap-grid.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-grid.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap-grid.min.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-grid.rtl.css +4123 -0
- package/assets/bootstrap/dist/css/bootstrap-grid.rtl.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-grid.rtl.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap-grid.rtl.min.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.css +488 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.min.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.rtl.css +485 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.rtl.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.rtl.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap-reboot.rtl.min.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.css +4197 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.min.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.rtl.css +4188 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.rtl.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.rtl.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap-utilities.rtl.min.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap.css +10907 -0
- package/assets/bootstrap/dist/css/bootstrap.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap.min.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap.rtl.css +10867 -0
- package/assets/bootstrap/dist/css/bootstrap.rtl.css.map +1 -0
- package/assets/bootstrap/dist/css/bootstrap.rtl.min.css +7 -0
- package/assets/bootstrap/dist/css/bootstrap.rtl.min.css.map +1 -0
- package/assets/bootstrap/dist/js/bootstrap.bundle.js +7066 -0
- package/assets/bootstrap/dist/js/bootstrap.bundle.js.map +1 -0
- package/assets/bootstrap/dist/js/bootstrap.bundle.min.js +7 -0
- package/assets/bootstrap/dist/js/bootstrap.bundle.min.js.map +1 -0
- package/assets/bootstrap/dist/js/bootstrap.esm.js +5204 -0
- package/assets/bootstrap/dist/js/bootstrap.esm.js.map +1 -0
- package/assets/bootstrap/dist/js/bootstrap.esm.min.js +7 -0
- package/assets/bootstrap/dist/js/bootstrap.esm.min.js.map +1 -0
- package/assets/bootstrap/dist/js/bootstrap.js +5251 -0
- package/assets/bootstrap/dist/js/bootstrap.js.map +1 -0
- package/assets/bootstrap/dist/js/bootstrap.min.js +7 -0
- package/assets/bootstrap/dist/js/bootstrap.min.js.map +1 -0
- package/assets/bootstrap/js/dist/alert.js +100 -0
- package/assets/bootstrap/js/dist/alert.js.map +1 -0
- package/assets/bootstrap/js/dist/base-component.js +100 -0
- package/assets/bootstrap/js/dist/base-component.js.map +1 -0
- package/assets/bootstrap/js/dist/button.js +82 -0
- package/assets/bootstrap/js/dist/button.js.map +1 -0
- package/assets/bootstrap/js/dist/carousel.js +471 -0
- package/assets/bootstrap/js/dist/carousel.js.map +1 -0
- package/assets/bootstrap/js/dist/collapse.js +311 -0
- package/assets/bootstrap/js/dist/collapse.js.map +1 -0
- package/assets/bootstrap/js/dist/dom/data.js +67 -0
- package/assets/bootstrap/js/dist/dom/data.js.map +1 -0
- package/assets/bootstrap/js/dist/dom/event-handler.js +284 -0
- package/assets/bootstrap/js/dist/dom/event-handler.js.map +1 -0
- package/assets/bootstrap/js/dist/dom/manipulator.js +85 -0
- package/assets/bootstrap/js/dist/dom/manipulator.js.map +1 -0
- package/assets/bootstrap/js/dist/dom/selector-engine.js +86 -0
- package/assets/bootstrap/js/dist/dom/selector-engine.js.map +1 -0
- package/assets/bootstrap/js/dist/dropdown.js +471 -0
- package/assets/bootstrap/js/dist/dropdown.js.map +1 -0
- package/assets/bootstrap/js/dist/modal.js +397 -0
- package/assets/bootstrap/js/dist/modal.js.map +1 -0
- package/assets/bootstrap/js/dist/offcanvas.js +298 -0
- package/assets/bootstrap/js/dist/offcanvas.js.map +1 -0
- package/assets/bootstrap/js/dist/popover.js +102 -0
- package/assets/bootstrap/js/dist/popover.js.map +1 -0
- package/assets/bootstrap/js/dist/scrollspy.js +308 -0
- package/assets/bootstrap/js/dist/scrollspy.js.map +1 -0
- package/assets/bootstrap/js/dist/tab.js +334 -0
- package/assets/bootstrap/js/dist/tab.js.map +1 -0
- package/assets/bootstrap/js/dist/toast.js +237 -0
- package/assets/bootstrap/js/dist/toast.js.map +1 -0
- package/assets/bootstrap/js/dist/tooltip.js +663 -0
- package/assets/bootstrap/js/dist/tooltip.js.map +1 -0
- package/assets/bootstrap/js/dist/util/backdrop.js +166 -0
- package/assets/bootstrap/js/dist/util/backdrop.js.map +1 -0
- package/assets/bootstrap/js/dist/util/component-functions.js +47 -0
- package/assets/bootstrap/js/dist/util/component-functions.js.map +1 -0
- package/assets/bootstrap/js/dist/util/config.js +80 -0
- package/assets/bootstrap/js/dist/util/config.js.map +1 -0
- package/assets/bootstrap/js/dist/util/focustrap.js +130 -0
- package/assets/bootstrap/js/dist/util/focustrap.js.map +1 -0
- package/assets/bootstrap/js/dist/util/index.js +351 -0
- package/assets/bootstrap/js/dist/util/index.js.map +1 -0
- package/assets/bootstrap/js/dist/util/sanitizer.js +123 -0
- package/assets/bootstrap/js/dist/util/sanitizer.js.map +1 -0
- package/assets/bootstrap/js/dist/util/scrollbar.js +139 -0
- package/assets/bootstrap/js/dist/util/scrollbar.js.map +1 -0
- package/assets/bootstrap/js/dist/util/swipe.js +156 -0
- package/assets/bootstrap/js/dist/util/swipe.js.map +1 -0
- package/assets/bootstrap/js/dist/util/template-factory.js +178 -0
- package/assets/bootstrap/js/dist/util/template-factory.js.map +1 -0
- package/assets/bootstrap/js/index.esm.js +19 -19
- package/assets/bootstrap/js/index.umd.js +34 -34
- package/assets/bootstrap/js/src/alert.js +87 -87
- package/assets/bootstrap/js/src/base-component.js +85 -85
- package/assets/bootstrap/js/src/button.js +72 -72
- package/assets/bootstrap/js/src/carousel.js +475 -475
- package/assets/bootstrap/js/src/collapse.js +302 -302
- package/assets/bootstrap/js/src/dom/data.js +55 -55
- package/assets/bootstrap/js/src/dom/event-handler.js +320 -320
- package/assets/bootstrap/js/src/dom/manipulator.js +71 -71
- package/assets/bootstrap/js/src/dom/selector-engine.js +83 -83
- package/assets/bootstrap/js/src/dropdown.js +445 -445
- package/assets/bootstrap/js/src/modal.js +373 -373
- package/assets/bootstrap/js/src/offcanvas.js +283 -283
- package/assets/bootstrap/js/src/popover.js +97 -97
- package/assets/bootstrap/js/src/scrollspy.js +290 -290
- package/assets/bootstrap/js/src/tab.js +307 -307
- package/assets/bootstrap/js/src/toast.js +220 -220
- package/assets/bootstrap/js/src/tooltip.js +651 -651
- package/assets/bootstrap/js/src/util/backdrop.js +149 -149
- package/assets/bootstrap/js/src/util/component-functions.js +34 -34
- package/assets/bootstrap/js/src/util/config.js +66 -66
- package/assets/bootstrap/js/src/util/focustrap.js +115 -115
- package/assets/bootstrap/js/src/util/index.js +336 -336
- package/assets/bootstrap/js/src/util/sanitizer.js +118 -118
- package/assets/bootstrap/js/src/util/scrollbar.js +114 -114
- package/assets/bootstrap/js/src/util/swipe.js +146 -146
- package/assets/bootstrap/js/src/util/template-factory.js +160 -160
- package/assets/bootstrap/package.json +180 -180
- package/assets/bootstrap/scss/_accordion.scss +146 -146
- package/assets/bootstrap/scss/_button-group.scss +142 -142
- package/assets/bootstrap/scss/_buttons.scss +186 -186
- package/assets/bootstrap/scss/_carousel.scss +229 -229
- package/assets/bootstrap/scss/_dropdown.scss +248 -248
- package/assets/bootstrap/scss/_functions.scss +302 -302
- package/assets/bootstrap/scss/_list-group.scss +191 -191
- package/assets/bootstrap/scss/_modal.scss +237 -237
- package/assets/bootstrap/scss/_nav.scss +172 -172
- package/assets/bootstrap/scss/_navbar.scss +276 -276
- package/assets/bootstrap/scss/_offcanvas.scss +143 -143
- package/assets/bootstrap/scss/_pagination.scss +109 -109
- package/assets/bootstrap/scss/_popover.scss +196 -196
- package/assets/bootstrap/scss/_toasts.scss +70 -70
- package/assets/bootstrap/scss/_variables-dark.scss +87 -87
- package/assets/bootstrap/scss/_variables.scss +1633 -1633
- package/assets/bootstrap/scss/bootstrap-utilities.scss +15 -15
- package/assets/bootstrap/scss/forms/_floating-labels.scss +74 -74
- package/assets/bootstrap/scss/forms/_input-group.scss +129 -129
- package/assets/bootstrap/scss/helpers/_focus-ring.scss +5 -5
- package/assets/bootstrap/scss/helpers/_icon-link.scss +25 -25
- package/assets/bootstrap/scss/mixins/_banner.scss +9 -9
- package/assets/bootstrap/scss/mixins/_color-mode.scss +21 -21
- package/assets/bootstrap/scss/mixins/_forms.scss +152 -152
- package/assets/bootstrap/scss/mixins/_table-variants.scss +24 -24
- package/assets/bootstrap/scss/mixins/_utilities.scss +97 -97
- package/assets/css/components/actionbar.component.css +1 -1
- package/assets/css/components/actionbar.component.css.map +1 -1
- package/assets/css/components/address-lookup.component.css +1 -1
- package/assets/css/components/address-lookup.component.css.map +1 -1
- package/assets/css/components/applied-filters.css +1 -1
- package/assets/css/components/applied-filters.css.map +1 -1
- package/assets/css/components/barchart.component.css +1 -1
- package/assets/css/components/barchart.component.css.map +1 -1
- package/assets/css/components/calendar.component.css +1 -1
- package/assets/css/components/calendar.component.css.map +1 -1
- package/assets/css/components/card.component.css +1 -1
- package/assets/css/components/card.component.css.map +1 -1
- package/assets/css/components/card.module.css +1 -1
- package/assets/css/components/card.module.css.map +1 -1
- package/assets/css/components/carousel.component.css +1 -1
- package/assets/css/components/carousel.component.css.map +1 -1
- package/assets/css/components/charts.css +1 -1
- package/assets/css/components/charts.css.map +1 -1
- package/assets/css/components/collapsible-side.css +1 -1
- package/assets/css/components/collapsible-side.css.map +1 -1
- package/assets/css/components/config.component.css +1 -1
- package/assets/css/components/config.component.css.map +1 -1
- package/assets/css/components/content.component.css +1 -1
- package/assets/css/components/content.component.css.map +1 -1
- package/assets/css/components/doughnutchart.component.css +1 -1
- package/assets/css/components/doughnutchart.component.css.map +1 -1
- package/assets/css/components/fileupload.css +1 -1
- package/assets/css/components/fileupload.css.map +1 -1
- package/assets/css/components/filter-card.component.css +1 -1
- package/assets/css/components/filter-card.component.css.map +1 -1
- package/assets/css/components/header.css +1 -1
- package/assets/css/components/header.css.map +1 -1
- package/assets/css/components/inline-edit.css +1 -1
- package/assets/css/components/inline-edit.css.map +1 -1
- package/assets/css/components/input.component.css.map +1 -1
- package/assets/css/components/modal.component.css +1 -1
- package/assets/css/components/modal.component.css.map +1 -1
- package/assets/css/components/multi-step-modal.component.css +1 -1
- package/assets/css/components/multi-step-modal.component.css.map +1 -1
- package/assets/css/components/multiselect.css +1 -1
- package/assets/css/components/multiselect.css.map +1 -1
- package/assets/css/components/nav.component.css +1 -1
- package/assets/css/components/nav.component.css.map +1 -1
- package/assets/css/components/pagination.css +1 -1
- package/assets/css/components/pagination.css.map +1 -1
- package/assets/css/components/record-card.component.css +1 -1
- package/assets/css/components/record-card.component.css.map +1 -1
- package/assets/css/components/slider.css +1 -1
- package/assets/css/components/slider.css.map +1 -1
- package/assets/css/components/split-button.component.css +1 -1
- package/assets/css/components/split-button.component.css.map +1 -1
- package/assets/css/components/tabs.component.css +1 -1
- package/assets/css/components/tabs.component.css.map +1 -1
- package/assets/css/components/tabs.config.css +1 -1
- package/assets/css/components/tabs.config.css.map +1 -1
- package/assets/css/components/tag.component.css +1 -1
- package/assets/css/components/tag.component.css.map +1 -1
- package/assets/css/components/video-card.component.css +1 -1
- package/assets/css/components/video-card.component.css.map +1 -1
- package/assets/css/components/video-modal.component.css +1 -1
- package/assets/css/components/video-modal.component.css.map +1 -1
- package/assets/css/components/video.component.css +1 -0
- package/assets/css/components/video.component.css.map +1 -0
- package/assets/css/core.min.css +1 -1
- package/assets/css/core.min.css.map +1 -1
- package/assets/css/elements/badge-tag.css +1 -1
- package/assets/css/elements/badge-tag.css.map +1 -1
- package/assets/css/elements/buttons--action.css +1 -1
- package/assets/css/elements/buttons--action.css.map +1 -1
- package/assets/css/elements/buttons--global.css +1 -1
- package/assets/css/elements/buttons--global.css.map +1 -1
- package/assets/css/elements/buttons--secondary.css +1 -1
- package/assets/css/elements/buttons--secondary.css.map +1 -1
- package/assets/css/elements/buttons--special.css +1 -1
- package/assets/css/elements/buttons--special.css.map +1 -1
- package/assets/css/elements/buttons--tertiary.css +1 -1
- package/assets/css/elements/buttons--tertiary.css.map +1 -1
- package/assets/css/elements/buttons.css +1 -1
- package/assets/css/elements/buttons.css.map +1 -1
- package/assets/css/elements/container.css +1 -1
- package/assets/css/elements/container.css.map +1 -1
- package/assets/css/elements/details.css +1 -1
- package/assets/css/elements/details.css.map +1 -1
- package/assets/css/elements/dialog.css.map +1 -1
- package/assets/css/elements/dropdown.css +1 -1
- package/assets/css/elements/dropdown.css.map +1 -1
- package/assets/css/elements/feature.css +1 -1
- package/assets/css/elements/feature.css.map +1 -1
- package/assets/css/elements/forms.css +1 -1
- package/assets/css/elements/forms.css.map +1 -1
- package/assets/css/elements/label.css +1 -1
- package/assets/css/elements/label.css.map +1 -1
- package/assets/css/elements/links--collapsible-side.css +1 -0
- package/assets/css/elements/links--collapsible-side.css.map +1 -0
- package/assets/css/elements/links--global.css +1 -0
- package/assets/css/elements/links--global.css.map +1 -0
- package/assets/css/elements/links--video.css +1 -0
- package/assets/css/elements/links--video.css.map +1 -0
- package/assets/css/elements/links.css +1 -1
- package/assets/css/elements/links.css.map +1 -1
- package/assets/css/elements/modal.css.map +1 -1
- package/assets/css/elements/progress.css.map +1 -1
- package/assets/css/elements/textarea.css +1 -1
- package/assets/css/elements/textarea.css.map +1 -1
- package/assets/css/elements/toggle-button.css +1 -1
- package/assets/css/elements/toggle-button.css.map +1 -1
- package/assets/css/elements/tooltips.css +1 -1
- package/assets/css/elements/tooltips.css.map +1 -1
- package/assets/css/style.min.css +1 -1
- package/assets/css/style.min.css.map +1 -1
- package/assets/favicons/README.md +20 -20
- package/assets/favicons/browserconfig.xml +9 -9
- package/assets/favicons/manifest.json +31 -31
- package/assets/favicons/safari-pinned-tab.svg +35 -35
- package/assets/favicons/site.webmanifest +20 -20
- package/assets/js/components/accordion/accordion.component.js +15 -15
- package/assets/js/components/accordion/accordion.component.min.js +1 -1
- package/assets/js/components/accordion/accordion.component.min.js.map +1 -1
- package/assets/js/components/actionbar/actionbar.component.js +68 -68
- package/assets/js/components/actionbar/actionbar.component.min.js +2 -2
- package/assets/js/components/actionbar/actionbar.component.min.js.map +1 -1
- package/assets/js/components/address-lookup/address-lookup.component.js +60 -60
- package/assets/js/components/address-lookup/address-lookup.component.min.js +4 -4
- package/assets/js/components/address-lookup/address-lookup.component.min.js.map +1 -1
- package/assets/js/components/advanced-select/advanced-select.component.js +20 -20
- package/assets/js/components/advanced-select/advanced-select.component.min.js +1 -1
- package/assets/js/components/advanced-select/advanced-select.component.min.js.map +1 -1
- package/assets/js/components/applied-filters/applied-filters.component.js +7 -7
- package/assets/js/components/applied-filters/applied-filters.component.min.js +2 -2
- package/assets/js/components/applied-filters/applied-filters.component.min.js.map +1 -1
- package/assets/js/components/barchart/barchart.component.js +2 -2
- package/assets/js/components/barchart/barchart.component.min.js +3 -3
- package/assets/js/components/barchart/barchart.component.min.js.map +1 -1
- package/assets/js/components/bento-grid/bento-grid.component.js +9 -9
- package/assets/js/components/bento-grid/bento-grid.component.min.js +1 -1
- package/assets/js/components/bento-grid/bento-grid.component.min.js.map +1 -1
- package/assets/js/components/calendar/calendar.component.js +2 -2
- package/assets/js/components/calendar/calendar.component.min.js +2 -2
- package/assets/js/components/calendar/calendar.component.min.js.map +1 -1
- package/assets/js/components/card/card.component.js +3 -3
- package/assets/js/components/card/card.component.min.js +2 -2
- package/assets/js/components/card/card.component.min.js.map +1 -1
- package/assets/js/components/carousel/carousel.component.js +2 -2
- package/assets/js/components/carousel/carousel.component.min.js +4 -4
- package/assets/js/components/carousel/carousel.component.min.js.map +1 -1
- package/assets/js/components/chart/chart.component.js +1 -1
- package/assets/js/components/collapsible-side/collapsible-side.component.js +20 -20
- package/assets/js/components/collapsible-side/collapsible-side.component.min.js +4 -4
- package/assets/js/components/collapsible-side/collapsible-side.component.min.js.map +1 -1
- package/assets/js/components/config/config.component.js +54 -54
- package/assets/js/components/config/config.component.min.js +2 -2
- package/assets/js/components/config/config.component.min.js.map +1 -1
- package/assets/js/components/content/content.component.js +9 -9
- package/assets/js/components/content/content.component.min.js +4 -4
- package/assets/js/components/content/content.component.min.js.map +1 -1
- package/assets/js/components/darkmode/darkmode.component.js +4 -4
- package/assets/js/components/darkmode/darkmode.component.min.js +1 -1
- package/assets/js/components/darkmode/darkmode.component.min.js.map +1 -1
- package/assets/js/components/doughnutchart/doughnutchart.component.js +2 -2
- package/assets/js/components/doughnutchart/doughnutchart.component.min.js +2 -2
- package/assets/js/components/doughnutchart/doughnutchart.component.min.js.map +1 -1
- package/assets/js/components/fileupload/fileupload.component.js +17 -17
- package/assets/js/components/fileupload/fileupload.component.min.js +2 -2
- package/assets/js/components/fileupload/fileupload.component.min.js.map +1 -1
- package/assets/js/components/filter-card/filter-card.component.js +9 -9
- package/assets/js/components/filter-card/filter-card.component.min.js +5 -5
- package/assets/js/components/filter-card/filter-card.component.min.js.map +1 -1
- package/assets/js/components/filterlist/filterlist.component.js +1 -1
- package/assets/js/components/filterlist/filterlist.component.min.js +1 -1
- package/assets/js/components/filterlist/filterlist.component.min.js.map +1 -1
- package/assets/js/components/form/form.component.js +5 -5
- package/assets/js/components/form/form.component.min.js +1 -1
- package/assets/js/components/form/form.component.min.js.map +1 -1
- package/assets/js/components/header/header.component.js +53 -53
- package/assets/js/components/header/header.component.min.js +2 -2
- package/assets/js/components/header/header.component.min.js.map +1 -1
- package/assets/js/components/inline-edit/inline-edit.component.js +16 -16
- package/assets/js/components/inline-edit/inline-edit.component.min.js +4 -4
- package/assets/js/components/inline-edit/inline-edit.component.min.js.map +1 -1
- package/assets/js/components/input/input.component.js +11 -11
- package/assets/js/components/input/input.component.min.js +1 -1
- package/assets/js/components/input/input.component.min.js.map +1 -1
- package/assets/js/components/input-range/input-range.component.js +9 -9
- package/assets/js/components/input-range/input-range.component.min.js +1 -1
- package/assets/js/components/input-range/input-range.component.min.js.map +1 -1
- package/assets/js/components/marketing/marketing.component.js +10 -10
- package/assets/js/components/marketing/marketing.component.min.js +1 -1
- package/assets/js/components/marketing/marketing.component.min.js.map +1 -1
- package/assets/js/components/menu/menu.component.js +6 -6
- package/assets/js/components/menu/menu.component.min.js +1 -1
- package/assets/js/components/menu/menu.component.min.js.map +1 -1
- package/assets/js/components/milestone/milestone.component.js +2 -2
- package/assets/js/components/milestone/milestone.component.min.js +1 -1
- package/assets/js/components/milestone/milestone.component.min.js.map +1 -1
- package/assets/js/components/milestone-group/milestone-group.component.js +2 -2
- package/assets/js/components/milestone-group/milestone-group.component.min.js +1 -1
- package/assets/js/components/milestone-group/milestone-group.component.min.js.map +1 -1
- package/assets/js/components/modal/modal.component.js +25 -25
- package/assets/js/components/modal/modal.component.min.js +4 -4
- package/assets/js/components/modal/modal.component.min.js.map +1 -1
- package/assets/js/components/multi-step/multi-step.component.js +1 -1
- package/assets/js/components/multi-step/multi-step.component.min.js +1 -1
- package/assets/js/components/multi-step/multi-step.component.min.js.map +1 -1
- package/assets/js/components/multi-step-modal/multi-step-modal.component.js +12 -12
- package/assets/js/components/multi-step-modal/multi-step-modal.component.min.js +4 -4
- package/assets/js/components/multi-step-modal/multi-step-modal.component.min.js.map +1 -1
- package/assets/js/components/multiselect/multiselect.component.js +21 -21
- package/assets/js/components/multiselect/multiselect.component.min.js +4 -4
- package/assets/js/components/multiselect/multiselect.component.min.js.map +1 -1
- package/assets/js/components/nav/nav.component.js +45 -45
- package/assets/js/components/nav/nav.component.min.js +2 -2
- package/assets/js/components/nav/nav.component.min.js.map +1 -1
- package/assets/js/components/notification/notification.component.js +14 -14
- package/assets/js/components/notification/notification.component.min.js +1 -1
- package/assets/js/components/notification/notification.component.min.js.map +1 -1
- package/assets/js/components/pagination/pagination.component.js +39 -39
- package/assets/js/components/pagination/pagination.component.min.js +3 -3
- package/assets/js/components/pagination/pagination.component.min.js.map +1 -1
- package/assets/js/components/password/password.component.js +11 -11
- package/assets/js/components/password/password.component.min.js +1 -1
- package/assets/js/components/password/password.component.min.js.map +1 -1
- package/assets/js/components/popover/popover.component.js +8 -8
- package/assets/js/components/popover/popover.component.min.js +1 -1
- package/assets/js/components/popover/popover.component.min.js.map +1 -1
- package/assets/js/components/rank/rank.component.js +360 -360
- package/assets/js/components/rank/rank.component.min.js +1 -1
- package/assets/js/components/rank/rank.component.min.js.map +1 -1
- package/assets/js/components/rankings/rankings.component.js +18 -18
- package/assets/js/components/rankings/rankings.component.min.js +1 -1
- package/assets/js/components/rankings/rankings.component.min.js.map +1 -1
- package/assets/js/components/rating/rating.component.js +10 -10
- package/assets/js/components/rating/rating.component.min.js +1 -1
- package/assets/js/components/rating/rating.component.min.js.map +1 -1
- package/assets/js/components/record-card/record-card.component.js +2 -2
- package/assets/js/components/record-card/record-card.component.min.js +2 -2
- package/assets/js/components/record-card/record-card.component.min.js.map +1 -1
- package/assets/js/components/search/search.component.js +19 -19
- package/assets/js/components/search/search.component.min.js +1 -1
- package/assets/js/components/search/search.component.min.js.map +1 -1
- package/assets/js/components/slider/slider.component.js +12 -12
- package/assets/js/components/slider/slider.component.min.js +2 -2
- package/assets/js/components/slider/slider.component.min.js.map +1 -1
- package/assets/js/components/split-button/split-button.component.js +19 -19
- package/assets/js/components/split-button/split-button.component.min.js +3 -3
- package/assets/js/components/split-button/split-button.component.min.js.map +1 -1
- package/assets/js/components/std-address-lookup/std-address-lookup.component.js +114 -114
- package/assets/js/components/std-address-lookup/std-address-lookup.component.min.js +4 -4
- package/assets/js/components/std-address-lookup/std-address-lookup.component.min.js.map +1 -1
- package/assets/js/components/table/table.component.js +17 -17
- package/assets/js/components/table/table.component.min.js +1 -1
- package/assets/js/components/table/table.component.min.js.map +1 -1
- package/assets/js/components/table-ajax/table-ajax.component.js +17 -17
- package/assets/js/components/table-ajax/table-ajax.component.min.js +1 -1
- package/assets/js/components/table-ajax/table-ajax.component.min.js.map +1 -1
- package/assets/js/components/table-basic/table-basic.component.js +16 -16
- package/assets/js/components/table-basic/table-basic.component.min.js +1 -1
- package/assets/js/components/table-basic/table-basic.component.min.js.map +1 -1
- package/assets/js/components/table-no-submit/table-no-submit.component.js +17 -17
- package/assets/js/components/table-no-submit/table-no-submit.component.min.js +1 -1
- package/assets/js/components/table-no-submit/table-no-submit.component.min.js.map +1 -1
- package/assets/js/components/table-submit/table-submit.component.js +17 -17
- package/assets/js/components/table-submit/table-submit.component.min.js +1 -1
- package/assets/js/components/table-submit/table-submit.component.min.js.map +1 -1
- package/assets/js/components/tabs/tabs.component.js +31 -18
- package/assets/js/components/tabs/tabs.component.min.js +4 -4
- package/assets/js/components/tabs/tabs.component.min.js.map +1 -1
- package/assets/js/components/tag/tag.component.js +14 -14
- package/assets/js/components/tag/tag.component.min.js +4 -4
- package/assets/js/components/tag/tag.component.min.js.map +1 -1
- package/assets/js/components/tooltip/tooltip.component.js +9 -9
- package/assets/js/components/tooltip/tooltip.component.min.js +1 -1
- package/assets/js/components/tooltip/tooltip.component.min.js.map +1 -1
- package/assets/js/components/video/video.component.js +67 -0
- package/assets/js/components/video/video.component.min.js +21 -0
- package/assets/js/components/video/video.component.min.js.map +1 -0
- package/assets/js/components/video-card/video-card.component.js +53 -70
- package/assets/js/components/video-card/video-card.component.min.js +15 -7
- package/assets/js/components/video-card/video-card.component.min.js.map +1 -1
- package/assets/js/components/video-modal/video-modal.component.js +24 -58
- package/assets/js/components/video-modal/video-modal.component.min.js +12 -6
- package/assets/js/components/video-modal/video-modal.component.min.js.map +1 -1
- package/assets/js/components/word-count/word-count.component.js +1 -1
- package/assets/js/components/word-count/word-count.component.min.js +1 -1
- package/assets/js/components/word-count/word-count.component.min.js.map +1 -1
- package/assets/js/modules/card.module.js +14 -14
- package/assets/js/modules/chart.js +1 -1
- package/assets/js/modules/chart.module.js +5 -5
- package/assets/js/modules/helper.test.js +2 -2
- package/assets/js/modules/integration-tests.js +3 -3
- package/assets/js/modules/modal.js +4 -2
- package/assets/js/modules/table.js +3 -3
- package/assets/js/modules/tabs.js +1 -1
- package/assets/js/modules/videos.js +42 -0
- package/assets/js/scripts.bundle.js +1 -1
- package/assets/js/scripts.bundle.js.map +1 -1
- package/assets/js/scripts.bundle.min.js +1 -1
- package/assets/js/scripts.bundle.min.js.map +1 -1
- package/assets/js/scripts.js +4 -4
- package/assets/sass/_bs_grid.scss +41 -41
- package/assets/sass/_bs_utilities.scss +51 -51
- package/assets/sass/_components.scss +162 -162
- package/assets/sass/_corefiles.scss +31 -31
- package/assets/sass/_elements.scss +30 -30
- package/assets/sass/_fonts.scss +28 -28
- package/assets/sass/_func.scss +2 -2
- package/assets/sass/_functions/bs_functions.scss +487 -487
- package/assets/sass/_functions/bs_mixins.scss +2103 -2103
- package/assets/sass/_functions/bs_utilities.scss +922 -922
- package/assets/sass/_functions/bs_variables.scss +1701 -1703
- package/assets/sass/_functions/functions.scss +48 -48
- package/assets/sass/_functions/mixins.scss +1 -1
- package/assets/sass/_grid.scss +320 -320
- package/assets/sass/_print.scss +64 -64
- package/assets/sass/_utilities.scss +35 -35
- package/assets/sass/components/actionbar.component.scss +421 -421
- package/assets/sass/components/actionbar.global.scss +115 -115
- package/assets/sass/components/address-lookup.component.scss +161 -161
- package/assets/sass/components/address-lookup.preload.scss +90 -90
- package/assets/sass/components/applied-filters.scss +19 -19
- package/assets/sass/components/barchart.component.scss +347 -347
- package/assets/sass/components/bento-grid.component.scss +109 -109
- package/assets/sass/components/bento-grid.global.scss +248 -248
- package/assets/sass/components/calendar.component.scss +1272 -1272
- package/assets/sass/components/calendar.config.scss +423 -423
- package/assets/sass/components/card.component.scss +187 -182
- package/assets/sass/components/card.module.scss +154 -151
- package/assets/sass/components/carousel.component.scss +631 -631
- package/assets/sass/components/carousel.config.scss +84 -84
- package/assets/sass/components/charts.config.scss +86 -86
- package/assets/sass/components/charts.module.scss +588 -588
- package/assets/sass/components/charts.scss +1298 -1298
- package/assets/sass/components/collapsible-side.scss +307 -307
- package/assets/sass/components/config.component.scss +235 -235
- package/assets/sass/components/content.component.scss +18 -18
- package/assets/sass/components/darkmode.component.scss +20 -20
- package/assets/sass/components/doughnutchart.component.scss +206 -206
- package/assets/sass/components/fileupload.scss +162 -162
- package/assets/sass/components/filter-card.component.scss +99 -99
- package/assets/sass/components/header.scss +251 -256
- package/assets/sass/components/inline-edit.preload.scss +203 -203
- package/assets/sass/components/inline-edit.scss +40 -40
- package/assets/sass/components/input-range.component.scss +46 -46
- package/assets/sass/components/input.component.scss +101 -101
- package/assets/sass/components/marketing.component.scss +65 -65
- package/assets/sass/components/menu.component.scss +161 -190
- package/assets/sass/components/menu.global.scss +82 -82
- package/assets/sass/components/milestone.scss +216 -216
- package/assets/sass/components/modal.component.scss +252 -252
- package/assets/sass/components/multi-step-modal.component.scss +255 -255
- package/assets/sass/components/multi-step-modal.global.scss +92 -92
- package/assets/sass/components/multi-step.component.scss +144 -144
- package/assets/sass/components/multiselect.preload.scss +8 -8
- package/assets/sass/components/multiselect.scss +238 -238
- package/assets/sass/components/nav.component.scss +718 -718
- package/assets/sass/components/nav.docs.scss +55 -55
- package/assets/sass/components/nav.global.scss +870 -870
- package/assets/sass/components/nav.preload.scss +54 -54
- package/assets/sass/components/notification.scss +218 -218
- package/assets/sass/components/pagination.scss +237 -237
- package/assets/sass/components/password.component.scss +56 -56
- package/assets/sass/components/popover.component.scss +28 -28
- package/assets/sass/components/property-searchbar.scss +139 -139
- package/assets/sass/components/rank.component.scss +275 -275
- package/assets/sass/components/rankings.component.scss +70 -70
- package/assets/sass/components/rankings.global.scss +140 -140
- package/assets/sass/components/rating.component.css +211 -211
- package/assets/sass/components/record-card.component.scss +191 -191
- package/assets/sass/components/slider.scss +127 -127
- package/assets/sass/components/snapshot.scss +65 -65
- package/assets/sass/components/split-button.component.scss +83 -83
- package/assets/sass/components/stepper.scss +157 -157
- package/assets/sass/components/table-basic.component.scss +136 -136
- package/assets/sass/components/table-basic.global.scss +676 -676
- package/assets/sass/components/table.component.scss +51 -51
- package/assets/sass/components/table.global.scss +398 -398
- package/assets/sass/components/tabs.component.scss +34 -9
- package/assets/sass/components/tabs.config.scss +258 -254
- package/assets/sass/components/tag.component.scss +59 -59
- package/assets/sass/components/tag.preload.scss +20 -20
- package/assets/sass/components/testimonial.scss +125 -125
- package/assets/sass/components/timeline.scss +92 -92
- package/assets/sass/components/tooltip.component.scss +148 -148
- package/assets/sass/components/video-card.component.scss +49 -75
- package/assets/sass/components/video-modal.component.scss +26 -24
- package/assets/sass/components/video.component.scss +75 -0
- package/assets/sass/components/word-count.component.scss +26 -26
- package/assets/sass/core.scss +4 -4
- package/assets/sass/elements/admin-panel.css +310 -310
- package/assets/sass/elements/badge-tag.css +101 -101
- package/assets/sass/elements/brand.css +80 -80
- package/assets/sass/elements/button__group.css +135 -135
- package/assets/sass/elements/buttons--action.css +71 -54
- package/assets/sass/elements/buttons--compact.css +168 -168
- package/assets/sass/elements/{buttons--global.scss → buttons--global.css} +239 -246
- package/assets/sass/elements/{buttons--secondary.scss → buttons--secondary.css} +18 -24
- package/assets/sass/elements/{buttons--special.scss → buttons--special.css} +164 -171
- package/assets/sass/elements/{buttons--tertiary.scss → buttons--tertiary.css} +51 -57
- package/assets/sass/elements/buttons.scss +9 -14
- package/assets/sass/elements/code.css +45 -45
- package/assets/sass/elements/container.scss +118 -155
- package/assets/sass/elements/{details.scss → details.css} +224 -227
- package/assets/sass/elements/dialog.scss +75 -86
- package/assets/sass/elements/{dropdown.scss → dropdown.css} +85 -87
- package/assets/sass/elements/{feature.scss → feature.css} +174 -180
- package/assets/sass/elements/forms.scss +1337 -1338
- package/assets/sass/elements/highlight.css +76 -76
- package/assets/sass/elements/hr.css +41 -41
- package/assets/sass/elements/icons.css +48 -48
- package/assets/sass/elements/input.scss +212 -212
- package/assets/sass/elements/{label.scss → label.css} +20 -20
- package/assets/sass/elements/links--collapsible-side.scss +130 -0
- package/assets/sass/elements/links--global.scss +155 -0
- package/assets/sass/elements/links--video.scss +73 -0
- package/assets/sass/elements/links.scss +5 -348
- package/assets/sass/elements/lists--breadcrumbs.scss +26 -26
- package/assets/sass/elements/lists--steps.css +171 -171
- package/assets/sass/elements/lists--tick-list.scss +112 -112
- package/assets/sass/elements/lists.scss +99 -99
- package/assets/sass/elements/media.css +20 -20
- package/assets/sass/elements/modal.scss +411 -415
- package/assets/sass/elements/popover.scss +259 -259
- package/assets/sass/elements/prefix.scss +139 -139
- package/assets/sass/elements/progress.scss +208 -214
- package/assets/sass/elements/table.element.scss +144 -144
- package/assets/sass/elements/{textarea.scss → textarea.css} +84 -96
- package/assets/sass/elements/{toggle-button.scss → toggle-button.css} +49 -55
- package/assets/sass/elements/tooltips.scss +152 -151
- package/assets/sass/elements/type.css +166 -166
- package/assets/sass/email.scss +68 -68
- package/assets/sass/error.scss +31 -33
- package/assets/sass/foundations/animations.scss +2 -2
- package/assets/sass/foundations/colours.scss +104 -104
- package/assets/sass/foundations/reboot.scss +166 -166
- package/assets/sass/foundations/root.scss +269 -269
- package/assets/sass/main.scss +7 -7
- package/assets/sass/templates/auth.scss +106 -106
- package/assets/sass/templates/form.scss +95 -95
- package/assets/sass/utilities/{align.scss → align.css} +24 -24
- package/assets/sass/utilities/{border.scss → border.css} +65 -68
- package/assets/sass/utilities/{clearfix.scss → clearfix.css} +8 -8
- package/assets/sass/utilities/colours.scss +43 -43
- package/assets/sass/utilities/{columns.scss → columns.css} +61 -61
- package/assets/sass/utilities/display.scss +89 -89
- package/assets/sass/utilities/{fixed.scss → fixed.css} +16 -16
- package/assets/sass/utilities/flex.scss +291 -291
- package/assets/sass/utilities/{font-awesome-iso-fallbacks.scss → font-awesome-iso-fallbacks.css} +43 -43
- package/assets/sass/utilities/gap.css +26 -0
- package/assets/sass/utilities/{gradients.scss → gradients.css} +39 -39
- package/assets/sass/utilities/{js-display.scss → js-display.css} +12 -12
- package/assets/sass/utilities/{line-clamp.scss → line-clamp.css} +24 -24
- package/assets/sass/utilities/margins.scss +74 -74
- package/assets/sass/utilities/max-height.scss +93 -93
- package/assets/sass/utilities/{opacity.scss → opacity.css} +20 -20
- package/assets/sass/utilities/order.css +104 -0
- package/assets/sass/utilities/{overflow.scss → overflow.css} +16 -16
- package/assets/sass/utilities/paddings.scss +33 -33
- package/assets/sass/utilities/{pointer-events.scss → pointer-events.css} +8 -8
- package/assets/sass/utilities/position.css +68 -0
- package/assets/sass/utilities/{ratio.scss → ratio.css} +33 -33
- package/assets/sass/utilities/{rounded.scss → rounded.css} +56 -56
- package/assets/sass/utilities/{shadow.scss → shadow.css} +7 -7
- package/assets/sass/utilities/{sizes.scss → sizes.css} +92 -92
- package/assets/sass/utilities/{sticky.scss → sticky.css} +38 -38
- package/assets/sass/utilities/{text-truncate.scss → text-truncate.css} +6 -6
- package/assets/sass/utilities/{text.scss → text.css} +190 -190
- package/assets/sass/utilities/{visible.scss → visible.css} +8 -8
- package/assets/sass/utilities/{visually-hidden.scss → visually-hidden.css} +13 -13
- package/assets/sass/utilities/wider-colours.scss +8 -8
- package/assets/svg/illustrations/table.svg +165 -165
- package/assets/svg/logo.svg +56 -56
- package/assets/ts/components/accordion/accordion.component.ts +77 -77
- package/assets/ts/components/actionbar/actionbar.component.ts +567 -567
- package/assets/ts/components/address-lookup/address-lookup.component.ts +672 -672
- package/assets/ts/components/advanced-select/advanced-select.component.ts +116 -116
- package/assets/ts/components/applied-filters/applied-filters.component.ts +37 -37
- package/assets/ts/components/bento-grid/bento-grid.component.ts +88 -88
- package/assets/ts/components/collapsible-side/collapsible-side.component.ts +165 -165
- package/assets/ts/components/config/config.component.ts +699 -699
- package/assets/ts/components/content/content.component.ts +78 -78
- package/assets/ts/components/darkmode/darkmode.component.ts +108 -108
- package/assets/ts/components/fileupload/fileupload.component.ts +74 -74
- package/assets/ts/components/filter-card/filter-card.component.ts +106 -106
- package/assets/ts/components/form/form.component.ts +102 -102
- package/assets/ts/components/header/header.component.ts +97 -97
- package/assets/ts/components/inline-edit/inline-edit.component.ts +212 -212
- package/assets/ts/components/input/input.component.ts +278 -278
- package/assets/ts/components/input-range/input-range.component.ts +78 -78
- package/assets/ts/components/marketing/marketing.component.ts +44 -44
- package/assets/ts/components/menu/menu.component.ts +212 -212
- package/assets/ts/components/modal/modal.component.ts +184 -184
- package/assets/ts/components/multi-step-modal/multi-step-modal.component.ts +304 -304
- package/assets/ts/components/multiselect/multiselect.component.ts +349 -349
- package/assets/ts/components/nav/nav.component.ts +369 -369
- package/assets/ts/components/notification/notification.component.ts +172 -172
- package/assets/ts/components/pagination/pagination.component.ts +213 -213
- package/assets/ts/components/password/password.component.ts +118 -118
- package/assets/ts/components/popover/popover.component.ts +50 -50
- package/assets/ts/components/rank/rank.component.ts +394 -394
- package/assets/ts/components/rankings/rankings.component.ts +79 -79
- package/assets/ts/components/rating/rating.component.ts +86 -86
- package/assets/ts/components/search/search.component.ts +244 -244
- package/assets/ts/components/slider/slider.component.ts +170 -170
- package/assets/ts/components/split-button/split-button.component.ts +63 -63
- package/assets/ts/components/std-address-lookup/std-address-lookup.component.ts +1919 -1919
- package/assets/ts/components/table/table.component.ts +94 -94
- package/assets/ts/components/table-ajax/table-ajax.component.ts +70 -70
- package/assets/ts/components/table-basic/table-basic.component.ts +56 -56
- package/assets/ts/components/table-no-submit/table-no-submit.component.ts +130 -130
- package/assets/ts/components/table-submit/table-submit.component.ts +71 -71
- package/assets/ts/components/tabs/tabs.component.ts +70 -51
- package/assets/ts/components/tag/tag.component.ts +104 -104
- package/assets/ts/components/tooltip/tooltip.component.ts +98 -98
- package/assets/ts/components/video/video.component.ts +74 -0
- package/assets/ts/components/video-card/video-card.component.ts +129 -150
- package/assets/ts/components/video-modal/video-modal.component.ts +88 -137
- package/assets/ts/modules/advanced-select.ts +186 -186
- package/assets/ts/modules/applied-filters.ts +238 -238
- package/assets/ts/modules/card.module.ts +46 -46
- package/assets/ts/modules/chart.module.ts +594 -594
- package/assets/ts/modules/data-layer.md +71 -71
- package/assets/ts/modules/dialogs.ts +259 -259
- package/assets/ts/modules/dropdown.ts +216 -216
- package/assets/ts/modules/helper.test.ts +143 -143
- package/assets/ts/modules/helpers.ts +212 -212
- package/assets/ts/modules/integration-tests.ts +525 -525
- package/assets/ts/modules/modal.ts +45 -43
- package/assets/ts/modules/password.ts +82 -82
- package/assets/ts/modules/table.ts +1500 -1500
- package/assets/ts/modules/test.ts +22 -22
- package/assets/ts/modules/videos.ts +233 -176
- package/assets/ts/scripts.ts +111 -111
- package/dist/components.es.js +25 -25
- package/dist/components.umd.js +143 -113
- package/package.json +115 -116
- package/src/components/AdvancedSelect/AdvancedSelect.vue +28 -28
- package/src/components/Config/Config.vue +23 -23
- package/src/components/DarkMode/DarkMode.vue +19 -19
- package/src/components/Filterlist/Filterlist.vue +23 -23
- package/src/components/Form/Form.vue +22 -22
- package/src/components/Header/Header.vue +36 -36
- package/src/components/Input/Input.vue +22 -22
- package/src/components/InputRange/InputRange.vue +22 -22
- package/src/components/Modal/Modal.vue +22 -22
- package/src/components/MultiStepModal/MultiStepModal.vue +23 -23
- package/src/components/NoteFeed/NoteFeed.vue +82 -82
- package/src/components/Password/Password.vue +23 -23
- package/src/components/Popover/Popover.vue +22 -22
- package/src/components/PropertySearchbar/PropertySearchbar.vue +235 -235
- package/src/components/PropertySearchbar/README.md +25 -25
- package/src/components/Rating/Rating.vue +22 -22
- package/src/components/STDAddressLookup/STDAddressLookup.vue +22 -22
- package/src/components/Snapshot/Snapshot.vue +30 -30
- package/src/components/Tag/Tag.vue +22 -22
- package/src/components/Tooltip/Tooltip.vue +22 -22
- package/src/components/Video/Video.vue +22 -0
- package/src/components/VideoModal/VideoModal.vue +22 -22
- package/assets/sass/utilities/gap.scss +0 -8
- package/assets/sass/utilities/order.scss +0 -43
- package/assets/sass/utilities/position.scss +0 -52
|
@@ -1,1500 +1,1500 @@
|
|
|
1
|
-
import { doc } from 'prettier';
|
|
2
|
-
import { zeroPad, isNumeric, ucfirst, resolvePath, uniqueID } from './helpers';
|
|
3
|
-
|
|
4
|
-
// #region Helpers
|
|
5
|
-
export const formatCell = (format, cellOutput): any => {
|
|
6
|
-
switch (format) {
|
|
7
|
-
case 'datetime':
|
|
8
|
-
return (
|
|
9
|
-
new Date(cellOutput).toLocaleDateString('en-gb', {
|
|
10
|
-
weekday: 'short',
|
|
11
|
-
year: '2-digit',
|
|
12
|
-
month: 'long',
|
|
13
|
-
day: 'numeric',
|
|
14
|
-
}) +
|
|
15
|
-
' ' +
|
|
16
|
-
new Date(cellOutput).toLocaleTimeString('en-gb', { hour: '2-digit', minute: '2-digit' })
|
|
17
|
-
);
|
|
18
|
-
case 'date':
|
|
19
|
-
return new Date(cellOutput).toLocaleDateString('en-gb', {
|
|
20
|
-
day: 'numeric',
|
|
21
|
-
month: 'long',
|
|
22
|
-
year: '2-digit',
|
|
23
|
-
});
|
|
24
|
-
case 'capitalise':
|
|
25
|
-
return (cellOutput = ucfirst(cellOutput));
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const filterFilters = function (form): object {
|
|
30
|
-
const filters = new Object();
|
|
31
|
-
|
|
32
|
-
// Filter
|
|
33
|
-
const filterInputs = Array.from(form.querySelectorAll('[data-filter]'));
|
|
34
|
-
|
|
35
|
-
filterInputs.forEach((filterInput) => {
|
|
36
|
-
// Ignore uncked radio inputs
|
|
37
|
-
if (filterInput.type == 'radio' && !filterInput.checked) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (filterInput.type == 'checkbox' && !filterInput.checked) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (filterInput && filterInput.value) {
|
|
46
|
-
const dataFilter = filterInput.getAttribute('data-filter');
|
|
47
|
-
let filterValue = filterInput.value;
|
|
48
|
-
|
|
49
|
-
if (filterInput.hasAttribute('data-date-from')) filterValue += '-date-from';
|
|
50
|
-
|
|
51
|
-
if (filterInput.hasAttribute('data-date-to')) filterValue += '-date-to';
|
|
52
|
-
|
|
53
|
-
if (!filters[dataFilter]) filters[dataFilter] = [];
|
|
54
|
-
|
|
55
|
-
filters[dataFilter].push(filterValue);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
return filters;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const moveAttributesToComponents = (component): void => {
|
|
63
|
-
let form = document.createElement('form');
|
|
64
|
-
const table = component.querySelector('table');
|
|
65
|
-
|
|
66
|
-
if (component.hasAttribute('data-filterby')) {
|
|
67
|
-
form = document.querySelector(`#${component.getAttribute('data-filterby')}`);
|
|
68
|
-
} else if (component.closest('form')) {
|
|
69
|
-
form = component.closest('form');
|
|
70
|
-
} else {
|
|
71
|
-
table.parentNode.insertBefore(form, table.nextSibling);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (form.hasAttribute('data-ajax')) component.setAttribute('data-ajax', form.getAttribute('data-ajax'));
|
|
75
|
-
|
|
76
|
-
if (form.hasAttribute('data-schema')) component.setAttribute('data-schema', form.getAttribute('data-schema'));
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const paginateTable = (component, table, form, pagination, callback): void => {
|
|
80
|
-
if (!form.querySelector('[name=show]'))
|
|
81
|
-
form.insertAdjacentHTML(
|
|
82
|
-
'beforeend',
|
|
83
|
-
`<input name="show" type="hidden" value="${component.getAttribute('data-show')}" />`
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
if (!form.querySelector('[name=page]'))
|
|
87
|
-
form.insertAdjacentHTML(
|
|
88
|
-
'beforeend',
|
|
89
|
-
`<input name="page" type="hidden" value="${component.getAttribute('data-page')}" />`
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
pagination.addEventListener('update-show', (event) => {
|
|
93
|
-
if (form.querySelector('[name=show]').value != event.detail.show) {
|
|
94
|
-
form.querySelector('[name=show]').value = event.detail.show;
|
|
95
|
-
|
|
96
|
-
const updateEvent = new CustomEvent('update-show', { detail: { show: event.detail.show } });
|
|
97
|
-
component.dispatchEvent(updateEvent);
|
|
98
|
-
|
|
99
|
-
updateAttributes(component, pagination);
|
|
100
|
-
|
|
101
|
-
callback();
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
pagination.addEventListener('update-page', (event) => {
|
|
106
|
-
|
|
107
|
-
if (form.querySelector('[name=page]').value != event.detail.page) {
|
|
108
|
-
form.querySelector('[name=page]').value = event.detail.page;
|
|
109
|
-
|
|
110
|
-
const updateEvent = new CustomEvent('update-page', { detail: { page: event.detail.page } });
|
|
111
|
-
component.dispatchEvent(updateEvent);
|
|
112
|
-
|
|
113
|
-
updateAttributes(component, pagination);
|
|
114
|
-
|
|
115
|
-
callback();
|
|
116
|
-
|
|
117
|
-
// scroll back to the top of the table
|
|
118
|
-
if (!component.hasAttribute('data-no-scroll')) {
|
|
119
|
-
const yOffset = -250;
|
|
120
|
-
const y = table.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
|
121
|
-
window.scrollTo({ top: y, behavior: 'smooth' });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export const findForm = (component, table): HTMLElement => {
|
|
128
|
-
let form = document.createElement('form');
|
|
129
|
-
|
|
130
|
-
if (component.hasAttribute('data-filterby')) {
|
|
131
|
-
form = document.querySelector(`#${component.getAttribute('data-filterby')}`);
|
|
132
|
-
} else if (component.closest('form')) {
|
|
133
|
-
form = component.closest('form');
|
|
134
|
-
}
|
|
135
|
-
else if (component.querySelector('form')){
|
|
136
|
-
form = component.querySelector('form');
|
|
137
|
-
}else {
|
|
138
|
-
table.parentNode.insertBefore(form, table.nextSibling);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if(component.hasAttribute('data-ajax')){
|
|
143
|
-
form.setAttribute('data-ajax',component.getAttribute('data-ajax'))
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return form;
|
|
147
|
-
};
|
|
148
|
-
// #endregion
|
|
149
|
-
|
|
150
|
-
export const setupBasicTable = (component, table, form, pagination): void => {
|
|
151
|
-
const tableWrapper = component.shadowRoot.querySelector('.table__wrapper');
|
|
152
|
-
|
|
153
|
-
if (!component.hasAttribute('data-total'))
|
|
154
|
-
component.setAttribute('data-total', component.querySelectorAll('tbody tr').length);
|
|
155
|
-
if (!component.hasAttribute('data-page')) component.setAttribute('data-page', 1);
|
|
156
|
-
if (!component.hasAttribute('data-show')) component.setAttribute('data-show', 15);
|
|
157
|
-
if (!component.hasAttribute('data-increment'))
|
|
158
|
-
component.setAttribute('data-increment', component.getAttribute('data-show'));
|
|
159
|
-
|
|
160
|
-
transferAttributes(component, pagination);
|
|
161
|
-
|
|
162
|
-
addDataAttributes(table);
|
|
163
|
-
createMobileButton(component, table);
|
|
164
|
-
|
|
165
|
-
// Max height
|
|
166
|
-
if (component.classList.contains('mh-sm')) tableWrapper.classList.add('mh-sm');
|
|
167
|
-
if (component.classList.contains('mh-md')) tableWrapper.classList.add('mh-md');
|
|
168
|
-
if (component.classList.contains('mh-lg')) tableWrapper.classList.add('mh-lg');
|
|
169
|
-
|
|
170
|
-
if (component.classList.contains('table--cta')) {
|
|
171
|
-
getLargestLastColWidth(component, table);
|
|
172
|
-
getRowHeight(component, table);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
highlightRows(component);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// #region Basic table fnctions
|
|
179
|
-
export const highlightRows = (component): void => {
|
|
180
|
-
|
|
181
|
-
Array.from(component.querySelectorAll('tr[data-highlight]')).forEach((row) => {
|
|
182
|
-
row.insertAdjacentHTML('afterend',`<tr role="presentation" class="tr--highlight">
|
|
183
|
-
<td colspan="100%"><i class="fa-solid fa-star"></i> ${row.getAttribute('data-highlight')}</td>
|
|
184
|
-
</tr>`);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export const transferAttributes = (component, pagination): void => {
|
|
189
|
-
if (component.hasAttribute('data-total')) pagination.setAttribute('data-total', component.getAttribute('data-total'));
|
|
190
|
-
if (component.hasAttribute('data-page')) pagination.setAttribute('data-page', component.getAttribute('data-page'));
|
|
191
|
-
if (component.hasAttribute('data-show')) pagination.setAttribute('data-show', component.getAttribute('data-show'));
|
|
192
|
-
if (component.hasAttribute('data-increment'))
|
|
193
|
-
pagination.setAttribute('data-increment', component.getAttribute('data-show'));
|
|
194
|
-
|
|
195
|
-
if (component.hasAttribute('data-page-jump')) pagination.setAttribute('data-page-jump', 'true');
|
|
196
|
-
if (component.hasAttribute('data-per-page')) pagination.setAttribute('data-per-page', 'true');
|
|
197
|
-
if (component.hasAttribute('data-item-count')) pagination.setAttribute('data-item-count', 'true');
|
|
198
|
-
if (component.hasAttribute('data-loading')) pagination.setAttribute('data-loading', 'true');
|
|
199
|
-
|
|
200
|
-
if (component.classList.contains('table--fullwidth')) pagination.setAttribute('data-minimal', 'true');
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
export const updateAttributes = (component, pagination): void => {
|
|
204
|
-
component.setAttribute('data-total', pagination.getAttribute('data-total'));
|
|
205
|
-
component.setAttribute('data-page', pagination.getAttribute('data-page'));
|
|
206
|
-
component.setAttribute('data-show', pagination.getAttribute('data-show'));
|
|
207
|
-
component.setAttribute('data-increment', pagination.getAttribute('data-show'));
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
export const paginateRows = (component): void => {
|
|
211
|
-
const total = component.getAttribute('data-total');
|
|
212
|
-
const page = component.getAttribute('data-page');
|
|
213
|
-
const show = component.getAttribute('data-show');
|
|
214
|
-
const increment = component.getAttribute('data-increment');
|
|
215
|
-
|
|
216
|
-
const table = component.querySelector('table');
|
|
217
|
-
|
|
218
|
-
const end = page * show;
|
|
219
|
-
const start = end - show;
|
|
220
|
-
|
|
221
|
-
Array.from(table.querySelectorAll('tbody tr')).forEach((row, index) => {
|
|
222
|
-
if (index >= start && index < end) {
|
|
223
|
-
row.classList.add('show');
|
|
224
|
-
} else {
|
|
225
|
-
row.classList.remove('show');
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
export const addDataAttributes = (table): void => {
|
|
231
|
-
const colHeadings = Array.from(table.querySelectorAll('thead th'));
|
|
232
|
-
const colRows = Array.from(table.querySelectorAll('tbody tr'));
|
|
233
|
-
|
|
234
|
-
colRows.forEach((row) => {
|
|
235
|
-
const cells = Array.from(row.querySelectorAll('th, td'));
|
|
236
|
-
const statuses = [
|
|
237
|
-
'0',
|
|
238
|
-
'low',
|
|
239
|
-
'medium',
|
|
240
|
-
'high',
|
|
241
|
-
'unknown',
|
|
242
|
-
'n/a',
|
|
243
|
-
'pending',
|
|
244
|
-
'verified',
|
|
245
|
-
'due',
|
|
246
|
-
'overdue',
|
|
247
|
-
'incomplete',
|
|
248
|
-
'complete',
|
|
249
|
-
'completed',
|
|
250
|
-
'approval required',
|
|
251
|
-
'upcoming',
|
|
252
|
-
'requires approval',
|
|
253
|
-
'to do',
|
|
254
|
-
'on track',
|
|
255
|
-
'not started',
|
|
256
|
-
'warning',
|
|
257
|
-
'successful',
|
|
258
|
-
'failed',
|
|
259
|
-
];
|
|
260
|
-
|
|
261
|
-
cells.forEach((cell, cellIndex) => {
|
|
262
|
-
const heading = colHeadings[cellIndex];
|
|
263
|
-
if (typeof heading != 'undefined') {
|
|
264
|
-
const tempDiv = document.createElement('div');
|
|
265
|
-
tempDiv.innerHTML = heading.innerHTML;
|
|
266
|
-
const headingText = tempDiv.textContent || tempDiv.innerText || '';
|
|
267
|
-
cell.setAttribute('data-label', headingText);
|
|
268
|
-
|
|
269
|
-
if (heading.hasAttribute('data-td-class')) cell.setAttribute('class', heading.getAttribute('data-td-class'));
|
|
270
|
-
|
|
271
|
-
if (heading.hasAttribute('data-format')) {
|
|
272
|
-
cell.setAttribute('data-format', heading.getAttribute('data-format'));
|
|
273
|
-
cell.innerHTML = formatCell(heading.getAttribute('data-format'), cell.textContent.trim()); //Make sure date format is consistent
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (statuses.includes(cell.textContent.trim().toLowerCase())) {
|
|
277
|
-
cell.setAttribute('data-content', cell.textContent.trim().toLowerCase());
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
export const createMobileButton = (component, table): void => {
|
|
285
|
-
if (component.classList.contains('table--fullwidth') && !component.hasAttribute('data-expandable')) return false;
|
|
286
|
-
|
|
287
|
-
if (table.querySelectorAll('thead tr th').length < 4 && !component.hasAttribute('data-expandable')) return false;
|
|
288
|
-
|
|
289
|
-
//If the expand column already exists we don't need to add a new one.
|
|
290
|
-
Array.from(table.querySelectorAll('thead tr')).forEach((row) => {
|
|
291
|
-
if (!table.querySelectorAll('thead tr th.expand-button-heading').length) {
|
|
292
|
-
row.insertAdjacentHTML(
|
|
293
|
-
'afterbegin',
|
|
294
|
-
`<th class="${component.hasAttribute('data-expandable') ? 'th--fixed ' : ''}expand-button-heading"></th>`
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
Array.from(table.querySelectorAll('tbody tr')).forEach((row, index) => {
|
|
300
|
-
const preExpanded = row.getAttribute('data-view') === 'full' ? 'aria-expanded' : '';
|
|
301
|
-
row.insertAdjacentHTML(
|
|
302
|
-
'afterbegin',
|
|
303
|
-
`<td class="${component.hasAttribute('data-expandable') ? 'td--fixed ' : ''}td--expand"><button class="btn btn-compact btn-secondary btn-sm fa-circle-plus" data-expand-button ${preExpanded} data-index="${index}">Expand</button></td>`
|
|
304
|
-
);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
table.addEventListener('click', (event) => {
|
|
308
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('[data-expand-button]')) {
|
|
309
|
-
const button = event.target.closest('[data-expand-button]');
|
|
310
|
-
const tableRow = button.closest('tr');
|
|
311
|
-
|
|
312
|
-
button.toggleAttribute('aria-expanded');
|
|
313
|
-
|
|
314
|
-
if(button.classList.contains('fa-circle-plus')){
|
|
315
|
-
button.classList.remove('fa-circle-plus');
|
|
316
|
-
button.classList.add('fa-circle-minus');
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
|
|
320
|
-
button.classList.remove('fa-circle-minus');
|
|
321
|
-
button.classList.add('fa-circle-plus');
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (tableRow.getAttribute('data-view') == 'full') tableRow.setAttribute('data-view', 'default');
|
|
325
|
-
else tableRow.setAttribute('data-view', 'full');
|
|
326
|
-
|
|
327
|
-
button.blur();
|
|
328
|
-
|
|
329
|
-
component.dispatchEvent(new CustomEvent('row-expanded', { detail: { row: button.getAttribute('data-index') } }));
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
export const getLargestLastColWidth = (component, table): void => {
|
|
335
|
-
let largestWidth = 0;
|
|
336
|
-
|
|
337
|
-
Array.from(table.querySelectorAll('tbody tr')).forEach((row) => {
|
|
338
|
-
const htmlStyles = window.getComputedStyle(document.querySelector('html'));
|
|
339
|
-
const lastColChild = row.querySelector(':scope > *:last-child > *:first-child');
|
|
340
|
-
|
|
341
|
-
if (lastColChild) {
|
|
342
|
-
lastColChild.classList.add('text-nowrap');
|
|
343
|
-
let responsiveWidth = lastColChild.offsetWidth / parseFloat(htmlStyles.fontSize);
|
|
344
|
-
responsiveWidth += 1.8;
|
|
345
|
-
largestWidth = largestWidth > responsiveWidth ? largestWidth : responsiveWidth;
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
component.style.setProperty('--cta-width', `${largestWidth}rem`);
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
export const getRowHeight = (component, table): void => {
|
|
353
|
-
function outputsize(): void {
|
|
354
|
-
Array.from(table.querySelectorAll('tr')).forEach((row) => {
|
|
355
|
-
const rowHeight = row.offsetHeight;
|
|
356
|
-
|
|
357
|
-
row.style.setProperty('--row-height', `${rowHeight}px`);
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
new ResizeObserver(outputsize).observe(table);
|
|
362
|
-
};
|
|
363
|
-
// #endregion
|
|
364
|
-
|
|
365
|
-
export const setupAdvancedTable = (component, table): void => {
|
|
366
|
-
if (
|
|
367
|
-
component.querySelector('iam-actionbar[data-selectall]') ||
|
|
368
|
-
document.querySelector(`iam-actionbar[data-for='${component.getAttribute('id')}']`)
|
|
369
|
-
) {
|
|
370
|
-
const actionbar = component.querySelector('iam-actionbar[data-selectall]')
|
|
371
|
-
? component.querySelector('iam-actionbar[data-selectall]')
|
|
372
|
-
: document.querySelector(`iam-actionbar[data-for='${component.getAttribute('id')}']`);
|
|
373
|
-
|
|
374
|
-
addSelectboxes(component, table, actionbar);
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
component.querySelectorAll('.dialog__wrapper .btn-compact').forEach((btn, index) => {
|
|
379
|
-
const wrapper = btn.closest('.dialog__wrapper');
|
|
380
|
-
const dialog = wrapper.querySelector('dialog');
|
|
381
|
-
|
|
382
|
-
// Transform dialog into a menu custom element
|
|
383
|
-
if (dialog) {
|
|
384
|
-
const id = `menu${uniqueID(index)}`;
|
|
385
|
-
|
|
386
|
-
dialog.setAttribute('id', id);
|
|
387
|
-
dialog.setAttribute('popover', 'auto');
|
|
388
|
-
btn.setAttribute('popovertarget', id);
|
|
389
|
-
|
|
390
|
-
dialog.outerHTML = dialog.outerHTML.replace(/<dialog/g, '<iam-menu').replace(/<\/dialog>/g, '</iam-menu>');
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
btn.classList.add('btn-sm');
|
|
394
|
-
btn.classList.add('m-0');
|
|
395
|
-
|
|
396
|
-
const tr = btn.closest('tr');
|
|
397
|
-
const td = btn.closest('td');
|
|
398
|
-
|
|
399
|
-
const trChildren = Array.prototype.slice.call(tr.children);
|
|
400
|
-
const cellIndex = trChildren.indexOf(td);
|
|
401
|
-
|
|
402
|
-
td.classList.add('td--fixed');
|
|
403
|
-
table.querySelector(`thead tr th:nth-child(${cellIndex + 1})`).classList.add('th--fixed');
|
|
404
|
-
});
|
|
405
|
-
};
|
|
406
|
-
// #region Advanced table functions
|
|
407
|
-
export const addSelectboxes = (component, table, actionbar): void => {
|
|
408
|
-
Array.from(table.querySelectorAll('thead tr')).forEach((row) => {
|
|
409
|
-
if (row.querySelector('.expand-button-heading'))
|
|
410
|
-
row.querySelector('.expand-button-heading').insertAdjacentHTML('afterend', `<th class="th--fixed"></th>`);
|
|
411
|
-
else row.insertAdjacentHTML('afterbegin', `<th class="th--fixed"></th>`);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
Array.from(table.querySelectorAll('tbody tr')).forEach((row, index) => {
|
|
415
|
-
row.setAttribute('data-index', index + 1);
|
|
416
|
-
if (!row.querySelector('.selectrow')) {
|
|
417
|
-
const rowID = `row${uniqueID(index)}`;
|
|
418
|
-
|
|
419
|
-
if (row.querySelector('.td--expand'))
|
|
420
|
-
row
|
|
421
|
-
.querySelector('.td--expand')
|
|
422
|
-
.insertAdjacentHTML(
|
|
423
|
-
'afterend',
|
|
424
|
-
`<td class="td--fixed selectrow selected"><input type="checkbox" name="row" id="${rowID}" ${row.hasAttribute('data-selected') ? `checked="true"` : ''}/><label for="${rowID}"><span class="visually-hidden">Select row</span></label></td>`
|
|
425
|
-
);
|
|
426
|
-
else
|
|
427
|
-
row.insertAdjacentHTML(
|
|
428
|
-
'afterbegin',
|
|
429
|
-
`<td class="td--fixed selectrow selected"><input type="checkbox" name="row" id="${rowID}" ${row.hasAttribute('data-selected') ? `checked="true"` : ''}/><label for="${rowID}"><span class="visually-hidden">Select row</span></label></td>`
|
|
430
|
-
);
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
table.addEventListener('change', (event) => {
|
|
435
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('.selectrow input')) {
|
|
436
|
-
const input = event.target.closest('.selectrow input');
|
|
437
|
-
const row = event.target.closest('tr');
|
|
438
|
-
|
|
439
|
-
const count = table.querySelectorAll('.selectrow input[type="checkbox"]').length;
|
|
440
|
-
const countChecked = table.querySelectorAll('.selectrow input[type="checkbox"]:checked').length;
|
|
441
|
-
|
|
442
|
-
actionbar.setAttribute('data-selected', count == countChecked ? 'all' : countChecked);
|
|
443
|
-
|
|
444
|
-
const dispatchedEvent = new CustomEvent('row-selected', {
|
|
445
|
-
detail: {
|
|
446
|
-
rowIndex: row.getAttribute('data-index'),
|
|
447
|
-
checked: input.checked ? true : false,
|
|
448
|
-
},
|
|
449
|
-
});
|
|
450
|
-
component.dispatchEvent(dispatchedEvent);
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
actionbar.addEventListener('selected', (event) => {
|
|
455
|
-
if (event.detail.selected == '0') {
|
|
456
|
-
Array.from(table.querySelectorAll('.selectrow input[type="checkbox"]')).forEach((input) => {
|
|
457
|
-
input.checked = false;
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
const dispatchedEvent = new CustomEvent('all-rows-unselected');
|
|
461
|
-
component.dispatchEvent(dispatchedEvent);
|
|
462
|
-
} else if (event.detail.selected == 'all') {
|
|
463
|
-
Array.from(table.querySelectorAll('.selectrow input[type="checkbox"]')).forEach((input) => {
|
|
464
|
-
input.checked = true;
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
const dispatchedEvent = new CustomEvent('all-rows-selected');
|
|
468
|
-
component.dispatchEvent(dispatchedEvent);
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
// Export CSV Data
|
|
474
|
-
export const addExportEventListeners = (button, table): void | boolean => {
|
|
475
|
-
if (!button) {
|
|
476
|
-
return false;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
button.addEventListener('click', () => {
|
|
480
|
-
exportAsCSV(table);
|
|
481
|
-
});
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
export const exportAsCSV = function (table): void {
|
|
485
|
-
let csvData = [];
|
|
486
|
-
// Get each row data
|
|
487
|
-
const rows = table.getElementsByTagName('tr');
|
|
488
|
-
for (let i = 0; i < rows.length; i++) {
|
|
489
|
-
// Get each column data
|
|
490
|
-
const cols = rows[i].querySelectorAll('td,th');
|
|
491
|
-
|
|
492
|
-
// Stores each csv row data
|
|
493
|
-
const csvRow = [];
|
|
494
|
-
for (let j = 0; j < cols.length; j++) {
|
|
495
|
-
// Get the text data of each cell of a row and push it to csvrow
|
|
496
|
-
csvRow.push(`"${cols[j].textContent}"`);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// Combine each column value with comma
|
|
500
|
-
csvData.push(csvRow.join(','));
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// Combine each row data with new line character
|
|
504
|
-
csvData = csvData.join('\n');
|
|
505
|
-
|
|
506
|
-
// Create CSV file object and feed our csvData into it
|
|
507
|
-
const CSVFile = new Blob([csvData], {
|
|
508
|
-
type: 'text/csv',
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
// Create to temporary link to initiate download process
|
|
512
|
-
const tempLink = document.createElement('a');
|
|
513
|
-
tempLink.download = 'export.csv';
|
|
514
|
-
const url = window.URL.createObjectURL(CSVFile);
|
|
515
|
-
tempLink.href = url;
|
|
516
|
-
|
|
517
|
-
// This link should not be displayed
|
|
518
|
-
tempLink.style.display = 'none';
|
|
519
|
-
document.body.appendChild(tempLink);
|
|
520
|
-
|
|
521
|
-
// Automatically click the link to trigger download
|
|
522
|
-
tempLink.click();
|
|
523
|
-
document.body.removeChild(tempLink);
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
// #endregion
|
|
527
|
-
|
|
528
|
-
export const setupNoSubmitTable = (component, table, form, pagination, savedTableBody): void => {
|
|
529
|
-
sortViaHeaders(component, table);
|
|
530
|
-
|
|
531
|
-
createSearchDataList(component, table);
|
|
532
|
-
|
|
533
|
-
form.addEventListener('change', (event) => {
|
|
534
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('[data-sort]')) {
|
|
535
|
-
sortTable(table, form, savedTableBody);
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
/*
|
|
539
|
-
addFilterEventListeners(component, table, form, pagination, savedTableBody);
|
|
540
|
-
*/
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
// #region No submit table functions
|
|
544
|
-
export const sortViaHeaders = (component, table): void => {
|
|
545
|
-
table.addEventListener('click', (event) => {
|
|
546
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('[data-sort]')) {
|
|
547
|
-
const heading = event.target.closest('[data-sort]');
|
|
548
|
-
heading.setAttribute('data-sort', 'true');
|
|
549
|
-
|
|
550
|
-
// Turn other headings off
|
|
551
|
-
Array.from(table.querySelectorAll('th[data-sort]')).forEach((element) => {
|
|
552
|
-
if (element != heading) {
|
|
553
|
-
element.setAttribute('data-sort', '');
|
|
554
|
-
element.removeAttribute('data-order-by');
|
|
555
|
-
heading.setAttribute('title', 'Click to sort ascending');
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
if (heading.hasAttribute('data-order-by') && heading.getAttribute('data-order-by') == 'asc') {
|
|
560
|
-
heading.setAttribute('data-order-by', 'desc');
|
|
561
|
-
heading.setAttribute('title', 'Click to sort ascending');
|
|
562
|
-
} else {
|
|
563
|
-
heading.setAttribute('data-order-by', 'asc');
|
|
564
|
-
heading.setAttribute('title', 'Click to sort descending');
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// dispath event
|
|
568
|
-
const dispatchedEvent = new CustomEvent('sort-by-heading', {
|
|
569
|
-
detail: {
|
|
570
|
-
heading: heading.textContent,
|
|
571
|
-
sortBy: heading.getAttribute('data-order-by'),
|
|
572
|
-
ref: heading.getAttribute('data-ref'),
|
|
573
|
-
},
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
component.dispatchEvent(dispatchedEvent);
|
|
577
|
-
|
|
578
|
-
const sortBy = heading.textContent.trim();
|
|
579
|
-
const order = heading.getAttribute('data-order-by');
|
|
580
|
-
|
|
581
|
-
if (!component.hasAttribute('data-submit')) {
|
|
582
|
-
// TODO
|
|
583
|
-
sortTableByValues(table, sortBy, order);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
export const createSearchDataList = (component, table): void => {
|
|
590
|
-
const actionbar = component.querySelector('iam-actionbar');
|
|
591
|
-
if (!actionbar) return false;
|
|
592
|
-
|
|
593
|
-
const searchInput = actionbar.shadowRoot?.querySelector('input#search');
|
|
594
|
-
if (!searchInput) return false;
|
|
595
|
-
|
|
596
|
-
const searchID = searchInput.getAttribute('id');
|
|
597
|
-
const inputWrapper = searchInput.parentNode;
|
|
598
|
-
|
|
599
|
-
const searchableTerms = {};
|
|
600
|
-
table.querySelectorAll('tbody td:not(.td--fixed)').forEach((td) => {
|
|
601
|
-
if (td.querySelector('.td__content'))
|
|
602
|
-
searchableTerms[td.querySelector('.td__content').textContent] = td.querySelector('.td__content').textContent;
|
|
603
|
-
else searchableTerms[td.textContent] = td.textContent;
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
searchInput.setAttribute('list', `${searchID}_list`);
|
|
607
|
-
searchInput.setAttribute('autocomplete', 'off');
|
|
608
|
-
|
|
609
|
-
if (!inputWrapper.querySelector('datalist')) inputWrapper.innerHTML += `<datalist id="${searchID}_list"></datalist>`;
|
|
610
|
-
|
|
611
|
-
inputWrapper.querySelector('datalist').innerHTML = `${Object.keys(searchableTerms)
|
|
612
|
-
.map((term) => `<option value="${term}"></option>`)
|
|
613
|
-
.join('')}`;
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
export const sortTable = (table, form, savedTableBody): void | boolean => {
|
|
617
|
-
if (form.getAttribute('data-ajax')) {
|
|
618
|
-
return false;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
const tbody = table.querySelector('tbody');
|
|
622
|
-
|
|
623
|
-
let selectedOption = form.querySelector(`input[type="radio"][data-sort]:checked`);
|
|
624
|
-
|
|
625
|
-
if (form.querySelector('select[data-sort]')) {
|
|
626
|
-
const select = form.querySelector('select[data-sort]');
|
|
627
|
-
selectedOption = form.querySelector(`select[data-sort] option:nth-child(${select.selectedIndex + 1})`);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
const sortBy = selectedOption.getAttribute('data-sort');
|
|
631
|
-
const order = selectedOption.getAttribute('data-order');
|
|
632
|
-
const format = selectedOption.getAttribute('data-format');
|
|
633
|
-
|
|
634
|
-
if (!sortBy) {
|
|
635
|
-
tbody.innerHTML = savedTableBody.innerHTML;
|
|
636
|
-
addDataAttributes(table);
|
|
637
|
-
return false;
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
sortTableByValues(table, sortBy, order, format);
|
|
641
|
-
};
|
|
642
|
-
|
|
643
|
-
export const sortTableByValues = (table, sortBy, order, format = ''): void => {
|
|
644
|
-
const tbody = table.querySelector('tbody');
|
|
645
|
-
|
|
646
|
-
let orderArray = [];
|
|
647
|
-
if (!['asc', 'desc', 'descending'].includes(order)) {
|
|
648
|
-
orderArray = order.split(',');
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
// Create an array from the table rows, the index created is then used to sort the array
|
|
652
|
-
let tableArr = [];
|
|
653
|
-
Array.from(tbody.querySelectorAll('tr')).forEach((tableRow) => {
|
|
654
|
-
let rowIndex = tableRow
|
|
655
|
-
.querySelector('td[data-label="' + sortBy + '"], th[data-label="' + sortBy + '"]')
|
|
656
|
-
.textContent.trim();
|
|
657
|
-
|
|
658
|
-
if (tableRow.querySelector('[data-label="' + sortBy + '"] .td__content')) {
|
|
659
|
-
rowIndex = tableRow.querySelector('[data-label="' + sortBy + '"] .td__content').textContent.trim();
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// If a predefined order set replace the search term with an ordered numeric value so it can be sorted
|
|
663
|
-
if (orderArray.length && orderArray.includes(rowIndex)) {
|
|
664
|
-
rowIndex = orderArray.indexOf(rowIndex);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
if (isNumeric(rowIndex)) {
|
|
668
|
-
rowIndex = zeroPad(rowIndex, 10);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// If the sort format is date then lets transform the index to a sortable date (this is never displayed)
|
|
672
|
-
if (format && format == 'date') {
|
|
673
|
-
rowIndex = new Date(rowIndex);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
const dataRow = {
|
|
677
|
-
index: rowIndex,
|
|
678
|
-
row: tableRow,
|
|
679
|
-
};
|
|
680
|
-
tableArr.push(dataRow);
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
// Sort array alphabetically
|
|
684
|
-
tableArr.sort((a, b) => (a.index > b.index ? 1 : -1));
|
|
685
|
-
|
|
686
|
-
// Reverse if descending
|
|
687
|
-
if (order == 'descending' || order == 'desc') {
|
|
688
|
-
tableArr = tableArr.reverse();
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
// Create a string to return and populate the tbody
|
|
692
|
-
let strTbody = '';
|
|
693
|
-
tableArr.forEach((tableRow) => {
|
|
694
|
-
strTbody += tableRow.row.outerHTML;
|
|
695
|
-
});
|
|
696
|
-
tbody.innerHTML = strTbody;
|
|
697
|
-
};
|
|
698
|
-
|
|
699
|
-
export const addFilterEventListeners = (component, table, form, pagination, savedTableBody): void => {
|
|
700
|
-
let timer;
|
|
701
|
-
|
|
702
|
-
// Check what conditions are set on the table to see what the form actions are
|
|
703
|
-
const formSubmit = function (event, paginate = false): void | boolean {
|
|
704
|
-
if (form.classList.contains('processing')) return false;
|
|
705
|
-
|
|
706
|
-
Array.from(form.querySelectorAll('iam-applied-filters')).forEach((element) => {
|
|
707
|
-
const event = new Event('tags-set');
|
|
708
|
-
element.dispatchEvent(event);
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
// Before submitting check if any duplicate checkboxes within the filters dialog needs to upset the original input
|
|
712
|
-
if (event.type == 'submit') {
|
|
713
|
-
form.classList.add('processing');
|
|
714
|
-
form.classList.remove('processing');
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
filterTable(component, table, form, pagination);
|
|
718
|
-
populateDataQueries(component, table, form);
|
|
719
|
-
|
|
720
|
-
/*
|
|
721
|
-
// Pass post data back to the page
|
|
722
|
-
if (form.hasAttribute('data-ajax-post')) {
|
|
723
|
-
const formData = new FormData(form);
|
|
724
|
-
const queryString = new URLSearchParams(formData).toString();
|
|
725
|
-
const http = new XMLHttpRequest();
|
|
726
|
-
http.open('GET', `${window.location.href}?ajax=true&${queryString}`);
|
|
727
|
-
http.send();
|
|
728
|
-
}
|
|
729
|
-
*/
|
|
730
|
-
};
|
|
731
|
-
/*
|
|
732
|
-
if (component.querySelector('iam-actionbar[data-search]')) {
|
|
733
|
-
component.querySelector('iam-actionbar[data-search]').addEventListener('search-submit', (event) => {
|
|
734
|
-
if (form.querySelector('input[data-search]')) {
|
|
735
|
-
form.querySelector('input[data-search]').value = event.detail.search;
|
|
736
|
-
} else {
|
|
737
|
-
form.insertAdjacentHTML(
|
|
738
|
-
'beforeend',
|
|
739
|
-
`<input type="hidden" name="search" data-search="${component.querySelector('iam-actionbar[data-search]').getAttribute('data-search')}" value="${event.detail.search}"/>`
|
|
740
|
-
);
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
const submitEvent = new CustomEvent('search-submit', {
|
|
744
|
-
detail: event.details,
|
|
745
|
-
});
|
|
746
|
-
component.dispatchEvent(submitEvent);
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
clearTimeout(timer);
|
|
750
|
-
|
|
751
|
-
if(component.tagName != "IAM-TABLE-NO-SUBMIT")
|
|
752
|
-
formSubmit(event);
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
if (component.querySelector('iam-actionbar') && !component.querySelector('iam-actionbar').closest('form')) {
|
|
757
|
-
component.querySelector('iam-actionbar').addEventListener('change', (event) => {
|
|
758
|
-
if (!form.querySelector('.duplicate-actionbar')) {
|
|
759
|
-
form.insertAdjacentHTML(
|
|
760
|
-
'beforeend',
|
|
761
|
-
`<div class="duplicate-actionbar" style="visibility: hidden; pointer-events: none; position: absolute;"></div>`
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
form.querySelector('.duplicate-actionbar').innerHTML = component.querySelector('iam-actionbar').innerHTML;
|
|
766
|
-
filterTable(component, table, form, pagination);
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
*/
|
|
770
|
-
form.addEventListener('keyup', (event) => {
|
|
771
|
-
clearTimeout(timer);
|
|
772
|
-
|
|
773
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('input[data-search]')) {
|
|
774
|
-
timer = setTimeout(function () {
|
|
775
|
-
formSubmit(event);
|
|
776
|
-
}, 500);
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
|
|
780
|
-
form.addEventListener('change', (event) => {
|
|
781
|
-
clearTimeout(timer);
|
|
782
|
-
|
|
783
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('input[data-search]')) {
|
|
784
|
-
formSubmit(event);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('[data-filter][data-no-ajax]')) {
|
|
788
|
-
// Allow for input fields to filter the current results without a new ajax call
|
|
789
|
-
|
|
790
|
-
filterTable(component, table, form, pagination);
|
|
791
|
-
populateDataQueries(table, form);
|
|
792
|
-
} else if (
|
|
793
|
-
event &&
|
|
794
|
-
event.target instanceof HTMLElement &&
|
|
795
|
-
event.target.closest('[data-filter]') &&
|
|
796
|
-
event.target.closest('form .dialog__wrapper > dialog')
|
|
797
|
-
) {
|
|
798
|
-
formSubmit(event);
|
|
799
|
-
} else if (
|
|
800
|
-
event &&
|
|
801
|
-
event.target instanceof HTMLElement &&
|
|
802
|
-
event.target.closest('[data-filter]') &&
|
|
803
|
-
!event.target.closest('form dialog')
|
|
804
|
-
) {
|
|
805
|
-
formSubmit(event);
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('[data-show]')) {
|
|
809
|
-
formSubmit(event);
|
|
810
|
-
}
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
form.addEventListener('click', (event) => {
|
|
814
|
-
clearTimeout(timer);
|
|
815
|
-
|
|
816
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('dialog button:not([type="button"])')) {
|
|
817
|
-
const button = event.target.closest('dialog button:not([type="button"])');
|
|
818
|
-
const modal = button.closest('dialog');
|
|
819
|
-
|
|
820
|
-
modal.close();
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// Prevent the form from submitting
|
|
824
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('.dialog__close')) {
|
|
825
|
-
event.preventDefault();
|
|
826
|
-
event.stopPropagation();
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
if (event && event.target instanceof HTMLElement && event.target.closest('[data-clear]')) {
|
|
830
|
-
form.classList.add('processing');
|
|
831
|
-
// Make sure any applied filters have been removed
|
|
832
|
-
Array.from(form.querySelectorAll('.applied-filters')).forEach((filters) => {
|
|
833
|
-
filters.innerHTML = '';
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
// Make sure cards are unlicked
|
|
837
|
-
const frm_elements = form.elements;
|
|
838
|
-
|
|
839
|
-
for (let i = 0; i < frm_elements.length; i++) {
|
|
840
|
-
const field_type = frm_elements[i].type.toLowerCase() ? frm_elements[i].type.toLowerCase() : 'text';
|
|
841
|
-
switch (field_type) {
|
|
842
|
-
case 'text':
|
|
843
|
-
case 'password':
|
|
844
|
-
case 'textarea':
|
|
845
|
-
frm_elements[i].value = '';
|
|
846
|
-
break;
|
|
847
|
-
case 'radio':
|
|
848
|
-
case 'checkbox':
|
|
849
|
-
if (frm_elements[i].checked) {
|
|
850
|
-
const input = frm_elements[i];
|
|
851
|
-
const id = input.getAttribute('id');
|
|
852
|
-
const label = document.querySelector(`[for="${id}"`);
|
|
853
|
-
|
|
854
|
-
if (label.querySelector('iam-card')) {
|
|
855
|
-
const card = label.querySelector('iam-card');
|
|
856
|
-
const clickEvent = new Event('click');
|
|
857
|
-
card.dispatchEvent(clickEvent);
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
input.checked = false;
|
|
861
|
-
}
|
|
862
|
-
break;
|
|
863
|
-
case 'select-one':
|
|
864
|
-
case 'select-multi':
|
|
865
|
-
frm_elements[i].selectedIndex = -1;
|
|
866
|
-
break;
|
|
867
|
-
case 'hidden':
|
|
868
|
-
default:
|
|
869
|
-
break;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
form.classList.remove('processing');
|
|
874
|
-
|
|
875
|
-
if (!form.hasAttribute('data-submit')) {
|
|
876
|
-
sortTable(table, form, savedTableBody);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
formSubmit(event);
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
form.addEventListener('submit', (event) => {
|
|
884
|
-
clearTimeout(timer);
|
|
885
|
-
|
|
886
|
-
if (!form.hasAttribute('data-submit')) {
|
|
887
|
-
event.preventDefault();
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
formSubmit(event);
|
|
891
|
-
});
|
|
892
|
-
|
|
893
|
-
form.addEventListener('force', (event) => {
|
|
894
|
-
formSubmit(event);
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
form.addEventListener('paginate', (event) => {
|
|
898
|
-
formSubmit(event, true);
|
|
899
|
-
});
|
|
900
|
-
|
|
901
|
-
};
|
|
902
|
-
|
|
903
|
-
export const filterTable = (component, table, form, pagination): void => {
|
|
904
|
-
table.classList.remove('table--filtered');
|
|
905
|
-
|
|
906
|
-
const filters = filterFilters(form);
|
|
907
|
-
const searches = [];
|
|
908
|
-
let matched = 0;
|
|
909
|
-
const page = form.querySelector('[data-pagination]') ? parseInt(form.querySelector('[data-pagination]').value) : 1;
|
|
910
|
-
const showRows = form.querySelector('[data-show]') ? parseInt(form.querySelector('[data-show]').value) : 15;
|
|
911
|
-
|
|
912
|
-
// Reset
|
|
913
|
-
Array.from(table.querySelectorAll('tbody tr')).forEach((row) => {
|
|
914
|
-
row.classList.remove('filtered');
|
|
915
|
-
row.classList.remove('filtered--matched');
|
|
916
|
-
row.classList.remove('filtered--show');
|
|
917
|
-
|
|
918
|
-
row.removeAttribute('data-filtered-by');
|
|
919
|
-
});
|
|
920
|
-
|
|
921
|
-
// Add search columns too
|
|
922
|
-
if (form.querySelector('input[data-search]')) {
|
|
923
|
-
const searchInput = form.querySelector('input[data-search]');
|
|
924
|
-
//const searchColumns = form.querySelector('input[data-search],[part="search-input"]').getAttribute('data-search').split(',');
|
|
925
|
-
|
|
926
|
-
table.querySelectorAll('thead tr th').forEach((column) => {
|
|
927
|
-
searches.push({ column: `${column.textContent.trim()}`, value: `${searchInput.value}` });
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
//Display the filter count
|
|
932
|
-
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
933
|
-
element.innerHTML = '';
|
|
934
|
-
element.parentNode.classList.remove('hover');
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
let filterCount = 0;
|
|
938
|
-
Object.values(filters).forEach((filter) => {
|
|
939
|
-
if (typeof filter == 'object' && Object.values(filter).length) {
|
|
940
|
-
filterCount += Object.values(filter).length;
|
|
941
|
-
} else {
|
|
942
|
-
filterCount++;
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
|
|
946
|
-
if (filterCount) {
|
|
947
|
-
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
948
|
-
element.innerHTML += `(${filterCount})`;
|
|
949
|
-
element.parentNode.classList.add('hover');
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// Filter the table
|
|
954
|
-
table.classList.add('table--filtered');
|
|
955
|
-
for (const [key, filterValue] of Object.entries(filters)) {
|
|
956
|
-
Array.from(table.querySelectorAll('tbody tr:not(.filtered)')).forEach((row) => {
|
|
957
|
-
let isMatched = false;
|
|
958
|
-
filterValue.forEach((filter) => {
|
|
959
|
-
const filterTd = row.querySelector(`[data-label="${key}"]`);
|
|
960
|
-
|
|
961
|
-
if (filter.includes('-date-from')) {
|
|
962
|
-
const fromDate = new Date(filter.replace('-date-from', ''));
|
|
963
|
-
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
964
|
-
|
|
965
|
-
fromDate.setHours(0, 0, 0, 0);
|
|
966
|
-
checkDate.setHours(0, 0, 0, 0);
|
|
967
|
-
|
|
968
|
-
if (checkDate < fromDate) {
|
|
969
|
-
row.classList.add('less-than-from-date');
|
|
970
|
-
isMatched = false;
|
|
971
|
-
} else if (
|
|
972
|
-
!row.classList.contains('less-than-from-date') &&
|
|
973
|
-
!row.classList.contains('greater-than-to-date')
|
|
974
|
-
) {
|
|
975
|
-
isMatched = true;
|
|
976
|
-
}
|
|
977
|
-
} else if (filter.includes('-date-to')) {
|
|
978
|
-
const toDate = new Date(filter.replace('-date-to', ''));
|
|
979
|
-
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
980
|
-
|
|
981
|
-
toDate.setHours(0, 0, 0, 0);
|
|
982
|
-
checkDate.setHours(0, 0, 0, 0);
|
|
983
|
-
|
|
984
|
-
if (checkDate > toDate) {
|
|
985
|
-
row.classList.add('greater-than-to-date');
|
|
986
|
-
isMatched = false;
|
|
987
|
-
} else if (
|
|
988
|
-
!row.classList.contains('less-than-from-date') &&
|
|
989
|
-
!row.classList.contains('greater-than-to-date')
|
|
990
|
-
) {
|
|
991
|
-
isMatched = true;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// Dynamic values
|
|
996
|
-
if (filter && filter == '$today') {
|
|
997
|
-
filter = formatCell('date', new Date());
|
|
998
|
-
} else if (filter && filter == '$yesterday') {
|
|
999
|
-
const yesterday = new Date();
|
|
1000
|
-
yesterday.setDate(yesterday.getDate() - 1);
|
|
1001
|
-
filter = formatCell('date', yesterday);
|
|
1002
|
-
} else if (filter && (filter == '$thisWeek' || filter == '$lastWeek')) {
|
|
1003
|
-
const today = new Date();
|
|
1004
|
-
const mondayThisWeek = new Date(today.setDate(today.getDate() - (today.getDay() - 1)));
|
|
1005
|
-
const sundayThisWeek = new Date(today.setDate(today.getDate() - today.getDay() + 7));
|
|
1006
|
-
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
1007
|
-
|
|
1008
|
-
today.setHours(0, 0, 0, 0);
|
|
1009
|
-
mondayThisWeek.setHours(0, 0, 0, 0);
|
|
1010
|
-
sundayThisWeek.setHours(0, 0, 0, 0);
|
|
1011
|
-
checkDate.setHours(0, 0, 0, 0);
|
|
1012
|
-
|
|
1013
|
-
if (filter == '$thisWeek') {
|
|
1014
|
-
isMatched = checkDate >= mondayThisWeek && checkDate <= sundayThisWeek;
|
|
1015
|
-
} else {
|
|
1016
|
-
const mondayLastWeek = new Date(mondayThisWeek.setDate(mondayThisWeek.getDate() - 7));
|
|
1017
|
-
const sundayLastWeek = new Date(sundayThisWeek.setDate(sundayThisWeek.getDate() - 7));
|
|
1018
|
-
|
|
1019
|
-
mondayLastWeek.setHours(0, 0, 0, 0);
|
|
1020
|
-
sundayLastWeek.setHours(0, 0, 0, 0);
|
|
1021
|
-
|
|
1022
|
-
isMatched = checkDate >= mondayLastWeek && checkDate <= sundayLastWeek;
|
|
1023
|
-
}
|
|
1024
|
-
} else if (filter && filter == '$thisMonth') {
|
|
1025
|
-
const today = new Date(),
|
|
1026
|
-
year = today.getFullYear(),
|
|
1027
|
-
month = today.getMonth();
|
|
1028
|
-
|
|
1029
|
-
const firstDayMonth = new Date(year, month, 1);
|
|
1030
|
-
const lastDayMonth = new Date(year, month + 1, 0);
|
|
1031
|
-
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
1032
|
-
|
|
1033
|
-
firstDayMonth.setHours(0, 0, 0, 0);
|
|
1034
|
-
lastDayMonth.setHours(0, 0, 0, 0);
|
|
1035
|
-
checkDate.setHours(0, 0, 0, 0);
|
|
1036
|
-
|
|
1037
|
-
isMatched = checkDate >= firstDayMonth && checkDate <= lastDayMonth;
|
|
1038
|
-
} else if (filter && filter == '$lastMonth') {
|
|
1039
|
-
const today = new Date(),
|
|
1040
|
-
year = today.getFullYear(),
|
|
1041
|
-
month = today.getMonth();
|
|
1042
|
-
|
|
1043
|
-
const firstDayLastMonth = new Date(year, month - 1, 1);
|
|
1044
|
-
const lastDayLastMonth = new Date(year, month, 0);
|
|
1045
|
-
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
1046
|
-
|
|
1047
|
-
firstDayLastMonth.setHours(0, 0, 0, 0);
|
|
1048
|
-
lastDayLastMonth.setHours(0, 0, 0, 0);
|
|
1049
|
-
checkDate.setHours(0, 0, 0, 0);
|
|
1050
|
-
|
|
1051
|
-
isMatched = checkDate >= firstDayLastMonth && checkDate <= lastDayLastMonth;
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
if (filterTd && filterTd.textContent.toLowerCase().includes(filter.replace('-', ' ').toLowerCase())) {
|
|
1055
|
-
isMatched = true;
|
|
1056
|
-
}
|
|
1057
|
-
});
|
|
1058
|
-
|
|
1059
|
-
if (!isMatched) {
|
|
1060
|
-
row.classList.add('filtered');
|
|
1061
|
-
row.setAttribute('data-filtered-by', key);
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
// Search whats left of the table after filtering
|
|
1066
|
-
Array.from(table.querySelectorAll('tbody tr:not(.filtered)')).forEach((row) => {
|
|
1067
|
-
let isSearched = searches.length > 0 && searches[0].value.length >= 3 ? false : true;
|
|
1068
|
-
|
|
1069
|
-
searches.forEach((search) => {
|
|
1070
|
-
const searchTd = row.querySelector(`[data-label="${search.column}"]`);
|
|
1071
|
-
|
|
1072
|
-
if (
|
|
1073
|
-
searchTd &&
|
|
1074
|
-
search.value.length >= 3 &&
|
|
1075
|
-
searchTd.textContent.toLowerCase().includes(search.value.toLowerCase())
|
|
1076
|
-
) {
|
|
1077
|
-
isSearched = true;
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
|
|
1081
|
-
if (!isSearched) {
|
|
1082
|
-
row.classList.add('filtered');
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
|
|
1086
|
-
// Work out what to display after pagination
|
|
1087
|
-
Array.from(table.querySelectorAll('tbody tr:not(.filtered)')).forEach((row) => {
|
|
1088
|
-
matched++;
|
|
1089
|
-
|
|
1090
|
-
row.classList.add('filtered--matched');
|
|
1091
|
-
|
|
1092
|
-
// pagination bit
|
|
1093
|
-
const matchesPage = Math.ceil(matched / showRows);
|
|
1094
|
-
if (matchesPage == parseInt(page)) {
|
|
1095
|
-
row.classList.add('filtered--show');
|
|
1096
|
-
}
|
|
1097
|
-
});
|
|
1098
|
-
|
|
1099
|
-
if (pagination) {
|
|
1100
|
-
pagination.setAttribute('data-total', matched);
|
|
1101
|
-
pagination.setAttribute('data-show', showRows);
|
|
1102
|
-
pagination.setAttribute('data-page', page);
|
|
1103
|
-
}
|
|
1104
|
-
};
|
|
1105
|
-
|
|
1106
|
-
export const populateDataQueries = (component, table, form): void | boolean => {
|
|
1107
|
-
const dataQueries = Array.from(form.querySelectorAll('[data-query]'));
|
|
1108
|
-
|
|
1109
|
-
dataQueries.forEach((queryElement) => {
|
|
1110
|
-
const query = queryElement.getAttribute('data-query');
|
|
1111
|
-
let numberOfMatchedRows = 0;
|
|
1112
|
-
|
|
1113
|
-
if (query == 'total') {
|
|
1114
|
-
if (component.hasAttribute('data-total')) numberOfMatchedRows = component.getAttribute('data-total');
|
|
1115
|
-
else
|
|
1116
|
-
numberOfMatchedRows = table.classList.contains('table--filtered')
|
|
1117
|
-
? table.querySelectorAll('tbody tr').length
|
|
1118
|
-
: table.querySelectorAll('tbody tr').length;
|
|
1119
|
-
} else if (!query.includes(' == ') && query.includes(' & ')) {
|
|
1120
|
-
const queries = query.split(' & ');
|
|
1121
|
-
let selector = '';
|
|
1122
|
-
|
|
1123
|
-
queries.forEach((element) => {
|
|
1124
|
-
selector += `:not([data-filtered-by="${element}"])`;
|
|
1125
|
-
});
|
|
1126
|
-
|
|
1127
|
-
numberOfMatchedRows = Array.from(table.querySelectorAll(`tbody tr${selector}`)).length;
|
|
1128
|
-
} else if (!query.includes(' == ')) {
|
|
1129
|
-
numberOfMatchedRows = Array.from(table.querySelectorAll(`tbody tr:not([data-filtered-by="${query}"])`)).length;
|
|
1130
|
-
} else if (query.includes(' && ')) {
|
|
1131
|
-
const queries = query.split(' && ');
|
|
1132
|
-
|
|
1133
|
-
numberOfMatchedRows = Array.from(table.querySelectorAll(`tbody tr:not(.filtered)`)).filter(function (row) {
|
|
1134
|
-
let matched = true;
|
|
1135
|
-
|
|
1136
|
-
for (const value of Object.entries(queries)) {
|
|
1137
|
-
const queryParts = value.split(' == ');
|
|
1138
|
-
|
|
1139
|
-
if (
|
|
1140
|
-
!row.querySelector(`td[data-label="${queryParts[0]}"]`) ||
|
|
1141
|
-
row.querySelector(`td[data-label="${queryParts[0]}"]`).textContent != `${queryParts[1]}`
|
|
1142
|
-
)
|
|
1143
|
-
matched = false;
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
return matched;
|
|
1147
|
-
}).length;
|
|
1148
|
-
} else {
|
|
1149
|
-
const queryParts = query.split(' == ');
|
|
1150
|
-
numberOfMatchedRows = Array.from(
|
|
1151
|
-
table.querySelectorAll(
|
|
1152
|
-
`tbody tr.filtered--matched td[data-label="${queryParts[0]}"], tbody tr[data-filtered-by="${queryParts[0]}"] td[data-label="${queryParts[0]}"]`
|
|
1153
|
-
)
|
|
1154
|
-
).filter(function (element) {
|
|
1155
|
-
return element.textContent === queryParts[1];
|
|
1156
|
-
}).length;
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
if (queryElement.hasAttribute('data-total')) {
|
|
1160
|
-
queryElement.setAttribute('data-total', numberOfMatchedRows);
|
|
1161
|
-
} else {
|
|
1162
|
-
queryElement.innerHTML = numberOfMatchedRows;
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
1165
|
-
};
|
|
1166
|
-
// #endregion
|
|
1167
|
-
|
|
1168
|
-
export const setupSubmitTable = (component, table, form, pagination): void => {
|
|
1169
|
-
form.setAttribute('method', 'get');
|
|
1170
|
-
|
|
1171
|
-
const actionbar = component.querySelector('iam-actionbar');
|
|
1172
|
-
|
|
1173
|
-
if (actionbar) {
|
|
1174
|
-
actionbar.addEventListener('change', (event) => {
|
|
1175
|
-
form.submit();
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
|
|
1180
|
-
// #region submit tables functions
|
|
1181
|
-
|
|
1182
|
-
// #endregion
|
|
1183
|
-
|
|
1184
|
-
export const setupAjaxTable = (component, table, form, pagination): void => {
|
|
1185
|
-
loadAjaxTable(component, table, form, pagination);
|
|
1186
|
-
|
|
1187
|
-
const actionbar = component.querySelector('iam-actionbar');
|
|
1188
|
-
|
|
1189
|
-
form.addEventListener('submit', (event) => {
|
|
1190
|
-
|
|
1191
|
-
Array.from(form.querySelectorAll('[data-duplicate]')).forEach((loopElement) => {
|
|
1192
|
-
|
|
1193
|
-
const element = loopElement.tagName == "IAM-INPUT" ? loopElement.querySelector('input') : loopElement;
|
|
1194
|
-
const id = loopElement.getAttribute('data-duplicate');
|
|
1195
|
-
|
|
1196
|
-
if (document.querySelector(`[id="${id}"], [name="${id}"]`)) {
|
|
1197
|
-
|
|
1198
|
-
document.querySelector(`[id="${id}"], [name="${id}"]`).checked = element.checked;
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
|
|
1202
|
-
loadAjaxTable(component, table, form, pagination);
|
|
1203
|
-
|
|
1204
|
-
event.preventDefault();
|
|
1205
|
-
});
|
|
1206
|
-
|
|
1207
|
-
form.addEventListener('change', (event) => {
|
|
1208
|
-
|
|
1209
|
-
if(!event.target.closest('iam-modal')){
|
|
1210
|
-
|
|
1211
|
-
loadAjaxTable(component, table, form, pagination);
|
|
1212
|
-
}
|
|
1213
|
-
});
|
|
1214
|
-
|
|
1215
|
-
// watch hidden fields for change events
|
|
1216
|
-
Array.from(form.querySelectorAll('[type="hidden"]')).forEach((input) => {
|
|
1217
|
-
|
|
1218
|
-
input.addEventListener('change', (event) => {
|
|
1219
|
-
|
|
1220
|
-
loadAjaxTable(component, table, form, pagination);
|
|
1221
|
-
});
|
|
1222
|
-
});
|
|
1223
|
-
|
|
1224
|
-
if (actionbar) {
|
|
1225
|
-
actionbar.addEventListener('change', (event) => {
|
|
1226
|
-
loadAjaxTable(component, table, form, pagination);
|
|
1227
|
-
});
|
|
1228
|
-
|
|
1229
|
-
actionbar.addEventListener('search-submit', (event) => {
|
|
1230
|
-
if (form.querySelector('input[data-search]')) {
|
|
1231
|
-
form.querySelector('input[data-search]').value = event.detail.search;
|
|
1232
|
-
} else {
|
|
1233
|
-
form.insertAdjacentHTML(
|
|
1234
|
-
'beforeend',
|
|
1235
|
-
`<input type="hidden" name="search" data-search="${component.querySelector('iam-actionbar[data-search]').getAttribute('data-search')}" value="${event.detail.search}"/>`
|
|
1236
|
-
);
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
const submitEvent = new CustomEvent('search-submit', {
|
|
1240
|
-
detail: event.details,
|
|
1241
|
-
});
|
|
1242
|
-
component.dispatchEvent(submitEvent);
|
|
1243
|
-
|
|
1244
|
-
loadAjaxTable(component, table, form, pagination);
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
};
|
|
1249
|
-
// #region ajax tables functions
|
|
1250
|
-
|
|
1251
|
-
export const loadAjaxTable = async function (component, table, form, pagination): void {
|
|
1252
|
-
// Add actionbar inputs into form
|
|
1253
|
-
if (component.querySelector('iam-actionbar') && !component.querySelector('iam-actionbar').closest('form')) {
|
|
1254
|
-
if (!form.querySelector('.duplicate-actionbar'))
|
|
1255
|
-
form.insertAdjacentHTML(
|
|
1256
|
-
'beforeend',
|
|
1257
|
-
`<div class="duplicate-actionbar" style="visibility: hidden; pointer-events: none; position: absolute;"></div>`
|
|
1258
|
-
);
|
|
1259
|
-
|
|
1260
|
-
form.querySelector('.duplicate-actionbar').innerHTML = component.querySelector('iam-actionbar').innerHTML;
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
// Add pagination inputs into form
|
|
1264
|
-
if (!form.querySelector('input[name=show]'))
|
|
1265
|
-
form.insertAdjacentHTML(
|
|
1266
|
-
'beforeend',
|
|
1267
|
-
`<input name="show" type="hidden" value="${component.getAttribute('data-show')}" />`
|
|
1268
|
-
);
|
|
1269
|
-
|
|
1270
|
-
if (!form.querySelector('input[name=page]'))
|
|
1271
|
-
form.insertAdjacentHTML(
|
|
1272
|
-
'beforeend',
|
|
1273
|
-
`<input name="page" type="hidden" value="${component.getAttribute('data-page')}" />`
|
|
1274
|
-
);
|
|
1275
|
-
|
|
1276
|
-
form.querySelector('input[name=page]').value = component.getAttribute('data-page');
|
|
1277
|
-
form.querySelector('input[name=show]').value = component.getAttribute('data-show');
|
|
1278
|
-
|
|
1279
|
-
// Construct form data to send to api
|
|
1280
|
-
const formData = new FormData(form);
|
|
1281
|
-
|
|
1282
|
-
formData.set('page_number',formData.get('page')); // Fix for compliance dashbaord
|
|
1283
|
-
|
|
1284
|
-
const queryString = new URLSearchParams(formData).toString();
|
|
1285
|
-
const columns = table.querySelectorAll('thead tr th:not(.expand-button-heading)');
|
|
1286
|
-
const tbody = table.querySelector('tbody');
|
|
1287
|
-
const ajaxURL = form.getAttribute('data-ajax');
|
|
1288
|
-
|
|
1289
|
-
component.classList.add('table--loading');
|
|
1290
|
-
|
|
1291
|
-
// Display the filter count
|
|
1292
|
-
const filters = filterFilters(form);
|
|
1293
|
-
|
|
1294
|
-
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
1295
|
-
element.innerHTML = '';
|
|
1296
|
-
element.parentNode.classList.remove('hover');
|
|
1297
|
-
});
|
|
1298
|
-
|
|
1299
|
-
let filterCount = 0;
|
|
1300
|
-
Object.values(filters).forEach((filter) => {
|
|
1301
|
-
if (typeof filter == 'object' && Object.values(filter).length) filterCount += Object.values(filter).length;
|
|
1302
|
-
else filterCount++;
|
|
1303
|
-
});
|
|
1304
|
-
|
|
1305
|
-
if (filterCount) {
|
|
1306
|
-
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
1307
|
-
element.innerHTML += `(${filterCount})`;
|
|
1308
|
-
element.parentNode.classList.add('hover');
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
// Setup controller vars if not already set
|
|
1313
|
-
if (!window.controller) window.controller = [];
|
|
1314
|
-
|
|
1315
|
-
// Abort if controller already present for this url
|
|
1316
|
-
if (window.controller[ajaxURL]) window.controller[ajaxURL].abort();
|
|
1317
|
-
|
|
1318
|
-
// Create a new controller so it can be aborted if new fetch made
|
|
1319
|
-
window.controller[ajaxURL] = new AbortController();
|
|
1320
|
-
const { signal } = controller[ajaxURL];
|
|
1321
|
-
|
|
1322
|
-
// Set loading on the pagination
|
|
1323
|
-
pagination.setAttribute('data-loading', 'true');
|
|
1324
|
-
form.classList.add('processing');
|
|
1325
|
-
|
|
1326
|
-
try {
|
|
1327
|
-
await fetch(ajaxURL + '?' + queryString, {
|
|
1328
|
-
signal: signal,
|
|
1329
|
-
method: 'get',
|
|
1330
|
-
credentials: 'same-origin',
|
|
1331
|
-
headers: new Headers({
|
|
1332
|
-
'Content-Type': 'application/json',
|
|
1333
|
-
Accept: 'application/json',
|
|
1334
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
1335
|
-
}),
|
|
1336
|
-
})
|
|
1337
|
-
.then((response) => response.json())
|
|
1338
|
-
.then((response) => {
|
|
1339
|
-
const schema = component.hasAttribute('data-schema') ? component.getAttribute('data-schema') : 'data';
|
|
1340
|
-
const totalNumberSchema = component.hasAttribute('data-schema-total')
|
|
1341
|
-
? component.getAttribute('data-schema-total')
|
|
1342
|
-
: 'meta.total';
|
|
1343
|
-
const currentPageSchema = component.hasAttribute('data-schema-page')
|
|
1344
|
-
? component.getAttribute('data-schema-page')
|
|
1345
|
-
: 'meta.current_page';
|
|
1346
|
-
|
|
1347
|
-
const totalNumber = resolvePath(response, totalNumberSchema, 15);
|
|
1348
|
-
const currentPage = resolvePath(response, currentPageSchema, 1);
|
|
1349
|
-
const data = resolvePath(response, schema);
|
|
1350
|
-
const emptyMsg = component.hasAttribute('data-empty-msg')
|
|
1351
|
-
? component.getAttribute('data-empty-msg')
|
|
1352
|
-
: 'No results found';
|
|
1353
|
-
|
|
1354
|
-
if (data) {
|
|
1355
|
-
tbody.innerHTML = '';
|
|
1356
|
-
|
|
1357
|
-
data.forEach((row) => {
|
|
1358
|
-
const table_row = document.createElement('tr');
|
|
1359
|
-
|
|
1360
|
-
columns.forEach((col) => {
|
|
1361
|
-
let cellOutput = '';
|
|
1362
|
-
const table_cell = document.createElement('td');
|
|
1363
|
-
// Add some data to help with the mobile layout design
|
|
1364
|
-
table_cell.setAttribute('data-label', col.innerText);
|
|
1365
|
-
|
|
1366
|
-
if (col.getAttribute('data-output')) {
|
|
1367
|
-
const cellTemplate = col.getAttribute('data-output');
|
|
1368
|
-
// Use a regex to replace {var} with actual values from the json data
|
|
1369
|
-
cellOutput = cellTemplate.replace(new RegExp(/{(.*?)}/, 'gm'), function (matched) {
|
|
1370
|
-
return resolvePath(row, matched.replace('{', '').replace('}', ''));
|
|
1371
|
-
});
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
// If an output array is defined then the content is going to made of of multiple values from an array
|
|
1375
|
-
if (col.hasAttribute('data-output-array')) {
|
|
1376
|
-
const cellTemplate = col.getAttribute('data-output');
|
|
1377
|
-
const arrValue = resolvePath(row, cellTemplate.replace('{', '').replace('}', ''));
|
|
1378
|
-
|
|
1379
|
-
cellOutput = '';
|
|
1380
|
-
arrValue.forEach((rowValue) => {
|
|
1381
|
-
const cellTemplateValue = col.getAttribute('data-output-array');
|
|
1382
|
-
let cellOutputValue = '';
|
|
1383
|
-
|
|
1384
|
-
// If we need to transform some of the data
|
|
1385
|
-
if (
|
|
1386
|
-
col.hasAttribute('data-output-array-property') &&
|
|
1387
|
-
col.hasAttribute('data-output-array-transform')
|
|
1388
|
-
) {
|
|
1389
|
-
const propertyValue = resolvePath(rowValue, col.getAttribute('data-output-array-property'));
|
|
1390
|
-
const transforms = JSON.parse(col.getAttribute('data-output-array-transform'));
|
|
1391
|
-
const transformValue = transforms[propertyValue];
|
|
1392
|
-
|
|
1393
|
-
cellOutputValue = cellTemplateValue.replace(
|
|
1394
|
-
`{${col.getAttribute('data-output-array-property')}}`,
|
|
1395
|
-
transformValue
|
|
1396
|
-
);
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
cellOutputValue = cellOutputValue.replace(new RegExp(/{(.*?)}/, 'gm'), function (matched) {
|
|
1400
|
-
return resolvePath(rowValue, matched.replace('{', '').replace('}', ''));
|
|
1401
|
-
});
|
|
1402
|
-
cellOutput += cellOutputValue;
|
|
1403
|
-
});
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
if (col.hasAttribute('data-transform')) {
|
|
1407
|
-
const transforms = JSON.parse(col.getAttribute('data-transform'));
|
|
1408
|
-
cellOutput = transforms[cellOutput];
|
|
1409
|
-
|
|
1410
|
-
if (!cellOutput && col.hasAttribute('data-default')) cellOutput = col.getAttribute('data-default');
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
table_cell.innerHTML = cellOutput;
|
|
1414
|
-
table_row.appendChild(table_cell);
|
|
1415
|
-
});
|
|
1416
|
-
|
|
1417
|
-
tbody.appendChild(table_row);
|
|
1418
|
-
});
|
|
1419
|
-
|
|
1420
|
-
component.setAttribute('data-total', parseInt(totalNumber));
|
|
1421
|
-
//component.setAttribute('data-page', parseInt(currentPage));
|
|
1422
|
-
|
|
1423
|
-
//pagination.setAttribute('data-total', totalNumber);
|
|
1424
|
-
//pagination.setAttribute('data-page', currentPage);
|
|
1425
|
-
|
|
1426
|
-
Array.from(form.querySelectorAll('[data-ajax-query]')).forEach((queryElement) => {
|
|
1427
|
-
const totalNumber = resolvePath(response, queryElement.getAttribute('data-ajax-query'), '');
|
|
1428
|
-
|
|
1429
|
-
if (queryElement.hasAttribute('data-total')) queryElement.setAttribute('data-total', totalNumber);
|
|
1430
|
-
else queryElement.innerHTML = totalNumber;
|
|
1431
|
-
});
|
|
1432
|
-
|
|
1433
|
-
if (parseInt(totalNumber) == 0) {
|
|
1434
|
-
tbody.innerHTML = `<tr><td colspan="100%"><span>${emptyMsg}</span></td></tr>`;
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
component.classList.remove('table--loading');
|
|
1438
|
-
|
|
1439
|
-
window.dataLayer = window.dataLayer || [];
|
|
1440
|
-
window.dataLayer.push({
|
|
1441
|
-
event: 'Ajax table loaded',
|
|
1442
|
-
url: ajaxURL,
|
|
1443
|
-
formData: queryString,
|
|
1444
|
-
});
|
|
1445
|
-
|
|
1446
|
-
setupBasicTable(component, table, form, pagination);
|
|
1447
|
-
setupAdvancedTable(component, table, form, pagination);
|
|
1448
|
-
} else {
|
|
1449
|
-
tbody.innerHTML = '<tr><td colspan="100%"><span>Error loading table</span></td></tr>';
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
// Remove loading on the pagination
|
|
1453
|
-
pagination.removeAttribute('data-loading');
|
|
1454
|
-
form.classList.remove('processing');
|
|
1455
|
-
});
|
|
1456
|
-
} catch (error) {
|
|
1457
|
-
console.log(error);
|
|
1458
|
-
}
|
|
1459
|
-
};
|
|
1460
|
-
// #endregion
|
|
1461
|
-
|
|
1462
|
-
/*
|
|
1463
|
-
// Pagination - still needed?
|
|
1464
|
-
export const addPaginationEventListeners = function (component, table, form, pagination): void | boolean {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
pagination.addEventListener('update-page', (event) => {
|
|
1468
|
-
const paginationInput = form.querySelector('[data-pagination]');
|
|
1469
|
-
const newPage = event.detail.page;
|
|
1470
|
-
|
|
1471
|
-
// Set the filter value
|
|
1472
|
-
paginationInput.value = newPage;
|
|
1473
|
-
form.dispatchEvent(new Event('paginate'));
|
|
1474
|
-
|
|
1475
|
-
// Reset the data attribute
|
|
1476
|
-
component.setAttribute('data-page', newPage);
|
|
1477
|
-
|
|
1478
|
-
if (table.hasAttribute('data-show-history')) {
|
|
1479
|
-
const url = new URL(location);
|
|
1480
|
-
url.searchParams.set('page', newPage);
|
|
1481
|
-
history.pushState({ type: 'pagination', form: form.getAttribute('id'), page: newPage }, '', url);
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
// scroll back to the top of the table
|
|
1485
|
-
if (!component.hasAttribute('data-no-scroll')) {
|
|
1486
|
-
const yOffset = -250;
|
|
1487
|
-
const y = table.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
|
1488
|
-
window.scrollTo({ top: y, behavior: 'smooth' });
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
|
|
1492
|
-
pagination.addEventListener('update-show', (event) => {
|
|
1493
|
-
const showInput = form.querySelector('[data-show]');
|
|
1494
|
-
const showRows = event.detail.show;
|
|
1495
|
-
showInput.value = showRows;
|
|
1496
|
-
component.setAttribute('data-show', showRows);
|
|
1497
|
-
form.dispatchEvent(new Event('submit'));
|
|
1498
|
-
});
|
|
1499
|
-
};
|
|
1500
|
-
*/
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { zeroPad, isNumeric, ucfirst, resolvePath, uniqueID } from './helpers';
|
|
3
|
+
|
|
4
|
+
// #region Helpers
|
|
5
|
+
export const formatCell = (format, cellOutput): any => {
|
|
6
|
+
switch (format) {
|
|
7
|
+
case 'datetime':
|
|
8
|
+
return (
|
|
9
|
+
new Date(cellOutput).toLocaleDateString('en-gb', {
|
|
10
|
+
weekday: 'short',
|
|
11
|
+
year: '2-digit',
|
|
12
|
+
month: 'long',
|
|
13
|
+
day: 'numeric',
|
|
14
|
+
}) +
|
|
15
|
+
' ' +
|
|
16
|
+
new Date(cellOutput).toLocaleTimeString('en-gb', { hour: '2-digit', minute: '2-digit' })
|
|
17
|
+
);
|
|
18
|
+
case 'date':
|
|
19
|
+
return new Date(cellOutput).toLocaleDateString('en-gb', {
|
|
20
|
+
day: 'numeric',
|
|
21
|
+
month: 'long',
|
|
22
|
+
year: '2-digit',
|
|
23
|
+
});
|
|
24
|
+
case 'capitalise':
|
|
25
|
+
return (cellOutput = ucfirst(cellOutput));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const filterFilters = function (form): object {
|
|
30
|
+
const filters = new Object();
|
|
31
|
+
|
|
32
|
+
// Filter
|
|
33
|
+
const filterInputs = Array.from(form.querySelectorAll('[data-filter]'));
|
|
34
|
+
|
|
35
|
+
filterInputs.forEach((filterInput) => {
|
|
36
|
+
// Ignore uncked radio inputs
|
|
37
|
+
if (filterInput.type == 'radio' && !filterInput.checked) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (filterInput.type == 'checkbox' && !filterInput.checked) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (filterInput && filterInput.value) {
|
|
46
|
+
const dataFilter = filterInput.getAttribute('data-filter');
|
|
47
|
+
let filterValue = filterInput.value;
|
|
48
|
+
|
|
49
|
+
if (filterInput.hasAttribute('data-date-from')) filterValue += '-date-from';
|
|
50
|
+
|
|
51
|
+
if (filterInput.hasAttribute('data-date-to')) filterValue += '-date-to';
|
|
52
|
+
|
|
53
|
+
if (!filters[dataFilter]) filters[dataFilter] = [];
|
|
54
|
+
|
|
55
|
+
filters[dataFilter].push(filterValue);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return filters;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const moveAttributesToComponents = (component): void => {
|
|
63
|
+
let form = document.createElement('form');
|
|
64
|
+
const table = component.querySelector('table');
|
|
65
|
+
|
|
66
|
+
if (component.hasAttribute('data-filterby')) {
|
|
67
|
+
form = document.querySelector(`#${component.getAttribute('data-filterby')}`);
|
|
68
|
+
} else if (component.closest('form')) {
|
|
69
|
+
form = component.closest('form');
|
|
70
|
+
} else {
|
|
71
|
+
table.parentNode.insertBefore(form, table.nextSibling);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (form.hasAttribute('data-ajax')) component.setAttribute('data-ajax', form.getAttribute('data-ajax'));
|
|
75
|
+
|
|
76
|
+
if (form.hasAttribute('data-schema')) component.setAttribute('data-schema', form.getAttribute('data-schema'));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const paginateTable = (component, table, form, pagination, callback): void => {
|
|
80
|
+
if (!form.querySelector('[name=show]'))
|
|
81
|
+
form.insertAdjacentHTML(
|
|
82
|
+
'beforeend',
|
|
83
|
+
`<input name="show" type="hidden" value="${component.getAttribute('data-show')}" />`
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (!form.querySelector('[name=page]'))
|
|
87
|
+
form.insertAdjacentHTML(
|
|
88
|
+
'beforeend',
|
|
89
|
+
`<input name="page" type="hidden" value="${component.getAttribute('data-page')}" />`
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
pagination.addEventListener('update-show', (event) => {
|
|
93
|
+
if (form.querySelector('[name=show]').value != event.detail.show) {
|
|
94
|
+
form.querySelector('[name=show]').value = event.detail.show;
|
|
95
|
+
|
|
96
|
+
const updateEvent = new CustomEvent('update-show', { detail: { show: event.detail.show } });
|
|
97
|
+
component.dispatchEvent(updateEvent);
|
|
98
|
+
|
|
99
|
+
updateAttributes(component, pagination);
|
|
100
|
+
|
|
101
|
+
callback();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
pagination.addEventListener('update-page', (event) => {
|
|
106
|
+
|
|
107
|
+
if (form.querySelector('[name=page]').value != event.detail.page) {
|
|
108
|
+
form.querySelector('[name=page]').value = event.detail.page;
|
|
109
|
+
|
|
110
|
+
const updateEvent = new CustomEvent('update-page', { detail: { page: event.detail.page } });
|
|
111
|
+
component.dispatchEvent(updateEvent);
|
|
112
|
+
|
|
113
|
+
updateAttributes(component, pagination);
|
|
114
|
+
|
|
115
|
+
callback();
|
|
116
|
+
|
|
117
|
+
// scroll back to the top of the table
|
|
118
|
+
if (!component.hasAttribute('data-no-scroll')) {
|
|
119
|
+
const yOffset = -250;
|
|
120
|
+
const y = table.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
|
121
|
+
window.scrollTo({ top: y, behavior: 'smooth' });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const findForm = (component, table): HTMLElement => {
|
|
128
|
+
let form = document.createElement('form');
|
|
129
|
+
|
|
130
|
+
if (component.hasAttribute('data-filterby')) {
|
|
131
|
+
form = document.querySelector(`#${component.getAttribute('data-filterby')}`);
|
|
132
|
+
} else if (component.closest('form')) {
|
|
133
|
+
form = component.closest('form');
|
|
134
|
+
}
|
|
135
|
+
else if (component.querySelector('form')){
|
|
136
|
+
form = component.querySelector('form');
|
|
137
|
+
}else {
|
|
138
|
+
table.parentNode.insertBefore(form, table.nextSibling);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if(component.hasAttribute('data-ajax')){
|
|
143
|
+
form.setAttribute('data-ajax',component.getAttribute('data-ajax'))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return form;
|
|
147
|
+
};
|
|
148
|
+
// #endregion
|
|
149
|
+
|
|
150
|
+
export const setupBasicTable = (component, table, form, pagination): void => {
|
|
151
|
+
const tableWrapper = component.shadowRoot.querySelector('.table__wrapper');
|
|
152
|
+
|
|
153
|
+
if (!component.hasAttribute('data-total'))
|
|
154
|
+
component.setAttribute('data-total', component.querySelectorAll('tbody tr').length);
|
|
155
|
+
if (!component.hasAttribute('data-page')) component.setAttribute('data-page', 1);
|
|
156
|
+
if (!component.hasAttribute('data-show')) component.setAttribute('data-show', 15);
|
|
157
|
+
if (!component.hasAttribute('data-increment'))
|
|
158
|
+
component.setAttribute('data-increment', component.getAttribute('data-show'));
|
|
159
|
+
|
|
160
|
+
transferAttributes(component, pagination);
|
|
161
|
+
|
|
162
|
+
addDataAttributes(table);
|
|
163
|
+
createMobileButton(component, table);
|
|
164
|
+
|
|
165
|
+
// Max height
|
|
166
|
+
if (component.classList.contains('mh-sm')) tableWrapper.classList.add('mh-sm');
|
|
167
|
+
if (component.classList.contains('mh-md')) tableWrapper.classList.add('mh-md');
|
|
168
|
+
if (component.classList.contains('mh-lg')) tableWrapper.classList.add('mh-lg');
|
|
169
|
+
|
|
170
|
+
if (component.classList.contains('table--cta')) {
|
|
171
|
+
getLargestLastColWidth(component, table);
|
|
172
|
+
getRowHeight(component, table);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
highlightRows(component);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// #region Basic table fnctions
|
|
179
|
+
export const highlightRows = (component): void => {
|
|
180
|
+
|
|
181
|
+
Array.from(component.querySelectorAll('tr[data-highlight]')).forEach((row) => {
|
|
182
|
+
row.insertAdjacentHTML('afterend',`<tr role="presentation" class="tr--highlight">
|
|
183
|
+
<td colspan="100%"><i class="fa-solid fa-star"></i> ${row.getAttribute('data-highlight')}</td>
|
|
184
|
+
</tr>`);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export const transferAttributes = (component, pagination): void => {
|
|
189
|
+
if (component.hasAttribute('data-total')) pagination.setAttribute('data-total', component.getAttribute('data-total'));
|
|
190
|
+
if (component.hasAttribute('data-page')) pagination.setAttribute('data-page', component.getAttribute('data-page'));
|
|
191
|
+
if (component.hasAttribute('data-show')) pagination.setAttribute('data-show', component.getAttribute('data-show'));
|
|
192
|
+
if (component.hasAttribute('data-increment'))
|
|
193
|
+
pagination.setAttribute('data-increment', component.getAttribute('data-show'));
|
|
194
|
+
|
|
195
|
+
if (component.hasAttribute('data-page-jump')) pagination.setAttribute('data-page-jump', 'true');
|
|
196
|
+
if (component.hasAttribute('data-per-page')) pagination.setAttribute('data-per-page', 'true');
|
|
197
|
+
if (component.hasAttribute('data-item-count')) pagination.setAttribute('data-item-count', 'true');
|
|
198
|
+
if (component.hasAttribute('data-loading')) pagination.setAttribute('data-loading', 'true');
|
|
199
|
+
|
|
200
|
+
if (component.classList.contains('table--fullwidth')) pagination.setAttribute('data-minimal', 'true');
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export const updateAttributes = (component, pagination): void => {
|
|
204
|
+
component.setAttribute('data-total', pagination.getAttribute('data-total'));
|
|
205
|
+
component.setAttribute('data-page', pagination.getAttribute('data-page'));
|
|
206
|
+
component.setAttribute('data-show', pagination.getAttribute('data-show'));
|
|
207
|
+
component.setAttribute('data-increment', pagination.getAttribute('data-show'));
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export const paginateRows = (component): void => {
|
|
211
|
+
const total = component.getAttribute('data-total');
|
|
212
|
+
const page = component.getAttribute('data-page');
|
|
213
|
+
const show = component.getAttribute('data-show');
|
|
214
|
+
const increment = component.getAttribute('data-increment');
|
|
215
|
+
|
|
216
|
+
const table = component.querySelector('table');
|
|
217
|
+
|
|
218
|
+
const end = page * show;
|
|
219
|
+
const start = end - show;
|
|
220
|
+
|
|
221
|
+
Array.from(table.querySelectorAll('tbody tr')).forEach((row, index) => {
|
|
222
|
+
if (index >= start && index < end) {
|
|
223
|
+
row.classList.add('show');
|
|
224
|
+
} else {
|
|
225
|
+
row.classList.remove('show');
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const addDataAttributes = (table): void => {
|
|
231
|
+
const colHeadings = Array.from(table.querySelectorAll('thead th'));
|
|
232
|
+
const colRows = Array.from(table.querySelectorAll('tbody tr'));
|
|
233
|
+
|
|
234
|
+
colRows.forEach((row) => {
|
|
235
|
+
const cells = Array.from(row.querySelectorAll('th, td'));
|
|
236
|
+
const statuses = [
|
|
237
|
+
'0',
|
|
238
|
+
'low',
|
|
239
|
+
'medium',
|
|
240
|
+
'high',
|
|
241
|
+
'unknown',
|
|
242
|
+
'n/a',
|
|
243
|
+
'pending',
|
|
244
|
+
'verified',
|
|
245
|
+
'due',
|
|
246
|
+
'overdue',
|
|
247
|
+
'incomplete',
|
|
248
|
+
'complete',
|
|
249
|
+
'completed',
|
|
250
|
+
'approval required',
|
|
251
|
+
'upcoming',
|
|
252
|
+
'requires approval',
|
|
253
|
+
'to do',
|
|
254
|
+
'on track',
|
|
255
|
+
'not started',
|
|
256
|
+
'warning',
|
|
257
|
+
'successful',
|
|
258
|
+
'failed',
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
cells.forEach((cell, cellIndex) => {
|
|
262
|
+
const heading = colHeadings[cellIndex];
|
|
263
|
+
if (typeof heading != 'undefined') {
|
|
264
|
+
const tempDiv = document.createElement('div');
|
|
265
|
+
tempDiv.innerHTML = heading.innerHTML;
|
|
266
|
+
const headingText = tempDiv.textContent || tempDiv.innerText || '';
|
|
267
|
+
cell.setAttribute('data-label', headingText);
|
|
268
|
+
|
|
269
|
+
if (heading.hasAttribute('data-td-class')) cell.setAttribute('class', heading.getAttribute('data-td-class'));
|
|
270
|
+
|
|
271
|
+
if (heading.hasAttribute('data-format')) {
|
|
272
|
+
cell.setAttribute('data-format', heading.getAttribute('data-format'));
|
|
273
|
+
cell.innerHTML = formatCell(heading.getAttribute('data-format'), cell.textContent.trim()); //Make sure date format is consistent
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (statuses.includes(cell.textContent.trim().toLowerCase())) {
|
|
277
|
+
cell.setAttribute('data-content', cell.textContent.trim().toLowerCase());
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export const createMobileButton = (component, table): void => {
|
|
285
|
+
if (component.classList.contains('table--fullwidth') && !component.hasAttribute('data-expandable')) return false;
|
|
286
|
+
|
|
287
|
+
if (table.querySelectorAll('thead tr th').length < 4 && !component.hasAttribute('data-expandable')) return false;
|
|
288
|
+
|
|
289
|
+
//If the expand column already exists we don't need to add a new one.
|
|
290
|
+
Array.from(table.querySelectorAll('thead tr')).forEach((row) => {
|
|
291
|
+
if (!table.querySelectorAll('thead tr th.expand-button-heading').length) {
|
|
292
|
+
row.insertAdjacentHTML(
|
|
293
|
+
'afterbegin',
|
|
294
|
+
`<th class="${component.hasAttribute('data-expandable') ? 'th--fixed ' : ''}expand-button-heading"></th>`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
Array.from(table.querySelectorAll('tbody tr')).forEach((row, index) => {
|
|
300
|
+
const preExpanded = row.getAttribute('data-view') === 'full' ? 'aria-expanded' : '';
|
|
301
|
+
row.insertAdjacentHTML(
|
|
302
|
+
'afterbegin',
|
|
303
|
+
`<td class="${component.hasAttribute('data-expandable') ? 'td--fixed ' : ''}td--expand"><button class="btn btn-compact btn-secondary btn-sm fa-circle-plus" data-expand-button ${preExpanded} data-index="${index}">Expand</button></td>`
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
table.addEventListener('click', (event) => {
|
|
308
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('[data-expand-button]')) {
|
|
309
|
+
const button = event.target.closest('[data-expand-button]');
|
|
310
|
+
const tableRow = button.closest('tr');
|
|
311
|
+
|
|
312
|
+
button.toggleAttribute('aria-expanded');
|
|
313
|
+
|
|
314
|
+
if(button.classList.contains('fa-circle-plus')){
|
|
315
|
+
button.classList.remove('fa-circle-plus');
|
|
316
|
+
button.classList.add('fa-circle-minus');
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
|
|
320
|
+
button.classList.remove('fa-circle-minus');
|
|
321
|
+
button.classList.add('fa-circle-plus');
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (tableRow.getAttribute('data-view') == 'full') tableRow.setAttribute('data-view', 'default');
|
|
325
|
+
else tableRow.setAttribute('data-view', 'full');
|
|
326
|
+
|
|
327
|
+
button.blur();
|
|
328
|
+
|
|
329
|
+
component.dispatchEvent(new CustomEvent('row-expanded', { detail: { row: button.getAttribute('data-index') } }));
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
export const getLargestLastColWidth = (component, table): void => {
|
|
335
|
+
let largestWidth = 0;
|
|
336
|
+
|
|
337
|
+
Array.from(table.querySelectorAll('tbody tr')).forEach((row) => {
|
|
338
|
+
const htmlStyles = window.getComputedStyle(document.querySelector('html'));
|
|
339
|
+
const lastColChild = row.querySelector(':scope > *:last-child > *:first-child');
|
|
340
|
+
|
|
341
|
+
if (lastColChild) {
|
|
342
|
+
lastColChild.classList.add('text-nowrap');
|
|
343
|
+
let responsiveWidth = lastColChild.offsetWidth / parseFloat(htmlStyles.fontSize);
|
|
344
|
+
responsiveWidth += 1.8;
|
|
345
|
+
largestWidth = largestWidth > responsiveWidth ? largestWidth : responsiveWidth;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
component.style.setProperty('--cta-width', `${largestWidth}rem`);
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
export const getRowHeight = (component, table): void => {
|
|
353
|
+
function outputsize(): void {
|
|
354
|
+
Array.from(table.querySelectorAll('tr')).forEach((row) => {
|
|
355
|
+
const rowHeight = row.offsetHeight;
|
|
356
|
+
|
|
357
|
+
row.style.setProperty('--row-height', `${rowHeight}px`);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
new ResizeObserver(outputsize).observe(table);
|
|
362
|
+
};
|
|
363
|
+
// #endregion
|
|
364
|
+
|
|
365
|
+
export const setupAdvancedTable = (component, table): void => {
|
|
366
|
+
if (
|
|
367
|
+
component.querySelector('iam-actionbar[data-selectall]') ||
|
|
368
|
+
document.querySelector(`iam-actionbar[data-for='${component.getAttribute('id')}']`)
|
|
369
|
+
) {
|
|
370
|
+
const actionbar = component.querySelector('iam-actionbar[data-selectall]')
|
|
371
|
+
? component.querySelector('iam-actionbar[data-selectall]')
|
|
372
|
+
: document.querySelector(`iam-actionbar[data-for='${component.getAttribute('id')}']`);
|
|
373
|
+
|
|
374
|
+
addSelectboxes(component, table, actionbar);
|
|
375
|
+
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
component.querySelectorAll('.dialog__wrapper .btn-compact').forEach((btn, index) => {
|
|
379
|
+
const wrapper = btn.closest('.dialog__wrapper');
|
|
380
|
+
const dialog = wrapper.querySelector('dialog');
|
|
381
|
+
|
|
382
|
+
// Transform dialog into a menu custom element
|
|
383
|
+
if (dialog) {
|
|
384
|
+
const id = `menu${uniqueID(index)}`;
|
|
385
|
+
|
|
386
|
+
dialog.setAttribute('id', id);
|
|
387
|
+
dialog.setAttribute('popover', 'auto');
|
|
388
|
+
btn.setAttribute('popovertarget', id);
|
|
389
|
+
|
|
390
|
+
dialog.outerHTML = dialog.outerHTML.replace(/<dialog/g, '<iam-menu').replace(/<\/dialog>/g, '</iam-menu>');
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
btn.classList.add('btn-sm');
|
|
394
|
+
btn.classList.add('m-0');
|
|
395
|
+
|
|
396
|
+
const tr = btn.closest('tr');
|
|
397
|
+
const td = btn.closest('td');
|
|
398
|
+
|
|
399
|
+
const trChildren = Array.prototype.slice.call(tr.children);
|
|
400
|
+
const cellIndex = trChildren.indexOf(td);
|
|
401
|
+
|
|
402
|
+
td.classList.add('td--fixed');
|
|
403
|
+
table.querySelector(`thead tr th:nth-child(${cellIndex + 1})`).classList.add('th--fixed');
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
// #region Advanced table functions
|
|
407
|
+
export const addSelectboxes = (component, table, actionbar): void => {
|
|
408
|
+
Array.from(table.querySelectorAll('thead tr')).forEach((row) => {
|
|
409
|
+
if (row.querySelector('.expand-button-heading'))
|
|
410
|
+
row.querySelector('.expand-button-heading').insertAdjacentHTML('afterend', `<th class="th--fixed"></th>`);
|
|
411
|
+
else row.insertAdjacentHTML('afterbegin', `<th class="th--fixed"></th>`);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
Array.from(table.querySelectorAll('tbody tr')).forEach((row, index) => {
|
|
415
|
+
row.setAttribute('data-index', index + 1);
|
|
416
|
+
if (!row.querySelector('.selectrow')) {
|
|
417
|
+
const rowID = `row${uniqueID(index)}`;
|
|
418
|
+
|
|
419
|
+
if (row.querySelector('.td--expand'))
|
|
420
|
+
row
|
|
421
|
+
.querySelector('.td--expand')
|
|
422
|
+
.insertAdjacentHTML(
|
|
423
|
+
'afterend',
|
|
424
|
+
`<td class="td--fixed selectrow selected"><input type="checkbox" name="row" id="${rowID}" ${row.hasAttribute('data-selected') ? `checked="true"` : ''}/><label for="${rowID}"><span class="visually-hidden">Select row</span></label></td>`
|
|
425
|
+
);
|
|
426
|
+
else
|
|
427
|
+
row.insertAdjacentHTML(
|
|
428
|
+
'afterbegin',
|
|
429
|
+
`<td class="td--fixed selectrow selected"><input type="checkbox" name="row" id="${rowID}" ${row.hasAttribute('data-selected') ? `checked="true"` : ''}/><label for="${rowID}"><span class="visually-hidden">Select row</span></label></td>`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
table.addEventListener('change', (event) => {
|
|
435
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('.selectrow input')) {
|
|
436
|
+
const input = event.target.closest('.selectrow input');
|
|
437
|
+
const row = event.target.closest('tr');
|
|
438
|
+
|
|
439
|
+
const count = table.querySelectorAll('.selectrow input[type="checkbox"]').length;
|
|
440
|
+
const countChecked = table.querySelectorAll('.selectrow input[type="checkbox"]:checked').length;
|
|
441
|
+
|
|
442
|
+
actionbar.setAttribute('data-selected', count == countChecked ? 'all' : countChecked);
|
|
443
|
+
|
|
444
|
+
const dispatchedEvent = new CustomEvent('row-selected', {
|
|
445
|
+
detail: {
|
|
446
|
+
rowIndex: row.getAttribute('data-index'),
|
|
447
|
+
checked: input.checked ? true : false,
|
|
448
|
+
},
|
|
449
|
+
});
|
|
450
|
+
component.dispatchEvent(dispatchedEvent);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
actionbar.addEventListener('selected', (event) => {
|
|
455
|
+
if (event.detail.selected == '0') {
|
|
456
|
+
Array.from(table.querySelectorAll('.selectrow input[type="checkbox"]')).forEach((input) => {
|
|
457
|
+
input.checked = false;
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
const dispatchedEvent = new CustomEvent('all-rows-unselected');
|
|
461
|
+
component.dispatchEvent(dispatchedEvent);
|
|
462
|
+
} else if (event.detail.selected == 'all') {
|
|
463
|
+
Array.from(table.querySelectorAll('.selectrow input[type="checkbox"]')).forEach((input) => {
|
|
464
|
+
input.checked = true;
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
const dispatchedEvent = new CustomEvent('all-rows-selected');
|
|
468
|
+
component.dispatchEvent(dispatchedEvent);
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// Export CSV Data
|
|
474
|
+
export const addExportEventListeners = (button, table): void | boolean => {
|
|
475
|
+
if (!button) {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
button.addEventListener('click', () => {
|
|
480
|
+
exportAsCSV(table);
|
|
481
|
+
});
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
export const exportAsCSV = function (table): void {
|
|
485
|
+
let csvData = [];
|
|
486
|
+
// Get each row data
|
|
487
|
+
const rows = table.getElementsByTagName('tr');
|
|
488
|
+
for (let i = 0; i < rows.length; i++) {
|
|
489
|
+
// Get each column data
|
|
490
|
+
const cols = rows[i].querySelectorAll('td,th');
|
|
491
|
+
|
|
492
|
+
// Stores each csv row data
|
|
493
|
+
const csvRow = [];
|
|
494
|
+
for (let j = 0; j < cols.length; j++) {
|
|
495
|
+
// Get the text data of each cell of a row and push it to csvrow
|
|
496
|
+
csvRow.push(`"${cols[j].textContent}"`);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Combine each column value with comma
|
|
500
|
+
csvData.push(csvRow.join(','));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Combine each row data with new line character
|
|
504
|
+
csvData = csvData.join('\n');
|
|
505
|
+
|
|
506
|
+
// Create CSV file object and feed our csvData into it
|
|
507
|
+
const CSVFile = new Blob([csvData], {
|
|
508
|
+
type: 'text/csv',
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
// Create to temporary link to initiate download process
|
|
512
|
+
const tempLink = document.createElement('a');
|
|
513
|
+
tempLink.download = 'export.csv';
|
|
514
|
+
const url = window.URL.createObjectURL(CSVFile);
|
|
515
|
+
tempLink.href = url;
|
|
516
|
+
|
|
517
|
+
// This link should not be displayed
|
|
518
|
+
tempLink.style.display = 'none';
|
|
519
|
+
document.body.appendChild(tempLink);
|
|
520
|
+
|
|
521
|
+
// Automatically click the link to trigger download
|
|
522
|
+
tempLink.click();
|
|
523
|
+
document.body.removeChild(tempLink);
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
// #endregion
|
|
527
|
+
|
|
528
|
+
export const setupNoSubmitTable = (component, table, form, pagination, savedTableBody): void => {
|
|
529
|
+
sortViaHeaders(component, table);
|
|
530
|
+
|
|
531
|
+
createSearchDataList(component, table);
|
|
532
|
+
|
|
533
|
+
form.addEventListener('change', (event) => {
|
|
534
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('[data-sort]')) {
|
|
535
|
+
sortTable(table, form, savedTableBody);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
/*
|
|
539
|
+
addFilterEventListeners(component, table, form, pagination, savedTableBody);
|
|
540
|
+
*/
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// #region No submit table functions
|
|
544
|
+
export const sortViaHeaders = (component, table): void => {
|
|
545
|
+
table.addEventListener('click', (event) => {
|
|
546
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('[data-sort]')) {
|
|
547
|
+
const heading = event.target.closest('[data-sort]');
|
|
548
|
+
heading.setAttribute('data-sort', 'true');
|
|
549
|
+
|
|
550
|
+
// Turn other headings off
|
|
551
|
+
Array.from(table.querySelectorAll('th[data-sort]')).forEach((element) => {
|
|
552
|
+
if (element != heading) {
|
|
553
|
+
element.setAttribute('data-sort', '');
|
|
554
|
+
element.removeAttribute('data-order-by');
|
|
555
|
+
heading.setAttribute('title', 'Click to sort ascending');
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
if (heading.hasAttribute('data-order-by') && heading.getAttribute('data-order-by') == 'asc') {
|
|
560
|
+
heading.setAttribute('data-order-by', 'desc');
|
|
561
|
+
heading.setAttribute('title', 'Click to sort ascending');
|
|
562
|
+
} else {
|
|
563
|
+
heading.setAttribute('data-order-by', 'asc');
|
|
564
|
+
heading.setAttribute('title', 'Click to sort descending');
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// dispath event
|
|
568
|
+
const dispatchedEvent = new CustomEvent('sort-by-heading', {
|
|
569
|
+
detail: {
|
|
570
|
+
heading: heading.textContent,
|
|
571
|
+
sortBy: heading.getAttribute('data-order-by'),
|
|
572
|
+
ref: heading.getAttribute('data-ref'),
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
component.dispatchEvent(dispatchedEvent);
|
|
577
|
+
|
|
578
|
+
const sortBy = heading.textContent.trim();
|
|
579
|
+
const order = heading.getAttribute('data-order-by');
|
|
580
|
+
|
|
581
|
+
if (!component.hasAttribute('data-submit')) {
|
|
582
|
+
// TODO
|
|
583
|
+
sortTableByValues(table, sortBy, order);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
export const createSearchDataList = (component, table): void => {
|
|
590
|
+
const actionbar = component.querySelector('iam-actionbar');
|
|
591
|
+
if (!actionbar) return false;
|
|
592
|
+
|
|
593
|
+
const searchInput = actionbar.shadowRoot?.querySelector('input#search');
|
|
594
|
+
if (!searchInput) return false;
|
|
595
|
+
|
|
596
|
+
const searchID = searchInput.getAttribute('id');
|
|
597
|
+
const inputWrapper = searchInput.parentNode;
|
|
598
|
+
|
|
599
|
+
const searchableTerms = {};
|
|
600
|
+
table.querySelectorAll('tbody td:not(.td--fixed)').forEach((td) => {
|
|
601
|
+
if (td.querySelector('.td__content'))
|
|
602
|
+
searchableTerms[td.querySelector('.td__content').textContent] = td.querySelector('.td__content').textContent;
|
|
603
|
+
else searchableTerms[td.textContent] = td.textContent;
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
searchInput.setAttribute('list', `${searchID}_list`);
|
|
607
|
+
searchInput.setAttribute('autocomplete', 'off');
|
|
608
|
+
|
|
609
|
+
if (!inputWrapper.querySelector('datalist')) inputWrapper.innerHTML += `<datalist id="${searchID}_list"></datalist>`;
|
|
610
|
+
|
|
611
|
+
inputWrapper.querySelector('datalist').innerHTML = `${Object.keys(searchableTerms)
|
|
612
|
+
.map((term) => `<option value="${term}"></option>`)
|
|
613
|
+
.join('')}`;
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
export const sortTable = (table, form, savedTableBody): void | boolean => {
|
|
617
|
+
if (form.getAttribute('data-ajax')) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const tbody = table.querySelector('tbody');
|
|
622
|
+
|
|
623
|
+
let selectedOption = form.querySelector(`input[type="radio"][data-sort]:checked`);
|
|
624
|
+
|
|
625
|
+
if (form.querySelector('select[data-sort]')) {
|
|
626
|
+
const select = form.querySelector('select[data-sort]');
|
|
627
|
+
selectedOption = form.querySelector(`select[data-sort] option:nth-child(${select.selectedIndex + 1})`);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const sortBy = selectedOption.getAttribute('data-sort');
|
|
631
|
+
const order = selectedOption.getAttribute('data-order');
|
|
632
|
+
const format = selectedOption.getAttribute('data-format');
|
|
633
|
+
|
|
634
|
+
if (!sortBy) {
|
|
635
|
+
tbody.innerHTML = savedTableBody.innerHTML;
|
|
636
|
+
addDataAttributes(table);
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
sortTableByValues(table, sortBy, order, format);
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
export const sortTableByValues = (table, sortBy, order, format = ''): void => {
|
|
644
|
+
const tbody = table.querySelector('tbody');
|
|
645
|
+
|
|
646
|
+
let orderArray = [];
|
|
647
|
+
if (!['asc', 'desc', 'descending'].includes(order)) {
|
|
648
|
+
orderArray = order.split(',');
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// Create an array from the table rows, the index created is then used to sort the array
|
|
652
|
+
let tableArr = [];
|
|
653
|
+
Array.from(tbody.querySelectorAll('tr')).forEach((tableRow) => {
|
|
654
|
+
let rowIndex = tableRow
|
|
655
|
+
.querySelector('td[data-label="' + sortBy + '"], th[data-label="' + sortBy + '"]')
|
|
656
|
+
.textContent.trim();
|
|
657
|
+
|
|
658
|
+
if (tableRow.querySelector('[data-label="' + sortBy + '"] .td__content')) {
|
|
659
|
+
rowIndex = tableRow.querySelector('[data-label="' + sortBy + '"] .td__content').textContent.trim();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// If a predefined order set replace the search term with an ordered numeric value so it can be sorted
|
|
663
|
+
if (orderArray.length && orderArray.includes(rowIndex)) {
|
|
664
|
+
rowIndex = orderArray.indexOf(rowIndex);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (isNumeric(rowIndex)) {
|
|
668
|
+
rowIndex = zeroPad(rowIndex, 10);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// If the sort format is date then lets transform the index to a sortable date (this is never displayed)
|
|
672
|
+
if (format && format == 'date') {
|
|
673
|
+
rowIndex = new Date(rowIndex);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const dataRow = {
|
|
677
|
+
index: rowIndex,
|
|
678
|
+
row: tableRow,
|
|
679
|
+
};
|
|
680
|
+
tableArr.push(dataRow);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
// Sort array alphabetically
|
|
684
|
+
tableArr.sort((a, b) => (a.index > b.index ? 1 : -1));
|
|
685
|
+
|
|
686
|
+
// Reverse if descending
|
|
687
|
+
if (order == 'descending' || order == 'desc') {
|
|
688
|
+
tableArr = tableArr.reverse();
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// Create a string to return and populate the tbody
|
|
692
|
+
let strTbody = '';
|
|
693
|
+
tableArr.forEach((tableRow) => {
|
|
694
|
+
strTbody += tableRow.row.outerHTML;
|
|
695
|
+
});
|
|
696
|
+
tbody.innerHTML = strTbody;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
export const addFilterEventListeners = (component, table, form, pagination, savedTableBody): void => {
|
|
700
|
+
let timer;
|
|
701
|
+
|
|
702
|
+
// Check what conditions are set on the table to see what the form actions are
|
|
703
|
+
const formSubmit = function (event, paginate = false): void | boolean {
|
|
704
|
+
if (form.classList.contains('processing')) return false;
|
|
705
|
+
|
|
706
|
+
Array.from(form.querySelectorAll('iam-applied-filters')).forEach((element) => {
|
|
707
|
+
const event = new Event('tags-set');
|
|
708
|
+
element.dispatchEvent(event);
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// Before submitting check if any duplicate checkboxes within the filters dialog needs to upset the original input
|
|
712
|
+
if (event.type == 'submit') {
|
|
713
|
+
form.classList.add('processing');
|
|
714
|
+
form.classList.remove('processing');
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
filterTable(component, table, form, pagination);
|
|
718
|
+
populateDataQueries(component, table, form);
|
|
719
|
+
|
|
720
|
+
/*
|
|
721
|
+
// Pass post data back to the page
|
|
722
|
+
if (form.hasAttribute('data-ajax-post')) {
|
|
723
|
+
const formData = new FormData(form);
|
|
724
|
+
const queryString = new URLSearchParams(formData).toString();
|
|
725
|
+
const http = new XMLHttpRequest();
|
|
726
|
+
http.open('GET', `${window.location.href}?ajax=true&${queryString}`);
|
|
727
|
+
http.send();
|
|
728
|
+
}
|
|
729
|
+
*/
|
|
730
|
+
};
|
|
731
|
+
/*
|
|
732
|
+
if (component.querySelector('iam-actionbar[data-search]')) {
|
|
733
|
+
component.querySelector('iam-actionbar[data-search]').addEventListener('search-submit', (event) => {
|
|
734
|
+
if (form.querySelector('input[data-search]')) {
|
|
735
|
+
form.querySelector('input[data-search]').value = event.detail.search;
|
|
736
|
+
} else {
|
|
737
|
+
form.insertAdjacentHTML(
|
|
738
|
+
'beforeend',
|
|
739
|
+
`<input type="hidden" name="search" data-search="${component.querySelector('iam-actionbar[data-search]').getAttribute('data-search')}" value="${event.detail.search}"/>`
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const submitEvent = new CustomEvent('search-submit', {
|
|
744
|
+
detail: event.details,
|
|
745
|
+
});
|
|
746
|
+
component.dispatchEvent(submitEvent);
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
clearTimeout(timer);
|
|
750
|
+
|
|
751
|
+
if(component.tagName != "IAM-TABLE-NO-SUBMIT")
|
|
752
|
+
formSubmit(event);
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (component.querySelector('iam-actionbar') && !component.querySelector('iam-actionbar').closest('form')) {
|
|
757
|
+
component.querySelector('iam-actionbar').addEventListener('change', (event) => {
|
|
758
|
+
if (!form.querySelector('.duplicate-actionbar')) {
|
|
759
|
+
form.insertAdjacentHTML(
|
|
760
|
+
'beforeend',
|
|
761
|
+
`<div class="duplicate-actionbar" style="visibility: hidden; pointer-events: none; position: absolute;"></div>`
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
form.querySelector('.duplicate-actionbar').innerHTML = component.querySelector('iam-actionbar').innerHTML;
|
|
766
|
+
filterTable(component, table, form, pagination);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
*/
|
|
770
|
+
form.addEventListener('keyup', (event) => {
|
|
771
|
+
clearTimeout(timer);
|
|
772
|
+
|
|
773
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('input[data-search]')) {
|
|
774
|
+
timer = setTimeout(function () {
|
|
775
|
+
formSubmit(event);
|
|
776
|
+
}, 500);
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
form.addEventListener('change', (event) => {
|
|
781
|
+
clearTimeout(timer);
|
|
782
|
+
|
|
783
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('input[data-search]')) {
|
|
784
|
+
formSubmit(event);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('[data-filter][data-no-ajax]')) {
|
|
788
|
+
// Allow for input fields to filter the current results without a new ajax call
|
|
789
|
+
|
|
790
|
+
filterTable(component, table, form, pagination);
|
|
791
|
+
populateDataQueries(table, form);
|
|
792
|
+
} else if (
|
|
793
|
+
event &&
|
|
794
|
+
event.target instanceof HTMLElement &&
|
|
795
|
+
event.target.closest('[data-filter]') &&
|
|
796
|
+
event.target.closest('form .dialog__wrapper > dialog')
|
|
797
|
+
) {
|
|
798
|
+
formSubmit(event);
|
|
799
|
+
} else if (
|
|
800
|
+
event &&
|
|
801
|
+
event.target instanceof HTMLElement &&
|
|
802
|
+
event.target.closest('[data-filter]') &&
|
|
803
|
+
!event.target.closest('form dialog')
|
|
804
|
+
) {
|
|
805
|
+
formSubmit(event);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('[data-show]')) {
|
|
809
|
+
formSubmit(event);
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
form.addEventListener('click', (event) => {
|
|
814
|
+
clearTimeout(timer);
|
|
815
|
+
|
|
816
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('dialog button:not([type="button"])')) {
|
|
817
|
+
const button = event.target.closest('dialog button:not([type="button"])');
|
|
818
|
+
const modal = button.closest('dialog');
|
|
819
|
+
|
|
820
|
+
modal.close();
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// Prevent the form from submitting
|
|
824
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('.dialog__close')) {
|
|
825
|
+
event.preventDefault();
|
|
826
|
+
event.stopPropagation();
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
if (event && event.target instanceof HTMLElement && event.target.closest('[data-clear]')) {
|
|
830
|
+
form.classList.add('processing');
|
|
831
|
+
// Make sure any applied filters have been removed
|
|
832
|
+
Array.from(form.querySelectorAll('.applied-filters')).forEach((filters) => {
|
|
833
|
+
filters.innerHTML = '';
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// Make sure cards are unlicked
|
|
837
|
+
const frm_elements = form.elements;
|
|
838
|
+
|
|
839
|
+
for (let i = 0; i < frm_elements.length; i++) {
|
|
840
|
+
const field_type = frm_elements[i].type.toLowerCase() ? frm_elements[i].type.toLowerCase() : 'text';
|
|
841
|
+
switch (field_type) {
|
|
842
|
+
case 'text':
|
|
843
|
+
case 'password':
|
|
844
|
+
case 'textarea':
|
|
845
|
+
frm_elements[i].value = '';
|
|
846
|
+
break;
|
|
847
|
+
case 'radio':
|
|
848
|
+
case 'checkbox':
|
|
849
|
+
if (frm_elements[i].checked) {
|
|
850
|
+
const input = frm_elements[i];
|
|
851
|
+
const id = input.getAttribute('id');
|
|
852
|
+
const label = document.querySelector(`[for="${id}"`);
|
|
853
|
+
|
|
854
|
+
if (label.querySelector('iam-card')) {
|
|
855
|
+
const card = label.querySelector('iam-card');
|
|
856
|
+
const clickEvent = new Event('click');
|
|
857
|
+
card.dispatchEvent(clickEvent);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
input.checked = false;
|
|
861
|
+
}
|
|
862
|
+
break;
|
|
863
|
+
case 'select-one':
|
|
864
|
+
case 'select-multi':
|
|
865
|
+
frm_elements[i].selectedIndex = -1;
|
|
866
|
+
break;
|
|
867
|
+
case 'hidden':
|
|
868
|
+
default:
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
form.classList.remove('processing');
|
|
874
|
+
|
|
875
|
+
if (!form.hasAttribute('data-submit')) {
|
|
876
|
+
sortTable(table, form, savedTableBody);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
formSubmit(event);
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
form.addEventListener('submit', (event) => {
|
|
884
|
+
clearTimeout(timer);
|
|
885
|
+
|
|
886
|
+
if (!form.hasAttribute('data-submit')) {
|
|
887
|
+
event.preventDefault();
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
formSubmit(event);
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
form.addEventListener('force', (event) => {
|
|
894
|
+
formSubmit(event);
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
form.addEventListener('paginate', (event) => {
|
|
898
|
+
formSubmit(event, true);
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
export const filterTable = (component, table, form, pagination): void => {
|
|
904
|
+
table.classList.remove('table--filtered');
|
|
905
|
+
|
|
906
|
+
const filters = filterFilters(form);
|
|
907
|
+
const searches = [];
|
|
908
|
+
let matched = 0;
|
|
909
|
+
const page = form.querySelector('[data-pagination]') ? parseInt(form.querySelector('[data-pagination]').value) : 1;
|
|
910
|
+
const showRows = form.querySelector('[data-show]') ? parseInt(form.querySelector('[data-show]').value) : 15;
|
|
911
|
+
|
|
912
|
+
// Reset
|
|
913
|
+
Array.from(table.querySelectorAll('tbody tr')).forEach((row) => {
|
|
914
|
+
row.classList.remove('filtered');
|
|
915
|
+
row.classList.remove('filtered--matched');
|
|
916
|
+
row.classList.remove('filtered--show');
|
|
917
|
+
|
|
918
|
+
row.removeAttribute('data-filtered-by');
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
// Add search columns too
|
|
922
|
+
if (form.querySelector('input[data-search]')) {
|
|
923
|
+
const searchInput = form.querySelector('input[data-search]');
|
|
924
|
+
//const searchColumns = form.querySelector('input[data-search],[part="search-input"]').getAttribute('data-search').split(',');
|
|
925
|
+
|
|
926
|
+
table.querySelectorAll('thead tr th').forEach((column) => {
|
|
927
|
+
searches.push({ column: `${column.textContent.trim()}`, value: `${searchInput.value}` });
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
//Display the filter count
|
|
932
|
+
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
933
|
+
element.innerHTML = '';
|
|
934
|
+
element.parentNode.classList.remove('hover');
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
let filterCount = 0;
|
|
938
|
+
Object.values(filters).forEach((filter) => {
|
|
939
|
+
if (typeof filter == 'object' && Object.values(filter).length) {
|
|
940
|
+
filterCount += Object.values(filter).length;
|
|
941
|
+
} else {
|
|
942
|
+
filterCount++;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
if (filterCount) {
|
|
947
|
+
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
948
|
+
element.innerHTML += `(${filterCount})`;
|
|
949
|
+
element.parentNode.classList.add('hover');
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// Filter the table
|
|
954
|
+
table.classList.add('table--filtered');
|
|
955
|
+
for (const [key, filterValue] of Object.entries(filters)) {
|
|
956
|
+
Array.from(table.querySelectorAll('tbody tr:not(.filtered)')).forEach((row) => {
|
|
957
|
+
let isMatched = false;
|
|
958
|
+
filterValue.forEach((filter) => {
|
|
959
|
+
const filterTd = row.querySelector(`[data-label="${key}"]`);
|
|
960
|
+
|
|
961
|
+
if (filter.includes('-date-from')) {
|
|
962
|
+
const fromDate = new Date(filter.replace('-date-from', ''));
|
|
963
|
+
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
964
|
+
|
|
965
|
+
fromDate.setHours(0, 0, 0, 0);
|
|
966
|
+
checkDate.setHours(0, 0, 0, 0);
|
|
967
|
+
|
|
968
|
+
if (checkDate < fromDate) {
|
|
969
|
+
row.classList.add('less-than-from-date');
|
|
970
|
+
isMatched = false;
|
|
971
|
+
} else if (
|
|
972
|
+
!row.classList.contains('less-than-from-date') &&
|
|
973
|
+
!row.classList.contains('greater-than-to-date')
|
|
974
|
+
) {
|
|
975
|
+
isMatched = true;
|
|
976
|
+
}
|
|
977
|
+
} else if (filter.includes('-date-to')) {
|
|
978
|
+
const toDate = new Date(filter.replace('-date-to', ''));
|
|
979
|
+
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
980
|
+
|
|
981
|
+
toDate.setHours(0, 0, 0, 0);
|
|
982
|
+
checkDate.setHours(0, 0, 0, 0);
|
|
983
|
+
|
|
984
|
+
if (checkDate > toDate) {
|
|
985
|
+
row.classList.add('greater-than-to-date');
|
|
986
|
+
isMatched = false;
|
|
987
|
+
} else if (
|
|
988
|
+
!row.classList.contains('less-than-from-date') &&
|
|
989
|
+
!row.classList.contains('greater-than-to-date')
|
|
990
|
+
) {
|
|
991
|
+
isMatched = true;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// Dynamic values
|
|
996
|
+
if (filter && filter == '$today') {
|
|
997
|
+
filter = formatCell('date', new Date());
|
|
998
|
+
} else if (filter && filter == '$yesterday') {
|
|
999
|
+
const yesterday = new Date();
|
|
1000
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
1001
|
+
filter = formatCell('date', yesterday);
|
|
1002
|
+
} else if (filter && (filter == '$thisWeek' || filter == '$lastWeek')) {
|
|
1003
|
+
const today = new Date();
|
|
1004
|
+
const mondayThisWeek = new Date(today.setDate(today.getDate() - (today.getDay() - 1)));
|
|
1005
|
+
const sundayThisWeek = new Date(today.setDate(today.getDate() - today.getDay() + 7));
|
|
1006
|
+
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
1007
|
+
|
|
1008
|
+
today.setHours(0, 0, 0, 0);
|
|
1009
|
+
mondayThisWeek.setHours(0, 0, 0, 0);
|
|
1010
|
+
sundayThisWeek.setHours(0, 0, 0, 0);
|
|
1011
|
+
checkDate.setHours(0, 0, 0, 0);
|
|
1012
|
+
|
|
1013
|
+
if (filter == '$thisWeek') {
|
|
1014
|
+
isMatched = checkDate >= mondayThisWeek && checkDate <= sundayThisWeek;
|
|
1015
|
+
} else {
|
|
1016
|
+
const mondayLastWeek = new Date(mondayThisWeek.setDate(mondayThisWeek.getDate() - 7));
|
|
1017
|
+
const sundayLastWeek = new Date(sundayThisWeek.setDate(sundayThisWeek.getDate() - 7));
|
|
1018
|
+
|
|
1019
|
+
mondayLastWeek.setHours(0, 0, 0, 0);
|
|
1020
|
+
sundayLastWeek.setHours(0, 0, 0, 0);
|
|
1021
|
+
|
|
1022
|
+
isMatched = checkDate >= mondayLastWeek && checkDate <= sundayLastWeek;
|
|
1023
|
+
}
|
|
1024
|
+
} else if (filter && filter == '$thisMonth') {
|
|
1025
|
+
const today = new Date(),
|
|
1026
|
+
year = today.getFullYear(),
|
|
1027
|
+
month = today.getMonth();
|
|
1028
|
+
|
|
1029
|
+
const firstDayMonth = new Date(year, month, 1);
|
|
1030
|
+
const lastDayMonth = new Date(year, month + 1, 0);
|
|
1031
|
+
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
1032
|
+
|
|
1033
|
+
firstDayMonth.setHours(0, 0, 0, 0);
|
|
1034
|
+
lastDayMonth.setHours(0, 0, 0, 0);
|
|
1035
|
+
checkDate.setHours(0, 0, 0, 0);
|
|
1036
|
+
|
|
1037
|
+
isMatched = checkDate >= firstDayMonth && checkDate <= lastDayMonth;
|
|
1038
|
+
} else if (filter && filter == '$lastMonth') {
|
|
1039
|
+
const today = new Date(),
|
|
1040
|
+
year = today.getFullYear(),
|
|
1041
|
+
month = today.getMonth();
|
|
1042
|
+
|
|
1043
|
+
const firstDayLastMonth = new Date(year, month - 1, 1);
|
|
1044
|
+
const lastDayLastMonth = new Date(year, month, 0);
|
|
1045
|
+
const checkDate = new Date(filterTd.textContent.toLowerCase());
|
|
1046
|
+
|
|
1047
|
+
firstDayLastMonth.setHours(0, 0, 0, 0);
|
|
1048
|
+
lastDayLastMonth.setHours(0, 0, 0, 0);
|
|
1049
|
+
checkDate.setHours(0, 0, 0, 0);
|
|
1050
|
+
|
|
1051
|
+
isMatched = checkDate >= firstDayLastMonth && checkDate <= lastDayLastMonth;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
if (filterTd && filterTd.textContent.toLowerCase().includes(filter.replace('-', ' ').toLowerCase())) {
|
|
1055
|
+
isMatched = true;
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
if (!isMatched) {
|
|
1060
|
+
row.classList.add('filtered');
|
|
1061
|
+
row.setAttribute('data-filtered-by', key);
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
// Search whats left of the table after filtering
|
|
1066
|
+
Array.from(table.querySelectorAll('tbody tr:not(.filtered)')).forEach((row) => {
|
|
1067
|
+
let isSearched = searches.length > 0 && searches[0].value.length >= 3 ? false : true;
|
|
1068
|
+
|
|
1069
|
+
searches.forEach((search) => {
|
|
1070
|
+
const searchTd = row.querySelector(`[data-label="${search.column}"]`);
|
|
1071
|
+
|
|
1072
|
+
if (
|
|
1073
|
+
searchTd &&
|
|
1074
|
+
search.value.length >= 3 &&
|
|
1075
|
+
searchTd.textContent.toLowerCase().includes(search.value.toLowerCase())
|
|
1076
|
+
) {
|
|
1077
|
+
isSearched = true;
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
if (!isSearched) {
|
|
1082
|
+
row.classList.add('filtered');
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
// Work out what to display after pagination
|
|
1087
|
+
Array.from(table.querySelectorAll('tbody tr:not(.filtered)')).forEach((row) => {
|
|
1088
|
+
matched++;
|
|
1089
|
+
|
|
1090
|
+
row.classList.add('filtered--matched');
|
|
1091
|
+
|
|
1092
|
+
// pagination bit
|
|
1093
|
+
const matchesPage = Math.ceil(matched / showRows);
|
|
1094
|
+
if (matchesPage == parseInt(page)) {
|
|
1095
|
+
row.classList.add('filtered--show');
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
if (pagination) {
|
|
1100
|
+
pagination.setAttribute('data-total', matched);
|
|
1101
|
+
pagination.setAttribute('data-show', showRows);
|
|
1102
|
+
pagination.setAttribute('data-page', page);
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
export const populateDataQueries = (component, table, form): void | boolean => {
|
|
1107
|
+
const dataQueries = Array.from(form.querySelectorAll('[data-query]'));
|
|
1108
|
+
|
|
1109
|
+
dataQueries.forEach((queryElement) => {
|
|
1110
|
+
const query = queryElement.getAttribute('data-query');
|
|
1111
|
+
let numberOfMatchedRows = 0;
|
|
1112
|
+
|
|
1113
|
+
if (query == 'total') {
|
|
1114
|
+
if (component.hasAttribute('data-total')) numberOfMatchedRows = component.getAttribute('data-total');
|
|
1115
|
+
else
|
|
1116
|
+
numberOfMatchedRows = table.classList.contains('table--filtered')
|
|
1117
|
+
? table.querySelectorAll('tbody tr').length
|
|
1118
|
+
: table.querySelectorAll('tbody tr').length;
|
|
1119
|
+
} else if (!query.includes(' == ') && query.includes(' & ')) {
|
|
1120
|
+
const queries = query.split(' & ');
|
|
1121
|
+
let selector = '';
|
|
1122
|
+
|
|
1123
|
+
queries.forEach((element) => {
|
|
1124
|
+
selector += `:not([data-filtered-by="${element}"])`;
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
numberOfMatchedRows = Array.from(table.querySelectorAll(`tbody tr${selector}`)).length;
|
|
1128
|
+
} else if (!query.includes(' == ')) {
|
|
1129
|
+
numberOfMatchedRows = Array.from(table.querySelectorAll(`tbody tr:not([data-filtered-by="${query}"])`)).length;
|
|
1130
|
+
} else if (query.includes(' && ')) {
|
|
1131
|
+
const queries = query.split(' && ');
|
|
1132
|
+
|
|
1133
|
+
numberOfMatchedRows = Array.from(table.querySelectorAll(`tbody tr:not(.filtered)`)).filter(function (row) {
|
|
1134
|
+
let matched = true;
|
|
1135
|
+
|
|
1136
|
+
for (const value of Object.entries(queries)) {
|
|
1137
|
+
const queryParts = value.split(' == ');
|
|
1138
|
+
|
|
1139
|
+
if (
|
|
1140
|
+
!row.querySelector(`td[data-label="${queryParts[0]}"]`) ||
|
|
1141
|
+
row.querySelector(`td[data-label="${queryParts[0]}"]`).textContent != `${queryParts[1]}`
|
|
1142
|
+
)
|
|
1143
|
+
matched = false;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
return matched;
|
|
1147
|
+
}).length;
|
|
1148
|
+
} else {
|
|
1149
|
+
const queryParts = query.split(' == ');
|
|
1150
|
+
numberOfMatchedRows = Array.from(
|
|
1151
|
+
table.querySelectorAll(
|
|
1152
|
+
`tbody tr.filtered--matched td[data-label="${queryParts[0]}"], tbody tr[data-filtered-by="${queryParts[0]}"] td[data-label="${queryParts[0]}"]`
|
|
1153
|
+
)
|
|
1154
|
+
).filter(function (element) {
|
|
1155
|
+
return element.textContent === queryParts[1];
|
|
1156
|
+
}).length;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
if (queryElement.hasAttribute('data-total')) {
|
|
1160
|
+
queryElement.setAttribute('data-total', numberOfMatchedRows);
|
|
1161
|
+
} else {
|
|
1162
|
+
queryElement.innerHTML = numberOfMatchedRows;
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
};
|
|
1166
|
+
// #endregion
|
|
1167
|
+
|
|
1168
|
+
export const setupSubmitTable = (component, table, form, pagination): void => {
|
|
1169
|
+
form.setAttribute('method', 'get');
|
|
1170
|
+
|
|
1171
|
+
const actionbar = component.querySelector('iam-actionbar');
|
|
1172
|
+
|
|
1173
|
+
if (actionbar) {
|
|
1174
|
+
actionbar.addEventListener('change', (event) => {
|
|
1175
|
+
form.submit();
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
// #region submit tables functions
|
|
1181
|
+
|
|
1182
|
+
// #endregion
|
|
1183
|
+
|
|
1184
|
+
export const setupAjaxTable = (component, table, form, pagination): void => {
|
|
1185
|
+
loadAjaxTable(component, table, form, pagination);
|
|
1186
|
+
|
|
1187
|
+
const actionbar = component.querySelector('iam-actionbar');
|
|
1188
|
+
|
|
1189
|
+
form.addEventListener('submit', (event) => {
|
|
1190
|
+
|
|
1191
|
+
Array.from(form.querySelectorAll('[data-duplicate]')).forEach((loopElement) => {
|
|
1192
|
+
|
|
1193
|
+
const element = loopElement.tagName == "IAM-INPUT" ? loopElement.querySelector('input') : loopElement;
|
|
1194
|
+
const id = loopElement.getAttribute('data-duplicate');
|
|
1195
|
+
|
|
1196
|
+
if (document.querySelector(`[id="${id}"], [name="${id}"]`)) {
|
|
1197
|
+
|
|
1198
|
+
document.querySelector(`[id="${id}"], [name="${id}"]`).checked = element.checked;
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
loadAjaxTable(component, table, form, pagination);
|
|
1203
|
+
|
|
1204
|
+
event.preventDefault();
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
form.addEventListener('change', (event) => {
|
|
1208
|
+
|
|
1209
|
+
if(!event.target.closest('iam-modal')){
|
|
1210
|
+
|
|
1211
|
+
loadAjaxTable(component, table, form, pagination);
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1215
|
+
// watch hidden fields for change events
|
|
1216
|
+
Array.from(form.querySelectorAll('[type="hidden"]')).forEach((input) => {
|
|
1217
|
+
|
|
1218
|
+
input.addEventListener('change', (event) => {
|
|
1219
|
+
|
|
1220
|
+
loadAjaxTable(component, table, form, pagination);
|
|
1221
|
+
});
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
if (actionbar) {
|
|
1225
|
+
actionbar.addEventListener('change', (event) => {
|
|
1226
|
+
loadAjaxTable(component, table, form, pagination);
|
|
1227
|
+
});
|
|
1228
|
+
|
|
1229
|
+
actionbar.addEventListener('search-submit', (event) => {
|
|
1230
|
+
if (form.querySelector('input[data-search]')) {
|
|
1231
|
+
form.querySelector('input[data-search]').value = event.detail.search;
|
|
1232
|
+
} else {
|
|
1233
|
+
form.insertAdjacentHTML(
|
|
1234
|
+
'beforeend',
|
|
1235
|
+
`<input type="hidden" name="search" data-search="${component.querySelector('iam-actionbar[data-search]').getAttribute('data-search')}" value="${event.detail.search}"/>`
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
const submitEvent = new CustomEvent('search-submit', {
|
|
1240
|
+
detail: event.details,
|
|
1241
|
+
});
|
|
1242
|
+
component.dispatchEvent(submitEvent);
|
|
1243
|
+
|
|
1244
|
+
loadAjaxTable(component, table, form, pagination);
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
};
|
|
1249
|
+
// #region ajax tables functions
|
|
1250
|
+
|
|
1251
|
+
export const loadAjaxTable = async function (component, table, form, pagination): void {
|
|
1252
|
+
// Add actionbar inputs into form
|
|
1253
|
+
if (component.querySelector('iam-actionbar') && !component.querySelector('iam-actionbar').closest('form')) {
|
|
1254
|
+
if (!form.querySelector('.duplicate-actionbar'))
|
|
1255
|
+
form.insertAdjacentHTML(
|
|
1256
|
+
'beforeend',
|
|
1257
|
+
`<div class="duplicate-actionbar" style="visibility: hidden; pointer-events: none; position: absolute;"></div>`
|
|
1258
|
+
);
|
|
1259
|
+
|
|
1260
|
+
form.querySelector('.duplicate-actionbar').innerHTML = component.querySelector('iam-actionbar').innerHTML;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// Add pagination inputs into form
|
|
1264
|
+
if (!form.querySelector('input[name=show]'))
|
|
1265
|
+
form.insertAdjacentHTML(
|
|
1266
|
+
'beforeend',
|
|
1267
|
+
`<input name="show" type="hidden" value="${component.getAttribute('data-show')}" />`
|
|
1268
|
+
);
|
|
1269
|
+
|
|
1270
|
+
if (!form.querySelector('input[name=page]'))
|
|
1271
|
+
form.insertAdjacentHTML(
|
|
1272
|
+
'beforeend',
|
|
1273
|
+
`<input name="page" type="hidden" value="${component.getAttribute('data-page')}" />`
|
|
1274
|
+
);
|
|
1275
|
+
|
|
1276
|
+
form.querySelector('input[name=page]').value = component.getAttribute('data-page');
|
|
1277
|
+
form.querySelector('input[name=show]').value = component.getAttribute('data-show');
|
|
1278
|
+
|
|
1279
|
+
// Construct form data to send to api
|
|
1280
|
+
const formData = new FormData(form);
|
|
1281
|
+
|
|
1282
|
+
formData.set('page_number',formData.get('page')); // Fix for compliance dashbaord
|
|
1283
|
+
|
|
1284
|
+
const queryString = new URLSearchParams(formData).toString();
|
|
1285
|
+
const columns = table.querySelectorAll('thead tr th:not(.expand-button-heading)');
|
|
1286
|
+
const tbody = table.querySelector('tbody');
|
|
1287
|
+
const ajaxURL = form.getAttribute('data-ajax');
|
|
1288
|
+
|
|
1289
|
+
component.classList.add('table--loading');
|
|
1290
|
+
|
|
1291
|
+
// Display the filter count
|
|
1292
|
+
const filters = filterFilters(form);
|
|
1293
|
+
|
|
1294
|
+
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
1295
|
+
element.innerHTML = '';
|
|
1296
|
+
element.parentNode.classList.remove('hover');
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1299
|
+
let filterCount = 0;
|
|
1300
|
+
Object.values(filters).forEach((filter) => {
|
|
1301
|
+
if (typeof filter == 'object' && Object.values(filter).length) filterCount += Object.values(filter).length;
|
|
1302
|
+
else filterCount++;
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
if (filterCount) {
|
|
1306
|
+
Array.from(form.querySelectorAll('[data-filter-count]')).forEach((element) => {
|
|
1307
|
+
element.innerHTML += `(${filterCount})`;
|
|
1308
|
+
element.parentNode.classList.add('hover');
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// Setup controller vars if not already set
|
|
1313
|
+
if (!window.controller) window.controller = [];
|
|
1314
|
+
|
|
1315
|
+
// Abort if controller already present for this url
|
|
1316
|
+
if (window.controller[ajaxURL]) window.controller[ajaxURL].abort();
|
|
1317
|
+
|
|
1318
|
+
// Create a new controller so it can be aborted if new fetch made
|
|
1319
|
+
window.controller[ajaxURL] = new AbortController();
|
|
1320
|
+
const { signal } = controller[ajaxURL];
|
|
1321
|
+
|
|
1322
|
+
// Set loading on the pagination
|
|
1323
|
+
pagination.setAttribute('data-loading', 'true');
|
|
1324
|
+
form.classList.add('processing');
|
|
1325
|
+
|
|
1326
|
+
try {
|
|
1327
|
+
await fetch(ajaxURL + '?' + queryString, {
|
|
1328
|
+
signal: signal,
|
|
1329
|
+
method: 'get',
|
|
1330
|
+
credentials: 'same-origin',
|
|
1331
|
+
headers: new Headers({
|
|
1332
|
+
'Content-Type': 'application/json',
|
|
1333
|
+
Accept: 'application/json',
|
|
1334
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
1335
|
+
}),
|
|
1336
|
+
})
|
|
1337
|
+
.then((response) => response.json())
|
|
1338
|
+
.then((response) => {
|
|
1339
|
+
const schema = component.hasAttribute('data-schema') ? component.getAttribute('data-schema') : 'data';
|
|
1340
|
+
const totalNumberSchema = component.hasAttribute('data-schema-total')
|
|
1341
|
+
? component.getAttribute('data-schema-total')
|
|
1342
|
+
: 'meta.total';
|
|
1343
|
+
const currentPageSchema = component.hasAttribute('data-schema-page')
|
|
1344
|
+
? component.getAttribute('data-schema-page')
|
|
1345
|
+
: 'meta.current_page';
|
|
1346
|
+
|
|
1347
|
+
const totalNumber = resolvePath(response, totalNumberSchema, 15);
|
|
1348
|
+
const currentPage = resolvePath(response, currentPageSchema, 1);
|
|
1349
|
+
const data = resolvePath(response, schema);
|
|
1350
|
+
const emptyMsg = component.hasAttribute('data-empty-msg')
|
|
1351
|
+
? component.getAttribute('data-empty-msg')
|
|
1352
|
+
: 'No results found';
|
|
1353
|
+
|
|
1354
|
+
if (data) {
|
|
1355
|
+
tbody.innerHTML = '';
|
|
1356
|
+
|
|
1357
|
+
data.forEach((row) => {
|
|
1358
|
+
const table_row = document.createElement('tr');
|
|
1359
|
+
|
|
1360
|
+
columns.forEach((col) => {
|
|
1361
|
+
let cellOutput = '';
|
|
1362
|
+
const table_cell = document.createElement('td');
|
|
1363
|
+
// Add some data to help with the mobile layout design
|
|
1364
|
+
table_cell.setAttribute('data-label', col.innerText);
|
|
1365
|
+
|
|
1366
|
+
if (col.getAttribute('data-output')) {
|
|
1367
|
+
const cellTemplate = col.getAttribute('data-output');
|
|
1368
|
+
// Use a regex to replace {var} with actual values from the json data
|
|
1369
|
+
cellOutput = cellTemplate.replace(new RegExp(/{(.*?)}/, 'gm'), function (matched) {
|
|
1370
|
+
return resolvePath(row, matched.replace('{', '').replace('}', ''));
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// If an output array is defined then the content is going to made of of multiple values from an array
|
|
1375
|
+
if (col.hasAttribute('data-output-array')) {
|
|
1376
|
+
const cellTemplate = col.getAttribute('data-output');
|
|
1377
|
+
const arrValue = resolvePath(row, cellTemplate.replace('{', '').replace('}', ''));
|
|
1378
|
+
|
|
1379
|
+
cellOutput = '';
|
|
1380
|
+
arrValue.forEach((rowValue) => {
|
|
1381
|
+
const cellTemplateValue = col.getAttribute('data-output-array');
|
|
1382
|
+
let cellOutputValue = '';
|
|
1383
|
+
|
|
1384
|
+
// If we need to transform some of the data
|
|
1385
|
+
if (
|
|
1386
|
+
col.hasAttribute('data-output-array-property') &&
|
|
1387
|
+
col.hasAttribute('data-output-array-transform')
|
|
1388
|
+
) {
|
|
1389
|
+
const propertyValue = resolvePath(rowValue, col.getAttribute('data-output-array-property'));
|
|
1390
|
+
const transforms = JSON.parse(col.getAttribute('data-output-array-transform'));
|
|
1391
|
+
const transformValue = transforms[propertyValue];
|
|
1392
|
+
|
|
1393
|
+
cellOutputValue = cellTemplateValue.replace(
|
|
1394
|
+
`{${col.getAttribute('data-output-array-property')}}`,
|
|
1395
|
+
transformValue
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
cellOutputValue = cellOutputValue.replace(new RegExp(/{(.*?)}/, 'gm'), function (matched) {
|
|
1400
|
+
return resolvePath(rowValue, matched.replace('{', '').replace('}', ''));
|
|
1401
|
+
});
|
|
1402
|
+
cellOutput += cellOutputValue;
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
if (col.hasAttribute('data-transform')) {
|
|
1407
|
+
const transforms = JSON.parse(col.getAttribute('data-transform'));
|
|
1408
|
+
cellOutput = transforms[cellOutput];
|
|
1409
|
+
|
|
1410
|
+
if (!cellOutput && col.hasAttribute('data-default')) cellOutput = col.getAttribute('data-default');
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
table_cell.innerHTML = cellOutput;
|
|
1414
|
+
table_row.appendChild(table_cell);
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
tbody.appendChild(table_row);
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1420
|
+
component.setAttribute('data-total', parseInt(totalNumber));
|
|
1421
|
+
//component.setAttribute('data-page', parseInt(currentPage));
|
|
1422
|
+
|
|
1423
|
+
//pagination.setAttribute('data-total', totalNumber);
|
|
1424
|
+
//pagination.setAttribute('data-page', currentPage);
|
|
1425
|
+
|
|
1426
|
+
Array.from(form.querySelectorAll('[data-ajax-query]')).forEach((queryElement) => {
|
|
1427
|
+
const totalNumber = resolvePath(response, queryElement.getAttribute('data-ajax-query'), '');
|
|
1428
|
+
|
|
1429
|
+
if (queryElement.hasAttribute('data-total')) queryElement.setAttribute('data-total', totalNumber);
|
|
1430
|
+
else queryElement.innerHTML = totalNumber;
|
|
1431
|
+
});
|
|
1432
|
+
|
|
1433
|
+
if (parseInt(totalNumber) == 0) {
|
|
1434
|
+
tbody.innerHTML = `<tr><td colspan="100%"><span>${emptyMsg}</span></td></tr>`;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
component.classList.remove('table--loading');
|
|
1438
|
+
|
|
1439
|
+
window.dataLayer = window.dataLayer || [];
|
|
1440
|
+
window.dataLayer.push({
|
|
1441
|
+
event: 'Ajax table loaded',
|
|
1442
|
+
url: ajaxURL,
|
|
1443
|
+
formData: queryString,
|
|
1444
|
+
});
|
|
1445
|
+
|
|
1446
|
+
setupBasicTable(component, table, form, pagination);
|
|
1447
|
+
setupAdvancedTable(component, table, form, pagination);
|
|
1448
|
+
} else {
|
|
1449
|
+
tbody.innerHTML = '<tr><td colspan="100%"><span>Error loading table</span></td></tr>';
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
// Remove loading on the pagination
|
|
1453
|
+
pagination.removeAttribute('data-loading');
|
|
1454
|
+
form.classList.remove('processing');
|
|
1455
|
+
});
|
|
1456
|
+
} catch (error) {
|
|
1457
|
+
console.log(error);
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
// #endregion
|
|
1461
|
+
|
|
1462
|
+
/*
|
|
1463
|
+
// Pagination - still needed?
|
|
1464
|
+
export const addPaginationEventListeners = function (component, table, form, pagination): void | boolean {
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
pagination.addEventListener('update-page', (event) => {
|
|
1468
|
+
const paginationInput = form.querySelector('[data-pagination]');
|
|
1469
|
+
const newPage = event.detail.page;
|
|
1470
|
+
|
|
1471
|
+
// Set the filter value
|
|
1472
|
+
paginationInput.value = newPage;
|
|
1473
|
+
form.dispatchEvent(new Event('paginate'));
|
|
1474
|
+
|
|
1475
|
+
// Reset the data attribute
|
|
1476
|
+
component.setAttribute('data-page', newPage);
|
|
1477
|
+
|
|
1478
|
+
if (table.hasAttribute('data-show-history')) {
|
|
1479
|
+
const url = new URL(location);
|
|
1480
|
+
url.searchParams.set('page', newPage);
|
|
1481
|
+
history.pushState({ type: 'pagination', form: form.getAttribute('id'), page: newPage }, '', url);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// scroll back to the top of the table
|
|
1485
|
+
if (!component.hasAttribute('data-no-scroll')) {
|
|
1486
|
+
const yOffset = -250;
|
|
1487
|
+
const y = table.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
|
1488
|
+
window.scrollTo({ top: y, behavior: 'smooth' });
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1492
|
+
pagination.addEventListener('update-show', (event) => {
|
|
1493
|
+
const showInput = form.querySelector('[data-show]');
|
|
1494
|
+
const showRows = event.detail.show;
|
|
1495
|
+
showInput.value = showRows;
|
|
1496
|
+
component.setAttribute('data-show', showRows);
|
|
1497
|
+
form.dispatchEvent(new Event('submit'));
|
|
1498
|
+
});
|
|
1499
|
+
};
|
|
1500
|
+
*/
|