2019-11-02 00:06:25 +01:00
|
|
|
const render_announce_stream_docs = require('../templates/announce_stream_docs.hbs');
|
|
|
|
const render_new_stream_users = require('../templates/new_stream_users.hbs');
|
|
|
|
const render_subscription_invites_warning_modal = require('../templates/subscription_invites_warning_modal.hbs');
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let created_stream;
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
exports.reset_created_stream = function () {
|
|
|
|
created_stream = undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.set_name = function (stream) {
|
|
|
|
created_stream = stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_name = function () {
|
|
|
|
return created_stream;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_subscription_error = (function () {
|
|
|
|
const self = {};
|
2018-01-21 09:34:50 +01:00
|
|
|
|
|
|
|
self.report_no_subs_to_stream = function () {
|
|
|
|
$("#stream_subscription_error").text(i18n.t("You cannot create a stream with no subscribers!"));
|
|
|
|
$("#stream_subscription_error").show();
|
|
|
|
};
|
|
|
|
|
2018-02-03 09:04:45 +01:00
|
|
|
self.cant_create_stream_without_susbscribing = function () {
|
2018-03-17 00:53:36 +01:00
|
|
|
$("#stream_subscription_error").text(i18n.t("You must be an organization administrator to create a stream without subscribing."));
|
2018-02-03 09:04:45 +01:00
|
|
|
$("#stream_subscription_error").show();
|
|
|
|
};
|
|
|
|
|
2018-01-21 09:34:50 +01:00
|
|
|
self.clear_errors = function () {
|
|
|
|
$("#stream_subscription_error").hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_name_error = (function () {
|
|
|
|
const self = {};
|
2017-04-28 22:04:32 +02:00
|
|
|
|
|
|
|
self.report_already_exists = function () {
|
|
|
|
$("#stream_name_error").text(i18n.t("A stream with this name already exists"));
|
|
|
|
$("#stream_name_error").show();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.clear_errors = function () {
|
|
|
|
$("#stream_name_error").hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.report_empty_stream = function () {
|
|
|
|
$("#stream_name_error").text(i18n.t("A stream needs to have a name"));
|
|
|
|
$("#stream_name_error").show();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.select = function () {
|
|
|
|
$("#create_stream_name").focus().select();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.pre_validate = function (stream_name) {
|
|
|
|
// Don't worry about empty strings...we just want to call this
|
|
|
|
// to warn users early before they start doing too much work
|
|
|
|
// after they make the effort to type in a stream name. (The
|
|
|
|
// use case here is that I go to create a stream, only to find
|
|
|
|
// out it already exists, and I was just too lazy to look at
|
|
|
|
// the public streams that I'm not subscribed to yet. Once I
|
|
|
|
// realize the stream already exists, I may want to cancel.)
|
|
|
|
if (stream_name && stream_data.get_sub(stream_name)) {
|
|
|
|
self.report_already_exists();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.clear_errors();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.validate_for_submit = function (stream_name) {
|
|
|
|
if (!stream_name) {
|
|
|
|
self.report_empty_stream();
|
|
|
|
self.select();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_data.get_sub(stream_name)) {
|
|
|
|
self.report_already_exists();
|
|
|
|
self.select();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got this far, then we think we have a new unique stream
|
|
|
|
// name, so we'll submit to the server. (It's still plausible,
|
|
|
|
// however, that there's some invite-only stream that we don't
|
|
|
|
// know about locally that will cause a name collision.)
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}());
|
|
|
|
|
2018-05-03 18:52:39 +02:00
|
|
|
function ajaxSubscribeForCreation(stream_name, description, principals, invite_only,
|
2018-05-30 16:02:13 +02:00
|
|
|
is_announcement_only, announce, history_public_to_subscribers) {
|
2017-04-22 22:22:25 +02:00
|
|
|
// Subscribe yourself and possible other people to a new stream.
|
|
|
|
return channel.post({
|
|
|
|
url: "/json/users/me/subscriptions",
|
2017-07-08 04:31:11 +02:00
|
|
|
data: {subscriptions: JSON.stringify([{name: stream_name,
|
|
|
|
description: description}]),
|
2017-04-22 22:22:25 +02:00
|
|
|
principals: JSON.stringify(principals),
|
|
|
|
invite_only: JSON.stringify(invite_only),
|
2018-05-30 16:02:13 +02:00
|
|
|
is_announcement_only: JSON.stringify(is_announcement_only),
|
2017-04-22 22:22:25 +02:00
|
|
|
announce: JSON.stringify(announce),
|
2018-05-03 18:52:39 +02:00
|
|
|
history_public_to_subscribers: JSON.stringify(history_public_to_subscribers),
|
2017-04-22 22:22:25 +02:00
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
$("#create_stream_name").val("");
|
|
|
|
$("#create_stream_description").val("");
|
2018-01-16 18:31:15 +01:00
|
|
|
ui_report.success(i18n.t("Stream successfully created!"), $(".stream_create_info"));
|
2017-11-04 19:19:12 +01:00
|
|
|
loading.destroy_indicator($('#stream_creating_indicator'));
|
2017-04-22 22:22:25 +02:00
|
|
|
// The rest of the work is done via the subscribe event we will get
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg = JSON.parse(xhr.responseText).msg;
|
2017-04-28 22:04:32 +02:00
|
|
|
if (msg.indexOf('access') >= 0) {
|
|
|
|
// If we can't access the stream, we can safely assume it's
|
|
|
|
// a duplicate stream that we are not invited to.
|
2017-07-08 04:31:11 +02:00
|
|
|
stream_name_error.report_already_exists(stream_name);
|
2017-04-28 22:04:32 +02:00
|
|
|
stream_name_error.select();
|
|
|
|
}
|
|
|
|
|
2018-01-16 18:31:15 +01:00
|
|
|
ui_report.error(i18n.t("Error creating stream"), xhr, $(".stream_create_info"));
|
2017-11-04 19:19:12 +01:00
|
|
|
loading.destroy_indicator($('#stream_creating_indicator'));
|
2017-04-22 22:22:25 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Within the new stream modal...
|
|
|
|
function update_announce_stream_state() {
|
2017-05-16 18:34:36 +02:00
|
|
|
|
|
|
|
// If there is no notifications_stream, we simply hide the widget.
|
|
|
|
if (!page_params.notifications_stream) {
|
|
|
|
$('#announce-new-stream').hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-29 11:02:24 +01:00
|
|
|
// If the stream is invite only, disable the "Announce stream" option.
|
|
|
|
// Otherwise enable it.
|
2019-11-02 00:06:25 +01:00
|
|
|
const announce_stream_checkbox = $('#announce-new-stream input');
|
|
|
|
const announce_stream_label = $('#announce-new-stream');
|
|
|
|
let disable_it = false;
|
|
|
|
const privacy_type = $('input:radio[name=privacy]:checked').val();
|
|
|
|
const is_invite_only = privacy_type === "invite-only" || privacy_type === "invite-only-public-history";
|
2017-12-29 11:06:12 +01:00
|
|
|
announce_stream_label.removeClass("control-label-disabled");
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
if (is_invite_only) {
|
|
|
|
disable_it = true;
|
|
|
|
announce_stream_checkbox.prop('checked', false);
|
2017-12-29 11:06:12 +01:00
|
|
|
announce_stream_label.addClass("control-label-disabled");
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
announce_stream_checkbox.prop('disabled', disable_it);
|
2017-05-16 18:34:36 +02:00
|
|
|
$('#announce-new-stream').show();
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 04:04:55 +02:00
|
|
|
function get_principals() {
|
|
|
|
return _.map(
|
|
|
|
$("#stream_creation_form input:checkbox[name=user]:checked"),
|
|
|
|
function (elem) {
|
|
|
|
return $(elem).val();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-08 04:07:36 +02:00
|
|
|
function create_stream() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_name = $.trim($("#create_stream_name").val());
|
|
|
|
const description = $.trim($("#create_stream_description").val());
|
|
|
|
const privacy_setting = $('#stream_creation_form input[name=privacy]:checked').val();
|
|
|
|
const is_announcement_only = $('#stream_creation_form input[name=is-announcement-only]').prop('checked');
|
|
|
|
const principals = get_principals();
|
2017-07-08 04:07:36 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let invite_only;
|
|
|
|
let history_public_to_subscribers;
|
2018-05-03 18:52:39 +02:00
|
|
|
|
|
|
|
if (privacy_setting === 'invite-only') {
|
|
|
|
invite_only = true;
|
|
|
|
history_public_to_subscribers = false;
|
|
|
|
} else if (privacy_setting === 'invite-only-public-history') {
|
|
|
|
invite_only = true;
|
|
|
|
history_public_to_subscribers = true;
|
|
|
|
} else {
|
|
|
|
invite_only = false;
|
|
|
|
history_public_to_subscribers = true;
|
|
|
|
}
|
|
|
|
|
2017-07-08 04:31:11 +02:00
|
|
|
created_stream = stream_name;
|
2017-07-08 04:07:36 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const announce = !!page_params.notifications_stream &&
|
2018-06-06 18:19:09 +02:00
|
|
|
$('#announce-new-stream input').prop('checked');
|
2017-07-08 04:07:36 +02:00
|
|
|
|
2019-02-20 18:36:46 +01:00
|
|
|
// Even though we already check to make sure that while typing the user cannot enter
|
|
|
|
// newline characters (by pressing the enter key) it would still be possible to copy
|
|
|
|
// and paste over a description with newline characters in it. Prevent that.
|
|
|
|
if (description.indexOf('\n') !== -1) {
|
|
|
|
ui_report.message(i18n.t("The stream description cannot contain newline characters."), $(".stream_create_info"), 'alert-error');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-04 19:19:12 +01:00
|
|
|
loading.make_indicator($('#stream_creating_indicator'), {text: i18n.t('Creating stream...')});
|
|
|
|
|
2018-05-06 21:43:17 +02:00
|
|
|
ajaxSubscribeForCreation(
|
|
|
|
stream_name,
|
2017-07-08 04:07:36 +02:00
|
|
|
description,
|
|
|
|
principals,
|
2018-05-03 18:52:39 +02:00
|
|
|
invite_only,
|
2018-05-30 16:02:13 +02:00
|
|
|
is_announcement_only,
|
2018-05-03 18:52:39 +02:00
|
|
|
announce,
|
|
|
|
history_public_to_subscribers
|
2017-07-08 04:07:36 +02:00
|
|
|
);
|
|
|
|
}
|
2017-06-02 15:06:33 +02:00
|
|
|
|
2017-07-08 04:31:11 +02:00
|
|
|
exports.new_stream_clicked = function (stream_name) {
|
2017-04-22 22:22:25 +02: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");
|
|
|
|
|
|
|
|
$("#stream_settings_title, .subscriptions-container .settings, .nothing-selected").hide();
|
|
|
|
$("#stream-creation, #add_new_stream_title").show();
|
|
|
|
|
2017-07-08 04:31:11 +02:00
|
|
|
if (stream_name !== '') {
|
|
|
|
$('#create_stream_name').val(stream_name);
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
|
|
|
exports.show_new_stream_modal();
|
|
|
|
|
|
|
|
// at less than 700px we have a @media query that when you tap the
|
2017-09-29 19:17:03 +02:00
|
|
|
// .create_stream_button, the stream prompt slides in. However, when you
|
2017-04-22 22:22:25 +02:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-10 03:14:48 +01:00
|
|
|
function clear_error_display() {
|
|
|
|
stream_name_error.clear_errors();
|
|
|
|
$(".stream_create_info").hide();
|
|
|
|
stream_subscription_error.clear_errors();
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:22:25 +02:00
|
|
|
exports.show_new_stream_modal = function () {
|
|
|
|
$("#stream-creation").removeClass("hide");
|
|
|
|
$(".right .settings").hide();
|
2017-11-26 12:57:03 +01:00
|
|
|
|
2020-01-01 23:20:49 +01:00
|
|
|
const all_users = people.get_people_for_stream_create();
|
2017-11-26 12:57:03 +01:00
|
|
|
// Add current user on top of list
|
|
|
|
all_users.unshift(people.get_person_from_user_id(page_params.user_id));
|
2019-11-02 00:06:25 +01:00
|
|
|
const html = render_new_stream_users({
|
2017-11-26 12:57:03 +01:00
|
|
|
users: all_users,
|
2017-04-22 22:22:25 +02:00
|
|
|
streams: stream_data.get_streams_for_settings_page(),
|
2018-02-03 09:04:45 +01:00
|
|
|
is_admin: page_params.is_admin,
|
2018-03-25 18:11:23 +02:00
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const container = $('#people_to_add');
|
2018-03-25 18:11:23 +02:00
|
|
|
container.html(html);
|
|
|
|
exports.create_handlers_for_users(container);
|
2017-04-22 22:22:25 +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);
|
2017-05-16 18:34:36 +02:00
|
|
|
|
|
|
|
if (page_params.notifications_stream) {
|
|
|
|
$('#announce-new-stream').show();
|
|
|
|
$('#announce-new-stream input').prop('disabled', false);
|
|
|
|
$('#announce-new-stream input').prop('checked', true);
|
|
|
|
} else {
|
|
|
|
$('#announce-new-stream').hide();
|
|
|
|
}
|
2018-03-10 03:14:48 +01:00
|
|
|
clear_error_display();
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
$("#stream-checkboxes label.checkbox").on('change', function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const elem = $(this);
|
2019-12-30 12:51:16 +01:00
|
|
|
const stream_id = parseInt(elem.attr('data-stream-id'), 10);
|
2019-11-02 00:06:25 +01:00
|
|
|
const checked = elem.find('input').prop('checked');
|
|
|
|
const subscriber_ids = stream_data.get_sub_by_id(stream_id).subscribers;
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
$('#user-checkboxes label.checkbox').each(function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_elem = $(this);
|
2020-01-16 20:40:20 +01:00
|
|
|
const user_id = parseInt(user_elem.attr('data-user-id'), 10);
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
if (subscriber_ids.has(user_id)) {
|
|
|
|
user_elem.find('input').prop('checked', checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-03-25 18:11:23 +02:00
|
|
|
exports.create_handlers_for_users = function (container) {
|
|
|
|
// container should be $('#people_to_add')...see caller to verify
|
|
|
|
container.on('change', '#user-checkboxes input', update_announce_stream_state);
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
// 'Check all' and 'Uncheck all' visible users
|
2018-03-25 18:11:23 +02:00
|
|
|
container.on('click', '.subs_set_all_users', function (e) {
|
2017-04-22 22:22:25 +02:00
|
|
|
$('#user-checkboxes .checkbox').each(function (idx, li) {
|
|
|
|
if (li.style.display !== "none") {
|
|
|
|
$(li.firstElementChild).prop('checked', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
update_announce_stream_state();
|
|
|
|
});
|
|
|
|
|
2018-03-25 18:11:23 +02:00
|
|
|
container.on('click', '.subs_unset_all_users', function (e) {
|
2017-04-22 22:22:25 +02:00
|
|
|
$('#user-checkboxes .checkbox').each(function (idx, li) {
|
2018-02-03 09:04:45 +01:00
|
|
|
if (li.style.display !== "none") {
|
|
|
|
// The first checkbox is the one for ourself; this is the code path for:
|
|
|
|
// `stream_subscription_error.cant_create_stream_without_susbscribing`
|
|
|
|
if (idx === 0 && !page_params.is_admin) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-22 22:22:25 +02:00
|
|
|
$(li.firstElementChild).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
update_announce_stream_state();
|
|
|
|
});
|
|
|
|
|
2018-03-25 18:11:23 +02:00
|
|
|
container.on('click', '#copy-from-stream-expand-collapse', function (e) {
|
2017-04-22 22:22:25 +02:00
|
|
|
$('#stream-checkboxes').toggle();
|
2018-06-25 18:54:08 +02:00
|
|
|
$("#copy-from-stream-expand-collapse .toggle").toggleClass('fa-caret-right fa-caret-down');
|
2017-04-22 22:22:25 +02:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Search People or Streams
|
2018-03-25 18:11:23 +02:00
|
|
|
container.on('input', '.add-user-list-filter', function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_list = $(".add-user-list-filter");
|
2017-04-22 22:22:25 +02:00
|
|
|
if (user_list === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const search_term = user_list.expectOne().val().trim();
|
|
|
|
const search_terms = search_term.toLowerCase().split(",");
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
(function filter_user_checkboxes() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_labels = $("#user-checkboxes label.add-user-label");
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
if (search_term === '') {
|
|
|
|
user_labels.css({display: 'block'});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-01 23:20:49 +01:00
|
|
|
const users = people.get_people_for_stream_create();
|
2019-11-02 00:06:25 +01:00
|
|
|
const filtered_users = people.filter_people_by_search_terms(users, search_terms);
|
2017-04-22 22:22:25 +02:00
|
|
|
|
|
|
|
// 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 () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const elem = $(this);
|
2019-12-29 15:07:05 +01:00
|
|
|
const user_id = parseInt(elem.attr('data-user-id'), 10);
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_checked = filtered_users.has(user_id);
|
|
|
|
const display = user_checked ? "block" : "none";
|
2017-04-22 22:22:25 +02:00
|
|
|
elem.css({display: display});
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2018-03-25 17:43:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-03-25 18:46:10 +02:00
|
|
|
exports.set_up_handlers = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const container = $('#stream-creation').expectOne();
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2018-03-25 18:46:10 +02:00
|
|
|
container.on('change', '#make-invite-only input', update_announce_stream_state);
|
|
|
|
|
|
|
|
container.on("submit", "#stream_creation_form", function (e) {
|
2017-04-22 22:22:25 +02:00
|
|
|
e.preventDefault();
|
2018-03-10 03:14:48 +01:00
|
|
|
clear_error_display();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_name = $.trim($("#create_stream_name").val());
|
|
|
|
const name_ok = stream_name_error.validate_for_submit(stream_name);
|
2017-04-28 22:04:32 +02:00
|
|
|
|
|
|
|
if (!name_ok) {
|
|
|
|
return;
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
2017-06-02 15:06:33 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const principals = get_principals();
|
2018-01-21 09:34:50 +01:00
|
|
|
if (principals.length === 0) {
|
|
|
|
stream_subscription_error.report_no_subs_to_stream();
|
|
|
|
return;
|
|
|
|
}
|
2018-02-03 09:04:45 +01:00
|
|
|
if (principals.indexOf(people.my_current_email()) < 0 && !page_params.is_admin) {
|
|
|
|
stream_subscription_error.cant_create_stream_without_susbscribing();
|
|
|
|
return;
|
|
|
|
}
|
2018-01-21 09:34:50 +01:00
|
|
|
|
2017-07-08 04:21:19 +02:00
|
|
|
if (principals.length >= 50) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const invites_warning_modal = render_subscription_invites_warning_modal({
|
2019-07-09 21:24:00 +02:00
|
|
|
stream_name: stream_name,
|
|
|
|
count: principals.length,
|
|
|
|
});
|
2017-07-08 04:21:19 +02:00
|
|
|
$('#stream-creation').append(invites_warning_modal);
|
2017-06-02 15:06:33 +02:00
|
|
|
} else {
|
|
|
|
create_stream();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-25 18:46:10 +02:00
|
|
|
container.on("click", ".close-invites-warning-modal", function () {
|
2017-06-02 15:06:33 +02:00
|
|
|
$("#invites-warning-overlay").remove();
|
|
|
|
});
|
|
|
|
|
2018-03-25 18:46:10 +02:00
|
|
|
container.on("click", ".confirm-invites-warning-modal", function () {
|
2017-07-08 04:07:36 +02:00
|
|
|
create_stream();
|
2017-06-02 15:06:33 +02:00
|
|
|
$("#invites-warning-overlay").remove();
|
2017-04-22 22:22:25 +02:00
|
|
|
});
|
|
|
|
|
2018-03-25 18:46:10 +02:00
|
|
|
container.on("input", "#create_stream_name", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_name = $.trim($("#create_stream_name").val());
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2017-04-28 22:04:32 +02:00
|
|
|
// This is an inexpensive check.
|
2017-07-08 04:31:11 +02:00
|
|
|
stream_name_error.pre_validate(stream_name);
|
2017-04-22 22:22:25 +02:00
|
|
|
});
|
|
|
|
|
2018-03-25 18:46:10 +02:00
|
|
|
container.on("mouseover", "#announce-stream-docs", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const announce_stream_docs = $("#announce-stream-docs");
|
2018-05-06 21:43:17 +02:00
|
|
|
announce_stream_docs.popover({
|
|
|
|
placement: "right",
|
2019-07-09 21:24:00 +02:00
|
|
|
content: render_announce_stream_docs({
|
2018-05-06 21:43:17 +02:00
|
|
|
notifications_stream: page_params.notifications_stream}),
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2018-05-06 21:43:17 +02:00
|
|
|
trigger: "manual"});
|
2017-04-22 22:22:25 +02:00
|
|
|
announce_stream_docs.popover('show');
|
|
|
|
announce_stream_docs.data('popover').tip().css('z-index', 2000);
|
2017-12-01 17:48:32 +01:00
|
|
|
announce_stream_docs.data('popover').tip().find('.popover-content').css('margin', '9px 14px');
|
2017-04-22 22:22:25 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2018-03-25 18:46:10 +02:00
|
|
|
container.on("mouseout", "#announce-stream-docs", function (e) {
|
2017-04-22 22:22:25 +02:00
|
|
|
$("#announce-stream-docs").popover('hide');
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2019-02-20 18:36:46 +01:00
|
|
|
// Do not allow the user to enter newline characters while typing out the
|
|
|
|
// stream's description during it's creation.
|
|
|
|
container.on("keydown", "#create_stream_description", function (e) {
|
|
|
|
if ((e.keyCode || e.which) === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-25 18:46:10 +02:00
|
|
|
};
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.stream_create = exports;
|