diff --git a/modules/notifications/lib/notifications.css b/modules/notifications/lib/notifications.css index 85e70084d..c6e3a512a 100644 --- a/modules/notifications/lib/notifications.css +++ b/modules/notifications/lib/notifications.css @@ -91,4 +91,8 @@ #ef-usergroup-users h4 { margin-top: 0; +} + +.misc-pub-follower-count span { + font-weight: bold; } \ No newline at end of file diff --git a/modules/notifications/lib/notifications.js b/modules/notifications/lib/notifications.js index aee16be59..fd1f140fa 100644 --- a/modules/notifications/lib/notifications.js +++ b/modules/notifications/lib/notifications.js @@ -6,6 +6,9 @@ jQuery(document).ready(function($) { post_id: $('#post_ID').val(), }; + // Display the user/group follower count in the post submit box + ef_displayFollowerCountInSubmitBox(); + $('.ef-post_following_list li input:checkbox, .ef-following_usergroups li input:checkbox').click(function() { var user_group_ids = []; var parent_this = $(this); @@ -28,6 +31,8 @@ jQuery(document).ready(function($) { url : (ajaxurl) ? ajaxurl : wpListL10n.url, data : params, success : function(x) { + // Update the user/group follower count in the post submit box + ef_displayFollowerCountInSubmitBox(); var backgroundColor = parent_this.css( 'background-color' ); $(parent_this.parent().parent()) .animate( { 'backgroundColor':'#CCEEBB' }, 200 ) @@ -38,4 +43,45 @@ jQuery(document).ready(function($) { } }); }); -}); \ No newline at end of file +}); + +/** + * Count the users and user groups who will be notified of a status change + * Display the message in the submit box + */ +var ef_displayFollowerCountInSubmitBox = function() { + var checkedFollowers, checkedUserGroups, countDisplay, message = '', followerMessage = '', userGroupMessage = '',conjunction = ''; + + // Get checked checkboxes + checkedFollowers = jQuery('.ef-post_following_list li input:checkbox:checked'); + checkedUserGroups = jQuery('#ef-following_usergroups li input:checkbox:checked'); + // checkedFollowers includes user groups + userCount = checkedFollowers.length - checkedUserGroups.length; + userGroupCount = checkedUserGroups.length; + + // The within which the message will be displayed + countDisplay = jQuery('#post-follower-count-display'); + + // Create the individual messages + if (userCount > 0) { + followerMessage = userCount + ((userCount === 1) ? ' user' : ' users'); + } + if (userGroupCount > 0) { + userGroupMessage = userGroupCount + ((userGroupCount === 1) ? ' user group' : ' user groups'); + } + + if (userCount > 0 && userGroupCount > 0) { + // Both will be displayed, so we need a conjunction + conjunction = ' & '; + message = (followerMessage + conjunction + userGroupMessage); + } else if (userCount > 0 || userGroupCount > 0) { + // Only one will be displayed, the other is an empty string + message = (followerMessage + userGroupMessage); + } else { + // Default message + message = 'none'; + } + + // Print the message + countDisplay.html(message); +}; diff --git a/modules/notifications/notifications.php b/modules/notifications/notifications.php index 228cc9f87..7bf00c8d2 100644 --- a/modules/notifications/notifications.php +++ b/modules/notifications/notifications.php @@ -78,6 +78,7 @@ function init() { add_action( 'ef_post_insert_editorial_comment', array( $this, 'notification_comment') ); add_action( 'delete_user', array($this, 'delete_user_action') ); add_action( 'ef_send_scheduled_email', array( $this, 'send_single_email' ), 10, 4 ); + add_action( 'post_submitbox_misc_actions', array($this, 'submitbox_followers_message') ); add_action( 'admin_init', array( $this, 'register_settings' ) ); @@ -410,6 +411,20 @@ public function handle_user_post_subscription() { $this->print_ajax_response( 'success', (object)$this->get_follow_action_parts( $post ) ); } + /** + * Set up the submit box for displaying the number of users/user groups following a page/post + */ + function submitbox_followers_message() { + ?> +
+
: + + + + +
+