{"size": 1390, "ext": "js", "max_stars_repo_path": "assets/js/captcha.js", "max_stars_repo_name": "fridde/naturskolan_database", "max_stars_repo_stars_event_min_datetime": "2016-11-07T09:49:13.000Z", "max_stars_repo_stars_event_max_datetime": "2016-11-07T09:49:13.000Z", "max_issues_repo_path": "assets/js/captcha.js", "max_issues_repo_name": "fridde/naturskolan_database", "max_issues_repo_issues_event_min_datetime": "2017-05-23T19:13:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T19:36:47.000Z", "max_forks_repo_path": "assets/js/captcha.js", "max_forks_repo_name": "fridde/naturskolan_database", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 40.8823529412, "max_line_length": 194, "alphanum_fraction": 0.5086330935}
const $ = require('jquery');
const grecaptcha = require('grecaptcha');

$(document).ready(()=>{

    $('#send-question-submit').click(() => {
        let $form = $('div#send-question');
        $.ajax({
            url: 'api/send_contact_mail',
            method: 'POST',
            data: {
                captcha: grecaptcha.getResponse(),
                input_email: $('input[name="input_email"]').val(),
                input_message: $('textarea[name="input_message"]').val()
            },
            success: (data) => {
                if(!data.captcha_success){
                    $form.prepend('<div class="alert alert-warning">Din CAPTCHA blev tyvärr inte godkänt. Testa igen!</div>');
                    grecaptcha.reset();
                    return;
                } else if (!data.address_success){
                    $form.prepend('<div class="alert alert-warning">Du har glömt att ange en mejladress.</div>');
                    return;
                } else if(!data.mail_success){
                    $form.prepend('<div class="alert alert-danger">Det blev nåt fel. Ditt meddelande har tyvärr inte kunnat skickas. Testa igen eller kontakta oss via kontaktsidan ovan.</div>');
                    return;
                }
                $form.html('<div class="alert alert-success">Ditt meddelande har skickats!</div>');
            }
        });
    });

});
