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
export_reports_controller.js
85 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | import {downloadJSON} from "../download"; |
| 3 | |
| 4 | export default class extends Controller { |
| 5 | static targets = ['selectAllCheckbox', 'submitButton'] |
| 6 | |
| 7 | export() { |
| 8 | this.disableEverything() |
| 9 | this.submitButtonTarget.classList.add('sending') |
| 10 | |
| 11 | const data = { |
| 12 | ...iawpActions.export_reports, |
| 13 | ids: this.getCheckedReportIds() |
| 14 | }; |
| 15 | |
| 16 | jQuery.post(ajaxurl, data, (response) => { |
| 17 | downloadJSON('independent-analytics-reports.json', response.data.json) |
| 18 | this.resetUI() |
| 19 | this.submitButtonTarget.classList.remove('sending') |
| 20 | this.submitButtonTarget.classList.add('sent') |
| 21 | setTimeout(() => { |
| 22 | this.submitButtonTarget.classList.remove('sent') |
| 23 | }, 1000) |
| 24 | }).fail(() => { |
| 25 | this.resetUI() |
| 26 | }) |
| 27 | } |
| 28 | |
| 29 | handleToggleSelectAll(e) { |
| 30 | this.getAllCheckboxes().forEach(checkbox => checkbox.checked = e.target.checked) |
| 31 | this.updateSubmitButton() |
| 32 | } |
| 33 | |
| 34 | handleToggleReport(e) { |
| 35 | if (this.getCheckedCheckboxes().length === this.getAllCheckboxes().length) { |
| 36 | this.selectAllCheckboxTarget.checked = true |
| 37 | } else { |
| 38 | this.selectAllCheckboxTarget.checked = false |
| 39 | } |
| 40 | this.updateSubmitButton() |
| 41 | } |
| 42 | |
| 43 | updateSubmitButton() { |
| 44 | if (this.getCheckedCheckboxes().length === 0) { |
| 45 | this.submitButtonTarget.setAttribute('disabled', 'disabled') |
| 46 | } else { |
| 47 | this.submitButtonTarget.removeAttribute('disabled') |
| 48 | |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | disableEverything() { |
| 53 | this.submitButtonTarget.setAttribute('disabled', 'disabled') |
| 54 | this.selectAllCheckboxTarget.setAttribute('disabled', 'disabled') |
| 55 | this.getAllCheckboxes().forEach((checkbox) => { |
| 56 | checkbox.setAttribute('disabled', 'disabled') |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | resetUI() { |
| 61 | this.submitButtonTarget.setAttribute('disabled', 'disabled') |
| 62 | this.selectAllCheckboxTarget.removeAttribute('disabled') |
| 63 | this.selectAllCheckboxTarget.checked = false |
| 64 | this.getAllCheckboxes().forEach((checkbox) => { |
| 65 | checkbox.removeAttribute('disabled') |
| 66 | checkbox.checked = false |
| 67 | }) |
| 68 | } |
| 69 | |
| 70 | getCheckedReportIds() { |
| 71 | return this.getCheckedCheckboxes().map(checkbox => checkbox.value) |
| 72 | } |
| 73 | |
| 74 | getAllCheckboxes() { |
| 75 | return Array.from( |
| 76 | this.element.querySelectorAll('input[name="report_id"]') |
| 77 | ) |
| 78 | } |
| 79 | |
| 80 | getCheckedCheckboxes() { |
| 81 | return Array.from( |
| 82 | this.element.querySelectorAll('input[name="report_id"]:checked') |
| 83 | ) |
| 84 | } |
| 85 | } |