campaign_builder_controller.js
2 years ago
chart_controller.js
1 year ago
chart_geo_controller.js
2 years ago
chart_interval_controller.js
2 years ago
clipboard_controller.js
2 years ago
copy_report_controller.js
2 years ago
create_report_controller.js
2 years ago
delete_data_controller.js
2 years ago
delete_report_controller.js
2 years ago
easepick_controller.js
2 years ago
export_reports_controller.js
2 years ago
filters_controller.js
1 year ago
group_controller.js
2 years ago
import_reports_controller.js
2 years ago
migration_redirect_controller.js
2 years ago
modal_controller.js
2 years ago
plugin_group_options_controller.js
1 year ago
pruner_controller.js
1 year ago
quick_stats_controller.js
2 years ago
real_time_controller.js
2 years ago
rename_report_controller.js
2 years ago
report_controller.js
1 year ago
reset_analytics_controller.js
2 years 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
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 | } |