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
campaign_builder_controller.js
78 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | |
| 3 | export default class extends Controller { |
| 4 | static targets = ['form', 'submitButton', 'newCampaign'] |
| 5 | |
| 6 | submit(e) { |
| 7 | e.preventDefault(); |
| 8 | |
| 9 | const data = { |
| 10 | ...iawpActions.create_campaign, |
| 11 | 'path': this.formTarget.elements['path'].value, |
| 12 | 'utm_source': this.formTarget.elements['utm_source'].value, |
| 13 | 'utm_medium': this.formTarget.elements['utm_medium'].value, |
| 14 | 'utm_campaign': this.formTarget.elements['utm_campaign'].value, |
| 15 | 'utm_term': this.formTarget.elements['utm_term'].value, |
| 16 | 'utm_content': this.formTarget.elements['utm_content'].value, |
| 17 | }; |
| 18 | this.submitButtonTarget.setAttribute('disabled', 'disabled') |
| 19 | this.submitButtonTarget.classList.add('sending'); |
| 20 | jQuery.post(ajaxurl, data, (response) => { |
| 21 | this.submitButtonTarget.removeAttribute('disabled'); |
| 22 | this.submitButtonTarget.classList.remove('sending'); |
| 23 | this.element.outerHTML = response.data.html |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | reuse(e) { |
| 28 | try { |
| 29 | this.newCampaignTarget.remove() |
| 30 | } catch (e) { |
| 31 | // Do nothing if the element isn't there |
| 32 | } |
| 33 | const data = JSON.parse(e.target.dataset.result) |
| 34 | |
| 35 | Object.keys(this.formTarget.elements).forEach((elementName) => { |
| 36 | // Remove the error class from the input |
| 37 | this.formTarget.elements[elementName].classList.remove('error') |
| 38 | // Remove any sibling with error class |
| 39 | this.formTarget.elements[elementName].parentElement.querySelectorAll('p.error').forEach((element) => { |
| 40 | element.remove() |
| 41 | }) |
| 42 | }) |
| 43 | |
| 44 | // Iterate over all fields in object and populate matching input |
| 45 | Object.keys(data).forEach((key) => { |
| 46 | if (this.formTarget.elements[key]) { |
| 47 | this.formTarget.elements[key].value = data[key] |
| 48 | } |
| 49 | }) |
| 50 | this.formTarget.parentElement.scrollIntoView({behavior: 'smooth'}) |
| 51 | } |
| 52 | |
| 53 | delete(e) { |
| 54 | e.preventDefault(); |
| 55 | |
| 56 | const data = { |
| 57 | ...iawpActions.delete_campaign, |
| 58 | 'campaign_url_id': e.target.dataset.campaignUrlId |
| 59 | }; |
| 60 | |
| 61 | e.target.setAttribute('disabled', 'disabled') |
| 62 | e.target.classList.add('sending') |
| 63 | |
| 64 | jQuery.post(ajaxurl, data, (response) => { |
| 65 | e.target.removeAttribute('disabled'); |
| 66 | e.target.classList.add('sent') |
| 67 | e.target.classList.remove('sending') |
| 68 | |
| 69 | setTimeout(() => { |
| 70 | e.target.closest('.campaign').classList.add('removing') |
| 71 | }, 500) |
| 72 | |
| 73 | setTimeout(() => { |
| 74 | e.target.closest('.campaign').remove() |
| 75 | }, 1000) |
| 76 | }); |
| 77 | } |
| 78 | } |