Files

41 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

/* global ajaxurl, jQuery */
( function ( $ ) {
'use strict';
$( document ).on( 'click', '.woolist-manual-subscribe-btn', function () {
var $btn = $( this );
var $box = $btn.closest( '.woolist-metabox-wrap' );
var $resp = $box.find( '.woolist-metabox-response' );
var listId = $box.find( '.woolist-list-select' ).val();
$resp.hide().removeClass( 'woolist-mb-success woolist-mb-error' ).html( '' );
$btn.prop( 'disabled', true ).text( 'Subscribing\u2026' );
$.ajax( {
url: ajaxurl,
method: 'POST',
data: {
action: 'woolist_manual_subscribe',
nonce: $btn.data( 'nonce' ),
order_id: $btn.data( 'order-id' ),
list_id: listId,
},
} )
.done( function ( response ) {
if ( response.success ) {
$resp.addClass( 'woolist-mb-success' ).html( '✓ ' + response.data.message );
} else {
$resp.addClass( 'woolist-mb-error' ).html( '✗ ' + response.data.message );
}
$resp.show();
} )
.fail( function () {
$resp.addClass( 'woolist-mb-error' ).html( '✗ Request failed.' ).show();
} )
.always( function () {
$btn.prop( 'disabled', false ).text( 'Add to phpList' );
} );
} );
} )( jQuery );