mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
static/js/invite.js: Extract func submit_invitation_form.
Extract function `submit_invitation_form` and relocate some functions to make it easy to review diff.
This commit is contained in:
committed by
Tim Abbott
parent
37acb3e2cb
commit
f4067bb38b
@@ -2,44 +2,6 @@ var invite = (function () {
|
|||||||
|
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
// `get_invite_streams` is further modification of stream_data.invite_streams(), it is
|
|
||||||
// defined here to keep stream_data.invite_stream() generic.
|
|
||||||
exports.get_invite_streams = function () {
|
|
||||||
var streams = [];
|
|
||||||
|
|
||||||
_.each(stream_data.invite_streams(), function (value) {
|
|
||||||
var is_invite_only = stream_data.get_invite_only(value);
|
|
||||||
var is_notifications_stream = value === page_params.notifications_stream;
|
|
||||||
|
|
||||||
// You can't actually elect to invite someone to the
|
|
||||||
// notifications stream. We won't even show it as a choice unless
|
|
||||||
// it's the only stream you have, or if you've made it private.
|
|
||||||
if (stream_data.subscribed_streams().length === 1 ||
|
|
||||||
!is_notifications_stream ||
|
|
||||||
is_notifications_stream && is_invite_only) {
|
|
||||||
|
|
||||||
streams.push({
|
|
||||||
name: value,
|
|
||||||
invite_only: is_invite_only,
|
|
||||||
default_stream: stream_data.get_default_status(value),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sort by default status.
|
|
||||||
streams.sort(function (a, b) {
|
|
||||||
return b.default_stream - a.default_stream;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return streams;
|
|
||||||
};
|
|
||||||
|
|
||||||
function update_subscription_checkboxes() {
|
|
||||||
var data = {streams: exports.get_invite_streams()};
|
|
||||||
var html = templates.render('invite_subscription', data);
|
|
||||||
$('#streams_to_add').html(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset_error_messages() {
|
function reset_error_messages() {
|
||||||
var invite_status = $('#invite_status');
|
var invite_status = $('#invite_status');
|
||||||
var invitee_emails = $("#invitee_emails");
|
var invitee_emails = $("#invitee_emails");
|
||||||
@@ -52,22 +14,10 @@ function reset_error_messages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare_form_to_be_shown() {
|
function submit_invitation_form() {
|
||||||
update_subscription_checkboxes();
|
|
||||||
reset_error_messages();
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.launch = function () {
|
|
||||||
ui.set_up_scrollbar($("#invite_user_form .modal-body"));
|
|
||||||
var invite_status = $('#invite_status');
|
var invite_status = $('#invite_status');
|
||||||
var invitee_emails = $("#invitee_emails");
|
var invitee_emails = $("#invitee_emails");
|
||||||
var invitee_emails_group = invitee_emails.closest('.control-group');
|
var invitee_emails_group = invitee_emails.closest('.control-group');
|
||||||
|
|
||||||
$('#submit-invitation').button();
|
|
||||||
prepare_form_to_be_shown();
|
|
||||||
invitee_emails.focus().autosize();
|
|
||||||
|
|
||||||
$("#submit-invitation").on("click", function () {
|
|
||||||
var invite_as = $('#invite_as').val();
|
var invite_as = $('#invite_as').val();
|
||||||
var data = {
|
var data = {
|
||||||
invitee_emails: $("#invitee_emails").val(),
|
invitee_emails: $("#invitee_emails").val(),
|
||||||
@@ -139,8 +89,58 @@ exports.launch = function () {
|
|||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// `get_invite_streams` is further modification of stream_data.invite_streams(), it is
|
||||||
|
// defined here to keep stream_data.invite_stream() generic.
|
||||||
|
exports.get_invite_streams = function () {
|
||||||
|
var streams = [];
|
||||||
|
|
||||||
|
_.each(stream_data.invite_streams(), function (value) {
|
||||||
|
var is_invite_only = stream_data.get_invite_only(value);
|
||||||
|
var is_notifications_stream = value === page_params.notifications_stream;
|
||||||
|
|
||||||
|
// You can't actually elect to invite someone to the
|
||||||
|
// notifications stream. We won't even show it as a choice unless
|
||||||
|
// it's the only stream you have, or if you've made it private.
|
||||||
|
if (stream_data.subscribed_streams().length === 1 ||
|
||||||
|
!is_notifications_stream ||
|
||||||
|
is_notifications_stream && is_invite_only) {
|
||||||
|
|
||||||
|
streams.push({
|
||||||
|
name: value,
|
||||||
|
invite_only: is_invite_only,
|
||||||
|
default_stream: stream_data.get_default_status(value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sort by default status.
|
||||||
|
streams.sort(function (a, b) {
|
||||||
|
return b.default_stream - a.default_stream;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return streams;
|
||||||
|
};
|
||||||
|
|
||||||
|
function update_subscription_checkboxes() {
|
||||||
|
var data = {streams: exports.get_invite_streams()};
|
||||||
|
var html = templates.render('invite_subscription', data);
|
||||||
|
$('#streams_to_add').html(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepare_form_to_be_shown() {
|
||||||
|
update_subscription_checkboxes();
|
||||||
|
reset_error_messages();
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.launch = function () {
|
||||||
|
ui.set_up_scrollbar($("#invite_user_form .modal-body"));
|
||||||
|
|
||||||
|
$('#submit-invitation').button();
|
||||||
|
prepare_form_to_be_shown();
|
||||||
|
$("#invitee_emails").focus().autosize();
|
||||||
|
|
||||||
overlays.open_overlay({
|
overlays.open_overlay({
|
||||||
name: 'invite',
|
name: 'invite',
|
||||||
overlay: $('#invite-user'),
|
overlay: $('#invite-user'),
|
||||||
@@ -148,6 +148,7 @@ exports.launch = function () {
|
|||||||
hashchange.exit_overlay();
|
hashchange.exit_overlay();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
$("#submit-invitation").on("click", submit_invitation_form);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.initialize = function () {
|
exports.initialize = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user