var invite = (function () { var exports = {}; function reset_error_messages() { var invite_status = $('#invite_status'); var invitee_emails = $("#invitee_emails"); var invitee_emails_group = invitee_emails.closest('.control-group'); invite_status.hide().text('').removeClass('alert-error alert-warning alert-success'); invitee_emails_group.removeClass('warning error'); if (page_params.development_environment) { $('#dev_env_msg').hide().text('').removeClass('alert-error alert-warning alert-success'); } } function submit_invitation_form() { var invite_status = $('#invite_status'); var invitee_emails = $("#invitee_emails"); var invitee_emails_group = invitee_emails.closest('.control-group'); var invite_as = $('#invite_as').val(); var data = { invitee_emails: $("#invitee_emails").val(), invite_as_admin: invite_as === 'admin', csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').attr('value'), }; var streams = []; $.each($("#invite-stream-checkboxes input:checked"), function () { streams.push($(this).val()); }); data.stream = streams; channel.post({ url: "/json/invites", data: data, traditional: true, beforeSubmit: function () { reset_error_messages(); // TODO: You could alternatively parse the textarea here, and return errors to // the user if they don't match certain constraints (i.e. not real email addresses, // aren't in the right domain, etc.) // // OR, you could just let the server do it. Probably my temptation. $('#submit-invitation').button('loading'); return true; }, success: function () { $('#submit-invitation').button('reset'); invite_status.text(i18n.t('User(s) invited successfully.')) .addClass('alert-success') .show(); invitee_emails.val(''); if (page_params.development_environment) { var rendered_email_msg = templates.render('dev_env_email_access'); $('#dev_env_msg').html(rendered_email_msg).addClass('alert-info').show(); } }, error: function (xhr) { $('#submit-invitation').button('reset'); var arr = JSON.parse(xhr.responseText); if (arr.errors === undefined) { // There was a fatal error, no partial processing occurred. invite_status.text(arr.msg) .addClass('alert-error') .show(); } else { // Some users were not invited. var invitee_emails_errored = []; var error_list = $('