2017-04-24 04:11:25 +02:00
|
|
|
var stream_edit = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2017-10-03 00:15:42 +02:00
|
|
|
function setup_subscriptions_stream_hash(sub) {
|
|
|
|
var id = sub.stream_id;
|
2017-04-24 04:11:25 +02:00
|
|
|
subs.change_state.prevent_once();
|
2017-10-03 00:15:42 +02:00
|
|
|
|
|
|
|
window.location.hash = "#streams" + "/" + id + "/" + hash_util.encodeHashComponent(sub.name);
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function settings_for_sub(sub) {
|
|
|
|
var id = parseInt(sub.stream_id, 10);
|
|
|
|
return $("#subscription_overlay .subscription_settings[data-stream-id='" + id + "']");
|
|
|
|
}
|
|
|
|
|
2017-06-17 22:29:01 +02:00
|
|
|
function get_email_of_subscribers(subscribers) {
|
|
|
|
var emails = [];
|
|
|
|
subscribers.each(function (o, i) {
|
|
|
|
var email = people.get_person_from_user_id(i).email;
|
|
|
|
emails.push(email);
|
|
|
|
});
|
|
|
|
return emails;
|
|
|
|
}
|
|
|
|
|
2017-06-17 22:29:11 +02:00
|
|
|
function rerender_subscribers_list(sub) {
|
|
|
|
var emails = get_email_of_subscribers(sub.subscribers);
|
|
|
|
var subscribers_list = list_render.get("stream_subscribers/" + sub.stream_id);
|
|
|
|
|
|
|
|
// Changing the data clears the rendered list and the list needs to be re-rendered.
|
2017-06-27 22:02:11 +02:00
|
|
|
// Perform re-rendering only when the stream settings form of the corresponding
|
|
|
|
// stream is open.
|
|
|
|
if (subscribers_list) {
|
|
|
|
subscribers_list.data(emails);
|
|
|
|
subscribers_list.render();
|
2017-08-28 16:57:46 +02:00
|
|
|
ui.update_scrollbar($(".subscriber_list_container"));
|
2017-06-27 22:02:11 +02:00
|
|
|
}
|
2017-06-17 22:29:11 +02:00
|
|
|
}
|
|
|
|
|
2017-10-03 23:33:15 +02:00
|
|
|
exports.hide_sub_settings = function (sub) {
|
2017-10-03 00:16:36 +02:00
|
|
|
var $settings = $(".subscription_settings[data-stream-id='" + sub.stream_id + "']");
|
|
|
|
$settings.find(".regular_subscription_settings").removeClass('in');
|
2017-04-24 04:11:25 +02:00
|
|
|
};
|
|
|
|
|
2017-10-03 23:33:15 +02:00
|
|
|
exports.show_sub_settings = function (sub) {
|
2017-10-03 00:16:36 +02:00
|
|
|
var $settings = $(".subscription_settings[data-stream-id='" + sub.stream_id + "']");
|
|
|
|
$settings.find(".regular_subscription_settings").addClass('in');
|
2017-04-24 04:11:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.add_me_to_member_list = function (sub) {
|
|
|
|
// Add the user to the member list if they're currently
|
|
|
|
// viewing the members of this stream
|
|
|
|
var stream_settings = settings_for_sub(sub);
|
|
|
|
if (sub.render_subscribers && stream_settings.hasClass('in')) {
|
|
|
|
exports.prepend_subscriber(
|
|
|
|
stream_settings,
|
|
|
|
people.my_current_email());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.show_stream_row = function (node, show_settings) {
|
|
|
|
$(".display-type #add_new_stream_title").hide();
|
|
|
|
$(".display-type #stream_settings_title, .right .settings").show();
|
|
|
|
$(".stream-row.active").removeClass("active");
|
|
|
|
if (show_settings) {
|
|
|
|
subs.show_subs_pane.settings();
|
|
|
|
|
|
|
|
$(node).addClass("active");
|
|
|
|
stream_edit.show_settings_for(node);
|
|
|
|
} else {
|
|
|
|
subs.show_subs_pane.nothing_selected();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function format_member_list_elem(email) {
|
|
|
|
var person = people.get_by_email(email);
|
|
|
|
return templates.render('stream_member_list_entry',
|
|
|
|
{name: person.full_name, email: email,
|
|
|
|
displaying_for_admin: page_params.is_admin});
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_subscriber_list(sub_row) {
|
|
|
|
var id = sub_row.data("stream-id");
|
|
|
|
return $('.subscription_settings[data-stream-id="' + id + '"] .subscriber-list');
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.update_stream_name = function (sub, new_name) {
|
|
|
|
var sub_settings = settings_for_sub(sub);
|
|
|
|
sub_settings.find(".email-address").text(sub.email_address);
|
|
|
|
sub_settings.find(".stream-name-editable").text(new_name);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_stream_description = function (sub) {
|
|
|
|
var stream_settings = settings_for_sub(sub);
|
|
|
|
stream_settings.find('input.description').val(sub.description);
|
|
|
|
stream_settings.find('.stream-description-editable').html(sub.rendered_description);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.prepend_subscriber = function (sub_row, email) {
|
|
|
|
var list = get_subscriber_list(sub_row);
|
|
|
|
list.prepend(format_member_list_elem(email));
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.invite_user_to_stream = function (user_email, sub, success, failure) {
|
|
|
|
// TODO: use stream_id when backend supports it
|
|
|
|
var stream_name = sub.name;
|
|
|
|
return channel.post({
|
|
|
|
url: "/json/users/me/subscriptions",
|
|
|
|
data: {subscriptions: JSON.stringify([{name: stream_name}]),
|
|
|
|
principals: JSON.stringify([user_email])},
|
|
|
|
success: success,
|
|
|
|
error: failure,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.remove_user_from_stream = function (user_email, sub, success, failure) {
|
|
|
|
// TODO: use stream_id when backend supports it
|
|
|
|
var stream_name = sub.name;
|
|
|
|
return channel.del({
|
|
|
|
url: "/json/users/me/subscriptions",
|
|
|
|
data: {subscriptions: JSON.stringify([stream_name]),
|
|
|
|
principals: JSON.stringify([user_email])},
|
|
|
|
success: success,
|
|
|
|
error: failure,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function get_stream_id(target) {
|
|
|
|
if (target.constructor !== jQuery) {
|
|
|
|
target = $(target);
|
|
|
|
}
|
|
|
|
return target.closest(".stream-row, .subscription_settings").attr("data-stream-id");
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_sub_for_target(target) {
|
|
|
|
var stream_id = get_stream_id(target);
|
|
|
|
if (!stream_id) {
|
|
|
|
blueslip.error('Cannot find stream id for target');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
if (!sub) {
|
|
|
|
blueslip.error('get_sub_for_target() failed id lookup: ' + stream_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_subscription_settings(sub_row) {
|
|
|
|
var stream_id = sub_row.data("stream-id");
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
var sub_settings = settings_for_sub(sub);
|
|
|
|
var alerts = sub_settings
|
|
|
|
.find('.subscriber_list_container')
|
|
|
|
.find('.alert-warning, .alert-error');
|
|
|
|
|
|
|
|
var colorpicker = sub_settings.find('.colorpicker');
|
|
|
|
var color = stream_data.get_color(sub.name);
|
|
|
|
stream_color.set_colorpicker_color(colorpicker, color);
|
|
|
|
|
|
|
|
if (!sub.render_subscribers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// fetch subscriber list from memory.
|
|
|
|
var list = get_subscriber_list(sub_settings);
|
|
|
|
alerts.addClass("hide");
|
|
|
|
list.empty();
|
|
|
|
|
2017-06-17 22:29:01 +02:00
|
|
|
var emails = get_email_of_subscribers(sub.subscribers);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2017-04-17 23:21:37 +02:00
|
|
|
list_render(list, emails.sort(), {
|
|
|
|
name: "stream_subscribers/" + stream_id,
|
|
|
|
modifier: function (item) {
|
|
|
|
return format_member_list_elem(item);
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: $("[data-stream-id='" + stream_id + "'] .search"),
|
|
|
|
callback: function (item, value) {
|
|
|
|
var person = people.get_by_email(item);
|
|
|
|
|
|
|
|
if (person) {
|
|
|
|
var email = person.email.toLocaleLowerCase();
|
|
|
|
var full_name = person.full_name.toLowerCase();
|
|
|
|
|
|
|
|
return (email.indexOf(value) > -1 || full_name.indexOf(value) > -1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).init();
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2017-08-28 16:57:46 +02:00
|
|
|
ui.set_up_scrollbar($(".subscriber_list_container"));
|
|
|
|
|
2017-04-24 04:11:25 +02:00
|
|
|
sub_settings.find('input[name="principal"]').typeahead({
|
|
|
|
source: people.get_realm_persons, // This is a function.
|
|
|
|
items: 5,
|
|
|
|
highlighter: function (item) {
|
2017-06-12 19:15:57 +02:00
|
|
|
return typeahead_helper.render_person(item);
|
2017-04-24 04:11:25 +02:00
|
|
|
},
|
|
|
|
matcher: function (item) {
|
|
|
|
var query = $.trim(this.query.toLowerCase());
|
|
|
|
if (query === '' || query === item.email) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Case-insensitive.
|
2017-06-20 21:46:43 +02:00
|
|
|
var item_matches = (item.email.toLowerCase().indexOf(query) !== -1) ||
|
|
|
|
(item.full_name.toLowerCase().indexOf(query) !== -1);
|
|
|
|
var is_subscribed = stream_data.user_is_subscribed(sub.name, item.email);
|
|
|
|
return item_matches && !is_subscribed;
|
2017-04-24 04:11:25 +02:00
|
|
|
},
|
|
|
|
sorter: function (matches) {
|
|
|
|
var current_stream = compose_state.stream_name();
|
|
|
|
return typeahead_helper.sort_recipientbox_typeahead(
|
|
|
|
this.query, matches, current_stream);
|
|
|
|
},
|
|
|
|
updater: function (item) {
|
|
|
|
return item.email;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.show_settings_for = function (node) {
|
|
|
|
var stream_id = get_stream_id(node);
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
|
2017-05-10 20:02:21 +02:00
|
|
|
stream_data.update_calculated_fields(sub);
|
|
|
|
var html = templates.render('subscription_settings', sub);
|
|
|
|
$('.subscriptions .right .settings').html(html);
|
|
|
|
|
|
|
|
var sub_settings = settings_for_sub(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2017-05-10 20:02:21 +02:00
|
|
|
$(".nothing-selected").hide();
|
2017-07-28 14:07:58 +02:00
|
|
|
|
|
|
|
ui.update_scrollbar($("#subscription_overlay .settings"));
|
|
|
|
|
2017-04-24 04:11:25 +02:00
|
|
|
sub_settings.addClass("show");
|
|
|
|
|
2017-05-10 20:02:21 +02:00
|
|
|
show_subscription_settings(sub_settings);
|
2017-04-24 04:11:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function stream_home_view_clicked(e) {
|
|
|
|
var sub = get_sub_for_target(e.target);
|
|
|
|
if (!sub) {
|
|
|
|
blueslip.error('stream_home_view_clicked() fails');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sub_settings = settings_for_sub(sub);
|
|
|
|
var notification_checkboxes = sub_settings.find(".sub_notification_setting");
|
|
|
|
|
|
|
|
subs.toggle_home(sub);
|
|
|
|
|
|
|
|
if (sub.in_home_view) {
|
|
|
|
sub_settings.find(".mute-note").addClass("hide-mute-note");
|
|
|
|
notification_checkboxes.removeClass("muted-sub");
|
2017-06-30 00:57:46 +02:00
|
|
|
notification_checkboxes.find("input[type='checkbox']").prop("disabled", false);
|
2017-04-24 04:11:25 +02:00
|
|
|
} else {
|
|
|
|
sub_settings.find(".mute-note").removeClass("hide-mute-note");
|
|
|
|
notification_checkboxes.addClass("muted-sub");
|
|
|
|
notification_checkboxes.find("input[type='checkbox']").attr("disabled", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.set_stream_property = function (sub, property, value) {
|
|
|
|
// TODO: Fix backend so it takes a stream id.
|
2017-05-09 07:01:42 +02:00
|
|
|
var sub_data = {stream_id: sub.stream_id, property: property, value: value};
|
2017-04-24 04:11:25 +02:00
|
|
|
return channel.post({
|
2017-05-09 07:01:42 +02:00
|
|
|
url: '/json/users/me/subscriptions/properties',
|
2017-04-24 04:11:25 +02:00
|
|
|
data: {subscription_data: JSON.stringify([sub_data])},
|
|
|
|
timeout: 10*1000,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-05 23:36:32 +02:00
|
|
|
exports.set_notification_setting_for_all_streams = function (notification_type, new_setting) {
|
2017-04-24 04:11:25 +02:00
|
|
|
_.each(stream_data.subscribed_subs(), function (sub) {
|
|
|
|
if (sub[notification_type] !== new_setting) {
|
|
|
|
exports.set_stream_property(sub, notification_type, new_setting);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function redraw_privacy_related_stuff(sub_row, sub) {
|
|
|
|
var stream_settings = settings_for_sub(sub);
|
|
|
|
var html;
|
|
|
|
|
2017-05-11 15:39:30 +02:00
|
|
|
stream_data.update_calculated_fields(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
|
|
|
html = templates.render('subscription_setting_icon', sub);
|
|
|
|
sub_row.find('.icon').expectOne().replaceWith($(html));
|
|
|
|
|
|
|
|
html = templates.render('subscription_type', sub);
|
|
|
|
stream_settings.find('.subscription-type-text').expectOne().html(html);
|
|
|
|
|
|
|
|
if (sub.invite_only) {
|
|
|
|
stream_settings.find(".large-icon")
|
|
|
|
.removeClass("hash").addClass("lock")
|
|
|
|
.html("<i class='icon-vector-lock'></i>");
|
|
|
|
} else {
|
|
|
|
stream_settings.find(".large-icon")
|
|
|
|
.addClass("hash").removeClass("lock")
|
|
|
|
.html("");
|
|
|
|
}
|
|
|
|
|
2017-06-14 16:33:30 +02:00
|
|
|
stream_list.redraw_stream_privacy(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function change_stream_privacy(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var stream_id = $(e.target).data("stream-id");
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
|
|
|
|
$("#subscriptions-status").hide();
|
|
|
|
var data = {
|
|
|
|
stream_name: sub.name,
|
|
|
|
// toggle the privacy setting
|
|
|
|
is_private: !sub.invite_only,
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: "/json/streams/" + stream_id,
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
|
|
|
sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
var sub_row = $(".stream-row[data-stream-id='" + stream_id + "']");
|
|
|
|
|
|
|
|
// save new privacy settings.
|
|
|
|
sub.invite_only = !sub.invite_only;
|
|
|
|
|
|
|
|
redraw_privacy_related_stuff(sub_row, sub);
|
|
|
|
$("#stream_privacy_modal").remove();
|
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
$("#change-stream-privacy-button").text(i18n.t("Try again"));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function stream_desktop_notifications_clicked(e) {
|
|
|
|
var sub = get_sub_for_target(e.target);
|
|
|
|
sub.desktop_notifications = ! sub.desktop_notifications;
|
|
|
|
exports.set_stream_property(sub, 'desktop_notifications', sub.desktop_notifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stream_audible_notifications_clicked(e) {
|
|
|
|
var sub = get_sub_for_target(e.target);
|
|
|
|
sub.audible_notifications = ! sub.audible_notifications;
|
|
|
|
exports.set_stream_property(sub, 'audible_notifications', sub.audible_notifications);
|
|
|
|
}
|
|
|
|
|
2017-08-17 16:55:32 +02:00
|
|
|
function stream_push_notifications_clicked(e) {
|
|
|
|
var sub = get_sub_for_target(e.target);
|
|
|
|
sub.push_notifications = ! sub.push_notifications;
|
|
|
|
exports.set_stream_property(sub, 'push_notifications', sub.push_notifications);
|
|
|
|
}
|
|
|
|
|
2017-04-24 04:11:25 +02:00
|
|
|
function stream_pin_clicked(e) {
|
|
|
|
var sub = get_sub_for_target(e.target);
|
|
|
|
if (!sub) {
|
|
|
|
blueslip.error('stream_pin_clicked() fails');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
subs.toggle_pin_to_top_stream(sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.change_stream_name = function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var sub_settings = $(e.target).closest('.subscription_settings');
|
|
|
|
var stream_id = $(e.target).closest(".subscription_settings").attr("data-stream-id");
|
|
|
|
var new_name_box = sub_settings.find('.stream-name-editable');
|
|
|
|
var new_name = $.trim(new_name_box.text());
|
|
|
|
|
|
|
|
$("#subscriptions-status").hide();
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
// Stream names might contain unsafe characters so we must encode it first.
|
|
|
|
url: "/json/streams/" + stream_id,
|
|
|
|
data: {new_name: JSON.stringify(new_name)},
|
|
|
|
success: function () {
|
|
|
|
new_name_box.val('');
|
|
|
|
ui_report.success(i18n.t("The stream has been renamed!"), $("#subscriptions-status "),
|
|
|
|
'subscriptions-status');
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.error(i18n.t("Error renaming stream"), xhr,
|
|
|
|
$("#subscriptions-status"), 'subscriptions-status');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.change_stream_description = function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var sub_settings = $(e.target).closest('.subscription_settings');
|
|
|
|
var sub = get_sub_for_target(sub_settings);
|
|
|
|
if (!sub) {
|
|
|
|
blueslip.error('change_stream_description() fails');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var stream_id = sub.stream_id;
|
|
|
|
var description = sub_settings.find('.stream-description-editable').text().trim();
|
|
|
|
|
|
|
|
$('#subscriptions-status').hide();
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
// Stream names might contain unsafe characters so we must encode it first.
|
|
|
|
url: '/json/streams/' + stream_id,
|
|
|
|
data: {
|
|
|
|
description: JSON.stringify(description),
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
// The event from the server will update the rest of the UI
|
|
|
|
ui_report.success(i18n.t("The stream description has been updated!"),
|
|
|
|
$("#subscriptions-status"), 'subscriptions-status');
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.error(i18n.t("Error updating the stream description"), xhr,
|
|
|
|
$("#subscriptions-status"), 'subscriptions-status');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
$("#zfilt").on("click", ".stream_sub_unsub_button", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
var stream_name = narrow_state.stream();
|
2017-04-24 04:11:25 +02:00
|
|
|
if (stream_name === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
subs.sub_or_unsub(sub);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".change-stream-privacy", function (e) {
|
|
|
|
var stream_id = get_stream_id(e.target);
|
|
|
|
var stream = stream_data.get_sub_by_id(stream_id);
|
|
|
|
var template_data = {
|
|
|
|
is_private: stream.can_make_public,
|
|
|
|
stream_id: stream_id,
|
|
|
|
};
|
|
|
|
var change_privacy_modal = templates.render("subscription_stream_privacy_modal", template_data);
|
|
|
|
|
|
|
|
$("#subscriptions_table").append(change_privacy_modal);
|
|
|
|
|
|
|
|
$("#change-stream-privacy-button").click(function (e) {
|
|
|
|
change_stream_privacy(e);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".close-privacy-modal", function () {
|
|
|
|
$("#stream_privacy_modal").remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", "#sub_setting_not_in_home_view",
|
|
|
|
stream_home_view_clicked);
|
|
|
|
$("#subscriptions_table").on("click", "#sub_desktop_notifications_setting",
|
|
|
|
stream_desktop_notifications_clicked);
|
|
|
|
$("#subscriptions_table").on("click", "#sub_audible_notifications_setting",
|
|
|
|
stream_audible_notifications_clicked);
|
2017-08-17 16:55:32 +02:00
|
|
|
$("#subscriptions_table").on("click", "#sub_push_notifications_setting",
|
|
|
|
stream_push_notifications_clicked);
|
2017-04-24 04:11:25 +02:00
|
|
|
$("#subscriptions_table").on("click", "#sub_pin_setting",
|
|
|
|
stream_pin_clicked);
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("submit", ".subscriber_list_add form", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var settings_row = $(e.target).closest('.subscription_settings');
|
|
|
|
var sub = get_sub_for_target(settings_row);
|
|
|
|
if (!sub) {
|
|
|
|
blueslip.error('.subscriber_list_add form submit fails');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var text_box = settings_row.find('input[name="principal"]');
|
|
|
|
var principal = $.trim(text_box.val());
|
|
|
|
// TODO: clean up this error handling
|
|
|
|
var error_elem = settings_row.find('.subscriber_list_container .alert-error');
|
|
|
|
var warning_elem = settings_row.find('.subscriber_list_container .alert-warning');
|
|
|
|
|
|
|
|
function invite_success(data) {
|
|
|
|
text_box.val('');
|
|
|
|
|
|
|
|
if (data.subscribed.hasOwnProperty(principal)) {
|
|
|
|
error_elem.addClass("hide");
|
|
|
|
warning_elem.addClass("hide");
|
|
|
|
if (people.is_current_user(principal)) {
|
|
|
|
// mark_subscribed adds the user to the member list
|
|
|
|
// TODO: We should really let the event system
|
|
|
|
// handle this, as mark_subscribed has
|
|
|
|
// lots of side effects.
|
|
|
|
stream_events.mark_subscribed(sub);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_elem.addClass("hide");
|
|
|
|
warning_elem.removeClass("hide").text(i18n.t("User already subscribed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function invite_failure() {
|
|
|
|
warning_elem.addClass("hide");
|
|
|
|
error_elem.removeClass("hide").text(i18n.t("Could not add user to this stream"));
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.invite_user_to_stream(principal, sub, invite_success, invite_failure);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("submit", ".subscriber_list_remove form", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var list_entry = $(e.target).closest("tr");
|
|
|
|
var principal = list_entry.children(".subscriber-email").text();
|
|
|
|
var settings_row = $(e.target).closest('.subscription_settings');
|
|
|
|
|
|
|
|
var sub = get_sub_for_target(settings_row);
|
|
|
|
if (!sub) {
|
|
|
|
blueslip.error('.subscriber_list_remove form submit fails');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var error_elem = settings_row.find('.subscriber_list_container .alert-error');
|
|
|
|
var warning_elem = settings_row.find('.subscriber_list_container .alert-warning');
|
|
|
|
|
|
|
|
function removal_success(data) {
|
|
|
|
if (data.removed.length > 0) {
|
|
|
|
error_elem.addClass("hide");
|
|
|
|
warning_elem.addClass("hide");
|
|
|
|
|
|
|
|
// Remove the user from the subscriber list.
|
|
|
|
list_entry.remove();
|
|
|
|
|
|
|
|
if (people.is_current_user(principal)) {
|
|
|
|
// If you're unsubscribing yourself, mark whole
|
|
|
|
// stream entry as you being unsubscribed.
|
|
|
|
// TODO: We should really let the event system
|
|
|
|
// handle this, as mark_unsubscribed has
|
|
|
|
// lots of side effects.
|
|
|
|
stream_events.mark_unsubscribed(sub);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_elem.addClass("hide");
|
|
|
|
warning_elem.removeClass("hide").text(i18n.t("User is already not subscribed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removal_failure() {
|
|
|
|
warning_elem.addClass("hide");
|
|
|
|
error_elem.removeClass("hide").text(i18n.t("Error removing user from this stream"));
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.remove_user_from_stream(principal, sub, removal_success,
|
|
|
|
removal_failure);
|
|
|
|
});
|
|
|
|
|
|
|
|
// This handler isn't part of the normal edit interface; it's the convenient
|
|
|
|
// checkmark in the subscriber list.
|
|
|
|
$("#subscriptions_table").on("click", ".sub_unsub_button", function (e) {
|
|
|
|
var sub = get_sub_for_target(e.target);
|
|
|
|
var stream_row = $(this).parent();
|
|
|
|
subs.sub_or_unsub(sub);
|
|
|
|
var sub_settings = settings_for_sub(sub);
|
|
|
|
var regular_sub_settings = sub_settings.find(".regular_subscription_settings");
|
|
|
|
if (!sub.subscribed) {
|
|
|
|
regular_sub_settings.addClass("in");
|
|
|
|
exports.show_stream_row(stream_row, true);
|
|
|
|
} else {
|
|
|
|
regular_sub_settings.removeClass("in");
|
|
|
|
}
|
|
|
|
|
2017-10-03 00:15:42 +02:00
|
|
|
setup_subscriptions_stream_hash(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".stream-row", function (e) {
|
|
|
|
if ($(e.target).closest(".check, .subscription_settings").length === 0) {
|
|
|
|
exports.show_stream_row(this, true);
|
|
|
|
var stream_id = $(this).attr("data-stream-id");
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
2017-10-03 00:15:42 +02:00
|
|
|
setup_subscriptions_stream_hash(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('peer_subscribe.zulip', function (e, data) {
|
|
|
|
var sub = stream_data.get_sub(data.stream_name);
|
2017-06-17 22:29:18 +02:00
|
|
|
rerender_subscribers_list(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('peer_unsubscribe.zulip', function (e, data) {
|
|
|
|
var sub = stream_data.get_sub(data.stream_name);
|
2017-06-17 22:29:18 +02:00
|
|
|
rerender_subscribers_list(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = stream_edit;
|
|
|
|
}
|