2012-10-18 21:37:07 +02:00
|
|
|
var subs = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2014-01-03 20:35:52 +01:00
|
|
|
function add_admin_options(sub) {
|
|
|
|
return _.extend(sub, {
|
|
|
|
'is_admin': page_params.is_admin,
|
|
|
|
'can_make_public': page_params.is_admin && sub.invite_only && stream_data.is_subscribed(sub.name),
|
|
|
|
'can_make_private': page_params.is_admin && !sub.invite_only
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
var range, sel;
|
|
|
|
if (window.getSelection) {
|
|
|
|
sel = window.getSelection();
|
|
|
|
range = document.createRange();
|
|
|
|
range.selectNodeContents(element);
|
|
|
|
|
|
|
|
sel.removeAllRanges();
|
|
|
|
sel.addRange(range);
|
|
|
|
}
|
|
|
|
else if (document.body.createTextRange) {
|
|
|
|
range = document.body.createTextRange();
|
|
|
|
range.moveToElementText(element);
|
|
|
|
range.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 17:51:01 +01:00
|
|
|
function should_list_all_streams() {
|
2013-03-25 23:26:14 +01:00
|
|
|
return page_params.domain !== 'mit.edu';
|
2013-01-23 17:51:01 +01:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:43:56 +02:00
|
|
|
exports.stream_id = function (stream_name) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2013-05-06 18:33:03 +02:00
|
|
|
if (sub === undefined) {
|
|
|
|
blueslip.error("Tried to get subs.stream_id for a stream user is not subscribed to!");
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-07 16:55:54 +01:00
|
|
|
return parseInt(sub.stream_id, 10);
|
2013-03-02 03:10:32 +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',
|
2014-02-14 21:55:20 +01:00
|
|
|
data: {"subscription_data": JSON.stringify([sub_data])},
|
2013-04-08 19:43:11 +02:00
|
|
|
timeout: 10*1000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2013-02-12 22:32:14 +01:00
|
|
|
function stream_home_view_clicked(e) {
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream = sub_row.find('.subscription_name').text();
|
2014-02-10 22:47:10 +01:00
|
|
|
var sub = stream_data.get_sub(stream);
|
|
|
|
var notification_checkboxes = sub_row.find(".sub_notification_setting");
|
|
|
|
|
2013-05-14 21:00:28 +02:00
|
|
|
subs.toggle_home(stream);
|
2014-02-10 22:47:10 +01:00
|
|
|
|
|
|
|
if (sub.in_home_view) {
|
|
|
|
sub_row.find(".mute-note").addClass("hide-mute-note");
|
|
|
|
notification_checkboxes.removeClass("muted-sub");
|
|
|
|
notification_checkboxes.find("input[type='checkbox']").removeAttr("disabled");
|
|
|
|
} else {
|
|
|
|
sub_row.find(".mute-note").removeClass("hide-mute-note");
|
|
|
|
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 () {
|
2014-01-29 20:43:51 +01:00
|
|
|
var msg_offset, 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
|
|
|
|
|
|
|
// Recreate the home_msg_list with the newly filtered all_msg_list
|
2014-01-31 16:27:24 +01:00
|
|
|
message_store.add_messages(all_msg_list.all(), 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
|
|
|
|
|
|
|
// 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.
|
|
|
|
recenter_pointer_on_display = true;
|
|
|
|
suppress_scroll_pointer_update = true;
|
|
|
|
|
2013-02-22 20:48:31 +01:00
|
|
|
if (! home_msg_list.empty()) {
|
2014-01-31 23:13:22 +01:00
|
|
|
process_loaded_for_unread(home_msg_list.all());
|
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);
|
|
|
|
|
2014-02-07 16:55:54 +01:00
|
|
|
var not_in_home_view_checkbox = $("#subscription_" + sub.stream_id + " #sub_setting_not_in_home_view .sub_setting_control");
|
2013-11-04 04:30:19 +01:00
|
|
|
not_in_home_view_checkbox.attr('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
|
|
|
|
2014-02-05 23:21:02 +01:00
|
|
|
function update_stream_desktop_notifications(sub, value) {
|
|
|
|
var desktop_notifications_checkbox = $("#subscription_" + sub.stream_id + " #sub_desktop_notifications_setting .sub_setting_control");
|
|
|
|
desktop_notifications_checkbox.attr('checked', value);
|
|
|
|
sub.desktop_notifications = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_stream_audible_notifications(sub, value) {
|
|
|
|
var audible_notifications_checkbox = $("#subscription_" + sub.stream_id + " #sub_audible_notifications_setting .sub_setting_control");
|
|
|
|
audible_notifications_checkbox.attr('checked', value);
|
|
|
|
sub.audible_notifications = value;
|
2013-07-16 22:47:30 +02:00
|
|
|
}
|
|
|
|
|
2013-08-21 23:21:31 +02:00
|
|
|
function update_stream_name(sub, new_name) {
|
|
|
|
// Rename the stream internally.
|
|
|
|
var old_name = sub.name;
|
|
|
|
stream_data.delete_sub(old_name);
|
|
|
|
sub.name = new_name;
|
|
|
|
stream_data.add_sub(new_name, sub);
|
|
|
|
|
2013-10-21 22:26:19 +02:00
|
|
|
// Update the left sidebar.
|
|
|
|
stream_list.rename_stream(sub);
|
2013-08-21 23:21:31 +02:00
|
|
|
|
|
|
|
// Update the message feed.
|
|
|
|
_.each([home_msg_list, current_msg_list, all_msg_list], function (list) {
|
|
|
|
list.change_display_recipient(old_name, new_name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-01-24 18:19:27 +01:00
|
|
|
function update_stream_description(sub, description) {
|
|
|
|
sub.description = description;
|
|
|
|
|
2014-02-07 16:55:54 +01:00
|
|
|
var sub_settings_selector = '.subscription_row[data-subscription-id=' + sub.stream_id + ']';
|
2014-01-24 18:19:27 +01:00
|
|
|
$(sub_settings_selector + ' .subscription_description').text(description);
|
|
|
|
$(sub_settings_selector + ' input.description').val(description);
|
|
|
|
}
|
|
|
|
|
2014-02-05 23:21:02 +01:00
|
|
|
function stream_desktop_notifications_clicked(e) {
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream = sub_row.find('.subscription_name').text();
|
|
|
|
|
|
|
|
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) {
|
2013-04-09 02:14:13 +02:00
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream = sub_row.find('.subscription_name').text();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-08-07 19:28:06 +02:00
|
|
|
exports.set_color = function (stream_name, color) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2013-08-07 19:28:06 +02:00
|
|
|
stream_color.update_stream_color(sub, stream_name, color, {update_historical: true});
|
2013-04-08 19:43:11 +02:00
|
|
|
set_stream_property(stream_name, 'color', color);
|
2013-05-17 21:35:17 +02:00
|
|
|
};
|
|
|
|
|
2013-01-22 23:16:04 +01:00
|
|
|
function create_sub(stream_name, attrs) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2013-03-02 03:10:32 +01:00
|
|
|
if (sub !== undefined) {
|
|
|
|
// We've already created this subscription, no need to continue.
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:55:54 +01:00
|
|
|
if (!attrs.stream_id) {
|
|
|
|
// fail fast (blueslip.fatal will throw an error on our behalf)
|
|
|
|
blueslip.fatal("We cannot create a sub without a stream_id");
|
|
|
|
return; // this line is never actually reached
|
|
|
|
}
|
|
|
|
|
2013-09-16 23:28:48 +02:00
|
|
|
// Our internal data structure for subscriptions is mostly plain dictionaries,
|
|
|
|
// so we just reuse the attrs that are passed in to us, but we encapsulate how
|
|
|
|
// we handle subscribers.
|
|
|
|
var subscriber_emails = attrs.subscribers;
|
|
|
|
var raw_attrs = _.omit(attrs, 'subscribers');
|
|
|
|
|
|
|
|
sub = _.defaults(raw_attrs, {
|
2013-07-30 05:11:50 +02:00
|
|
|
name: stream_name,
|
2013-08-15 00:50:19 +02:00
|
|
|
render_subscribers: page_params.domain !== 'mit.edu' || attrs.invite_only === true,
|
2013-07-30 05:11:50 +02:00
|
|
|
subscribed: true,
|
|
|
|
in_home_view: true,
|
|
|
|
invite_only: false,
|
2014-02-05 23:21:02 +01:00
|
|
|
desktop_notifications: page_params.desktop_notifications_enabled,
|
|
|
|
audible_notifications: page_params.sounds_enabled,
|
2014-01-24 20:40:06 +01:00
|
|
|
description: ''
|
2013-07-30 05:11:50 +02:00
|
|
|
});
|
2013-08-07 20:23:12 +02:00
|
|
|
|
2013-09-16 23:28:48 +02:00
|
|
|
stream_data.set_subscribers(sub, subscriber_emails);
|
2013-09-07 03:10:08 +02:00
|
|
|
|
2013-08-07 20:23:12 +02:00
|
|
|
if (!sub.color) {
|
|
|
|
sub.color = get_color();
|
|
|
|
}
|
2013-03-02 03:10:32 +01:00
|
|
|
|
2013-08-15 21:11:07 +02:00
|
|
|
stream_data.add_sub(stream_name, sub);
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).trigger($.Event('sub_obj_created.zulip', {sub: sub}));
|
2013-01-22 23:16:04 +01:00
|
|
|
return sub;
|
|
|
|
}
|
2013-01-04 20:42:39 +01:00
|
|
|
|
2013-01-22 23:16:04 +01:00
|
|
|
function button_for_sub(sub) {
|
2014-02-07 16:55:54 +01:00
|
|
|
var id = parseInt(sub.stream_id, 10);
|
2013-01-22 23:16:04 +01:00
|
|
|
return $("#subscription_" + id + " .sub_unsub_button");
|
|
|
|
}
|
2013-01-04 20:42:39 +01:00
|
|
|
|
2013-01-23 19:43:11 +01:00
|
|
|
function settings_for_sub(sub) {
|
2014-02-07 16:55:54 +01:00
|
|
|
var id = parseInt(sub.stream_id, 10);
|
2013-01-23 19:43:11 +01:00
|
|
|
return $("#subscription_settings_" + id);
|
|
|
|
}
|
|
|
|
|
2013-06-18 22:15:41 +02:00
|
|
|
exports.show_settings_for = function (stream_name) {
|
2013-08-15 21:11:07 +02:00
|
|
|
settings_for_sub(stream_data.get_sub(stream_name)).collapse('show');
|
2013-06-18 22:15:41 +02:00
|
|
|
};
|
|
|
|
|
2013-08-26 20:22:22 +02:00
|
|
|
function add_email_hint(row) {
|
|
|
|
// 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);
|
|
|
|
email_address_hint.popover({"placement": "bottom",
|
|
|
|
"title": "Email integration",
|
2014-07-16 22:43:14 +02:00
|
|
|
"content": templates.render('email_address_hint',
|
|
|
|
{ page_params: page_params }),
|
2013-08-26 20:22:22 +02:00
|
|
|
"trigger": "manual"});
|
|
|
|
$("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) {
|
2014-01-03 20:35:52 +01:00
|
|
|
sub = add_admin_options(sub);
|
|
|
|
var html = templates.render('subscription', sub);
|
|
|
|
$('#create_stream_row').after(html);
|
2013-01-23 19:43:11 +01:00
|
|
|
settings_for_sub(sub).collapse('show');
|
2013-08-26 20:22:22 +02:00
|
|
|
add_email_hint(sub);
|
2013-01-23 19:43:11 +01:00
|
|
|
}
|
|
|
|
|
2013-01-23 21:34:48 +01:00
|
|
|
function format_member_list_elem(name, email) {
|
2014-01-30 17:10:52 +01:00
|
|
|
return templates.render('stream_member_list_entry',
|
|
|
|
{name: name, email: email,
|
|
|
|
displaying_for_admin: page_params.is_admin});
|
2013-11-08 10:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_element_to_member_list (tb, elem) {
|
|
|
|
tb.prepend(elem);
|
2013-01-23 21:34:48 +01:00
|
|
|
}
|
|
|
|
|
2013-11-08 10:12:05 +01:00
|
|
|
function add_to_member_list(tb, name, email) {
|
|
|
|
tb.prepend(format_member_list_elem(name, email));
|
2013-01-23 21:34:48 +01: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) {
|
2013-03-10 19:36:45 +01:00
|
|
|
// Create a new stream.
|
2013-02-05 20:30:00 +01:00
|
|
|
sub = create_sub(stream_name, attrs);
|
2013-01-23 19:43:11 +01:00
|
|
|
add_sub_to_table(sub);
|
2013-01-22 23:16:04 +01:00
|
|
|
} else if (! sub.subscribed) {
|
2013-09-07 03:10:08 +02:00
|
|
|
// Add yourself to a stream we already know about client-side.
|
2013-08-07 20:23:12 +02:00
|
|
|
var color = get_color();
|
|
|
|
exports.set_color(stream_name, color);
|
2013-01-22 23:16:04 +01:00
|
|
|
sub.subscribed = true;
|
2013-09-07 03:10:08 +02:00
|
|
|
sub.subscribers = Dict.from_array(attrs.subscribers);
|
2013-04-24 22:21:14 +02:00
|
|
|
var settings = settings_for_sub(sub);
|
2013-01-22 23:16:04 +01:00
|
|
|
var button = button_for_sub(sub);
|
|
|
|
if (button.length !== 0) {
|
2014-03-05 22:28:57 +01:00
|
|
|
button.text("Subscribed").addClass("subscribed-button").addClass("btn-success");
|
2013-04-24 22:21:14 +02: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')) {
|
2013-11-08 10:12:05 +01:00
|
|
|
var members = settings.find(".subscriber_list_container .subscriber-list");
|
2013-04-24 22:21:14 +02:00
|
|
|
add_to_member_list(members, page_params.fullname, page_params.email);
|
|
|
|
}
|
2013-01-22 23:16:04 +01:00
|
|
|
} else {
|
2013-01-23 19:43:11 +01:00
|
|
|
add_sub_to_table(sub);
|
2013-01-22 23:16:04 +01:00
|
|
|
}
|
2013-01-23 22:08:34 +01:00
|
|
|
|
|
|
|
// Display the swatch and subscription settings
|
|
|
|
var sub_row = settings.closest('.subscription_row');
|
2013-01-26 00:04:18 +01:00
|
|
|
sub_row.find(".color_swatch").addClass('in');
|
|
|
|
sub_row.find(".regular_subscription_settings").collapse('show');
|
2013-01-22 23:16:04 +01:00
|
|
|
} else {
|
|
|
|
// Already subscribed
|
|
|
|
return;
|
2012-10-18 21:37:07 +02:00
|
|
|
}
|
2013-03-21 22:13:17 +01:00
|
|
|
|
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
|
2014-01-31 23:13:22 +01:00
|
|
|
process_loaded_for_unread(all_msg_list.all());
|
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) {
|
2014-02-07 19:26:35 +01:00
|
|
|
stream_list.remove_narrow_filter(sub.name, 'stream');
|
2013-01-22 23:16:04 +01:00
|
|
|
sub.subscribed = false;
|
2014-03-05 22:28:57 +01:00
|
|
|
button_for_sub(sub).removeClass("subscribed-button").removeClass("btn-success").removeClass("btn-danger").text("Subscribe");
|
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
|
|
|
|
|
|
|
// Hide the swatch and subscription settings
|
|
|
|
var sub_row = settings.closest('.subscription_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
|
|
|
|
// that it's not empty on the MIT realm, even though it
|
|
|
|
// 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}));
|
2014-02-05 22:53:53 +01:00
|
|
|
};
|
2013-03-29 20:27:41 +01:00
|
|
|
|
2014-02-05 23:21:02 +01:00
|
|
|
exports.receives_desktop_notifications = function (stream_name) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2013-04-09 02:14:13 +02:00
|
|
|
if (sub === undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-05 23:21:02 +01:00
|
|
|
return sub.desktop_notifications;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.receives_audible_notifications = function (stream_name) {
|
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
if (sub === undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return sub.audible_notifications;
|
2013-04-09 02:14:13 +02:00
|
|
|
};
|
|
|
|
|
2013-06-12 21:16:05 +02:00
|
|
|
function populate_subscriptions(subs, subscribed) {
|
2013-04-04 22:30:28 +02:00
|
|
|
var sub_rows = [];
|
|
|
|
subs.sort(function (a, b) {
|
2013-05-03 19:16:50 +02:00
|
|
|
return util.strcmp(a.name, b.name);
|
2013-04-04 22:30:28 +02:00
|
|
|
});
|
|
|
|
subs.forEach(function (elem) {
|
|
|
|
var stream_name = elem.name;
|
|
|
|
var sub = create_sub(stream_name, {color: elem.color, in_home_view: elem.in_home_view,
|
2013-04-09 02:14:13 +02:00
|
|
|
invite_only: elem.invite_only,
|
2014-02-05 23:21:02 +01:00
|
|
|
desktop_notifications: elem.desktop_notifications,
|
|
|
|
audible_notifications: elem.audible_notifications,
|
|
|
|
subscribed: subscribed,
|
2013-09-07 02:48:44 +02:00
|
|
|
email_address: elem.email_address,
|
2014-02-05 19:58:41 +01:00
|
|
|
stream_id: elem.stream_id,
|
2014-01-24 20:40:06 +01:00
|
|
|
subscribers: elem.subscribers,
|
|
|
|
description: elem.description});
|
2013-04-04 22:30:28 +02:00
|
|
|
sub_rows.push(sub);
|
|
|
|
});
|
|
|
|
|
|
|
|
return sub_rows;
|
|
|
|
}
|
|
|
|
|
2013-01-10 20:30:15 +01:00
|
|
|
exports.setup_page = function () {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.make_indicator($('#subs_page_loading_indicator'));
|
2013-01-23 17:41:04 +01:00
|
|
|
|
2013-10-25 17:27:07 +02:00
|
|
|
function populate_and_fill(public_streams) {
|
|
|
|
|
|
|
|
// Build up our list of subscribed streams from the data we already have.
|
|
|
|
var subscribed_rows = stream_data.subscribed_subs();
|
|
|
|
|
|
|
|
// To avoid dups, build a set of names we already subscribed to.
|
|
|
|
var subscribed_set = new Dict({fold_case: true});
|
|
|
|
_.each(subscribed_rows, function (sub) {
|
|
|
|
subscribed_set.set(sub.name, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Right now the back end gives us all public streams; we really only
|
|
|
|
// need to add the ones we haven't already subscribed to.
|
2014-01-24 20:40:06 +01:00
|
|
|
var unsubscribed_streams = _.reject(public_streams.streams, function (stream) {
|
|
|
|
return subscribed_set.has(stream.name);
|
2013-10-25 17:27:07 +02:00
|
|
|
});
|
2013-01-23 17:41:04 +01:00
|
|
|
|
2013-10-25 17:27:07 +02:00
|
|
|
// Build up our list of unsubscribed rows.
|
|
|
|
var unsubscribed_rows = [];
|
2014-01-24 20:40:06 +01:00
|
|
|
_.each(unsubscribed_streams, function (stream) {
|
|
|
|
var sub = stream_data.get_sub(stream.name);
|
2013-10-21 20:35:09 +02:00
|
|
|
if (!sub) {
|
2014-01-24 20:40:06 +01:00
|
|
|
sub = create_sub(stream.name, _.extend({subscribed: false}, stream));
|
2013-06-17 20:42:35 +02:00
|
|
|
}
|
2013-10-25 17:27:07 +02:00
|
|
|
unsubscribed_rows.push(sub);
|
2013-06-17 20:42:35 +02:00
|
|
|
});
|
|
|
|
|
2013-10-25 17:27:07 +02:00
|
|
|
// Sort and combine all our streams.
|
|
|
|
function by_name(a,b) {
|
|
|
|
return util.strcmp(a.name, b.name);
|
|
|
|
}
|
|
|
|
subscribed_rows.sort(by_name);
|
|
|
|
unsubscribed_rows.sort(by_name);
|
|
|
|
var all_subs = subscribed_rows.concat(unsubscribed_rows);
|
|
|
|
|
|
|
|
// Add in admin options.
|
|
|
|
var sub_rows = [];
|
|
|
|
_.each(all_subs, function (sub) {
|
2014-01-03 20:35:52 +01:00
|
|
|
sub = add_admin_options(sub);
|
2013-01-23 17:41:04 +01:00
|
|
|
sub_rows.push(sub);
|
|
|
|
});
|
|
|
|
|
2013-07-26 20:43:14 +02:00
|
|
|
$('#subscriptions_table').empty();
|
2014-01-15 23:30:36 +01:00
|
|
|
var template_data = {
|
|
|
|
can_create_streams: page_params.can_create_streams,
|
|
|
|
subscriptions: sub_rows
|
|
|
|
};
|
|
|
|
var rendered = templates.render('subscription_table_body', template_data);
|
2013-07-26 20:43:14 +02:00
|
|
|
$('#subscriptions_table').append(rendered);
|
2013-01-31 21:13:28 +01:00
|
|
|
|
2013-08-26 20:22:22 +02:00
|
|
|
_.each(sub_rows, function (row) {
|
|
|
|
add_email_hint(row);
|
|
|
|
});
|
|
|
|
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator($('#subs_page_loading_indicator'));
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).trigger($.Event('subs_page_loaded.zulip'));
|
2013-01-23 17:41:04 +01:00
|
|
|
}
|
|
|
|
|
2013-04-04 22:30:28 +02:00
|
|
|
function failed_listing(xhr, error) {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator($('#subs_page_loading_indicator'));
|
2013-04-04 22:30:28 +02:00
|
|
|
ui.report_error("Error listing streams or subscriptions", xhr, $("#subscriptions-status"));
|
|
|
|
}
|
|
|
|
|
2013-01-23 17:51:01 +01:00
|
|
|
if (should_list_all_streams()) {
|
2013-12-18 19:55:18 +01:00
|
|
|
var req = channel.post({
|
2013-01-23 17:51:01 +01:00
|
|
|
url: '/json/get_public_streams',
|
2014-01-07 23:40:31 +01:00
|
|
|
idempotent: true,
|
2013-10-21 20:35:09 +02:00
|
|
|
timeout: 10*1000,
|
|
|
|
success: populate_and_fill,
|
|
|
|
error: failed_listing
|
2013-01-23 17:51:01 +01:00
|
|
|
});
|
|
|
|
} else {
|
2013-10-21 20:35:09 +02:00
|
|
|
populate_and_fill({streams: []});
|
2013-01-31 16:34:29 +01:00
|
|
|
$('#create_stream_button').val("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
|
|
|
|
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;
|
|
|
|
}
|
2013-07-16 22:21:41 +02:00
|
|
|
switch(property) {
|
|
|
|
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':
|
|
|
|
update_stream_name(sub, value);
|
|
|
|
break;
|
2014-01-24 18:19:27 +01:00
|
|
|
case 'description':
|
|
|
|
update_stream_description(sub, value);
|
|
|
|
break;
|
2014-02-05 20:52:12 +01:00
|
|
|
case 'email_address':
|
|
|
|
sub.email_address = value;
|
|
|
|
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({
|
2012-11-07 23:25:04 +01:00
|
|
|
url: "/json/subscriptions/add",
|
2013-06-24 21:32:56 +02:00
|
|
|
data: {"subscriptions": JSON.stringify([{"name": stream}]) },
|
2012-11-07 23:25:04 +01:00
|
|
|
success: function (resp, statusText, xhr, form) {
|
2013-01-31 21:09:34 +01:00
|
|
|
$("#create_stream_name").val("");
|
|
|
|
|
|
|
|
var res = $.parseJSON(xhr.responseText);
|
|
|
|
if (!$.isEmptyObject(res.already_subscribed)) {
|
|
|
|
// Display the canonical stream capitalization.
|
2013-03-25 23:26:14 +01:00
|
|
|
true_stream_name = res.already_subscribed[page_params.email][0];
|
2013-01-31 21:09:34 +01:00
|
|
|
ui.report_success("Already subscribed to " + true_stream_name,
|
|
|
|
$("#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) {
|
2012-11-16 16:45:39 +01:00
|
|
|
ui.report_error("Error adding subscription", xhr, $("#subscriptions-status"));
|
2013-01-23 19:10:51 +01:00
|
|
|
$("#create_stream_name").focus();
|
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) {
|
2013-12-18 19:55:18 +01:00
|
|
|
return channel.post({
|
2012-11-16 20:11:08 +01:00
|
|
|
url: "/json/subscriptions/remove",
|
|
|
|
data: {"subscriptions": JSON.stringify([stream]) },
|
2012-10-03 22:24:17 +02:00
|
|
|
success: function (resp, statusText, xhr, form) {
|
2012-11-16 20:11:08 +01:00
|
|
|
var name, res = $.parseJSON(xhr.responseText);
|
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) {
|
2012-11-16 16:45:39 +01:00
|
|
|
ui.report_error("Error removing subscription", xhr, $("#subscriptions-status"));
|
2013-01-23 19:10:51 +01:00
|
|
|
$("#create_stream_name").focus();
|
2012-10-03 22:24:17 +02:00
|
|
|
}
|
|
|
|
});
|
2013-01-10 22:15:55 +01:00
|
|
|
}
|
2012-11-16 20:11:08 +01:00
|
|
|
|
2013-08-27 19:14:18 +02:00
|
|
|
function ajaxSubscribeForCreation(stream, 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({
|
2013-01-31 21:09:34 +01:00
|
|
|
url: "/json/subscriptions/add",
|
2013-06-24 21:32:56 +02:00
|
|
|
data: {"subscriptions": JSON.stringify([{"name": stream}]),
|
2013-01-30 23:12:23 +01:00
|
|
|
"principals": JSON.stringify(principals),
|
2013-08-27 19:14:18 +02:00
|
|
|
"invite_only": JSON.stringify(invite_only),
|
|
|
|
"announce": JSON.stringify(announce)
|
2013-01-31 21:09:34 +01:00
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
$("#create_stream_name").val("");
|
2013-02-06 00:58:03 +01:00
|
|
|
$("#subscriptions-status").hide();
|
2013-01-31 21:09:34 +01:00
|
|
|
$('#stream-creation').modal("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) {
|
|
|
|
ui.report_error("Error creating stream", xhr, $("#subscriptions-status"));
|
|
|
|
$('#stream-creation').modal("hide");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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() {
|
2013-02-16 10:45:32 +01:00
|
|
|
$('#people_to_add').html(templates.render('new_stream_users', {
|
2014-01-30 22:42:19 +01:00
|
|
|
users: people.get_rest_of_realm()
|
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);
|
|
|
|
|
2013-01-31 21:09:34 +01:00
|
|
|
$('#stream-creation').modal("show");
|
|
|
|
}
|
|
|
|
|
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({
|
2013-09-16 21:13:11 +02:00
|
|
|
url: "/json/subscriptions/add",
|
|
|
|
data: {"subscriptions": JSON.stringify([{"name": stream_name}]),
|
|
|
|
"principals": JSON.stringify([user_email])},
|
|
|
|
success: success,
|
|
|
|
error: failure
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-30 17:10:52 +01:00
|
|
|
exports.remove_user_from_stream = function (user_email, stream_name, success, failure) {
|
|
|
|
return channel.post({
|
|
|
|
url: "/json/subscriptions/remove",
|
|
|
|
data: {"subscriptions": JSON.stringify([stream_name]),
|
|
|
|
"principals": JSON.stringify([user_email])},
|
|
|
|
success: success,
|
|
|
|
error: failure
|
|
|
|
});
|
|
|
|
};
|
2013-10-21 19:37:52 +02:00
|
|
|
|
|
|
|
function inline_emails_into_subscriber_list(subs, email_dict) {
|
|
|
|
// When we get subscriber lists from the back end, they are sent as user ids to
|
|
|
|
// save bandwidth, but the legacy JS code wants emails.
|
|
|
|
_.each(subs, function (sub) {
|
|
|
|
if (sub.subscribers) {
|
|
|
|
sub.subscribers = _.map(sub.subscribers, function (subscription) {
|
|
|
|
return email_dict[subscription];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-11-16 20:11:08 +01:00
|
|
|
$(function () {
|
|
|
|
var i;
|
2013-10-21 19:37:52 +02:00
|
|
|
|
2014-01-23 21:04:46 +01:00
|
|
|
inline_emails_into_subscriber_list(page_params.subbed_info, page_params.email_dict);
|
2013-10-21 19:37:52 +02:00
|
|
|
inline_emails_into_subscriber_list(page_params.unsubbed_info, page_params.email_dict);
|
|
|
|
|
2013-01-04 18:02:01 +01:00
|
|
|
// Populate stream_info with data handed over to client-side template.
|
2014-01-23 21:04:46 +01:00
|
|
|
populate_subscriptions(page_params.subbed_info, true);
|
2013-06-12 21:16:05 +02:00
|
|
|
populate_subscriptions(page_params.unsubbed_info, false);
|
2012-10-03 22:24:17 +02:00
|
|
|
|
2014-01-23 21:13:04 +01:00
|
|
|
// Garbage collect data structures that were only used for initialization.
|
|
|
|
delete page_params.subbed_info;
|
|
|
|
delete page_params.unsubbed_info;
|
|
|
|
|
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();
|
|
|
|
|
2013-07-26 20:43:14 +02:00
|
|
|
$("#subscriptions_table").on("submit", "#add_new_subscription", function (e) {
|
2012-10-31 18:36:08 +01:00
|
|
|
e.preventDefault();
|
2013-01-31 21:13:28 +01:00
|
|
|
|
|
|
|
if (!should_list_all_streams()) {
|
|
|
|
ajaxSubscribe($("#create_stream_name").val());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-31 21:09:34 +01:00
|
|
|
var stream = $.trim($("#create_stream_name").val());
|
2013-03-11 23:13:37 +01:00
|
|
|
var stream_status = compose.check_stream_existence(stream);
|
2013-01-31 21:09:34 +01:00
|
|
|
if (stream_status === "does-not-exist") {
|
|
|
|
$("#stream_name").text(stream);
|
|
|
|
show_new_stream_modal();
|
|
|
|
} else {
|
|
|
|
ajaxSubscribe(stream);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-08-27 19:14:18 +02:00
|
|
|
$('#stream_creation_form').on('change',
|
|
|
|
'#user-checkboxes input, #make-invite-only input',
|
|
|
|
update_announce_stream_state);
|
|
|
|
|
|
|
|
// 'Check all' and 'Uncheck all' links
|
|
|
|
$(document).on('click', '.subs_set_all_users', function (e) {
|
|
|
|
$('#people_to_add :checkbox').attr('checked', true);
|
|
|
|
e.preventDefault();
|
|
|
|
update_announce_stream_state();
|
|
|
|
});
|
|
|
|
$(document).on('click', '.subs_unset_all_users', function (e) {
|
|
|
|
$('#people_to_add :checkbox').attr('checked', false);
|
|
|
|
e.preventDefault();
|
|
|
|
update_announce_stream_state();
|
|
|
|
});
|
|
|
|
|
|
|
|
var announce_stream_docs = $("#announce-stream-docs");
|
|
|
|
announce_stream_docs.popover({"placement": "right",
|
|
|
|
"content": templates.render('announce_stream_docs'),
|
|
|
|
"trigger": "manual"});
|
|
|
|
$("body").on("mouseover", "#announce-stream-docs", function (e) {
|
|
|
|
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) {
|
|
|
|
announce_stream_docs.popover('hide');
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-01-31 21:09:34 +01:00
|
|
|
$("#stream_creation_form").on("submit", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var stream = $.trim($("#create_stream_name").val());
|
2013-07-30 00:35:44 +02:00
|
|
|
var principals = _.map(
|
|
|
|
$("#stream_creation_form input:checkbox[name=user]:checked"),
|
|
|
|
function (elem) {
|
|
|
|
return $(elem).val();
|
|
|
|
}
|
|
|
|
);
|
2013-01-31 21:09:34 +01:00
|
|
|
// You are always subscribed to streams you create.
|
2013-03-25 23:26:14 +01:00
|
|
|
principals.push(page_params.email);
|
2013-03-11 20:30:37 +01:00
|
|
|
ajaxSubscribeForCreation(stream,
|
|
|
|
principals,
|
2013-08-27 19:14:18 +02:00
|
|
|
$('#stream_creation_form input[name=privacy]:checked').val() === "invite-only",
|
|
|
|
$('#announce-new-stream input').prop('checked')
|
2013-03-11 20:30:37 +01:00
|
|
|
);
|
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) {
|
2014-03-05 22:28:57 +01:00
|
|
|
$(e.target).addClass("btn-danger").text("Unsubscribe");
|
2013-11-08 10:12:05 +01:00
|
|
|
}).on("mouseout", ".subscribed-button", function (e) {
|
2014-03-05 22:28:57 +01:00
|
|
|
$(e.target).removeClass("btn-danger").text("Subscribed");
|
2013-11-08 10:12:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".email-address", function (e) {
|
|
|
|
selectText(this);
|
|
|
|
});
|
|
|
|
|
2013-01-10 22:15:55 +01:00
|
|
|
$("#subscriptions_table").on("click", ".sub_unsub_button", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream_name = sub_row.find('.subscription_name').text();
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-01-16 20:16:28 +01:00
|
|
|
$("#subscriptions_table").on("show", ".subscription_settings", function (e) {
|
2013-03-08 23:44:02 +01:00
|
|
|
var subrow = $(e.target).closest('.subscription_row');
|
|
|
|
var colorpicker = subrow.find('.colorpicker');
|
2013-07-10 18:33:31 +02:00
|
|
|
|
2013-08-15 21:11:07 +02:00
|
|
|
var color = stream_data.get_color(subrow.find('.subscription_name').text());
|
2013-08-07 19:28:06 +02:00
|
|
|
stream_color.set_colorpicker_color(colorpicker, color);
|
2013-03-08 23:44:02 +01:00
|
|
|
|
|
|
|
// To figure out the worst case for an expanded row's height, we do some math:
|
|
|
|
// .subscriber_list_container max-height,
|
|
|
|
// .subscriber_list_settings,
|
|
|
|
// .regular_subscription_settings
|
|
|
|
// .subscription_header line-height,
|
|
|
|
// .subscription_header padding
|
|
|
|
var expanded_row_size = 200 + 30 + 100 + 30 + 5;
|
2014-01-27 19:40:12 +01:00
|
|
|
var cover = subrow.offset().top + expanded_row_size -
|
|
|
|
viewport.height() + viewport.scrollTop();
|
2013-03-08 23:44:02 +01:00
|
|
|
if (cover > 0) {
|
2014-01-27 19:40:12 +01:00
|
|
|
$('.app').animate({
|
2013-03-08 23:44:02 +01:00
|
|
|
scrollTop: viewport.scrollTop() + cover + 5
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-01-07 18:18:27 +01:00
|
|
|
// Make all inputs have a default tabindex
|
|
|
|
subrow.find('.subscription_settings :input').removeAttr('tabindex');
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("hide", ".subscription_settings", function (e) {
|
|
|
|
var subrow = $(e.target).closest('.subscription_row');
|
|
|
|
|
|
|
|
// Remove all inputs from the tabindex
|
|
|
|
subrow.find('.subscription_settings :input').attr('tabindex', '-1');
|
2013-01-16 20:16:28 +01:00
|
|
|
});
|
|
|
|
|
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);
|
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();
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream = sub_row.find('.subscription_name').text();
|
|
|
|
var text_box = sub_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
|
|
|
|
var error_elem = sub_row.find('.subscriber_list_container .alert-error');
|
|
|
|
var warning_elem = sub_row.find('.subscriber_list_container .alert-warning');
|
2013-11-08 10:12:05 +01:00
|
|
|
var list = sub_row.find('.subscriber_list_container .subscriber-list');
|
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");
|
|
|
|
if (principal === page_params.email) {
|
|
|
|
// 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
|
|
|
} else {
|
2014-01-30 22:42:19 +01:00
|
|
|
add_to_member_list(list, people.get_by_email(principal).full_name, principal);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function invite_failure(xhr) {
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream_name = sub_row.find('.subscription_name').text();
|
|
|
|
var error_elem = sub_row.find('.subscriber_list_container .alert-error');
|
|
|
|
var warning_elem = sub_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 (principal === page_params.email) {
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removal_failure(xhr) {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2013-09-10 11:45:57 +02:00
|
|
|
$("#subscriptions_table").on("submit", ".rename-stream form", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var old_name_box = sub_row.find('.subscription_name');
|
|
|
|
var old_name = old_name_box.text();
|
|
|
|
var new_name_box = sub_row.find('input[name="new-name"]');
|
|
|
|
var new_name = $.trim(new_name_box.val());
|
|
|
|
|
|
|
|
$("#subscriptions-status").hide();
|
|
|
|
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.post({
|
2013-09-10 11:45:57 +02:00
|
|
|
url: "/json/rename_stream",
|
|
|
|
data: {"old_name": old_name, "new_name": new_name},
|
|
|
|
success: function (data) {
|
|
|
|
new_name_box.val('');
|
|
|
|
// Update all visible instances of the old name to the new name.
|
|
|
|
old_name_box.text(new_name);
|
|
|
|
sub_row.find(".email-address").text(data.email_address);
|
|
|
|
|
|
|
|
ui.report_success("The stream has been renamed!", $("#subscriptions-status"));
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
ui.report_error("Error renaming stream", xhr, $("#subscriptions-status"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-22 20:20:10 +01:00
|
|
|
$('#subscriptions_table').on('submit', '.change-stream-description form', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var $form = $(e.target);
|
|
|
|
|
|
|
|
var $sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream_name = $sub_row.find('.subscription_name').text();
|
|
|
|
var description = $sub_row.find('input[name="description"]').val();
|
|
|
|
|
|
|
|
$('#subscription_status').hide();
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: '/json/streams/' + stream_name,
|
|
|
|
data: {
|
|
|
|
'description': JSON.stringify(description)
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
// The event from the server will update the rest of the UI
|
|
|
|
ui.report_success("The stream description has been updated!", $("#subscriptions-status"));
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
ui.report_error("Error updating the stream description", xhr, $("#subscriptions-status"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-03 20:35:52 +01:00
|
|
|
function redraw_privacy_related_stuff(sub_row, sub) {
|
|
|
|
var html;
|
|
|
|
|
|
|
|
sub = add_admin_options(sub);
|
|
|
|
|
|
|
|
html = templates.render('subscription_setting_icon', sub);
|
|
|
|
sub_row.find('.subscription-setting-icon').expectOne().html(html);
|
|
|
|
|
|
|
|
html = templates.render('subscription_type', sub);
|
|
|
|
sub_row.find('.subscription-type').expectOne().html(html);
|
|
|
|
|
|
|
|
html = templates.render('change_stream_privacy', sub);
|
|
|
|
sub_row.find('.change-stream-privacy').expectOne().html(html);
|
2014-01-17 18:59:56 +01:00
|
|
|
|
|
|
|
stream_list.redraw_stream_privacy(sub.name);
|
2014-01-03 20:35:52 +01:00
|
|
|
}
|
|
|
|
|
2014-01-06 17:22:10 +01:00
|
|
|
function change_stream_privacy(e, url, success_message, error_message, invite_only) {
|
2014-01-03 20:35:52 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var stream_name = $(e.target).attr("data-stream-name");
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
|
|
|
|
$("#subscriptions-status").hide();
|
|
|
|
var data = {"stream_name": stream_name};
|
|
|
|
|
|
|
|
channel.post({
|
2014-01-06 17:22:10 +01:00
|
|
|
url: url,
|
2014-01-03 20:35:52 +01:00
|
|
|
data: data,
|
|
|
|
success: function (data) {
|
|
|
|
var sub = stream_data.get_sub(stream_name);
|
2014-01-06 17:22:10 +01:00
|
|
|
sub.invite_only = invite_only;
|
2014-01-03 20:35:52 +01:00
|
|
|
redraw_privacy_related_stuff(sub_row, sub);
|
|
|
|
var feedback_div = sub_row.find(".change-stream-privacy-feedback").expectOne();
|
2014-01-06 17:22:10 +01:00
|
|
|
ui.report_success(success_message, feedback_div);
|
2014-01-03 20:35:52 +01:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
var feedback_div = sub_row.find(".change-stream-privacy-feedback").expectOne();
|
2014-01-06 17:22:10 +01:00
|
|
|
ui.report_error(error_message, xhr, feedback_div);
|
2014-01-03 20:35:52 +01:00
|
|
|
}
|
|
|
|
});
|
2014-01-06 17:22:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("click", ".make-stream-public-button", function (e) {
|
|
|
|
change_stream_privacy(
|
|
|
|
e,
|
|
|
|
"/json/make_stream_public",
|
|
|
|
"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,
|
|
|
|
"/json/make_stream_private",
|
|
|
|
"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-01-07 22:09:33 +01:00
|
|
|
$("#subscriptions_table").on("show", ".subscription_settings", function (e) {
|
|
|
|
var sub_row = $(e.target).closest('.subscription_row');
|
|
|
|
var stream = sub_row.find('.subscription_name').text();
|
2013-01-29 22:37:24 +01:00
|
|
|
var warning_elem = sub_row.find('.subscriber_list_container .alert-warning');
|
2013-01-10 19:33:56 +01:00
|
|
|
var error_elem = sub_row.find('.subscriber_list_container .alert-error');
|
2013-11-08 10:12:05 +01:00
|
|
|
var list = sub_row.find('.subscriber_list_container .subscriber-list');
|
2013-01-16 22:02:49 +01:00
|
|
|
var indicator_elem = sub_row.find('.subscriber_list_loading_indicator');
|
2013-01-10 20:22:25 +01:00
|
|
|
|
2013-08-20 23:15:53 +02:00
|
|
|
if (!stream_data.get_sub(stream).render_subscribers) {
|
2013-08-15 00:50:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-29 22:37:24 +01:00
|
|
|
warning_elem.addClass('hide');
|
2013-01-07 22:09:33 +01:00
|
|
|
error_elem.addClass('hide');
|
|
|
|
list.empty();
|
|
|
|
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.make_indicator(indicator_elem);
|
2013-01-16 22:02:49 +01:00
|
|
|
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.post({
|
2013-01-07 22:09:33 +01:00
|
|
|
url: "/json/get_subscribers",
|
2014-01-07 23:40:31 +01:00
|
|
|
idempotent: true,
|
2013-01-07 22:09:33 +01:00
|
|
|
data: {stream: stream},
|
|
|
|
success: function (data) {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator(indicator_elem);
|
2013-07-29 23:35:36 +02:00
|
|
|
var subscribers = _.map(data.subscribers, function (elem) {
|
2014-01-30 22:42:19 +01:00
|
|
|
var person = people.get_by_email(elem);
|
2013-01-15 23:28:58 +01:00
|
|
|
if (person === undefined) {
|
|
|
|
return elem;
|
|
|
|
}
|
2014-01-30 22:42:19 +01:00
|
|
|
return format_member_list_elem(people.get_by_email(elem).full_name, elem);
|
2013-01-14 22:19:13 +01:00
|
|
|
});
|
2013-07-30 00:35:44 +02:00
|
|
|
_.each(subscribers.sort().reverse(), function (elem) {
|
2013-11-08 10:12:05 +01:00
|
|
|
// add_element_to_member_list *prepends* the element,
|
2013-02-07 17:59:27 +01:00
|
|
|
// so we need to sort in reverse order for it to
|
|
|
|
// appear in alphabetical order.
|
2013-11-08 10:12:05 +01:00
|
|
|
add_element_to_member_list(list, elem);
|
2013-01-07 22:09:33 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator(indicator_elem);
|
2013-01-07 22:09:33 +01:00
|
|
|
error_elem.removeClass("hide").text("Could not fetch subscriber list");
|
|
|
|
}
|
|
|
|
});
|
2013-01-10 19:57:34 +01:00
|
|
|
|
|
|
|
sub_row.find('input[name="principal"]').typeahead({
|
2013-11-19 22:09:37 +01:00
|
|
|
source: page_params.people_list,
|
|
|
|
items: 5,
|
2013-01-10 19:57:34 +01:00
|
|
|
highlighter: function (item) {
|
2013-11-19 22:09:37 +01:00
|
|
|
var item_formatted = typeahead_helper.render_person(item);
|
|
|
|
return typeahead_helper.highlight_with_escaping(this.query, item_formatted);
|
2013-01-10 19:57:34 +01:00
|
|
|
},
|
2013-01-10 20:10:06 +01:00
|
|
|
matcher: function (item) {
|
2014-01-06 22:56:40 +01:00
|
|
|
var query = $.trim(this.query.toLowerCase());
|
2013-11-19 22:09:37 +01:00
|
|
|
if (query === '' || query === item.email) {
|
2013-01-10 20:10:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Case-insensitive.
|
2014-01-06 22:56:40 +01:00
|
|
|
return (item.email.toLowerCase().indexOf(query) !== -1) ||
|
|
|
|
(item.full_name.toLowerCase().indexOf(query) !== -1);
|
2013-01-10 20:10:06 +01:00
|
|
|
},
|
2013-11-19 22:09:37 +01:00
|
|
|
sorter: typeahead_helper.sort_recipientbox_typeahead,
|
2013-01-10 19:57:34 +01:00
|
|
|
updater: function (item) {
|
2013-11-19 22:09:37 +01:00
|
|
|
return item.email;
|
2013-01-10 19:57:34 +01:00
|
|
|
}
|
|
|
|
});
|
2013-01-07 22:09:33 +01:00
|
|
|
});
|
2013-06-25 17:49:48 +02:00
|
|
|
|
|
|
|
// Change the down arrow to an up arrow on expansion, and back to a down
|
|
|
|
// arrow on collapse.
|
|
|
|
// FIXME: If there's a way, it may be better to do this in pure CSS.
|
|
|
|
$("#subscriptions_table").on("show", ".subscription_settings", function (e) {
|
|
|
|
var sub_arrow = $(e.target).closest('.subscription_row').find('.sub_arrow i');
|
|
|
|
sub_arrow.removeClass('icon-vector-chevron-down');
|
|
|
|
sub_arrow.addClass('icon-vector-chevron-up');
|
|
|
|
});
|
|
|
|
$("#subscriptions_table").on("hide", ".subscription_settings", function (e) {
|
|
|
|
var sub_arrow = $(e.target).closest('.subscription_row').find('.sub_arrow i');
|
|
|
|
sub_arrow.removeClass('icon-vector-chevron-up');
|
|
|
|
sub_arrow.addClass('icon-vector-chevron-down');
|
|
|
|
});
|
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);
|
2013-03-29 19:55:28 +01:00
|
|
|
if (sub !== undefined) {
|
|
|
|
// This stream is in the list, so focus on it.
|
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: settings_for_sub(sub).offset().top
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// 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;
|
|
|
|
}
|