diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 98e774f58e..387d2a7d6a 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -243,6 +243,7 @@ exports.update_calculated_fields = function (sub) { sub.can_access_subscribers = page_params.is_admin || sub.subscribed || !page_params.is_guest && !sub.invite_only; sub.preview_url = hash_util.by_stream_uri(sub.stream_id); + sub.can_add_subscribers = !page_params.is_guest && (!sub.invite_only || sub.subscribed); exports.render_stream_description(sub); exports.update_subscribers_count(sub); }; diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 40e6e61b77..14dba138ad 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -187,6 +187,7 @@ function show_subscription_settings(sub_row) { var colorpicker = sub_settings.find('.colorpicker'); var color = stream_data.get_color(sub.name); stream_color.set_colorpicker_color(colorpicker, color); + subs.update_add_subscriptions_elements(sub.can_add_subscribers); if (!sub.render_subscribers) { return; diff --git a/static/js/subs.js b/static/js/subs.js index 98086ae7e7..0648d72cdd 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -248,7 +248,7 @@ exports.remove_stream = function (stream_id) { exports.update_settings_for_subscribed = function (sub) { var button = check_button_for_sub(sub); var settings_button = settings_button_for_sub(sub).removeClass("unsubscribed").show(); - $('.add_subscribers_container').show(); + exports.update_add_subscriptions_elements(sub.can_add_subscribers); $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #preview-stream-button").show(); if (button.length !== 0) { @@ -289,6 +289,42 @@ exports.add_tooltips_to_left_panel = function () { }); }; +exports.update_add_subscriptions_elements = function (allow_user_to_add_subs) { + var input_element = $('.add_subscribers_container').find('input[name="principal"]').expectOne(); + var button_element = $('.add_subscribers_container').find('button[name="add_subscriber"]').expectOne(); + + if (allow_user_to_add_subs) { + input_element.removeAttr("disabled"); + button_element.removeAttr("disabled"); + button_element.css('pointer-events', ""); + $('.add_subscriber_btn_wrapper').popover('destroy'); + } else { + input_element.attr("disabled", "disabled"); + button_element.attr("disabled", "disabled"); + + // Disabled button blocks mouse events(hover) from reaching + // to it's parent div element, so popover don't get triggered. + // Add css to prevent this. + button_element.css("pointer-events", "none"); + + $('.add_subscribers_container input').popover({ + placement: "bottom", + content: "
%s
".replace( + '%s', i18n.t('Only stream subscribers can add users to a private stream.')), + trigger: "manual", + html: true, + animation: false}); + $('.add_subscribers_container').on('mouseover', function (e) { + $('.add_subscribers_container input').popover('show'); + e.stopPropagation(); + }); + $('.add_subscribers_container').on('mouseout', function (e) { + $('.add_subscribers_container input').popover('hide'); + e.stopPropagation(); + }); + } +}; + exports.update_settings_for_unsubscribed = function (sub) { var button = check_button_for_sub(sub); var settings_button = settings_button_for_sub(sub).addClass("unsubscribed").show(); @@ -304,7 +340,7 @@ exports.update_settings_for_unsubscribed = function (sub) { // stream without invitation and cannot add subscribers to stream. if (!sub.should_display_subscription_button) { settings_button.hide(); - $('.add_subscribers_container').hide(); + exports.update_add_subscriptions_elements(sub.can_add_subscribers); } } diff --git a/static/styles/popovers.scss b/static/styles/popovers.scss index d28796ed5b..ebc34ba36d 100644 --- a/static/styles/popovers.scss +++ b/static/styles/popovers.scss @@ -327,3 +327,10 @@ ul.remind_me_popover .remind_icon { position: relative; top: 1px; } + +.popover .cant_add_subs_hint { + padding-left: 5px; + padding-right: 5px; + font-size: small; + text-align: justify; +} diff --git a/static/templates/subscription_members.handlebars b/static/templates/subscription_members.handlebars index 2aa0e260ad..4d51c5e919 100644 --- a/static/templates/subscription_members.handlebars +++ b/static/templates/subscription_members.handlebars @@ -8,11 +8,13 @@
-
+
- +
+ +