refactor: Avoid nesting in the compose invite handler.

We exit early now if email is undefined, rather than
having a big if statement.
This commit is contained in:
Steve Howell
2017-03-04 12:42:17 -08:00
committed by Tim Abbott
parent 24631a7405
commit 434f228135

View File

@@ -970,21 +970,23 @@ $(function () {
var invite_row = $(event.target).parents('.compose_invite_user'); var invite_row = $(event.target).parents('.compose_invite_user');
var email = $(invite_row).data('useremail'); var email = $(invite_row).data('useremail');
if (email !== undefined) { if (email === undefined) {
subs.invite_user_to_stream(email, compose.stream_name(), function () { return;
var all_invites = $("#compose_invite_users");
invite_row.remove();
if (all_invites.children().length === 0) {
all_invites.hide();
}
}, function () {
var error_msg = invite_row.find('.compose_invite_user_error');
error_msg.show();
$(event.target).attr('disabled', true);
});
} }
subs.invite_user_to_stream(email, compose.stream_name(), function () {
var all_invites = $("#compose_invite_users");
invite_row.remove();
if (all_invites.children().length === 0) {
all_invites.hide();
}
}, function () {
var error_msg = invite_row.find('.compose_invite_user_error');
error_msg.show();
$(event.target).attr('disabled', true);
});
}); });
$("#compose_invite_users").on('click', '.compose_invite_close', function (event) { $("#compose_invite_users").on('click', '.compose_invite_close', function (event) {