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
rename_report_controller.js
83 lines
| 1 | import {Controller} from "@hotwired/stimulus" |
| 2 | |
| 3 | export default class extends Controller { |
| 4 | static targets = ['modal', 'modalButton', 'renameButton', 'input'] |
| 5 | |
| 6 | static values = { |
| 7 | id: String, |
| 8 | name: String |
| 9 | } |
| 10 | |
| 11 | connect() { |
| 12 | document.addEventListener('click', this.maybeClose) |
| 13 | } |
| 14 | |
| 15 | disconnect() { |
| 16 | document.removeEventListener('click', this.maybeClose) |
| 17 | } |
| 18 | |
| 19 | maybeClose = (event) => { |
| 20 | const isOpen = this.modalTarget.classList.contains('show') |
| 21 | const isInComponent = this.element.contains(event.target) |
| 22 | |
| 23 | |
| 24 | if (isOpen && !isInComponent) { |
| 25 | this.closeModal() |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | toggleModal(e) { |
| 30 | e.preventDefault(); |
| 31 | const isOpen = this.modalTarget.classList.contains('show') |
| 32 | isOpen ? this.closeModal() : this.openModal() |
| 33 | } |
| 34 | |
| 35 | openModal() { |
| 36 | this.inputTarget.value = this.nameValue |
| 37 | this.modalTarget.classList.add('show') |
| 38 | this.modalButtonTarget.classList.add('open') |
| 39 | document.getElementById('iawp-layout').classList.add('modal-open'); |
| 40 | setTimeout(() => { |
| 41 | this.inputTarget.focus() |
| 42 | this.inputTarget.select() |
| 43 | }, 200) |
| 44 | } |
| 45 | |
| 46 | closeModal() { |
| 47 | this.modalTarget.classList.remove('show') |
| 48 | this.modalButtonTarget.classList.remove('open') |
| 49 | document.getElementById('iawp-layout').classList.remove('modal-open'); |
| 50 | } |
| 51 | |
| 52 | rename(e) { |
| 53 | e.preventDefault() |
| 54 | |
| 55 | const name = this.inputTarget.value.trim() |
| 56 | const data = { |
| 57 | ...iawpActions.rename_report, |
| 58 | id: this.idValue, |
| 59 | name |
| 60 | }; |
| 61 | |
| 62 | if(name.length === 0) { |
| 63 | this.inputTarget.value = ''; |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | this.renameButtonTarget.setAttribute('disabled', 'disabled') |
| 68 | this.renameButtonTarget.classList.add('sending') |
| 69 | jQuery.post(ajaxurl, data, (response) => { |
| 70 | this.renameButtonTarget.classList.remove('sending') |
| 71 | this.renameButtonTarget.classList.add('sent') |
| 72 | this.renameButtonTarget.classList.remove('sent') |
| 73 | this.renameButtonTarget.removeAttribute('disabled'); |
| 74 | this.closeModal() |
| 75 | this.nameValue = response.data.name |
| 76 | Array.from(document.querySelectorAll('[data-name-for-report-id="' + this.idValue + '"]')).forEach((element) => { |
| 77 | element.innerText = response.data.name |
| 78 | }) |
| 79 | }).fail(() => { |
| 80 | |
| 81 | }) |
| 82 | } |
| 83 | } |