PluginProbe
Edit Flow / trunk
Edit Flow vtrunk
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
edit-flow / modules / notifications / lib / notifications.js

notifications.js in Edit Flow trunk, at modules/notifications/lib/notifications.js

126 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 localization =
10 typeof ef_notifications_localization !== 'undefined' ? ef_notifications_localization : {};
11
12 /**
13 * Disable the post author checkbox if auto-subscribe is enabled.
14 * The checkbox is disabled because unchecking it would have no effect -
15 * the post author will be re-subscribed automatically on save.
16 */
17 const maybe_disable_post_author_checkbox = function () {
18 if ( ! localization.post_author_id || ! localization.post_author_auto_subscribe ) {
19 return;
20 }
21
22 const $checkbox = $( '#ef-selected-users-' + localization.post_author_id );
23 if ( $checkbox.length ) {
24 $checkbox.prop( 'disabled', true );
25 $checkbox.attr( 'title', localization.auto_subscribed );
26 }
27 };
28
29 // Initialize: disable post author checkbox if needed.
30 maybe_disable_post_author_checkbox();
31
32 const toggle_warning_badges = function ( container, response ) {
33 const userId = parseInt( $( container ).val(), 10 );
34 const $actionsDiv = $( container ).parent();
35
36 // Remove existing warning badges (but keep Post Author and Auto-subscribed badges).
37 $actionsDiv.find( '.post_following_list-no_access, .post_following_list-no_email' ).remove();
38
39 // "No Access" If this user was flagged as not having access.
40 const user_has_no_access = response.data.subscribers_with_no_access.includes( userId );
41 if ( user_has_no_access ) {
42 const span = $( '<span />' ).addClass( 'post_following_list-no_access' );
43 span.text( localization.no_access );
44 $actionsDiv.prepend( span );
45 warning_background = true;
46 }
47
48 // "No Email" If this user was flagged as not having an email.
49 const user_has_no_email = response.data.subscribers_with_no_email.includes( userId );
50 if ( user_has_no_email ) {
51 const span = $( '<span />' ).addClass( 'post_following_list-no_email' );
52 span.text( localization.no_email );
53 $actionsDiv.prepend( span );
54 warning_background = true;
55 }
56 };
57
58 $( document ).on(
59 'click',
60 '.ef-post_following_list li input:checkbox, .ef-following_usergroups li input:checkbox',
61 function () {
62 const user_group_ids = [];
63 const parent_this = $( this );
64 params.ef_notifications_name = $( this ).attr( 'name' );
65 params._nonce = $( '#ef_notifications_nonce' ).val();
66
67 $( this )
68 .parents( '.ef-post_following_list' )
69 .find( 'input:checked' )
70 .map( function () {
71 user_group_ids.push( $( this ).val() );
72 } );
73
74 params.user_group_ids = user_group_ids;
75
76 $.ajax( {
77 type: 'POST',
78 url: ajaxurl ? ajaxurl : wpListL10n.url,
79 data: params,
80
81 success( response ) {
82 // Reset background color (set during toggle_warning_badges if there's a warning)
83 warning_background = false;
84
85 // Toggle the warning badges ("No Access" and "No Email") to signal the user won't receive notifications
86 if ( undefined !== response.data ) {
87 toggle_warning_badges( $( parent_this ), response );
88 }
89 // Green 40% by default
90 var backgroundHighlightColor = '#90d296';
91 if ( warning_background ) {
92 // Red 40% if there's a warning
93 var backgroundHighlightColor = '#ea8484';
94 }
95 const backgroundColor = parent_this.css( 'background-color' );
96 $( parent_this.parents( 'li' ) )
97 .animate( { backgroundColor: backgroundHighlightColor }, 200 )
98 .animate( { backgroundColor }, 200 );
99
100 // This event is used to show an updated list of who will be notified of editorial comments and status updates.
101 $( '#ef-post_following_box' ).trigger( 'following_list_updated' );
102 },
103 error( r ) {
104 $( '#ef-post_following_users_box' )
105 .prev()
106 .append( ' <p class="error">There was an error. Please reload the page.</p>' );
107 },
108 } );
109 }
110 );
111
112 // TODO: Should change this to _not_ use JQuery
113 const webhookUrl = $( 'input#webhook_url' ).closest( 'tr' );
114 const sendToWebhook = $( 'select#send_to_webhook' );
115 if ( sendToWebhook.val() === 'off' ) {
116 webhookUrl.hide();
117 }
118 sendToWebhook.on( 'change', function () {
119 if ( $( this ).val() === 'off' ) {
120 webhookUrl.hide();
121 } else {
122 webhookUrl.show();
123 }
124 } );
125 } );
126