| 1 |
jQuery( document ).ready( function ( $ ) { |
| 2 |
$( '#ef-post_following_users_box ul' ).listFilterizer(); |
| 3 |
|
| 4 |
const params = { |
| 5 |
action: 'save_notifications', |
| 6 |
post_id: $( '#post_ID' ).val(), |
| 7 |
}; |
| 8 |
|
| 9 |
const toggle_warning_badges = function ( container, response ) { |
| 10 |
// Remove any existing badges |
| 11 |
if ( $( container ).siblings( 'span' ).length ) { |
| 12 |
$( container ).siblings( 'span' ).remove(); |
| 13 |
} |
| 14 |
|
| 15 |
// "No Access" If this user was flagged as not having access |
| 16 |
const user_has_no_access = response.data.subscribers_with_no_access.includes( |
| 17 |
parseInt( $( container ).val() ) |
| 18 |
); |
| 19 |
if ( user_has_no_access ) { |
| 20 |
var span = $( '<span />' ).addClass( 'post_following_list-no_access' ); |
| 21 |
span.text( ef_notifications_localization.no_access ); |
| 22 |
$( container ).parent().prepend( span ); |
| 23 |
warning_background = true; |
| 24 |
} |
| 25 |
// "No Email" If this user was flagged as not having an email |
| 26 |
const user_has_no_email = response.data.subscribers_with_no_email.includes( |
| 27 |
parseInt( $( container ).val() ) |
| 28 |
); |
| 29 |
if ( user_has_no_email ) { |
| 30 |
var span = $( '<span />' ).addClass( 'post_following_list-no_email' ); |
| 31 |
span.text( ef_notifications_localization.no_email ); |
| 32 |
$( container ).parent().prepend( span ); |
| 33 |
warning_background = true; |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
$( document ).on( |
| 38 |
'click', |
| 39 |
'.ef-post_following_list li input:checkbox, .ef-following_usergroups li input:checkbox', |
| 40 |
function () { |
| 41 |
const user_group_ids = []; |
| 42 |
const parent_this = $( this ); |
| 43 |
params.ef_notifications_name = $( this ).attr( 'name' ); |
| 44 |
params._nonce = $( '#ef_notifications_nonce' ).val(); |
| 45 |
|
| 46 |
$( this ) |
| 47 |
.parents( '.ef-post_following_list' ) |
| 48 |
.find( 'input:checked' ) |
| 49 |
.map( function () { |
| 50 |
user_group_ids.push( $( this ).val() ); |
| 51 |
} ); |
| 52 |
|
| 53 |
params.user_group_ids = user_group_ids; |
| 54 |
|
| 55 |
$.ajax( { |
| 56 |
type: 'POST', |
| 57 |
url: ajaxurl ? ajaxurl : wpListL10n.url, |
| 58 |
data: params, |
| 59 |
|
| 60 |
success( response ) { |
| 61 |
// Reset background color (set during toggle_warning_badges if there's a warning) |
| 62 |
warning_background = false; |
| 63 |
|
| 64 |
// Toggle the warning badges ("No Access" and "No Email") to signal the user won't receive notifications |
| 65 |
if ( undefined !== response.data ) { |
| 66 |
toggle_warning_badges( $( parent_this ), response ); |
| 67 |
} |
| 68 |
// Green 40% by default |
| 69 |
var backgroundHighlightColor = '#90d296'; |
| 70 |
if ( warning_background ) { |
| 71 |
// Red 40% if there's a warning |
| 72 |
var backgroundHighlightColor = '#ea8484'; |
| 73 |
} |
| 74 |
const backgroundColor = parent_this.css( 'background-color' ); |
| 75 |
$( parent_this.parents( 'li' ) ) |
| 76 |
.animate( { backgroundColor: backgroundHighlightColor }, 200 ) |
| 77 |
.animate( { backgroundColor }, 200 ); |
| 78 |
|
| 79 |
// This event is used to show an updated list of who will be notified of editorial comments and status updates. |
| 80 |
$( '#ef-post_following_box' ).trigger( 'following_list_updated' ); |
| 81 |
}, |
| 82 |
error( r ) { |
| 83 |
$( '#ef-post_following_users_box' ) |
| 84 |
.prev() |
| 85 |
.append( ' <p class="error">There was an error. Please reload the page.</p>' ); |
| 86 |
}, |
| 87 |
} ); |
| 88 |
} |
| 89 |
); |
| 90 |
} ); |
| 91 |
|