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
refresh_overview_controller.js
57 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | |
| 3 | export default class extends Controller { |
| 4 | static values = { |
| 5 | loadingText: String |
| 6 | } |
| 7 | |
| 8 | refresh() { |
| 9 | const data = { |
| 10 | ...iawpActions.refresh_modules |
| 11 | } |
| 12 | |
| 13 | const originalText = this.element.innerText |
| 14 | this.element.innerText = this.loadingTextValue |
| 15 | this.element.setAttribute('disabled', 'disabled') |
| 16 | this.fadeOutModules() |
| 17 | |
| 18 | jQuery.post(ajaxurl, data, (response) => { |
| 19 | this.element.innerText = originalText |
| 20 | this.element.removeAttribute('disabled') |
| 21 | response.data.modules.forEach(module => this.replaceModule(module.id, module.html)) |
| 22 | document.getElementById('iawp-modules-refreshed-at').innerText = response.data.modulesRefreshedAt |
| 23 | }).fail((error) => { |
| 24 | this.element.innerText = originalText |
| 25 | this.element.removeAttribute('disabled') |
| 26 | }) |
| 27 | } |
| 28 | |
| 29 | fadeOutModules() { |
| 30 | const elements = Array.from(document.querySelectorAll('.module:not(.module-picker)')) |
| 31 | |
| 32 | elements.forEach((element) => { |
| 33 | element.classList.add('will-be-refreshed') |
| 34 | // element.querySelector('[popover]').hidePopover() |
| 35 | // element.querySelector('[popovertarget]').setAttribute('disabled', 'disabled') |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | replaceModule(moduleId, html) { |
| 40 | const elementToReplace = document.querySelector(`[data-module-module-id-value="${moduleId}"]`) |
| 41 | |
| 42 | if(!elementToReplace) { |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | const isDraggable = elementToReplace.classList.contains('draggable-module') |
| 47 | elementToReplace.outerHTML = html |
| 48 | |
| 49 | // Update the new module with whatever draggable state the replaced module had |
| 50 | setTimeout(() => { |
| 51 | const module = document.querySelector(`[data-module-module-id-value="${moduleId}"]`) |
| 52 | if(module) { |
| 53 | module.classList.toggle('draggable-module', isDraggable) |
| 54 | } |
| 55 | }, 0) |
| 56 | } |
| 57 | } |