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
pruner_controller.js
96 lines
| 1 | import { Controller } from "@hotwired/stimulus"; |
| 2 | import MicroModal from "micromodal"; |
| 3 | |
| 4 | export default class extends Controller { |
| 5 | static targets = ["cutoffs", "saveButton", "confirmButton", "statusMessage", "confirmationText"]; |
| 6 | |
| 7 | isModalActuallyOpen = false; |
| 8 | |
| 9 | saveClick() { |
| 10 | this.actuallySave(false); |
| 11 | } |
| 12 | |
| 13 | async confirmClick() { |
| 14 | this.confirmButtonTarget.setAttribute("disabled", "disabled"); |
| 15 | this.confirmButtonTarget.innerText = this.confirmButtonTarget.dataset.loadingText; |
| 16 | |
| 17 | await this.actuallySave(true); |
| 18 | |
| 19 | this.confirmButtonTarget.removeAttribute("disabled"); |
| 20 | this.confirmButtonTarget.innerText = this.confirmButtonTarget.dataset.originalText; |
| 21 | |
| 22 | this.hideConfirmationModal(); |
| 23 | } |
| 24 | |
| 25 | selectChanged() { |
| 26 | this.saveButtonTarget.removeAttribute("disabled"); |
| 27 | } |
| 28 | |
| 29 | cancelConfirmation(e) { |
| 30 | if (e && e.target !== e.currentTarget) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | this.hideConfirmationModal(); |
| 35 | this.saveButtonTarget.removeAttribute("disabled"); |
| 36 | this.saveButtonTarget.innerText = this.saveButtonTarget.dataset.originalText; |
| 37 | } |
| 38 | |
| 39 | async actuallySave(isConfirmed = false) { |
| 40 | this.saveButtonTarget.setAttribute("disabled", "disabled"); |
| 41 | this.saveButtonTarget.innerText = this.saveButtonTarget.dataset.loadingText; |
| 42 | |
| 43 | const response = await this.sendRequest({ |
| 44 | pruningCutoff: this.cutoffsTarget.value, |
| 45 | isConfirmed: isConfirmed, |
| 46 | }); |
| 47 | |
| 48 | if (!response.wasSuccessful && response.confirmationText) { |
| 49 | this.showConfirmationModal(response.confirmationText); |
| 50 | } else { |
| 51 | this.statusMessageTarget.classList.toggle("is-scheduled", response.isEnabled); |
| 52 | this.statusMessageTarget.classList.toggle("is-hidden", !response.isEnabled); |
| 53 | this.statusMessageTarget.querySelector("p").innerHTML = response.statusMessage; |
| 54 | |
| 55 | this.saveButtonTarget.removeAttribute("disabled"); |
| 56 | this.saveButtonTarget.innerText = this.saveButtonTarget.dataset.originalText; |
| 57 | this.saveButtonTarget.setAttribute("disabled", "disabled"); |
| 58 | |
| 59 | this.hideConfirmationModal(); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | async sendRequest({ pruningCutoff, isConfirmed }) { |
| 64 | const data = { |
| 65 | ...iawpActions.configure_pruner, |
| 66 | pruningCutoff: pruningCutoff, |
| 67 | isConfirmed: isConfirmed, |
| 68 | }; |
| 69 | const response = await jQuery.post(ajaxurl, data); |
| 70 | |
| 71 | return { |
| 72 | wasSuccessful: response.success, |
| 73 | confirmationText: response.data.confirmationText, |
| 74 | isEnabled: response.data.isEnabled, |
| 75 | statusMessage: response.data.statusMessage, |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | showConfirmationModal = (confirmationText) => { |
| 80 | this.confirmationTextTarget.innerText = confirmationText; |
| 81 | this.isModalActuallyOpen = true; |
| 82 | MicroModal.show("prune-modal", { |
| 83 | onClose: () => { |
| 84 | this.cancelConfirmation(); |
| 85 | }, |
| 86 | }); |
| 87 | }; |
| 88 | |
| 89 | hideConfirmationModal = (e) => { |
| 90 | if (this.isModalActuallyOpen) { |
| 91 | this.isModalActuallyOpen = false; |
| 92 | MicroModal.close("prune-modal"); |
| 93 | } |
| 94 | }; |
| 95 | } |
| 96 |