stream_create: Use stream_name as local variable for stream names.

This is a lot clearer than using "stream", which could refer to an
actual object.
This commit is contained in:
Tim Abbott
2017-07-07 19:31:11 -07:00
parent cbdffeda82
commit e226073d1d

View File

@@ -76,11 +76,12 @@ var stream_name_error = (function () {
return self; return self;
}()); }());
function ajaxSubscribeForCreation(stream, description, principals, invite_only, announce) { function ajaxSubscribeForCreation(stream_name, description, principals, invite_only, announce) {
// Subscribe yourself and possible other people to a new stream. // Subscribe yourself and possible other people to a new stream.
return channel.post({ return channel.post({
url: "/json/users/me/subscriptions", url: "/json/users/me/subscriptions",
data: {subscriptions: JSON.stringify([{name: stream, description: description}]), data: {subscriptions: JSON.stringify([{name: stream_name,
description: description}]),
principals: JSON.stringify(principals), principals: JSON.stringify(principals),
invite_only: JSON.stringify(invite_only), invite_only: JSON.stringify(invite_only),
announce: JSON.stringify(announce), announce: JSON.stringify(announce),
@@ -96,7 +97,7 @@ function ajaxSubscribeForCreation(stream, description, principals, invite_only,
if (msg.indexOf('access') >= 0) { if (msg.indexOf('access') >= 0) {
// If we can't access the stream, we can safely assume it's // If we can't access the stream, we can safely assume it's
// a duplicate stream that we are not invited to. // a duplicate stream that we are not invited to.
stream_name_error.report_already_exists(stream); stream_name_error.report_already_exists(stream_name);
stream_name_error.select(); stream_name_error.select();
} }
@@ -144,7 +145,7 @@ function get_principals() {
} }
function create_stream() { function create_stream() {
var stream = $.trim($("#create_stream_name").val()); var stream_name = $.trim($("#create_stream_name").val());
var description = $.trim($("#create_stream_description").val()); var description = $.trim($("#create_stream_description").val());
var is_invite_only = $('#stream_creation_form input[name=privacy]:checked').val() === "invite-only"; var is_invite_only = $('#stream_creation_form input[name=privacy]:checked').val() === "invite-only";
var principals = get_principals(); var principals = get_principals();
@@ -152,12 +153,12 @@ function create_stream() {
// You are always subscribed to streams you create. // You are always subscribed to streams you create.
principals.push(people.my_current_email()); principals.push(people.my_current_email());
created_stream = stream; created_stream = stream_name;
var announce = (!!page_params.notifications_stream && var announce = (!!page_params.notifications_stream &&
$('#announce-new-stream input').prop('checked')); $('#announce-new-stream input').prop('checked'));
ajaxSubscribeForCreation(stream, ajaxSubscribeForCreation(stream_name,
description, description,
principals, principals,
is_invite_only, is_invite_only,
@@ -165,7 +166,7 @@ function create_stream() {
); );
} }
exports.new_stream_clicked = function (stream) { exports.new_stream_clicked = function (stream_name) {
// this changes the tab switcher (settings/preview) which isn't necessary // this changes the tab switcher (settings/preview) which isn't necessary
// to a add new stream title. // to a add new stream title.
$(".display-type #add_new_stream_title").show(); $(".display-type #add_new_stream_title").show();
@@ -176,8 +177,8 @@ exports.new_stream_clicked = function (stream) {
$("#stream_settings_title, .subscriptions-container .settings, .nothing-selected").hide(); $("#stream_settings_title, .subscriptions-container .settings, .nothing-selected").hide();
$("#stream-creation, #add_new_stream_title").show(); $("#stream-creation, #add_new_stream_title").show();
if (stream !== '') { if (stream_name !== '') {
$('#create_stream_name').val(stream); $('#create_stream_name').val(stream_name);
} }
exports.show_new_stream_modal(); exports.show_new_stream_modal();
@@ -313,8 +314,8 @@ $(function () {
$(".subscriptions").on("submit", "#stream_creation_form", function (e) { $(".subscriptions").on("submit", "#stream_creation_form", function (e) {
e.preventDefault(); e.preventDefault();
var stream = $.trim($("#create_stream_name").val()); var stream_name = $.trim($("#create_stream_name").val());
var name_ok = stream_name_error.validate_for_submit(stream); var name_ok = stream_name_error.validate_for_submit(stream_name);
if (!name_ok) { if (!name_ok) {
return; return;
@@ -323,7 +324,7 @@ $(function () {
var principals = get_principals(); var principals = get_principals();
if (principals.length >= 50) { if (principals.length >= 50) {
var invites_warning_modal = templates.render('subscription_invites_warning_modal', var invites_warning_modal = templates.render('subscription_invites_warning_modal',
{stream_name: stream, {stream_name: stream_name,
count: principals.length}); count: principals.length});
$('#stream-creation').append(invites_warning_modal); $('#stream-creation').append(invites_warning_modal);
} else { } else {
@@ -341,10 +342,10 @@ $(function () {
}); });
$(".subscriptions").on("input", "#create_stream_name", function () { $(".subscriptions").on("input", "#create_stream_name", function () {
var stream = $.trim($("#create_stream_name").val()); var stream_name = $.trim($("#create_stream_name").val());
// This is an inexpensive check. // This is an inexpensive check.
stream_name_error.pre_validate(stream); stream_name_error.pre_validate(stream_name);
}); });
$("body").on("mouseover", "#announce-stream-docs", function (e) { $("body").on("mouseover", "#announce-stream-docs", function (e) {