$(document).ready(function () {
    $("#callmeDiv").hide();
});

$("#consultant").on('change', function () {
    var consultant_id = $("#consultant").val();
    $("#email").val('');
    $("#mobile").val('');
    if (consultant_id != '') {
        $.ajax({
            url: '/consultant_details/' + consultant_id,
            success: function (result) {
                getresult = JSON.parse(result);
                $("#email").val(getresult.email);
                $("#mobile").val(getresult.mobile);
            }
        });
    }
});

$("#call_status").change(function () {
    if ($(this).val() == 'call_me_later') {
        $("#callmeDiv").show();
    } else {
        $("#callmeDiv").hide();
    }
});

/* Submiting Student Call */
$("#create_calllist_form").on('submit', function (e) {
    e.preventDefault();
    $.ajax({
        type: 'POST',
        url: '/calls',
        data: $("#create_calllist_form").serialize(),
        success: function (result) {
            console.log(result);
            var email = "'"+$("#email").val()+"'";
            var trData = '<tr>';
            trData += '<td>' + result.name + '</td>';
            trData += '<td>' + (result.call_status).toUpperCase() + '</td>';
            trData += '<td>' + result.comments + '</td>';
            trData += '<td>' + result.callback_date + '</td>';
            trData += '<td><a title="Send Mail" onclick="get_mail('+ email + ')" class="btn btn-outline-secondary btn-circle-iconic btn34"> <i class="material-icons"> mail </i></a><button class="btn btn-outline-secondary btn-circle-iconic btn34" type="button" onclick="addComment(' + result.si_no + ')"><i class="material-icons"> comment </i></button></td>';
            trData += '</tr>';
            $(".table-filter").children('tbody').prepend(trData);
            $(".close").trigger('click');
            document.getElementById("create_calllist_form").reset();
            swal({
                text: 'Call Added Successfully!.',
                timer: 1000,
            });
        }
    });
});

