overview
1 year ago
campaign_builder_controller.js
1 year ago
chart_controller.js
2 months ago
chart_interval_controller.js
2 years ago
clipboard_controller.js
1 year ago
copy_report_controller.js
2 years ago
create_report_controller.js
1 year ago
delete_data_controller.js
1 year ago
delete_report_controller.js
2 years ago
easepick_controller.js
2 years ago
examiner_controller.js
2 months ago
examiner_header_controller.js
11 months ago
export_overview_controller.js
9 months ago
export_reports_controller.js
2 years ago
filters_controller.js
6 months ago
group_controller.js
2 years ago
import_reports_controller.js
2 years ago
journey_controller.js
6 months ago
map_controller.js
9 months ago
migration_redirect_controller.js
2 years ago
modal_controller.js
2 years ago
pause_emails_controller.js
6 months ago
pie_chart_controller.js
6 months ago
plugin_group_options_controller.js
1 year ago
pruner_controller.js
5 months ago
quick_stats_controller.js
1 year ago
real_time_controller.js
6 months ago
refresh_overview_controller.js
1 year ago
rename_report_controller.js
2 years ago
report_controller.js
2 months ago
reset_analytics_controller.js
1 year ago
reset_overview_controller.js
1 year ago
save_report_controller.js
2 years ago
select_input_controller.js
2 years ago
set_favorite_report_controller.js
2 years ago
sort_controller.js
2 years ago
sortable_reports_controller.js
2 years ago
table_columns_controller.js
2 years ago
tooltip_controller.js
6 months ago
woocommerce_settings_controller.js
1 year ago
plugin_group_options_controller.js
108 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | |
| 3 | export default class extends Controller { |
| 4 | static targets = ['modal', 'modalButton', 'checkbox', 'checkboxContainer', 'tab', 'spinner'] |
| 5 | static values = { |
| 6 | optionType: String |
| 7 | } |
| 8 | |
| 9 | connect() { |
| 10 | document.addEventListener('click', this.maybeClose) |
| 11 | document.addEventListener('iawp:fetchingReport', this.onFetchingReport) |
| 12 | } |
| 13 | |
| 14 | disconnect() { |
| 15 | document.removeEventListener('click', this.maybeClose) |
| 16 | document.removeEventListener('iawp:fetchingReport', this.onFetchingReport) |
| 17 | |
| 18 | if(this.modalTarget.classList.contains('show')) { |
| 19 | this.closeModal() |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | onFetchingReport = () => { |
| 24 | const enabledElements = this.element.querySelectorAll('input:not([disabled])') |
| 25 | |
| 26 | enabledElements.forEach(element => element.disabled = true) |
| 27 | this.spinnerTarget.classList.remove('hidden') |
| 28 | |
| 29 | document.addEventListener('iawp:fetchedReport', () => { |
| 30 | enabledElements.forEach(element => element.disabled = false) |
| 31 | this.spinnerTarget.classList.add('hidden') |
| 32 | }, {once: true}) |
| 33 | } |
| 34 | |
| 35 | maybeClose = (event) => { |
| 36 | const isOpen = this.modalTarget.classList.contains('show') |
| 37 | const isInComponent = this.element.contains(event.target) |
| 38 | |
| 39 | |
| 40 | if (isOpen && !isInComponent) { |
| 41 | this.closeModal() |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | toggleModal(e) { |
| 46 | e.preventDefault(); |
| 47 | const isOpen = this.modalTarget.classList.contains('show') |
| 48 | isOpen ? this.closeModal() : this.openModal() |
| 49 | } |
| 50 | |
| 51 | openModal() { |
| 52 | this.modalTarget.classList.add('show') |
| 53 | this.modalButtonTarget.classList.add('open') |
| 54 | document.getElementById('iawp-layout').classList.add('modal-open'); |
| 55 | } |
| 56 | |
| 57 | closeModal() { |
| 58 | this.modalTarget.classList.remove('show') |
| 59 | this.modalButtonTarget.classList.remove('open') |
| 60 | document.getElementById('iawp-layout').classList.remove('modal-open'); |
| 61 | } |
| 62 | |
| 63 | requestGroupChange(e) { |
| 64 | e.preventDefault(); |
| 65 | this.changeGroup(e.currentTarget.dataset.optionId) |
| 66 | } |
| 67 | |
| 68 | changeGroup(newOptionId) { |
| 69 | this.tabTargets.forEach((element, index) => { |
| 70 | element.classList.toggle('current', element.dataset.optionId === newOptionId) |
| 71 | }) |
| 72 | this.checkboxContainerTargets.forEach((element, index) => { |
| 73 | element.classList.toggle('current', element.dataset.optionId === newOptionId) |
| 74 | }) |
| 75 | } |
| 76 | |
| 77 | toggleOption() { |
| 78 | const checkedCheckboxes = this.checkboxTargets.filter((checkbox) => checkbox.checked) |
| 79 | |
| 80 | this.checkboxTargets.forEach((checkbox) => { |
| 81 | checkbox.setAttribute('data-test-visibility', checkbox.checked ? 'visible' : 'hidden') |
| 82 | checkbox.removeAttribute('disabled') |
| 83 | }) |
| 84 | |
| 85 | // If only one selected, disable it |
| 86 | if (checkedCheckboxes.length === 1) { |
| 87 | checkedCheckboxes.at(0).setAttribute('disabled', 'disabled') |
| 88 | } |
| 89 | |
| 90 | document.dispatchEvent( |
| 91 | new CustomEvent(this.getEventName(), { |
| 92 | detail: { |
| 93 | optionIds: checkedCheckboxes.map(checkbox => checkbox.name) |
| 94 | } |
| 95 | }) |
| 96 | ) |
| 97 | } |
| 98 | |
| 99 | getEventName() { |
| 100 | switch(this.optionTypeValue) { |
| 101 | case 'columns': |
| 102 | return 'iawp:changeColumns' |
| 103 | case 'quick_stats': |
| 104 | return 'iawp:changeQuickStats' |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 |