addon-box.js
3 months ago
addons.css
1 month ago
backup-adstxt.js
3 months ago
dashboard.css
3 months ago
index.js
3 months ago
oneclick.css
3 months ago
spinner.css
3 months ago
subscribe.js
3 months ago
welcome.js
3 months ago
subscribe.js
53 lines
| 1 | export default function () { |
| 2 | document |
| 3 | .querySelectorAll( '.advads-multiple-subscribe_button' ) |
| 4 | .forEach( ( button ) => { |
| 5 | button.addEventListener( 'click', function () { |
| 6 | const parent = button.closest( '.advads-multiple-subscribe' ); |
| 7 | const groups = Array.from( |
| 8 | parent.querySelectorAll( |
| 9 | 'input[name="advads-multiple-subscribe"]:checked' |
| 10 | ) |
| 11 | ).map( function ( input ) { |
| 12 | return input.value; |
| 13 | } ); |
| 14 | |
| 15 | if ( groups.length === 0 ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | const spinner = document.createElement( 'span' ); |
| 20 | spinner.className = 'spinner advads-spinner'; |
| 21 | button.insertAdjacentElement( 'afterend', spinner ); |
| 22 | |
| 23 | const formData = new FormData(); |
| 24 | formData.append( 'action', 'advads-multiple-subscribe' ); |
| 25 | formData.append( 'groups', JSON.stringify( groups ) ); |
| 26 | formData.append( 'nonce', advadsglobal.ajax_nonce ); |
| 27 | |
| 28 | fetch( ajaxurl, { |
| 29 | method: 'POST', |
| 30 | body: formData, |
| 31 | } ) |
| 32 | .then( ( response ) => response.json() ) |
| 33 | .then( ( response ) => { |
| 34 | button.style.display = 'none'; |
| 35 | const message = document.createElement( 'p' ); |
| 36 | message.innerHTML = response.data.message; |
| 37 | parent.innerHTML = ''; |
| 38 | parent.appendChild( message ); |
| 39 | parent.classList.add( 'notice-success', 'notice' ); |
| 40 | } ) |
| 41 | .catch( ( error ) => { |
| 42 | const message = document.createElement( 'p' ); |
| 43 | message.innerHTML = |
| 44 | error.responseJSON?.data?.message || |
| 45 | 'An error occurred'; |
| 46 | parent.innerHTML = ''; |
| 47 | parent.appendChild( message ); |
| 48 | parent.classList.add( 'notice-error', 'notice' ); |
| 49 | } ); |
| 50 | } ); |
| 51 | } ); |
| 52 | } |
| 53 |