overview
1 year ago
campaign_builder_controller.js
1 year ago
chart_controller.js
6 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
9 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
6 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
import_reports_controller.js
74 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | import {downloadJSON} from "../download"; |
| 3 | |
| 4 | export default class extends Controller { |
| 5 | static targets = ['submitButton', 'warningMessage', 'fileInput'] |
| 6 | |
| 7 | static values = { |
| 8 | databaseVersion: String |
| 9 | } |
| 10 | |
| 11 | fileData = null |
| 12 | |
| 13 | import() { |
| 14 | this.disableSubmissions() |
| 15 | this.submitButtonTarget.classList.add('sending') |
| 16 | |
| 17 | const data = { |
| 18 | ...iawpActions.import_reports, |
| 19 | json: JSON.stringify(this.fileData) |
| 20 | }; |
| 21 | |
| 22 | jQuery.post(ajaxurl, data, (response) => { |
| 23 | this.clearFileInput() |
| 24 | this.submitButtonTarget.classList.remove('sending') |
| 25 | this.submitButtonTarget.classList.add('sent') |
| 26 | setTimeout(() => { |
| 27 | this.submitButtonTarget.classList.remove('sent') |
| 28 | window.location.reload() |
| 29 | }, 1000) |
| 30 | }).fail(() => { |
| 31 | |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | async handleFileSelected(e) { |
| 36 | const json = await e.target.files[0].text() |
| 37 | const data = JSON.parse(json) |
| 38 | this.fileData = null |
| 39 | this.hideWarning() |
| 40 | this.disableSubmissions() |
| 41 | |
| 42 | if(!data['database_version'] || !Array.isArray(data['reports'])) { |
| 43 | this.showWarning(iawpText.invalidReportArchive) |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | this.enableSubmissions() |
| 48 | this.fileData = data |
| 49 | } |
| 50 | |
| 51 | clearFileInput() { |
| 52 | this.fileData = null; |
| 53 | this.fileInputTarget.value = null |
| 54 | this.hideWarning() |
| 55 | this.disableSubmissions() |
| 56 | } |
| 57 | |
| 58 | showWarning(message) { |
| 59 | this.warningMessageTarget.innerText = message |
| 60 | this.warningMessageTarget.style.display = 'block'; |
| 61 | } |
| 62 | |
| 63 | hideWarning() { |
| 64 | this.warningMessageTarget.style.display = 'none'; |
| 65 | } |
| 66 | |
| 67 | enableSubmissions() { |
| 68 | this.submitButtonTarget.removeAttribute('disabled') |
| 69 | } |
| 70 | |
| 71 | disableSubmissions() { |
| 72 | this.submitButtonTarget.setAttribute('disabled', 'disabled') |
| 73 | } |
| 74 | } |