2012-10-18 21:37:07 +02:00
|
|
|
var subs = (function () {
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
var meta = {
|
|
|
|
callbacks: {},
|
2017-01-12 00:17:43 +01:00
|
|
|
stream_created: false,
|
2017-01-19 23:23:25 +01:00
|
|
|
is_open: false,
|
2016-11-01 22:32:10 +01:00
|
|
|
};
|
2012-10-18 21:37:07 +02:00
|
|
|
var exports = {};
|
|
|
|
|
2016-11-04 22:18:23 +01:00
|
|
|
function settings_for_sub(sub) {
|
|
|
|
var id = parseInt(sub.stream_id, 10);
|
2016-10-28 02:44:40 +02:00
|
|
|
return $("#subscription_overlay .subscription_settings[data-stream-id='" + id + "']");
|
2016-11-04 22:18:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function button_for_sub(sub) {
|
|
|
|
var id = parseInt(sub.stream_id, 10);
|
|
|
|
return $(".stream-row[data-stream-id='" + id + "'] .check");
|
|
|
|
}
|
|
|
|
|
2017-02-15 17:38:44 +01:00
|
|
|
function row_for_stream_id(stream_id) {
|
|
|
|
return $(".stream-row[data-stream-id='" + stream_id + "']");
|
|
|
|
}
|
|
|
|
|
2017-01-27 00:40:42 +01:00
|
|
|
function settings_button_for_sub(sub) {
|
|
|
|
var id = parseInt(sub.stream_id, 10);
|
|
|
|
return $(".subscription_settings[data-stream-id='" + id + "'] .subscribe-button");
|
|
|
|
}
|
|
|
|
|
2013-08-07 20:23:12 +02:00
|
|
|
function get_color() {
|
2013-08-15 21:11:07 +02:00
|
|
|
var used_colors = stream_data.get_colors();
|
2013-08-07 20:23:12 +02:00
|
|
|
var color = stream_color.pick_color(used_colors);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2013-11-08 10:12:05 +01:00
|
|
|
function selectText(element) {
|
2016-12-02 17:09:31 +01:00
|
|
|
var range;
|
|
|
|
var sel;
|
2013-11-08 10:12:05 +01:00
|
|
|
if (window.getSelection) {
|
|
|
|
sel = window.getSelection();
|
|
|
|
range = document.createRange();
|
|
|
|
range.selectNodeContents(element);
|
|
|
|
|
|
|
|
sel.removeAllRanges();
|
|
|
|
sel.addRange(range);
|
2016-06-09 23:05:34 +02:00
|
|
|
} else if (document.body.createTextRange) {
|
2013-11-08 10:12:05 +01:00
|
|
|
range = document.body.createTextRange();
|
|
|
|
range.moveToElementText(element);
|
|
|
|
range.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 17:51:01 +01:00
|
|
|
function should_list_all_streams() {
|
2016-07-27 01:45:29 +02:00
|
|
|
return !page_params.is_zephyr_mirror_realm;
|
2013-01-23 17:51:01 +01:00
|
|
|
}
|
|
|
|
|
2013-04-08 19:43:11 +02:00
|
|
|
function set_stream_property(stream_name, property, value) {
|
2014-02-14 21:55:20 +01:00
|
|
|
var sub_data = {stream: stream_name, property: property, value: value};
|
2013-12-18 19:55:18 +01:00
|
|
|
return channel.post({
|
2013-04-08 19:43:11 +02:00
|
|
|
url: '/json/subscriptions/property',
|
2016-12-03 03:08:47 +01:00
|
|
|
data: {subscription_data: JSON.stringify([sub_data])},
|
2017-01-12 00:17:43 +01:00
|
|
|
timeout: 10*1000,
|
2013-04-08 19:43:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-11 22:30:18 +01:00
|
|
|
function set_notification_setting_for_all_streams(notification_type, new_setting) {
|
|
|
|
_.each(stream_data.subscribed_subs(), function (sub) {
|
|
|
|
if (sub[notification_type] !== new_setting) {
|
|
|
|
set_stream_property(sub.name, notification_type, new_setting);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.set_all_stream_desktop_notifications_to = function (new_setting) {
|
|
|
|
set_notification_setting_for_all_streams("desktop_notifications", new_setting);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.set_all_stream_audible_notifications_to = function (new_setting) {
|
|
|
|
set_notification_setting_for_all_streams("audible_notifications", new_setting);
|
|
|
|
};
|
|
|
|
|
2017-01-21 12:58:27 +01:00
|
|
|
function get_stream_id(target) {
|
|
|
|
if (target.constructor !== jQuery) {
|
|
|
|
target = $(target);
|
|
|
|
}
|
|
|
|
return target.closest(".stream-row, .subscription_settings").attr("data-stream-id");
|
|
|
|
}
|
2016-10-29 02:39:06 +02:00
|
|
|
|
|
|
|
// Finds the stream name of a jquery object that's inside a
|
|
|
|
// .stream-row or .subscription_settings element.
|
2016-12-05 07:02:18 +01:00
|
|
|
function get_stream_name(target) {
|
2017-01-21 12:58:27 +01:00
|
|
|
var stream = stream_data.get_sub_by_id(get_stream_id(target));
|
|
|
|
if (stream) {
|
|
|
|
return stream.name;
|
2016-10-29 02:39:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-12 22:32:14 +01:00
|
|
|
function stream_home_view_clicked(e) {
|
2016-11-04 23:24:57 +01:00
|
|
|
var stream_name = get_stream_name(e.target);
|
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
var sub_settings = settings_for_sub(sub);
|
|
|
|
var notification_checkboxes = sub_settings.find(".sub_notification_setting");
|
2014-02-10 22:47:10 +01:00
|
|
|
|
2016-11-04 23:24:57 +01:00
|
|
|
subs.toggle_home(stream_name);
|
2014-02-10 22:47:10 +01:00
|
|
|
|
|
|
|
if (sub.in_home_view) {
|
2016-11-04 23:24:57 +01:00
|
|
|
sub_settings.find(".mute-note").addClass("hide-mute-note");
|
2014-02-10 22:47:10 +01:00
|
|
|
notification_checkboxes.removeClass("muted-sub");
|
|
|
|
notification_checkboxes.find("input[type='checkbox']").removeAttr("disabled");
|
|
|
|
} else {
|
2016-11-04 23:24:57 +01:00
|
|
|
sub_settings.find(".mute-note").removeClass("hide-mute-note");
|
2014-02-10 22:47:10 +01:00
|
|
|
notification_checkboxes.addClass("muted-sub");
|
|
|
|
notification_checkboxes.find("input[type='checkbox']").attr("disabled", true);
|
|
|
|
}
|
2013-05-14 21:00:28 +02:00
|
|
|
}
|
2013-02-12 22:32:14 +01:00
|
|
|
|
2013-07-16 22:47:30 +02:00
|
|
|
function update_in_home_view(sub, value) {
|
|
|
|
sub.in_home_view = value;
|
2013-02-12 22:32:14 +01:00
|
|
|
|
2013-02-20 16:28:52 +01:00
|
|
|
setTimeout(function () {
|
2016-12-02 17:09:31 +01:00
|
|
|
var msg_offset;
|
|
|
|
var saved_ypos;
|
2013-07-03 22:35:41 +02:00
|
|
|
// Save our current scroll position
|
|
|
|
if (ui.home_tab_obscured()) {
|
2014-01-29 20:43:51 +01:00
|
|
|
saved_ypos = viewport.scrollTop();
|
2013-12-18 19:06:55 +01:00
|
|
|
} else if (home_msg_list === current_msg_list &&
|
|
|
|
current_msg_list.selected_row().offset() !== null) {
|
2014-01-29 20:43:51 +01:00
|
|
|
msg_offset = current_msg_list.selected_row().offset().top;
|
2013-07-03 22:35:41 +02:00
|
|
|
}
|
2013-02-20 16:28:52 +01:00
|
|
|
|
2013-07-03 22:35:41 +02:00
|
|
|
home_msg_list.clear({clear_selected_id: false});
|
2013-02-22 20:48:31 +01:00
|
|
|
|
2016-04-21 22:49:23 +02:00
|
|
|
// Recreate the home_msg_list with the newly filtered message_list.all
|
2016-04-23 00:56:44 +02:00
|
|
|
message_store.add_messages(message_list.all.all_messages(), home_msg_list);
|
2013-02-20 16:28:52 +01:00
|
|
|
|
2013-02-23 05:19:22 +01:00
|
|
|
// Ensure we're still at the same scroll position
|
2013-07-03 22:35:41 +02:00
|
|
|
if (ui.home_tab_obscured()) {
|
2014-01-29 20:43:51 +01:00
|
|
|
viewport.scrollTop(saved_ypos);
|
2013-07-03 22:35:41 +02:00
|
|
|
} else if (home_msg_list === current_msg_list) {
|
|
|
|
// We pass use_closest to handle the case where the
|
|
|
|
// currently selected message is being hidden from the
|
|
|
|
// home view
|
|
|
|
home_msg_list.select_id(home_msg_list.selected_id(),
|
2013-12-18 19:06:55 +01:00
|
|
|
{use_closest: true, empty_ok: true});
|
2013-07-03 22:35:41 +02:00
|
|
|
if (current_msg_list.selected_id() !== -1) {
|
2014-01-29 20:43:51 +01:00
|
|
|
viewport.set_message_offset(msg_offset);
|
2013-07-03 22:35:41 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-20 16:28:52 +01:00
|
|
|
|
2016-12-02 15:16:33 +01:00
|
|
|
// In case we added messages to what's visible in the home view, we need to re-scroll to
|
|
|
|
// make sure the pointer is still visible. We don't want the auto-scroll handler to move
|
|
|
|
// our pointer to the old scroll location before we have a chance to update it.
|
2016-04-12 17:38:47 +02:00
|
|
|
pointer.recenter_pointer_on_display = true;
|
|
|
|
pointer.suppress_scroll_pointer_update = true;
|
2013-02-20 16:28:52 +01:00
|
|
|
|
2013-02-22 20:48:31 +01:00
|
|
|
if (! home_msg_list.empty()) {
|
2016-11-05 19:04:29 +01:00
|
|
|
message_store.do_unread_count_updates(home_msg_list.all_messages());
|
2013-02-20 16:28:52 +01:00
|
|
|
}
|
|
|
|
}, 0);
|
2013-02-12 22:32:14 +01:00
|
|
|
|
2013-07-16 22:47:30 +02:00
|
|
|
stream_list.set_in_home_view(sub.name, sub.in_home_view);
|
|
|
|
|
2016-10-28 23:52:52 +02:00
|
|
|
var not_in_home_view_checkbox = $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #sub_setting_not_in_home_view .sub_setting_control");
|
2016-08-24 22:24:45 +02:00
|
|
|
not_in_home_view_checkbox.prop('checked', !value);
|
2013-07-16 22:47:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.toggle_home = function (stream_name) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2013-07-16 22:47:30 +02:00
|
|
|
update_in_home_view(sub, ! sub.in_home_view);
|
2013-05-14 21:00:28 +02:00
|
|
|
set_stream_property(stream_name, 'in_home_view', sub.in_home_view);
|
|
|
|
};
|
2013-02-12 22:32:14 +01:00
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
exports.toggle_pin_to_top_stream = function (stream_name) {
|
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
set_stream_property(stream_name, 'pin_to_top', !sub.pin_to_top);
|
|
|
|
};
|
|
|
|
|
2014-02-05 23:21:02 +01:00
|
|
|
function update_stream_desktop_notifications(sub, value) {
|
2016-10-28 23:52:52 +02:00
|
|
|
var desktop_notifications_checkbox = $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #sub_desktop_notifications_setting .sub_setting_control");
|
2016-08-24 22:24:45 +02:00
|
|
|
desktop_notifications_checkbox.prop('checked', value);
|
2014-02-05 23:21:02 +01:00
|
|
|
sub.desktop_notifications = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_stream_audible_notifications(sub, value) {
|
2016-10-28 23:52:52 +02:00
|
|
|
var audible_notifications_checkbox = $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #sub_audible_notifications_setting .sub_setting_control");
|
2016-08-24 22:24:45 +02:00
|
|
|
audible_notifications_checkbox.prop('checked', value);
|
2014-02-05 23:21:02 +01:00
|
|
|
sub.audible_notifications = value;
|
2013-07-16 22:47:30 +02:00
|
|
|
}
|
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
function update_stream_pin(sub, value) {
|
|
|
|
var pin_checkbox = $('#pinstream-' + sub.stream_id);
|
2016-08-24 22:24:45 +02:00
|
|
|
pin_checkbox.prop('checked', value);
|
2016-07-01 07:26:09 +02:00
|
|
|
sub.pin_to_top = value;
|
|
|
|
}
|
|
|
|
|
2017-01-05 17:34:27 +01:00
|
|
|
function update_stream_name(stream_id, new_name) {
|
2013-08-21 23:21:31 +02:00
|
|
|
// Rename the stream internally.
|
2016-10-30 17:33:23 +01:00
|
|
|
var sub = stream_data.rename_sub(stream_id, new_name);
|
2013-08-21 23:21:31 +02:00
|
|
|
|
2013-10-21 22:26:19 +02:00
|
|
|
// Update the left sidebar.
|
2016-10-30 17:33:23 +01:00
|
|
|
stream_list.rename_stream(sub, new_name);
|
2013-08-21 23:21:31 +02:00
|
|
|
|
2016-11-05 00:11:45 +01:00
|
|
|
// Update the stream settings
|
|
|
|
var sub_settings = settings_for_sub(stream_data.get_sub_by_id(stream_id));
|
|
|
|
sub_settings.find(".email-address").text(sub.email_address);
|
2016-12-17 03:53:12 +01:00
|
|
|
sub_settings.find(".stream-name-editable").text(new_name);
|
2016-11-05 00:11:45 +01:00
|
|
|
|
2016-10-29 01:30:51 +02:00
|
|
|
// Update the subscriptions page
|
|
|
|
var sub_row = $(".stream-row[data-stream-id='" + sub.stream_id + "']");
|
2016-11-05 00:10:01 +01:00
|
|
|
sub_row.find(".stream-name").text(new_name);
|
2016-10-29 01:30:51 +02:00
|
|
|
|
2013-08-21 23:21:31 +02:00
|
|
|
// Update the message feed.
|
2017-01-05 17:34:27 +01:00
|
|
|
message_live_update.update_stream_name(stream_id, new_name);
|
2013-08-21 23:21:31 +02:00
|
|
|
}
|
|
|
|
|
2014-01-24 18:19:27 +01:00
|
|
|
function update_stream_description(sub, description) {
|
|
|
|
sub.description = description;
|
|
|
|
|
2016-11-04 22:11:23 +01:00
|
|
|
// Update stream row
|
|
|
|
var sub_row = $('.stream-row[data-stream-id=' + sub.stream_id + ']');
|
|
|
|
sub_row.find(".description").text(description);
|
|
|
|
|
|
|
|
// Update stream settings
|
|
|
|
var settings = settings_for_sub(sub);
|
|
|
|
settings.find('input.description').val(description);
|
2016-12-17 03:44:15 +01:00
|
|
|
settings.find('.stream-description-editable').text(description);
|
2014-01-24 18:19:27 +01:00
|
|
|
}
|
|
|
|
|
2014-02-05 23:21:02 +01:00
|
|
|
function stream_desktop_notifications_clicked(e) {
|
2016-10-29 02:39:06 +02:00
|
|
|
var stream = get_stream_name(e.target);
|
2014-02-05 23:21:02 +01:00
|
|
|
|
|
|
|
var sub = stream_data.get_sub(stream);
|
|
|
|
sub.desktop_notifications = ! sub.desktop_notifications;
|
|
|
|
set_stream_property(stream, 'desktop_notifications', sub.desktop_notifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stream_audible_notifications_clicked(e) {
|
2016-10-29 02:39:06 +02:00
|
|
|
var stream = get_stream_name(e.target);
|
2013-04-09 02:14:13 +02:00
|
|
|
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream);
|
2014-02-05 23:21:02 +01:00
|
|
|
sub.audible_notifications = ! sub.audible_notifications;
|
|
|
|
set_stream_property(stream, 'audible_notifications', sub.audible_notifications);
|
2013-04-09 02:14:13 +02:00
|
|
|
}
|
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
function stream_pin_clicked(e) {
|
2016-10-29 02:39:06 +02:00
|
|
|
var stream = get_stream_name(e.target);
|
2016-07-01 07:26:09 +02:00
|
|
|
|
|
|
|
exports.toggle_pin_to_top_stream(stream);
|
|
|
|
}
|
|
|
|
|
2016-11-05 00:24:55 +01:00
|
|
|
exports.set_color = function (stream_id, color) {
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
set_stream_property(sub.name, 'color', color);
|
2013-05-17 21:35:17 +02:00
|
|
|
};
|
|
|
|
|
2016-03-14 06:38:43 +01:00
|
|
|
exports.rerender_subscribers_count = function (sub) {
|
|
|
|
var id = parseInt(sub.stream_id, 10);
|
|
|
|
stream_data.update_subscribers_count(sub);
|
2016-11-01 22:32:10 +01:00
|
|
|
$(".stream-row[data-stream-id='" + id + "'] .subscriber-count-text").text(sub.subscriber_count);
|
2016-03-14 06:38:43 +01:00
|
|
|
};
|
|
|
|
|
2016-07-07 14:50:21 +02:00
|
|
|
function add_email_hint(row, email_address_hint_content) {
|
2013-08-26 20:22:22 +02:00
|
|
|
// Add a popover explaining stream e-mail addresses on hover.
|
2014-07-16 23:31:03 +02:00
|
|
|
var hint_id = "#email-address-hint-" + row.stream_id;
|
2013-08-26 20:22:22 +02:00
|
|
|
var email_address_hint = $(hint_id);
|
2016-12-03 03:08:47 +01:00
|
|
|
email_address_hint.popover({placement: "bottom",
|
|
|
|
title: "Email integration",
|
|
|
|
content: email_address_hint_content,
|
|
|
|
trigger: "manual"});
|
2016-07-07 14:50:21 +02:00
|
|
|
|
2013-08-26 20:22:22 +02:00
|
|
|
$("body").on("mouseover", hint_id, function (e) {
|
|
|
|
email_address_hint.popover('show');
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
$("body").on("mouseout", hint_id, function (e) {
|
|
|
|
email_address_hint.popover('hide');
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-23 19:43:11 +01:00
|
|
|
function add_sub_to_table(sub) {
|
2016-10-17 16:38:15 +02:00
|
|
|
sub = stream_data.add_admin_options(sub);
|
2016-03-14 06:38:43 +01:00
|
|
|
stream_data.update_subscribers_count(sub);
|
2014-01-03 20:35:52 +01:00
|
|
|
var html = templates.render('subscription', sub);
|
2016-11-01 22:32:10 +01:00
|
|
|
var settings_html = templates.render('subscription_settings', sub);
|
|
|
|
$(".streams-list").append(html);
|
|
|
|
$(".subscriptions .settings").append($(settings_html));
|
|
|
|
|
2016-07-07 14:50:21 +02:00
|
|
|
var email_address_hint_content = templates.render('email_address_hint', { page_params: page_params });
|
|
|
|
add_email_hint(sub, email_address_hint_content);
|
2016-11-01 22:32:10 +01:00
|
|
|
|
|
|
|
if (meta.stream_created) {
|
2017-01-21 12:58:27 +01:00
|
|
|
$(".stream-row[data-stream-id='" + stream_data.get_sub(meta.stream_created).stream_id + "']").click();
|
2016-11-01 22:32:10 +01:00
|
|
|
meta.stream_created = false;
|
|
|
|
}
|
2013-01-23 19:43:11 +01:00
|
|
|
}
|
|
|
|
|
2016-10-26 01:26:37 +02:00
|
|
|
function format_member_list_elem(email) {
|
|
|
|
var person = people.get_by_email(email);
|
2014-01-30 17:10:52 +01:00
|
|
|
return templates.render('stream_member_list_entry',
|
2016-10-26 01:26:37 +02:00
|
|
|
{name: person.full_name, email: email,
|
2014-01-30 17:10:52 +01:00
|
|
|
displaying_for_admin: page_params.is_admin});
|
2013-11-08 10:12:05 +01:00
|
|
|
}
|
|
|
|
|
2016-10-26 01:07:10 +02:00
|
|
|
function get_subscriber_list(sub_row) {
|
2016-11-04 22:17:28 +01:00
|
|
|
var id = sub_row.data("stream-id");
|
|
|
|
return $('.subscription_settings[data-stream-id="' + id + '"] .subscriber-list');
|
2016-10-26 01:07:10 +02:00
|
|
|
}
|
|
|
|
|
2016-10-26 01:26:37 +02:00
|
|
|
function prepend_subscriber(sub_row, email) {
|
2016-10-26 01:07:10 +02:00
|
|
|
var list = get_subscriber_list(sub_row);
|
2016-10-26 01:26:37 +02:00
|
|
|
list.prepend(format_member_list_elem(email));
|
2013-01-23 21:34:48 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 17:38:44 +01:00
|
|
|
exports.remove_stream = function (stream_id) {
|
|
|
|
// It is possible that row is empty when we deactivate a
|
|
|
|
// stream, but we let jQuery silently handle that.
|
|
|
|
var row = row_for_stream_id(stream_id);
|
|
|
|
row.remove();
|
|
|
|
};
|
|
|
|
|
2016-10-28 03:18:31 +02:00
|
|
|
function show_subscription_settings(sub_row) {
|
2016-11-04 23:07:19 +01:00
|
|
|
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 warning_elem = sub_settings.find('.subscriber_list_container .alert-warning');
|
|
|
|
var error_elem = sub_settings.find('.subscriber_list_container .alert-error');
|
|
|
|
var indicator_elem = sub_settings.find('.subscriber_list_loading_indicator');
|
|
|
|
|
|
|
|
if (!sub.render_subscribers) {
|
2016-10-28 03:18:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-04 23:07:19 +01:00
|
|
|
var list = get_subscriber_list(sub_settings);
|
2016-10-28 03:18:31 +02:00
|
|
|
warning_elem.addClass('hide');
|
|
|
|
error_elem.addClass('hide');
|
|
|
|
list.empty();
|
|
|
|
|
|
|
|
loading.make_indicator(indicator_elem);
|
|
|
|
|
2016-12-22 11:37:32 +01:00
|
|
|
channel.get({
|
2016-12-30 11:42:59 +01:00
|
|
|
url: "/json/streams/" + stream_id + "/members",
|
2016-10-28 03:18:31 +02:00
|
|
|
idempotent: true,
|
|
|
|
success: function (data) {
|
|
|
|
loading.destroy_indicator(indicator_elem);
|
|
|
|
var subscribers = _.map(data.subscribers, function (elem) {
|
|
|
|
var person = people.get_by_email(elem);
|
|
|
|
if (person === undefined) {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
return format_member_list_elem(elem);
|
|
|
|
});
|
|
|
|
_.each(subscribers.sort(), function (elem) {
|
|
|
|
list.append(elem);
|
|
|
|
});
|
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function () {
|
2016-10-28 03:18:31 +02:00
|
|
|
loading.destroy_indicator(indicator_elem);
|
|
|
|
error_elem.removeClass("hide").text("Could not fetch subscriber list");
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-10-28 03:18:31 +02:00
|
|
|
});
|
|
|
|
|
2016-11-04 23:07:19 +01:00
|
|
|
sub_settings.find('input[name="principal"]').typeahead({
|
2016-11-01 20:49:50 +01:00
|
|
|
source: people.get_realm_persons, // This is a function.
|
2016-10-28 03:18:31 +02:00
|
|
|
items: 5,
|
|
|
|
highlighter: function (item) {
|
|
|
|
var item_formatted = typeahead_helper.render_person(item);
|
|
|
|
return typeahead_helper.highlight_with_escaping(this.query, item_formatted);
|
|
|
|
},
|
|
|
|
matcher: function (item) {
|
|
|
|
var query = $.trim(this.query.toLowerCase());
|
|
|
|
if (query === '' || query === item.email) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Case-insensitive.
|
|
|
|
return (item.email.toLowerCase().indexOf(query) !== -1) ||
|
|
|
|
(item.full_name.toLowerCase().indexOf(query) !== -1);
|
|
|
|
},
|
|
|
|
sorter: typeahead_helper.sort_recipientbox_typeahead,
|
|
|
|
updater: function (item) {
|
|
|
|
return item.email;
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-10-28 03:18:31 +02:00
|
|
|
});
|
2016-10-28 07:22:28 +02:00
|
|
|
|
2016-11-04 23:07:19 +01:00
|
|
|
var colorpicker = sub_settings.find('.colorpicker');
|
|
|
|
var color = stream_data.get_color(sub.name);
|
2016-10-28 07:22:28 +02:00
|
|
|
stream_color.set_colorpicker_color(colorpicker, color);
|
2016-10-28 03:18:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-21 12:58:27 +01:00
|
|
|
exports.show_settings_for = function (stream_id) {
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
var sub_settings = settings_for_sub(sub);
|
|
|
|
|
|
|
|
var stream = $(".subscription_settings[data-stream-id='" + stream_id + "']");
|
2016-10-28 02:44:40 +02:00
|
|
|
$(".subscription_settings[data-stream].show").removeClass("show");
|
|
|
|
|
|
|
|
$("#subscription_overlay .subscription_settings.show").removeClass("show");
|
|
|
|
sub_settings.addClass("show");
|
2016-10-29 01:10:59 +02:00
|
|
|
|
2016-10-28 02:44:40 +02:00
|
|
|
show_subscription_settings(stream);
|
|
|
|
};
|
2016-10-29 01:10:59 +02:00
|
|
|
|
2014-02-05 22:53:53 +01:00
|
|
|
exports.mark_subscribed = function (stream_name, attrs) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2013-01-04 20:42:39 +01:00
|
|
|
|
2013-01-22 23:16:04 +01:00
|
|
|
if (sub === undefined) {
|
2016-10-30 19:03:18 +01:00
|
|
|
blueslip.error('Unknown stream in mark_subscribed: ' + stream_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-20 22:03:52 +01:00
|
|
|
if (sub.subscribed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add yourself to a stream we already know about client-side.
|
|
|
|
var color = get_color();
|
|
|
|
exports.set_color(sub.stream_id, color);
|
2017-01-20 23:04:40 +01:00
|
|
|
stream_data.subscribe_myself(sub);
|
2017-01-20 22:03:52 +01:00
|
|
|
if (attrs) {
|
|
|
|
stream_data.set_subscriber_emails(sub, attrs.subscribers);
|
|
|
|
}
|
|
|
|
var settings = settings_for_sub(sub);
|
|
|
|
var button = button_for_sub(sub);
|
2017-01-27 00:40:42 +01:00
|
|
|
var settings_button = settings_button_for_sub(sub).removeClass("unsubscribed");
|
2017-01-20 22:03:52 +01:00
|
|
|
|
|
|
|
if (button.length !== 0) {
|
|
|
|
exports.rerender_subscribers_count(sub);
|
2013-01-23 22:08:34 +01:00
|
|
|
|
2017-01-20 22:03:52 +01:00
|
|
|
button.toggleClass("checked");
|
2017-01-27 00:40:42 +01:00
|
|
|
settings_button.text(i18n.t("Unsubscribe"));
|
2017-01-20 22:03:52 +01:00
|
|
|
// Add the user to the member list if they're currently
|
|
|
|
// viewing the members of this stream
|
|
|
|
if (sub.render_subscribers && settings.hasClass('in')) {
|
|
|
|
prepend_subscriber(settings,
|
2017-01-20 23:11:08 +01:00
|
|
|
people.my_current_email());
|
2017-01-20 22:03:52 +01:00
|
|
|
}
|
2013-01-22 23:16:04 +01:00
|
|
|
} else {
|
2017-01-20 22:03:52 +01:00
|
|
|
add_sub_to_table(sub);
|
2012-10-18 21:37:07 +02:00
|
|
|
}
|
2013-03-21 22:13:17 +01:00
|
|
|
|
2017-01-20 22:03:52 +01:00
|
|
|
// Display the swatch and subscription settings
|
|
|
|
var sub_row = settings.closest('.stream-row');
|
|
|
|
sub_row.find(".color_swatch").addClass('in');
|
|
|
|
sub_row.find(".regular_subscription_settings").collapse('show');
|
|
|
|
|
2013-04-10 23:38:30 +02:00
|
|
|
if (current_msg_list.narrowed) {
|
|
|
|
current_msg_list.update_trailing_bookend();
|
|
|
|
}
|
|
|
|
|
2013-03-21 22:13:17 +01:00
|
|
|
// Update unread counts as the new stream in sidebar might
|
|
|
|
// need its unread counts re-calculated
|
2016-11-05 19:04:29 +01:00
|
|
|
message_store.do_unread_count_updates(message_list.all.all_messages());
|
2013-03-21 22:13:17 +01:00
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).trigger($.Event('subscription_add_done.zulip', {sub: sub}));
|
2014-02-05 22:53:53 +01:00
|
|
|
};
|
2012-10-18 21:37:07 +02:00
|
|
|
|
2014-02-05 22:53:53 +01:00
|
|
|
exports.mark_unsubscribed = function (stream_name) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2014-02-07 19:26:35 +01:00
|
|
|
exports.mark_sub_unsubscribed(sub);
|
|
|
|
};
|
2013-01-22 23:16:04 +01:00
|
|
|
|
2014-02-07 19:26:35 +01:00
|
|
|
exports.mark_sub_unsubscribed = function (sub) {
|
2013-01-22 23:16:04 +01:00
|
|
|
if (sub === undefined) {
|
|
|
|
// We don't know about this stream
|
|
|
|
return;
|
|
|
|
} else if (sub.subscribed) {
|
2016-11-09 16:26:35 +01:00
|
|
|
stream_data.unsubscribe_myself(sub);
|
2016-08-23 23:15:07 +02:00
|
|
|
|
|
|
|
var button = button_for_sub(sub);
|
2017-01-27 00:40:42 +01:00
|
|
|
var settings_button = settings_button_for_sub(sub).addClass("unsubscribed");
|
|
|
|
|
2016-10-29 01:58:22 +02:00
|
|
|
button.toggleClass("checked");
|
2017-01-27 00:40:42 +01:00
|
|
|
settings_button.text(i18n.t("Subscribe"));
|
2016-08-23 23:15:07 +02:00
|
|
|
|
2013-01-23 19:51:47 +01:00
|
|
|
var settings = settings_for_sub(sub);
|
|
|
|
if (settings.hasClass('in')) {
|
|
|
|
settings.collapse('hide');
|
|
|
|
}
|
2013-01-23 22:08:34 +01:00
|
|
|
|
2016-03-14 06:38:43 +01:00
|
|
|
exports.rerender_subscribers_count(sub);
|
|
|
|
|
2013-01-23 22:08:34 +01:00
|
|
|
// Hide the swatch and subscription settings
|
2016-10-28 23:25:00 +02:00
|
|
|
var sub_row = settings.closest('.stream-row');
|
2013-01-26 00:04:18 +01:00
|
|
|
sub_row.find(".color_swatch").removeClass('in');
|
2013-01-23 22:08:34 +01:00
|
|
|
if (sub.render_subscribers) {
|
|
|
|
// TODO: having a completely empty settings div messes
|
|
|
|
// with Bootstrap's collapser. We currently just ensure
|
2016-07-27 01:45:29 +02:00
|
|
|
// that it's not empty for Zephyr mirror realms, even though it
|
2013-01-23 22:08:34 +01:00
|
|
|
// looks weird
|
2013-01-26 00:04:18 +01:00
|
|
|
sub_row.find(".regular_subscription_settings").collapse('hide');
|
2013-01-23 22:08:34 +01:00
|
|
|
}
|
2013-01-22 23:16:04 +01:00
|
|
|
} else {
|
|
|
|
// Already unsubscribed
|
|
|
|
return;
|
|
|
|
}
|
2013-04-10 23:38:30 +02:00
|
|
|
|
|
|
|
if (current_msg_list.narrowed) {
|
|
|
|
current_msg_list.update_trailing_bookend();
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).trigger($.Event('subscription_remove_done.zulip', {sub: sub}));
|
2016-11-01 22:32:10 +01:00
|
|
|
|
|
|
|
$(".stream-row[data-stream-id='" + sub.stream_id + "']").attr("data-temp-view", true);
|
2014-02-05 22:53:53 +01:00
|
|
|
};
|
2013-03-29 20:27:41 +01:00
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
// these streams are miscategorized so they don't jump off the page when being
|
|
|
|
// unsubscribed from, but should be cleared and sorted when you apply an actual
|
|
|
|
// filter.
|
|
|
|
function remove_temporarily_miscategorized_streams() {
|
|
|
|
$("[data-temp-view]").removeAttr("data-temp-view", "false");
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.remove_miscategorized_streams = remove_temporarily_miscategorized_streams;
|
|
|
|
|
2017-01-03 13:26:48 +01:00
|
|
|
function stream_matches_query(query, sub, attr) {
|
2016-11-04 23:56:38 +01:00
|
|
|
var search_terms = query.input.toLowerCase().split(",").map(function (s) {
|
2016-10-12 08:53:57 +02:00
|
|
|
return s.trim();
|
|
|
|
});
|
|
|
|
|
2016-12-26 10:14:18 +01:00
|
|
|
var flag = true;
|
|
|
|
flag = flag && (function () {
|
2017-01-03 13:26:48 +01:00
|
|
|
var sub_attr = sub[attr].toLowerCase();
|
2016-12-28 03:13:21 +01:00
|
|
|
return _.any(search_terms, function (o) {
|
2017-01-03 13:26:48 +01:00
|
|
|
if (sub_attr.indexOf(o) !== -1) {
|
2017-02-04 13:02:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
2016-12-28 03:13:21 +01:00
|
|
|
});
|
2016-12-26 10:14:18 +01:00
|
|
|
}());
|
|
|
|
flag = flag && ((sub.subscribed || !query.subscribed_only) ||
|
|
|
|
sub.data_temp_view === "true");
|
|
|
|
return flag;
|
|
|
|
}
|
2017-01-03 13:26:48 +01:00
|
|
|
exports.stream_name_match_stream_ids = [];
|
|
|
|
exports.stream_description_match_stream_ids = [];
|
2016-12-26 10:14:18 +01:00
|
|
|
|
|
|
|
// query is now an object rather than a string.
|
|
|
|
// Query { input: String, subscribed_only: Boolean }
|
|
|
|
exports.filter_table = function (query) {
|
2017-01-03 13:26:48 +01:00
|
|
|
exports.stream_name_match_stream_ids = [];
|
|
|
|
exports.stream_description_match_stream_ids = [];
|
|
|
|
var others = [];
|
|
|
|
var stream_id_to_stream_name = {};
|
|
|
|
var widgets = {};
|
|
|
|
|
|
|
|
function sort_by_stream_name(a, b) {
|
|
|
|
var stream_a_name = stream_id_to_stream_name[a].toLocaleLowerCase();
|
|
|
|
var stream_b_name = stream_id_to_stream_name[b].toLocaleLowerCase();
|
|
|
|
return String.prototype.localeCompare.call(stream_a_name, stream_b_name);
|
|
|
|
}
|
|
|
|
|
2016-11-04 23:56:38 +01:00
|
|
|
_.each($("#subscriptions_table .stream-row"), function (row) {
|
|
|
|
var sub = stream_data.get_sub_by_id($(row).attr("data-stream-id"));
|
2016-12-26 10:14:18 +01:00
|
|
|
sub.data_temp_view = $(row).attr("data-temp-view");
|
2016-10-12 08:53:57 +02:00
|
|
|
|
2017-01-03 13:26:48 +01:00
|
|
|
if (stream_matches_query(query, sub, 'name')) {
|
2016-11-04 23:56:38 +01:00
|
|
|
$(row).removeClass("notdisplayed");
|
2017-01-03 13:26:48 +01:00
|
|
|
|
|
|
|
stream_id_to_stream_name[sub.stream_id] = sub.name;
|
|
|
|
exports.stream_name_match_stream_ids.push(sub.stream_id);
|
|
|
|
|
|
|
|
widgets[sub.stream_id] = $(row).detach();
|
|
|
|
} else if (stream_matches_query(query, sub, 'description')) {
|
|
|
|
$(row).removeClass("notdisplayed");
|
|
|
|
|
|
|
|
stream_id_to_stream_name[sub.stream_id] = sub.name;
|
|
|
|
exports.stream_description_match_stream_ids.push(sub.stream_id);
|
|
|
|
|
|
|
|
widgets[sub.stream_id] = $(row).detach();
|
|
|
|
} else {
|
2016-11-04 23:56:38 +01:00
|
|
|
$(row).addClass("notdisplayed");
|
2017-01-03 13:26:48 +01:00
|
|
|
others.push($(row).detach());
|
2016-10-12 08:53:57 +02:00
|
|
|
}
|
|
|
|
});
|
2016-11-01 22:32:10 +01:00
|
|
|
|
2017-01-03 13:26:48 +01:00
|
|
|
exports.stream_name_match_stream_ids.sort(sort_by_stream_name);
|
|
|
|
exports.stream_description_match_stream_ids.sort(sort_by_stream_name);
|
|
|
|
|
|
|
|
_.each(exports.stream_name_match_stream_ids, function (stream_id) {
|
|
|
|
$('#subscriptions_table .streams-list').append(widgets[stream_id]);
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(exports.stream_description_match_stream_ids, function (stream_id) {
|
|
|
|
$('#subscriptions_table .streams-list').append(widgets[stream_id]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#subscriptions_table .streams-list').append(others);
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
if ($(".stream-row.active").hasClass("notdisplayed")) {
|
|
|
|
$(".right .settings").hide();
|
|
|
|
$(".nothing-selected").show();
|
|
|
|
$(".stream-row.active").removeClass("active");
|
|
|
|
}
|
2016-10-12 08:53:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function actually_filter_streams() {
|
2016-11-01 22:32:10 +01:00
|
|
|
var search_box = $("#add_new_subscription input[type='text']");
|
2016-10-12 08:53:57 +02:00
|
|
|
var query = search_box.expectOne().val().trim();
|
2016-11-01 22:32:10 +01:00
|
|
|
var subscribed_only;
|
|
|
|
if (components.toggle.lookup("stream-filter-toggle")) {
|
|
|
|
subscribed_only = components.toggle.lookup("stream-filter-toggle").value() === "Subscribed";
|
|
|
|
} else {
|
|
|
|
subscribed_only = false;
|
|
|
|
}
|
|
|
|
exports.filter_table({ input: query, subscribed_only: subscribed_only });
|
2016-10-12 08:53:57 +02:00
|
|
|
}
|
|
|
|
|
2017-01-29 22:37:58 +01:00
|
|
|
function redraw_privacy_related_stuff(sub_row, sub) {
|
|
|
|
var stream_settings = settings_for_sub(sub);
|
|
|
|
var html;
|
|
|
|
|
|
|
|
sub = stream_data.add_admin_options(sub);
|
|
|
|
|
|
|
|
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').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("");
|
|
|
|
}
|
|
|
|
|
|
|
|
html = templates.render('change_stream_privacy', sub);
|
|
|
|
stream_settings.find('.change-stream-privacy').expectOne().html(html);
|
|
|
|
|
|
|
|
stream_list.redraw_stream_privacy(sub.name);
|
|
|
|
}
|
|
|
|
|
2017-02-23 22:08:00 +01:00
|
|
|
function change_stream_privacy(e, is_private, success_message, error_message, invite_only) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var stream_id = $(e.target).closest(".subscription_settings").attr("data-stream-id");
|
|
|
|
var sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
|
|
|
|
$("#subscriptions-status").hide();
|
|
|
|
var data = {stream_name: sub.name, is_private: is_private};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: "/json/streams/" + stream_id,
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
|
|
|
sub = stream_data.get_sub_by_id(stream_id);
|
|
|
|
var stream_settings = settings_for_sub(sub);
|
|
|
|
var sub_row = $(".stream-row[data-stream-id='" + stream_id + "']");
|
|
|
|
sub.invite_only = invite_only;
|
|
|
|
redraw_privacy_related_stuff(sub_row, sub);
|
|
|
|
var feedback_div = stream_settings.find(".change-stream-privacy-feedback").expectOne();
|
|
|
|
ui.report_success(success_message, feedback_div);
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
var stream_settings = settings_for_sub(sub);
|
|
|
|
var feedback_div = stream_settings.find(".change-stream-privacy-feedback").expectOne();
|
|
|
|
ui.report_error(error_message, xhr, feedback_div);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-12 08:53:57 +02:00
|
|
|
var filter_streams = _.throttle(actually_filter_streams, 50);
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
exports.setup_page = function (callback) {
|
|
|
|
function initialize_components() {
|
|
|
|
var stream_filter_toggle = components.toggle({
|
|
|
|
name: "stream-filter-toggle",
|
|
|
|
selected: 0,
|
|
|
|
values: [
|
|
|
|
{ label: "Subscribed" },
|
2017-01-15 20:23:37 +01:00
|
|
|
{ label: "All streams" },
|
2016-11-01 22:32:10 +01:00
|
|
|
],
|
2016-12-15 07:26:09 +01:00
|
|
|
callback: function () {
|
2016-11-01 22:32:10 +01:00
|
|
|
actually_filter_streams();
|
|
|
|
remove_temporarily_miscategorized_streams();
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-11-01 22:32:10 +01:00
|
|
|
}).get();
|
|
|
|
|
|
|
|
if (should_list_all_streams()) {
|
|
|
|
$("#subscriptions_table .search-container").prepend(stream_filter_toggle);
|
|
|
|
}
|
|
|
|
|
2017-01-15 20:21:33 +01:00
|
|
|
// show the "Stream settings" header by default.
|
2016-11-01 22:32:10 +01:00
|
|
|
$(".display-type #stream_settings_title").show();
|
|
|
|
}
|
2013-10-25 17:27:07 +02:00
|
|
|
|
2016-10-25 21:50:14 +02:00
|
|
|
function _populate_and_fill() {
|
2016-10-25 21:45:19 +02:00
|
|
|
var sub_rows = stream_data.get_streams_for_settings_page();
|
2013-01-23 17:41:04 +01:00
|
|
|
|
2013-07-26 20:43:14 +02:00
|
|
|
$('#subscriptions_table').empty();
|
2016-10-12 08:53:57 +02:00
|
|
|
|
2014-01-15 23:30:36 +01:00
|
|
|
var template_data = {
|
|
|
|
can_create_streams: page_params.can_create_streams,
|
2016-10-12 08:53:57 +02:00
|
|
|
subscriptions: sub_rows,
|
2017-01-12 00:17:43 +01:00
|
|
|
hide_all_streams: !should_list_all_streams(),
|
2014-01-15 23:30:36 +01:00
|
|
|
};
|
|
|
|
var rendered = templates.render('subscription_table_body', template_data);
|
2013-07-26 20:43:14 +02:00
|
|
|
$('#subscriptions_table').append(rendered);
|
2016-11-01 22:32:10 +01:00
|
|
|
initialize_components();
|
|
|
|
actually_filter_streams();
|
2016-07-07 14:50:21 +02:00
|
|
|
var email_address_hint_content = templates.render('email_address_hint', { page_params: page_params });
|
2013-08-26 20:22:22 +02:00
|
|
|
_.each(sub_rows, function (row) {
|
2016-07-07 14:50:21 +02:00
|
|
|
add_email_hint(row, email_address_hint_content);
|
2013-08-26 20:22:22 +02:00
|
|
|
});
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
$("#add_new_subscription input[type='text']").on("input", function () {
|
|
|
|
remove_temporarily_miscategorized_streams();
|
2016-12-15 07:36:30 +01:00
|
|
|
// Debounce filtering in case a user is typing quickly
|
|
|
|
filter_streams();
|
2016-11-01 22:32:10 +01:00
|
|
|
});
|
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).trigger($.Event('subs_page_loaded.zulip'));
|
2016-11-01 22:32:10 +01:00
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
exports.onlaunchtrigger();
|
|
|
|
}
|
2013-01-23 17:41:04 +01:00
|
|
|
}
|
|
|
|
|
2016-10-25 21:50:14 +02:00
|
|
|
function populate_and_fill() {
|
2016-06-10 09:03:36 +02:00
|
|
|
i18n.ensure_i18n(function () {
|
2016-10-25 21:50:14 +02:00
|
|
|
_populate_and_fill();
|
2016-06-10 09:03:36 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-25 21:50:14 +02:00
|
|
|
populate_and_fill();
|
2013-04-04 22:30:28 +02:00
|
|
|
|
2016-10-25 21:50:14 +02:00
|
|
|
if (!should_list_all_streams()) {
|
2016-06-13 08:40:35 +02:00
|
|
|
$('#create_stream_button').val(i18n.t("Subscribe"));
|
2013-01-23 17:51:01 +01:00
|
|
|
}
|
2012-10-18 21:37:07 +02:00
|
|
|
};
|
2012-10-03 22:24:17 +02:00
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
// add a function to run on subscription page launch by name,
|
|
|
|
// and specify whether it should be kept or just run once (boolean).
|
|
|
|
exports.onlaunch = function (name, callback, keep) {
|
|
|
|
meta.callbacks[name] = {
|
|
|
|
func: callback,
|
2017-01-12 00:17:43 +01:00
|
|
|
keep: keep,
|
2016-11-01 22:32:10 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.onlaunchtrigger = function () {
|
|
|
|
for (var x in meta.callbacks) {
|
|
|
|
if (typeof meta.callbacks[x].func === "function") {
|
|
|
|
meta.callbacks[x].func();
|
|
|
|
|
|
|
|
// delete if it should not be kept.
|
|
|
|
if (!meta.callbacks[x].keep) {
|
|
|
|
delete meta.callbacks[x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-21 18:13:32 +01:00
|
|
|
exports.change_state = (function () {
|
|
|
|
var prevent_next = false;
|
|
|
|
|
|
|
|
var func = function (hash) {
|
|
|
|
if (prevent_next) {
|
|
|
|
prevent_next = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there are any arguments the state should be modified.
|
|
|
|
if (hash.arguments.length > 0) {
|
|
|
|
// if in #subscriptions/new form.
|
|
|
|
if (hash.arguments[0] === "new") {
|
|
|
|
$("#create_stream_button").click();
|
|
|
|
components.toggle.lookup("stream-filter-toggle").goto("All streams");
|
2017-02-23 20:04:56 +01:00
|
|
|
} else if (hash.arguments[0] === "all") {
|
|
|
|
components.toggle.lookup("stream-filter-toggle").goto("All streams");
|
|
|
|
} else if (hash.arguments[0] === "subscribed") {
|
|
|
|
components.toggle.lookup("stream-filter-toggle").goto("Subscribed");
|
2017-02-21 18:13:32 +01:00
|
|
|
// if the first argument is a valid number.
|
|
|
|
} else if (/\d+/.test(hash.arguments[0])) {
|
|
|
|
var $stream_row = $(".stream-row[data-stream-id='" + hash.arguments[0] + "']");
|
|
|
|
var top = $stream_row.click()[0].offsetTop;
|
|
|
|
|
|
|
|
$(".streams-list").animate({ scrollTop: top }, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
func.prevent_once = function () {
|
|
|
|
prevent_next = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
return func;
|
|
|
|
}());
|
|
|
|
|
|
|
|
exports.launch = function (hash) {
|
2017-01-19 23:23:25 +01:00
|
|
|
meta.is_open = true;
|
2016-11-01 22:32:10 +01:00
|
|
|
exports.setup_page(function () {
|
2017-02-09 08:17:07 +01:00
|
|
|
$("#subscription_overlay").addClass("show");
|
2017-02-21 18:13:32 +01:00
|
|
|
|
|
|
|
exports.change_state(hash);
|
2016-11-01 22:32:10 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-19 23:23:25 +01:00
|
|
|
Object.defineProperty(exports, "is_open", {
|
|
|
|
get: function () {
|
|
|
|
return meta.is_open;
|
|
|
|
},
|
|
|
|
enumerable: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.close = function () {
|
2017-01-28 00:25:01 +01:00
|
|
|
hashchange.exit_settings();
|
2017-01-19 23:23:25 +01:00
|
|
|
meta.is_open = false;
|
2017-02-09 08:17:07 +01:00
|
|
|
$("#subscription_overlay").removeClass("show");
|
2017-01-19 23:23:25 +01:00
|
|
|
subs.remove_miscategorized_streams();
|
|
|
|
};
|
|
|
|
|
2013-07-16 22:21:41 +02:00
|
|
|
exports.update_subscription_properties = function (stream_name, property, value) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2014-01-27 20:38:31 +01:00
|
|
|
if (sub === undefined) {
|
|
|
|
// This isn't a stream we know about, so ignore it.
|
|
|
|
blueslip.warn("Update for an unknown subscription", {stream_name: stream_name,
|
|
|
|
property: property,
|
|
|
|
value: value});
|
|
|
|
return;
|
|
|
|
}
|
2016-12-01 20:02:56 +01:00
|
|
|
switch (property) {
|
2013-07-16 22:21:41 +02:00
|
|
|
case 'color':
|
2013-08-07 19:28:06 +02:00
|
|
|
stream_color.update_stream_color(sub, stream_name, value, {update_historical: true});
|
2013-07-16 22:21:41 +02:00
|
|
|
break;
|
|
|
|
case 'in_home_view':
|
2013-07-16 22:47:30 +02:00
|
|
|
update_in_home_view(sub, value);
|
2013-07-16 22:21:41 +02:00
|
|
|
break;
|
2014-02-05 23:21:02 +01:00
|
|
|
case 'desktop_notifications':
|
|
|
|
update_stream_desktop_notifications(sub, value);
|
|
|
|
break;
|
|
|
|
case 'audible_notifications':
|
|
|
|
update_stream_audible_notifications(sub, value);
|
2013-07-16 22:21:41 +02:00
|
|
|
break;
|
2013-08-21 23:21:31 +02:00
|
|
|
case 'name':
|
2017-01-05 17:34:27 +01:00
|
|
|
update_stream_name(sub.stream_id, value);
|
2013-08-21 23:21:31 +02:00
|
|
|
break;
|
2014-01-24 18:19:27 +01:00
|
|
|
case 'description':
|
2016-12-17 03:53:12 +01:00
|
|
|
update_stream_description(sub, value);
|
2014-01-24 18:19:27 +01:00
|
|
|
break;
|
2014-02-05 20:52:12 +01:00
|
|
|
case 'email_address':
|
|
|
|
sub.email_address = value;
|
|
|
|
break;
|
2016-07-01 07:26:09 +02:00
|
|
|
case 'pin_to_top':
|
|
|
|
update_stream_pin(sub, value);
|
2016-10-26 06:56:10 +02:00
|
|
|
stream_list.refresh_pinned_or_unpinned_stream(sub);
|
2016-07-01 07:26:09 +02:00
|
|
|
break;
|
2013-07-16 22:21:41 +02:00
|
|
|
default:
|
|
|
|
blueslip.warn("Unexpected subscription property type", {property: property,
|
|
|
|
value: value});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-22 23:16:04 +01:00
|
|
|
function ajaxSubscribe(stream) {
|
2013-01-31 21:09:34 +01:00
|
|
|
// Subscribe yourself to a single stream.
|
|
|
|
var true_stream_name;
|
|
|
|
|
2013-12-18 19:55:18 +01:00
|
|
|
return channel.post({
|
2015-11-30 21:39:40 +01:00
|
|
|
url: "/json/users/me/subscriptions",
|
2016-12-03 03:08:47 +01:00
|
|
|
data: {subscriptions: JSON.stringify([{name: stream}]) },
|
2016-12-02 14:06:06 +01:00
|
|
|
success: function (resp, statusText, xhr) {
|
2017-01-19 23:23:37 +01:00
|
|
|
if (subs.is_open) {
|
|
|
|
$("#create_stream_name").val("");
|
2016-11-01 22:32:10 +01:00
|
|
|
|
2017-01-19 23:23:37 +01:00
|
|
|
actually_filter_streams();
|
|
|
|
}
|
2013-01-31 21:09:34 +01:00
|
|
|
|
2016-08-24 23:56:23 +02:00
|
|
|
var res = JSON.parse(xhr.responseText);
|
2013-01-31 21:09:34 +01:00
|
|
|
if (!$.isEmptyObject(res.already_subscribed)) {
|
|
|
|
// Display the canonical stream capitalization.
|
2017-01-20 23:11:08 +01:00
|
|
|
true_stream_name = res.already_subscribed[people.my_current_email()][0];
|
2016-12-03 03:08:47 +01:00
|
|
|
ui.report_success(i18n.t("Already subscribed to __stream__", {stream: true_stream_name}),
|
2016-03-15 18:22:20 +01:00
|
|
|
$("#subscriptions-status"), 'subscriptions-status');
|
2012-11-07 23:25:04 +01:00
|
|
|
}
|
2013-03-29 20:49:05 +01:00
|
|
|
// The rest of the work is done via the subscribe event we will get
|
2012-11-07 23:25:04 +01:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2016-06-23 13:05:17 +02:00
|
|
|
ui.report_error(i18n.t("Error adding subscription"), xhr,
|
2016-03-15 18:22:20 +01:00
|
|
|
$("#subscriptions-status"), 'subscriptions-status');
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2012-11-07 23:25:04 +01:00
|
|
|
});
|
|
|
|
}
|
2012-10-09 21:01:41 +02:00
|
|
|
|
2013-01-22 23:16:04 +01:00
|
|
|
function ajaxUnsubscribe(stream) {
|
2016-12-23 02:37:10 +01:00
|
|
|
return channel.del({
|
|
|
|
url: "/json/users/me/subscriptions",
|
2016-12-03 03:08:47 +01:00
|
|
|
data: {subscriptions: JSON.stringify([stream]) },
|
2016-12-02 14:06:06 +01:00
|
|
|
success: function () {
|
2013-02-06 00:58:03 +01:00
|
|
|
$("#subscriptions-status").hide();
|
2013-03-29 20:49:05 +01:00
|
|
|
// The rest of the work is done via the unsubscribe event we will get
|
2012-10-03 22:24:17 +02:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2016-06-23 13:05:17 +02:00
|
|
|
ui.report_error(i18n.t("Error removing subscription"), xhr,
|
2016-03-15 18:22:20 +01:00
|
|
|
$("#subscriptions-status"), 'subscriptions-status');
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2012-10-03 22:24:17 +02:00
|
|
|
});
|
2013-01-10 22:15:55 +01:00
|
|
|
}
|
2012-11-16 20:11:08 +01:00
|
|
|
|
2016-11-20 20:33:41 +01:00
|
|
|
function ajaxSubscribeForCreation(stream, description, principals, invite_only, announce) {
|
2013-01-31 21:09:34 +01:00
|
|
|
// Subscribe yourself and possible other people to a new stream.
|
2013-12-18 19:55:18 +01:00
|
|
|
return channel.post({
|
2015-11-30 21:39:40 +01:00
|
|
|
url: "/json/users/me/subscriptions",
|
2016-12-03 03:08:47 +01:00
|
|
|
data: {subscriptions: JSON.stringify([{name: stream, description: description}]),
|
|
|
|
principals: JSON.stringify(principals),
|
|
|
|
invite_only: JSON.stringify(invite_only),
|
2017-01-12 00:17:43 +01:00
|
|
|
announce: JSON.stringify(announce),
|
2013-01-31 21:09:34 +01:00
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
success: function () {
|
2013-01-31 21:09:34 +01:00
|
|
|
$("#create_stream_name").val("");
|
2016-11-20 20:33:41 +01:00
|
|
|
$("#create_stream_description").val("");
|
2013-02-06 00:58:03 +01:00
|
|
|
$("#subscriptions-status").hide();
|
2013-03-29 20:49:05 +01:00
|
|
|
// The rest of the work is done via the subscribe event we will get
|
2013-01-31 21:09:34 +01:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2016-06-23 13:05:17 +02:00
|
|
|
ui.report_error(i18n.t("Error creating stream"), xhr,
|
2016-03-15 18:22:20 +01:00
|
|
|
$("#subscriptions-status"), 'subscriptions-status');
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2013-01-31 21:09:34 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-08-27 19:14:18 +02:00
|
|
|
// Within the new stream modal...
|
|
|
|
function update_announce_stream_state() {
|
|
|
|
// If the stream is invite only, or everyone's added, disable
|
|
|
|
// the "Announce stream" option. Otherwise enable it.
|
|
|
|
var announce_stream_checkbox = $('#announce-new-stream input');
|
|
|
|
var disable_it = false;
|
|
|
|
var is_invite_only = $('input:radio[name=privacy]:checked').val() === 'invite-only';
|
|
|
|
|
|
|
|
if (is_invite_only) {
|
|
|
|
disable_it = true;
|
|
|
|
announce_stream_checkbox.prop('checked', false);
|
|
|
|
} else {
|
|
|
|
disable_it = $('#user-checkboxes input').length
|
|
|
|
=== $('#user-checkboxes input:checked').length;
|
|
|
|
}
|
|
|
|
|
|
|
|
announce_stream_checkbox.prop('disabled', disable_it);
|
|
|
|
}
|
|
|
|
|
2013-01-31 21:09:34 +01:00
|
|
|
function show_new_stream_modal() {
|
2016-11-01 22:32:10 +01:00
|
|
|
$("#stream-creation").removeClass("hide");
|
|
|
|
$(".right .settings").hide();
|
2013-02-16 10:45:32 +01:00
|
|
|
$('#people_to_add').html(templates.render('new_stream_users', {
|
2016-12-17 19:28:51 +01:00
|
|
|
users: people.get_rest_of_realm(),
|
2017-01-12 00:17:43 +01:00
|
|
|
streams: stream_data.get_streams_for_settings_page(),
|
2013-01-31 21:09:34 +01:00
|
|
|
}));
|
2013-08-27 19:14:18 +02:00
|
|
|
|
|
|
|
// Make the options default to the same each time:
|
|
|
|
// public, "announce stream" on.
|
|
|
|
$('#make-invite-only input:radio[value=public]').prop('checked', true);
|
|
|
|
$('#announce-new-stream input').prop('disabled', false);
|
|
|
|
$('#announce-new-stream input').prop('checked', true);
|
|
|
|
|
2016-10-12 09:45:25 +02:00
|
|
|
$("#stream_name_error").hide();
|
2017-01-26 17:37:06 +01:00
|
|
|
|
|
|
|
$("#stream-checkboxes label.checkbox").on('change', function (e) {
|
|
|
|
var elem = $(this);
|
|
|
|
var stream_id = elem.attr('data-stream-id');
|
|
|
|
var checked = elem.find('input').prop('checked');
|
|
|
|
var subscriber_ids = stream_data.get_sub_by_id(stream_id).subscribers;
|
|
|
|
|
|
|
|
$('#user-checkboxes label.checkbox').each(function () {
|
|
|
|
var user_elem = $(this);
|
|
|
|
var user_id = user_elem.attr('data-user-id');
|
|
|
|
|
|
|
|
if (subscriber_ids.has(user_id)) {
|
|
|
|
user_elem.find('input').prop('checked', checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
update_announce_stream_state();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2013-01-31 21:09:34 +01:00
|
|
|
}
|
|
|
|
|
2013-09-16 21:13:11 +02:00
|
|
|
exports.invite_user_to_stream = function (user_email, stream_name, success, failure) {
|
2013-12-18 19:55:18 +01:00
|
|
|
return channel.post({
|
2015-11-30 21:39:40 +01:00
|
|
|
url: "/json/users/me/subscriptions",
|
2016-12-03 03:08:47 +01:00
|
|
|
data: {subscriptions: JSON.stringify([{name: stream_name}]),
|
|
|
|
principals: JSON.stringify([user_email])},
|
2013-09-16 21:13:11 +02:00
|
|
|
success: success,
|
2017-01-12 00:17:43 +01:00
|
|
|
error: failure,
|
2013-09-16 21:13:11 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-30 17:10:52 +01:00
|
|
|
exports.remove_user_from_stream = function (user_email, stream_name, success, failure) {
|
2016-12-23 02:37:10 +01:00
|
|
|
return channel.del({
|
|
|
|
url: "/json/users/me/subscriptions",
|
2016-12-03 03:08:47 +01:00
|
|
|
data: {subscriptions: JSON.stringify([stream_name]),
|
|
|
|
principals: JSON.stringify([user_email])},
|
2014-01-30 17:10:52 +01:00
|
|
|
success: success,
|
2017-01-12 00:17:43 +01:00
|
|
|
error: failure,
|
2014-01-30 17:10:52 +01:00
|
|
|
});
|
|
|
|
};
|
2013-10-21 19:37:52 +02:00
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
exports.change_stream_description = function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var sub_settings = $(e.target).closest('.subscription_settings');
|
|
|
|
var stream_name = get_stream_name(sub_settings);
|
|
|
|
var stream_id = stream_data.get_sub(stream_name).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: {
|
2017-01-27 23:53:54 +01:00
|
|
|
description: JSON.stringify(description),
|
2016-12-17 03:44:15 +01:00
|
|
|
},
|
|
|
|
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');
|
2017-01-27 23:53:54 +01:00
|
|
|
},
|
2016-12-17 03:44:15 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-12-17 03:53:12 +01:00
|
|
|
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');
|
2017-01-27 23:53:54 +01:00
|
|
|
},
|
2016-12-17 03:53:12 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2012-11-16 20:11:08 +01:00
|
|
|
$(function () {
|
2013-10-21 19:37:52 +02:00
|
|
|
|
Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.
Now there is a clear separation of concerns, with these methods
being called in succession:
stream_data.initialize_from_page_params();
stream_list.create_initial_sidebar_rows();
The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict. Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.
Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
2016-10-17 19:34:58 +02:00
|
|
|
stream_data.initialize_from_page_params();
|
|
|
|
stream_list.create_initial_sidebar_rows();
|
2014-01-23 21:13:04 +01:00
|
|
|
|
2014-01-23 21:19:26 +01:00
|
|
|
// We build the stream_list now. It may get re-built again very shortly
|
|
|
|
// when new messages come in, but it's fairly quick.
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
var show_subs_pane = {
|
|
|
|
nothing_selected: function () {
|
|
|
|
$(".nothing-selected, #stream_settings_title").show();
|
|
|
|
$("#add_new_stream_title, .settings, #stream-creation").hide();
|
|
|
|
},
|
|
|
|
stream_creation: function () {
|
2017-02-09 00:07:52 +01:00
|
|
|
$("#stream_settings_title, .subscriptions-container .settings, .nothing-selected").hide();
|
2016-11-01 22:32:10 +01:00
|
|
|
$("#stream-creation, #add_new_stream_title").show();
|
|
|
|
},
|
|
|
|
settings: function () {
|
|
|
|
$(".settings, #stream_settings_title").show();
|
|
|
|
$("#add_new_stream_title, #stream-creation, .nothing-selected").hide();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", "#create_stream_button", function (e) {
|
2012-10-31 18:36:08 +01:00
|
|
|
e.preventDefault();
|
2016-11-01 22:32:10 +01:00
|
|
|
// this changes the tab switcher (settings/preview) which isn't necessary
|
|
|
|
// to a add new stream title.
|
|
|
|
$(".display-type #add_new_stream_title").show();
|
|
|
|
$(".display-type #stream_settings_title").hide();
|
|
|
|
|
|
|
|
$(".stream-row.active").removeClass("active");
|
|
|
|
|
|
|
|
show_subs_pane.stream_creation();
|
2013-01-31 21:13:28 +01:00
|
|
|
|
|
|
|
if (!should_list_all_streams()) {
|
2016-10-12 08:53:57 +02:00
|
|
|
ajaxSubscribe($("#search_stream_name").val());
|
2013-01-31 21:13:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-12 08:53:57 +02:00
|
|
|
var stream = $.trim($("#search_stream_name").val());
|
2016-11-01 22:32:10 +01:00
|
|
|
$('#create_stream_name').val(stream);
|
|
|
|
show_new_stream_modal();
|
2017-02-09 00:07:52 +01:00
|
|
|
|
|
|
|
// at less than 700px we have a @media query that when you tap the
|
|
|
|
// #create_stream_button, the stream prompt slides in. However, when you
|
|
|
|
// focus the button on that page, the entire app view jumps over to
|
|
|
|
// the other tab, and the animation breaks.
|
|
|
|
// it is unclear whether this is a browser bug or "feature", however what
|
|
|
|
// is clear is that this shoudn't be touched unless you're also changing
|
|
|
|
// the mobile @media query at 700px.
|
|
|
|
if (window.innerWidth > 700) {
|
|
|
|
$('#create_stream_name').focus();
|
|
|
|
}
|
2017-02-21 18:13:32 +01:00
|
|
|
|
|
|
|
// change the hash to #subscriptions/new to allow for linking and
|
|
|
|
// easy discovery.
|
|
|
|
|
|
|
|
window.location.hash = "#subscriptions/new";
|
2013-01-31 21:09:34 +01:00
|
|
|
});
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
$('body').on('change', '#user-checkboxes input, #make-invite-only input', update_announce_stream_state);
|
|
|
|
|
|
|
|
|
|
|
|
$(".subscriptions").on("click", "[data-dismiss]", function (e) {
|
|
|
|
e.preventDefault();
|
2016-12-13 21:58:11 +01:00
|
|
|
// we want to make sure that the click is not just a simulated
|
|
|
|
// click; this fixes an issue where hitting "enter" would
|
|
|
|
// trigger this code path due to bootstrap magic.
|
|
|
|
if (e.clientY !== 0) {
|
|
|
|
show_subs_pane.nothing_selected();
|
|
|
|
}
|
2016-11-01 22:32:10 +01:00
|
|
|
});
|
2013-08-27 19:14:18 +02:00
|
|
|
|
2017-01-12 21:41:14 +01:00
|
|
|
// 'Check all' and 'Uncheck all' visible users
|
2013-08-27 19:14:18 +02:00
|
|
|
$(document).on('click', '.subs_set_all_users', function (e) {
|
2017-01-26 16:06:21 +01:00
|
|
|
$('#user-checkboxes .checkbox').each(function (idx, li) {
|
2017-01-12 21:41:14 +01:00
|
|
|
if (li.style.display !== "none") {
|
|
|
|
$(li.firstElementChild).prop('checked', true);
|
|
|
|
}
|
|
|
|
});
|
2013-08-27 19:14:18 +02:00
|
|
|
e.preventDefault();
|
|
|
|
update_announce_stream_state();
|
|
|
|
});
|
|
|
|
$(document).on('click', '.subs_unset_all_users', function (e) {
|
2017-01-26 16:06:21 +01:00
|
|
|
$('#user-checkboxes .checkbox').each(function (idx, li) {
|
2017-01-12 21:41:14 +01:00
|
|
|
if (li.style.display !== "none") {
|
|
|
|
$(li.firstElementChild).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
2013-08-27 19:14:18 +02:00
|
|
|
e.preventDefault();
|
|
|
|
update_announce_stream_state();
|
|
|
|
});
|
2016-12-17 19:28:51 +01:00
|
|
|
$(document).on('click', '#copy-from-stream-expand-collapse', function (e) {
|
|
|
|
$('#stream-checkboxes').toggle();
|
|
|
|
$("#copy-from-stream-expand-collapse .toggle").toggleClass('icon-vector-caret-right icon-vector-caret-down');
|
|
|
|
e.preventDefault();
|
|
|
|
update_announce_stream_state();
|
|
|
|
});
|
2013-08-27 19:14:18 +02:00
|
|
|
|
2016-12-17 19:28:51 +01:00
|
|
|
// Search People or Streams
|
2016-07-07 00:58:11 +02:00
|
|
|
$(document).on('input', '.add-user-list-filter', function (e) {
|
|
|
|
var user_list = $(".add-user-list-filter");
|
|
|
|
if (user_list === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var search_term = user_list.expectOne().val().trim();
|
|
|
|
var search_terms = search_term.toLowerCase().split(",");
|
|
|
|
|
2017-01-26 14:21:44 +01:00
|
|
|
(function filter_user_checkboxes() {
|
|
|
|
var user_labels = $("#user-checkboxes label.add-user-label");
|
|
|
|
|
|
|
|
if (search_term === '') {
|
|
|
|
user_labels.css({display: 'block'});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var users = people.get_rest_of_realm();
|
|
|
|
var filtered_users = people.filter_people_by_search_terms(users, search_terms);
|
|
|
|
|
|
|
|
// Be careful about modifying the follow code. A naive implementation
|
|
|
|
// will work very poorly with a large user population (~1000 users).
|
|
|
|
//
|
|
|
|
// I tested using: `./manage.py populate_db --extra-users 3500`
|
|
|
|
//
|
|
|
|
// This would break the previous implementation, whereas the new
|
|
|
|
// implementation is merely sluggish.
|
|
|
|
user_labels.each(function () {
|
|
|
|
var elem = $(this);
|
|
|
|
var user_id = elem.attr('data-user-id');
|
|
|
|
var user_checked = filtered_users.has(user_id);
|
|
|
|
var display = user_checked ? "block" : "none";
|
|
|
|
elem.css({display: display});
|
|
|
|
});
|
|
|
|
}());
|
2016-07-07 00:58:11 +02:00
|
|
|
|
|
|
|
update_announce_stream_state();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-08-27 19:14:18 +02:00
|
|
|
$("body").on("mouseover", "#announce-stream-docs", function (e) {
|
2016-11-01 22:32:10 +01:00
|
|
|
var announce_stream_docs = $("#announce-stream-docs");
|
|
|
|
announce_stream_docs.popover({placement: "right",
|
|
|
|
content: templates.render('announce_stream_docs'),
|
|
|
|
trigger: "manual"});
|
2013-08-27 19:14:18 +02:00
|
|
|
announce_stream_docs.popover('show');
|
|
|
|
announce_stream_docs.data('popover').tip().css('z-index', 2000);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
$("body").on("mouseout", "#announce-stream-docs", function (e) {
|
2016-11-01 22:32:10 +01:00
|
|
|
$("#announce-stream-docs").popover('hide');
|
2013-08-27 19:14:18 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
$(".subscriptions").on("focusout", "#create_stream_name", function () {
|
2016-10-12 09:45:25 +02:00
|
|
|
var stream = $.trim($("#create_stream_name").val());
|
2016-11-01 22:32:10 +01:00
|
|
|
if (stream.length !== 0) {
|
|
|
|
var stream_status = compose.check_stream_existence(stream);
|
|
|
|
|
|
|
|
if (stream_status !== "does-not-exist") {
|
|
|
|
$("#stream_name_error").text(i18n.t("A stream with this name already exists"));
|
|
|
|
$("#stream_name_error").show();
|
|
|
|
} else {
|
|
|
|
$("#stream_name_error").hide();
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-12 09:45:25 +02:00
|
|
|
$("#stream_name_error").text(i18n.t("A stream needs to have a name"));
|
|
|
|
$("#stream_name_error").show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
$(".subscriptions").on("submit", "#stream_creation_form", function (e) {
|
2013-01-31 21:09:34 +01:00
|
|
|
e.preventDefault();
|
|
|
|
var stream = $.trim($("#create_stream_name").val());
|
2016-11-20 20:33:41 +01:00
|
|
|
var description = $.trim($("#create_stream_description").val());
|
2016-10-12 09:45:25 +02:00
|
|
|
if (!$("#stream_name_error").is(":visible")) {
|
|
|
|
var principals = _.map(
|
|
|
|
$("#stream_creation_form input:checkbox[name=user]:checked"),
|
|
|
|
function (elem) {
|
|
|
|
return $(elem).val();
|
|
|
|
}
|
2013-03-11 20:30:37 +01:00
|
|
|
);
|
2016-12-17 19:28:51 +01:00
|
|
|
|
2016-10-12 09:45:25 +02:00
|
|
|
// You are always subscribed to streams you create.
|
2017-01-20 23:11:08 +01:00
|
|
|
principals.push(people.my_current_email());
|
2016-11-01 22:32:10 +01:00
|
|
|
|
|
|
|
meta.stream_created = stream;
|
|
|
|
|
2016-10-12 09:45:25 +02:00
|
|
|
ajaxSubscribeForCreation(stream,
|
2016-11-20 20:33:41 +01:00
|
|
|
description,
|
2016-10-12 09:45:25 +02:00
|
|
|
principals,
|
|
|
|
$('#stream_creation_form input[name=privacy]:checked').val() === "invite-only",
|
|
|
|
$('#announce-new-stream input').prop('checked')
|
|
|
|
);
|
|
|
|
}
|
2012-10-03 22:24:17 +02:00
|
|
|
});
|
2013-01-07 22:09:33 +01:00
|
|
|
|
2013-11-08 10:12:05 +01:00
|
|
|
$("body").on("mouseover", ".subscribed-button", function (e) {
|
2016-06-13 08:40:35 +02:00
|
|
|
$(e.target).addClass("btn-danger").text(i18n.t("Unsubscribe"));
|
2013-11-08 10:12:05 +01:00
|
|
|
}).on("mouseout", ".subscribed-button", function (e) {
|
2016-06-13 08:40:35 +02:00
|
|
|
$(e.target).removeClass("btn-danger").text(i18n.t("Subscribed"));
|
2013-11-08 10:12:05 +01:00
|
|
|
});
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$(".subscriptions").on("click", "#close-subscriptions-status", function () {
|
2016-03-15 18:22:20 +01:00
|
|
|
$("#subscriptions-status").hide();
|
|
|
|
});
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$("#subscriptions_table").on("click", ".email-address", function () {
|
2013-11-08 10:12:05 +01:00
|
|
|
selectText(this);
|
|
|
|
});
|
|
|
|
|
2016-12-05 07:02:18 +01:00
|
|
|
function sub_or_unsub(stream_name) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2013-01-10 22:15:55 +01:00
|
|
|
|
2013-01-22 23:16:04 +01:00
|
|
|
if (sub.subscribed) {
|
|
|
|
ajaxUnsubscribe(stream_name);
|
2013-01-10 22:15:55 +01:00
|
|
|
} else {
|
2013-01-22 23:16:04 +01:00
|
|
|
ajaxSubscribe(stream_name);
|
2013-01-10 22:15:55 +01:00
|
|
|
}
|
2016-08-23 02:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".sub_unsub_button", function (e) {
|
2016-10-29 02:39:06 +02:00
|
|
|
var stream_name = get_stream_name(e.target);
|
2016-08-23 02:46:12 +02:00
|
|
|
sub_or_unsub(stream_name);
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2016-10-28 02:44:40 +02:00
|
|
|
|
2016-08-23 02:46:12 +02:00
|
|
|
$("body").on("click", ".popover_sub_unsub_button", function (e) {
|
|
|
|
$(this).toggleClass("unsub");
|
|
|
|
$(this).closest(".popover").fadeOut(500).delay(500).remove();
|
|
|
|
|
|
|
|
var stream_name = $(e.target).data("name");
|
|
|
|
|
|
|
|
sub_or_unsub(stream_name);
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2013-01-10 22:15:55 +01:00
|
|
|
});
|
|
|
|
|
2016-03-07 03:51:10 +01:00
|
|
|
$("#zfilt").on("click", ".stream_sub_unsub_button", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var stream_name = narrow.stream();
|
|
|
|
if (stream_name === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
|
|
|
|
if (sub.subscribed) {
|
|
|
|
ajaxUnsubscribe(stream_name);
|
|
|
|
} else {
|
|
|
|
ajaxSubscribe(stream_name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-03-22 16:50:09 +01:00
|
|
|
$('.empty_feed_sub_unsub').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$('#subscription-status').hide();
|
|
|
|
var stream_name = narrow.stream();
|
|
|
|
if (stream_name === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
|
|
|
|
if (sub.subscribed) {
|
|
|
|
ajaxUnsubscribe(stream_name);
|
|
|
|
} else {
|
|
|
|
ajaxSubscribe(stream_name);
|
|
|
|
}
|
|
|
|
$('.empty_feed_notice').hide();
|
|
|
|
$('#empty_narrow_message').show();
|
|
|
|
});
|
|
|
|
|
2017-02-09 00:07:52 +01:00
|
|
|
$("#subscriptions_table").on("click", ".stream-row, #create_stream_button", function () {
|
|
|
|
$(".right").addClass("show");
|
|
|
|
$(".subscriptions-header").addClass("slide-left");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".icon-vector-chevron-left", function () {
|
|
|
|
$(".right").removeClass("show");
|
|
|
|
$(".subscriptions-header").removeClass("slide-left");
|
|
|
|
});
|
|
|
|
|
2013-04-08 20:53:12 +02:00
|
|
|
$("#subscriptions_table").on("click", ".sub_setting_checkbox", function (e) {
|
|
|
|
var control = $(e.target).closest('.sub_setting_checkbox').find('.sub_setting_control');
|
|
|
|
// A hack. Don't change the state of the checkbox if we
|
|
|
|
// clicked on the checkbox itself.
|
|
|
|
if (control[0] !== e.target) {
|
|
|
|
control.prop("checked", ! control.prop("checked"));
|
|
|
|
}
|
|
|
|
});
|
2013-11-04 04:30:19 +01:00
|
|
|
$("#subscriptions_table").on("click", "#sub_setting_not_in_home_view", stream_home_view_clicked);
|
2014-02-05 23:21:02 +01:00
|
|
|
$("#subscriptions_table").on("click", "#sub_desktop_notifications_setting",
|
|
|
|
stream_desktop_notifications_clicked);
|
|
|
|
$("#subscriptions_table").on("click", "#sub_audible_notifications_setting",
|
|
|
|
stream_audible_notifications_clicked);
|
2016-07-01 07:26:09 +02:00
|
|
|
$("#subscriptions_table").on("click", "#sub_pin_setting",
|
|
|
|
stream_pin_clicked);
|
2013-02-12 22:32:14 +01:00
|
|
|
|
2013-01-10 19:33:56 +01:00
|
|
|
$("#subscriptions_table").on("submit", ".subscriber_list_add form", function (e) {
|
|
|
|
e.preventDefault();
|
2016-11-04 23:27:01 +01:00
|
|
|
var settings_row = $(e.target).closest('.subscription_settings');
|
|
|
|
var stream = get_stream_name(settings_row);
|
|
|
|
var text_box = settings_row.find('input[name="principal"]');
|
2013-01-10 20:10:06 +01:00
|
|
|
var principal = $.trim(text_box.val());
|
2013-01-10 19:33:56 +01:00
|
|
|
// TODO: clean up this error handling
|
2016-11-04 23:27:01 +01:00
|
|
|
var error_elem = settings_row.find('.subscriber_list_container .alert-error');
|
|
|
|
var warning_elem = settings_row.find('.subscriber_list_container .alert-warning');
|
2013-01-10 19:33:56 +01:00
|
|
|
|
2013-09-16 21:13:11 +02:00
|
|
|
function invite_success(data) {
|
|
|
|
text_box.val('');
|
|
|
|
|
|
|
|
if (data.subscribed.hasOwnProperty(principal)) {
|
|
|
|
error_elem.addClass("hide");
|
|
|
|
warning_elem.addClass("hide");
|
2017-01-19 20:18:03 +01:00
|
|
|
if (people.is_current_user(principal)) {
|
2013-09-16 21:13:11 +02:00
|
|
|
// mark_subscribed adds the user to the member list
|
2014-02-05 22:53:53 +01:00
|
|
|
exports.mark_subscribed(stream);
|
2013-01-10 19:33:56 +01:00
|
|
|
}
|
2013-09-16 21:13:11 +02:00
|
|
|
} else {
|
|
|
|
error_elem.addClass("hide");
|
|
|
|
warning_elem.removeClass("hide").text("User already subscribed");
|
2013-01-10 19:33:56 +01:00
|
|
|
}
|
2013-09-16 21:13:11 +02:00
|
|
|
}
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
function invite_failure() {
|
2013-09-16 21:13:11 +02:00
|
|
|
warning_elem.addClass("hide");
|
|
|
|
error_elem.removeClass("hide").text("Could not add user to this stream");
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.invite_user_to_stream(principal, stream, invite_success, invite_failure);
|
2013-01-10 19:33:56 +01:00
|
|
|
});
|
2013-01-07 22:09:33 +01:00
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
function show_stream_row(node, e) {
|
|
|
|
$(".display-type #add_new_stream_title").hide();
|
|
|
|
$(".display-type #stream_settings_title, .right .settings").show();
|
|
|
|
$(".stream-row.active").removeClass("active");
|
|
|
|
if (e) {
|
|
|
|
show_subs_pane.settings();
|
|
|
|
|
|
|
|
$(node).addClass("active");
|
2017-01-21 12:58:27 +01:00
|
|
|
exports.show_settings_for(get_stream_id(node));
|
2016-11-01 22:32:10 +01:00
|
|
|
} else {
|
|
|
|
show_subs_pane.nothing_selected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-28 02:44:40 +02:00
|
|
|
$("#subscriptions_table").on("click", ".stream-row", function (e) {
|
|
|
|
if ($(e.target).closest(".check, .subscription_settings").length === 0) {
|
2016-11-01 22:32:10 +01:00
|
|
|
show_stream_row(this, e);
|
2017-02-21 18:13:32 +01:00
|
|
|
exports.change_state.prevent_once();
|
|
|
|
|
|
|
|
window.location.hash = "#subscriptions" + "/" +
|
|
|
|
$(this).attr("data-stream-id") + "/" +
|
|
|
|
hashchange.encodeHashComponent($(this).attr("data-stream-name"));
|
2016-10-28 02:44:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
(function defocus_sub_settings() {
|
|
|
|
var sel = ".search-container, .streams-list, .subscriptions-header";
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", sel, function (e) {
|
|
|
|
if ($(e.target).is(sel)) {
|
|
|
|
show_stream_row(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2014-01-30 17:10:52 +01:00
|
|
|
$("#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();
|
2016-11-04 23:27:01 +01:00
|
|
|
var settings_row = $(e.target).closest('.subscription_settings');
|
|
|
|
var stream_name = get_stream_name(settings_row);
|
|
|
|
var error_elem = settings_row.find('.subscriber_list_container .alert-error');
|
|
|
|
var warning_elem = settings_row.find('.subscriber_list_container .alert-warning');
|
2014-01-30 17:10:52 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2017-01-19 20:18:03 +01:00
|
|
|
if (people.is_current_user(principal)) {
|
2014-01-30 17:10:52 +01:00
|
|
|
// If you're unsubscribing yourself, mark whole
|
|
|
|
// stream entry as you being unsubscribed.
|
2014-02-05 22:53:53 +01:00
|
|
|
exports.mark_unsubscribed(stream_name);
|
2014-01-30 17:10:52 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_elem.addClass("hide");
|
|
|
|
warning_elem.removeClass("hide").text("User already not subscribed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
function removal_failure() {
|
2014-01-30 17:10:52 +01:00
|
|
|
warning_elem.addClass("hide");
|
|
|
|
error_elem.removeClass("hide").text("Could not remove user from this stream");
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.remove_user_from_stream(principal, stream_name, removal_success,
|
|
|
|
removal_failure);
|
|
|
|
});
|
|
|
|
|
2014-01-06 17:22:10 +01:00
|
|
|
$("#subscriptions_table").on("click", ".make-stream-public-button", function (e) {
|
|
|
|
change_stream_privacy(
|
|
|
|
e,
|
2016-12-23 09:15:30 +01:00
|
|
|
false,
|
2014-01-06 17:22:10 +01:00
|
|
|
"The stream has been made public!",
|
|
|
|
"Error making stream public",
|
|
|
|
false
|
|
|
|
);
|
2014-01-03 20:35:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".make-stream-private-button", function (e) {
|
2014-01-06 17:22:10 +01:00
|
|
|
change_stream_privacy(
|
|
|
|
e,
|
2016-12-23 09:15:30 +01:00
|
|
|
true,
|
2014-01-06 17:22:10 +01:00
|
|
|
"The stream has been made private!",
|
|
|
|
"Error making stream private",
|
|
|
|
true
|
|
|
|
);
|
2014-01-03 20:35:52 +01:00
|
|
|
});
|
|
|
|
|
2013-01-26 00:04:18 +01:00
|
|
|
$("#subscriptions_table").on("show", ".regular_subscription_settings", function (e) {
|
|
|
|
// We want 'show' events that originate from
|
|
|
|
// 'regular_subscription_settings' divs not to trigger the
|
|
|
|
// handler for the entire subscription_settings div
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-06-25 17:49:48 +02:00
|
|
|
$("#subscriptions_table").on("hide", ".subscription_settings", function (e) {
|
2016-10-28 23:25:00 +02:00
|
|
|
var sub_arrow = $(e.target).closest('.stream-row').find('.sub_arrow i');
|
2013-06-25 17:49:48 +02:00
|
|
|
sub_arrow.removeClass('icon-vector-chevron-up');
|
|
|
|
sub_arrow.addClass('icon-vector-chevron-down');
|
|
|
|
});
|
2016-10-25 23:12:28 +02:00
|
|
|
|
|
|
|
$(document).on('peer_subscribe.zulip', function (e, data) {
|
|
|
|
var sub = stream_data.get_sub(data.stream_name);
|
|
|
|
exports.rerender_subscribers_count(sub);
|
2016-10-26 01:41:42 +02:00
|
|
|
var sub_row = settings_for_sub(sub);
|
|
|
|
prepend_subscriber(sub_row, data.user_email);
|
2016-10-25 23:12:28 +02:00
|
|
|
});
|
|
|
|
$(document).on('peer_unsubscribe.zulip', function (e, data) {
|
|
|
|
var sub = stream_data.get_sub(data.stream_name);
|
|
|
|
exports.rerender_subscribers_count(sub);
|
2016-10-26 01:41:42 +02:00
|
|
|
|
|
|
|
var sub_row = settings_for_sub(sub);
|
|
|
|
var tr = sub_row.find("tr[data-subscriber-email='" +
|
|
|
|
data.user_email +
|
|
|
|
"']");
|
|
|
|
tr.remove();
|
2016-10-25 23:12:28 +02:00
|
|
|
});
|
|
|
|
|
2012-10-03 22:24:17 +02:00
|
|
|
});
|
2012-10-18 21:37:07 +02:00
|
|
|
|
2013-03-29 19:55:28 +01:00
|
|
|
function focus_on_narrowed_stream() {
|
2013-06-13 19:44:36 +02:00
|
|
|
var stream_name = narrow.stream();
|
|
|
|
if (stream_name === undefined) {
|
2013-03-29 19:55:28 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2016-10-28 02:44:40 +02:00
|
|
|
if (sub === undefined) {
|
2013-03-29 19:55:28 +01:00
|
|
|
// This stream doesn't exist, so prep for creating it.
|
|
|
|
$("#create_stream_name").val(stream_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.show_and_focus_on_narrow = function () {
|
2013-11-25 17:44:06 +01:00
|
|
|
$(document).one('subs_page_loaded.zulip', focus_on_narrowed_stream);
|
2013-03-29 19:55:28 +01:00
|
|
|
ui.change_tab_to("#subscriptions");
|
|
|
|
};
|
|
|
|
|
2012-10-18 21:37:07 +02:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
2013-08-09 02:05:23 +02:00
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = subs;
|
|
|
|
}
|