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
delete_data_controller.js
64 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | import MicroModal from "micromodal" |
| 3 | |
| 4 | document.addEventListener("DOMContentLoaded", () => MicroModal.init()) |
| 5 | |
| 6 | export default class extends Controller { |
| 7 | static values = { |
| 8 | confirmation: String |
| 9 | } |
| 10 | static targets = ["submit", "input"] |
| 11 | |
| 12 | isValidConfirmation(confirmationValue) { |
| 13 | return confirmationValue.toLowerCase() === "delete all data" |
| 14 | } |
| 15 | |
| 16 | confirmationValueChanged(confirmationValue) { |
| 17 | this.inputTarget.value = confirmationValue |
| 18 | const disable = !this.isValidConfirmation(confirmationValue) |
| 19 | this.submitTarget.toggleAttribute("disabled", disable) |
| 20 | } |
| 21 | |
| 22 | updateConfirmation(e) { |
| 23 | this.confirmationValue = e.target.value |
| 24 | } |
| 25 | |
| 26 | open() { |
| 27 | this.confirmationValue = "" |
| 28 | MicroModal.show("delete-data-modal") |
| 29 | } |
| 30 | |
| 31 | close(e) { |
| 32 | if(e.target !== e.currentTarget) { |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | MicroModal.close("delete-data-modal") |
| 37 | } |
| 38 | |
| 39 | submit(e) { |
| 40 | e.preventDefault() |
| 41 | |
| 42 | if (!this.isValidConfirmation(this.confirmationValue)) { |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | const data = { |
| 47 | ...iawpActions.delete_data, |
| 48 | confirmation: this.confirmationValue |
| 49 | } |
| 50 | |
| 51 | this.submitTarget.setAttribute('disabled', 'disabled') |
| 52 | this.submitTarget.classList.add('sending') |
| 53 | |
| 54 | jQuery.post(ajaxurl, data, (response) => { |
| 55 | this.submitTarget.classList.remove('sending') |
| 56 | this.submitTarget.classList.add('sent') |
| 57 | setTimeout(() => { |
| 58 | document.location = response.data.redirectUrl |
| 59 | this.submitTarget.classList.remove('sent') |
| 60 | }, 1000) |
| 61 | }) |
| 62 | |
| 63 | } |
| 64 | } |