<commit_before>import {addTeammemberTemplate, teammemberTemplate} from "./templates"
import {csrfToken, cancelPromise} from "../common"

/**
 * Sets up the contacts management. Helper functions for adding and removing contacts.
 */

//add a user to contact per ajax
let addMember = function(userString) {
    if (null === userString || 'undefined' == typeof(userString)) {
        return cancelPromise()
    }

    userString = jQuery.trim(userString)
    jQuery('#add-new-member .warning').detach()
    if ('' === userString) {
        return cancelPromise()
    }
    return new Promise((resolve, reject) => {
        jQuery.ajax({
            url: '/account/teammember/add',
            data: {
                'user_string': userString
            },
            type: 'POST',
            dataType: 'json',
            crossDomain: false, // obviates need for sameOrigin test
            beforeSend: (xhr, settings) =>
                xhr.setRequestHeader("X-CSRFToken", csrfToken),
            success: (response, textStatus, jqXHR) => {
                if (jqXHR.status == 201) { //user added to the contacts
                    jQuery("#add-new-member").dialog('close')
                    return resolve(response.member)
                } else { //user not found
                    let responseHtml

                    if (response.error === 1) {
                        responseHtml = gettext('You cannot add yourself to your contacts!')
                    } else if (response.error === 2) {
                        responseHtml = gettext('This person is already in your contacts')
                    } else if (userString.indexOf('@') != -1 && userString.indexOf('.') != -1) {
                        responseHtml = gettext('No user is registered with the given email address.') +
                            '<br />' +
                            gettext('Please invite him/her ') +
                            '<a target="_blank" href="mailto:' + userString + '?subject=' +
                            encodeURIComponent(gettext('Fidus Writer')) + '&body=' +
                            encodeURIComponent(gettext('Hey, I would like you to sign up for a Fidus Writer account.') +
                                "\n" + gettext('Please register at')) + ' ' +
                            window.location.origin +
                            '">' +
                            gettext('by sending an email') +
                            '</a>!'
                    } else {
                        responseHtml = gettext('User is not registered.')
                    }
                    jQuery('#add-new-member').append('<div class="warning" style="padding: 8px;">' + responseHtml + '</div>')
                    return resolve(cancelPromise())
                }
            },
            error: (jqXHR, textStatus, errorThrown) => {
                console.error(jqXHR.responseText)
                reject()
            }
        })<commit_msg>mailto not in new tab, fixes #456<commit_after>import {addTeammemberTemplate, teammemberTemplate} from "./templates"
import {csrfToken, cancelPromise} from "../common"

/**
 * Sets up the contacts management. Helper functions for adding and removing contacts.
 */

//add a user to contact per ajax
let addMember = function(userString) {
    if (null === userString || 'undefined' == typeof(userString)) {
        return cancelPromise()
    }

    userString = jQuery.trim(userString)
    jQuery('#add-new-member .warning').detach()
    if ('' === userString) {
        return cancelPromise()
    }
    return new Promise((resolve, reject) => {
        jQuery.ajax({
            url: '/account/teammember/add',
            data: {
                'user_string': userString
            },
            type: 'POST',
            dataType: 'json',
            crossDomain: false, // obviates need for sameOrigin test
            beforeSend: (xhr, settings) =>
                xhr.setRequestHeader("X-CSRFToken", csrfToken),
            success: (response, textStatus, jqXHR) => {
                if (jqXHR.status == 201) { //user added to the contacts
                    jQuery("#add-new-member").dialog('close')
                    return resolve(response.member)
                } else { //user not found
                    let responseHtml

                    if (response.error === 1) {
                        responseHtml = gettext('You cannot add yourself to your contacts!')
                    } else if (response.error === 2) {
                        responseHtml = gettext('This person is already in your contacts')
                    } else if (userString.indexOf('@') != -1 && userString.indexOf('.') != -1) {
                        responseHtml = gettext('No user is registered with the given email address.') +
                            '<br />' +
                            gettext('Please invite him/her ') +
                            `<a href="mailto:${userString}?subject=` +
                                `${encodeURIComponent(gettext('Fidus Writer'))}&body=` +
                                `${encodeURIComponent(gettext('Hey, I would like you to sign up for a Fidus Writer account.'))} ` +
                                `${encodeURIComponent(gettext('Please register at'))} ${window.location.origin}">` +
                            `${gettext('by sending an email')}</a>!`
                    } else {
                        responseHtml = gettext('User is not registered.')
                    }
                    jQuery('#add-new-member').append('<div class="warning" style="padding: 8px;">' + responseHtml + '</div>')
                    return resolve(cancelPromise())
                }
            },
            error: (jqXHR, textStatus, errorThrown) => {
                console.error(jqXHR.responseText)
                reject()
            }
        })
{'fraction_non_alphanumeric': 0.12348626982773324, 'fraction_numerical': 0.003240661777247143, 'mean_word_length': 1.5254091300602928, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2003491', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1420, 'n_words': 378}