mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
Allow admins to change public/private on streams.
This is the UI piece that finishes the features to let admins make streams private or public. (imported from commit 1a193165a6304dc358982e9850a75965fb3a03fd)
This commit is contained in:
@@ -4,6 +4,14 @@ var exports = {};
|
||||
|
||||
var next_sub_id = 0;
|
||||
|
||||
function add_admin_options(sub) {
|
||||
return _.extend(sub, {
|
||||
'is_admin': page_params.is_admin,
|
||||
'can_make_public': page_params.is_admin && sub.invite_only && stream_data.is_subscribed(sub.name),
|
||||
'can_make_private': page_params.is_admin && !sub.invite_only
|
||||
});
|
||||
}
|
||||
|
||||
function get_color() {
|
||||
var used_colors = stream_data.get_colors();
|
||||
var color = stream_color.pick_color(used_colors);
|
||||
@@ -225,9 +233,9 @@ function add_email_hint(row) {
|
||||
}
|
||||
|
||||
function add_sub_to_table(sub) {
|
||||
$('#create_stream_row').after(templates.render(
|
||||
'subscription',
|
||||
_.extend(sub, {'is_admin': page_params.is_admin})));
|
||||
sub = add_admin_options(sub);
|
||||
var html = templates.render('subscription', sub);
|
||||
$('#create_stream_row').after(html);
|
||||
settings_for_sub(sub).collapse('show');
|
||||
add_email_hint(sub);
|
||||
}
|
||||
@@ -407,7 +415,7 @@ exports.setup_page = function () {
|
||||
// Add in admin options.
|
||||
var sub_rows = [];
|
||||
_.each(all_subs, function (sub) {
|
||||
sub = _.extend(sub, {'is_admin': page_params.is_admin});
|
||||
sub = add_admin_options(sub);
|
||||
sub_rows.push(sub);
|
||||
});
|
||||
|
||||
@@ -802,6 +810,73 @@ $(function () {
|
||||
});
|
||||
});
|
||||
|
||||
function redraw_privacy_related_stuff(sub_row, sub) {
|
||||
var html;
|
||||
|
||||
sub = add_admin_options(sub);
|
||||
|
||||
html = templates.render('subscription_setting_icon', sub);
|
||||
sub_row.find('.subscription-setting-icon').expectOne().html(html);
|
||||
|
||||
html = templates.render('subscription_type', sub);
|
||||
sub_row.find('.subscription-type').expectOne().html(html);
|
||||
|
||||
html = templates.render('change_stream_privacy', sub);
|
||||
sub_row.find('.change-stream-privacy').expectOne().html(html);
|
||||
}
|
||||
|
||||
$("#subscriptions_table").on("click", ".make-stream-public-button", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var stream_name = $(e.target).attr("data-stream-name");
|
||||
var sub_row = $(e.target).closest('.subscription_row');
|
||||
|
||||
$("#subscriptions-status").hide();
|
||||
var data = {"stream_name": stream_name};
|
||||
|
||||
channel.post({
|
||||
url: "/json/make_stream_public",
|
||||
data: data,
|
||||
success: function (data) {
|
||||
var sub = stream_data.get_sub(stream_name);
|
||||
sub.invite_only = false;
|
||||
redraw_privacy_related_stuff(sub_row, sub);
|
||||
var feedback_div = sub_row.find(".change-stream-privacy-feedback").expectOne();
|
||||
ui.report_success("The stream has been made public!", feedback_div);
|
||||
},
|
||||
error: function (xhr) {
|
||||
var feedback_div = sub_row.find(".change-stream-privacy-feedback").expectOne();
|
||||
ui.report_error("Error making stream public", xhr, feedback_div);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#subscriptions_table").on("click", ".make-stream-private-button", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var stream_name = $(e.target).attr("data-stream-name");
|
||||
var sub_row = $(e.target).closest('.subscription_row');
|
||||
|
||||
$("#subscriptions-status").hide();
|
||||
var data = {"stream_name": stream_name};
|
||||
|
||||
channel.post({
|
||||
url: "/json/make_stream_private",
|
||||
data: data,
|
||||
success: function (data) {
|
||||
var sub = stream_data.get_sub(stream_name);
|
||||
sub.invite_only = true;
|
||||
redraw_privacy_related_stuff(sub_row, sub);
|
||||
var feedback_div = sub_row.find(".change-stream-privacy-feedback").expectOne();
|
||||
ui.report_success("The stream has been made private!", feedback_div);
|
||||
},
|
||||
error: function (xhr) {
|
||||
var feedback_div = sub_row.find(".change-stream-privacy-feedback").expectOne();
|
||||
ui.report_error("Error making stream private", xhr, feedback_div);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#subscriptions_table").on("show", ".regular_subscription_settings", function (e) {
|
||||
// We want 'show' events that originate from
|
||||
// 'regular_subscription_settings' divs not to trigger the
|
||||
|
||||
@@ -3720,3 +3720,12 @@ li.show-more-topics a {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.change-stream-privacy {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.change-stream-privacy-feedback {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
11
static/templates/change_stream_privacy.handlebars
Normal file
11
static/templates/change_stream_privacy.handlebars
Normal file
@@ -0,0 +1,11 @@
|
||||
{{#if can_make_public}}
|
||||
<button class="zulip-button blue-button make-stream-public-button" data-stream-name="{{name}}">
|
||||
Make stream public
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if can_make_private}}
|
||||
<button class="zulip-button red-button make-stream-private-button" data-stream-name="{{name}}">
|
||||
Make stream private
|
||||
</button>
|
||||
{{/if}}
|
||||
<div class="change-stream-privacy-feedback"></div>
|
||||
@@ -65,6 +65,9 @@
|
||||
<input type="submit" name="rename" value="Rename stream" class="zulip-button red-button stream-rename-button" />
|
||||
</form>
|
||||
</div>
|
||||
<div class="change-stream-privacy">
|
||||
{{partial "change_stream_privacy"}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#render_subscribers}}
|
||||
|
||||
@@ -403,6 +403,8 @@ function render(template_name, args) {
|
||||
render_subscribers: true,
|
||||
color: 'purple',
|
||||
invite_only: true,
|
||||
can_make_public: true,
|
||||
can_make_private: true, /* not logical, but that's ok */
|
||||
email_address: 'xxxxxxxxxxxxxxx@zulip.com',
|
||||
id: 888,
|
||||
in_home_view: true
|
||||
@@ -418,6 +420,7 @@ function render(template_name, args) {
|
||||
global.use_template('subscription'); // partial
|
||||
global.use_template('subscription_type'); // partial
|
||||
global.use_template('subscription_setting_icon'); // partial
|
||||
global.use_template('change_stream_privacy'); // partial
|
||||
var html = '';
|
||||
html += '<div id="subscriptions_table">';
|
||||
html += render('subscription_table_body', args);
|
||||
|
||||
Reference in New Issue
Block a user