PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.11.1
Independent Analytics – WordPress Analytics Plugin v2.11.1
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / javascript-source / controllers / reset_overview_controller.js
reset_overview_controller.js
63 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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() === "reset overview report"
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("reset-overview-modal")
29 }
30
31 close(e) {
32 if(e.target !== e.currentTarget) {
33 return
34 }
35
36 MicroModal.close("reset-overview-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.reset_overview,
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 MicroModal.close("reset-overview-modal")
59 this.submitTarget.classList.remove('sent')
60 }, 1000)
61 })
62 }
63 }