<commit_before>/*global $,psData,confirm*/

String.prototype.trim = function () {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

function copyEmail(email) {
    if (email.trim().length == 0) {
        return;
    }
    var data = email.trim();
    var current = $("#auto_emails").val();
    if (current.length > 0) {
        data = current + "," + email.trim();
    }
    $("#auto_emails").val(data);
}

function copyGuardianEmail(n) {
    $('#contact' + n + '_email').val($('#guardianemail' + n).text());
}

function copyAddress(type, n) {
    $('#c' + n + '_street').val($('#' + type + 'street' + n).text());
    $('#c' + n + '_city').val($('#' + type + 'city' + n).text());
    $('#c' + n + '_state').val($('#' + type + 'state' + n).text());
    $('#c' + n + '_zip').val($('#' + type + 'zip' + n).text());
}

function copyPhone(n) {
    $('#contact' + n + '_homephone').val($('#studentphone' + n).text());
}

function cleanEmailList() {
    var autoEmailsSelector = $('#auto_emails');
    var emails = autoEmailsSelector.val().replace(/\s+/g, ''); //clean all white space
    emails = emails.replace(/;+/g, ',').replace(/,+$/, ''); //all semi-colons to commas, remove trailing comma
    autoEmailsSelector.val(emails); //update field with clean value
}

var $ = jQuery.noConflict();

(function () {
    'use strict';
    var m_table;
    var m_keyindex = 0;
    var m_requestURL = '/guardian/data/getContacts.html';
    $(document).ready(function () {
        $.ajaxSetup({
            url: m_requestURL
        });
        $('#error_container').ajaxError(function (e, jqxhr, settings, err) {
            clearError();
            displayError("AJAX Error.  Page=" + settings.url + " Error=" + jqxhr.statusText);
        });
        m_table = $('#holder').addClass('display').dataTable({
            "bPaginate": false,
            "bFilter": false,
            "bJQueryUI": true,
            "sDom": '<"H"lfr<"addcontact">>t<"F"ip>',
            "aaSorting": [
                [5, 'asc'],
                [6, 'asc']
            ],
            "aoColumnDefs": [
                {"bSortable": false, "aTargets": ['_all']},
                {"bVisible": false, "aTargets": [m_keyindex, 5, 6]},
                {"sWidth": "100px", "aTargets": [4]},
                {
                    "fnRender": function (oObj) {
                        var result = '';
                        var info = oObj.aData[1];
                        if ($.isEmptyObject(info) || info == "") {
                            return "";
                        }
                        result += '<p style="font-weight:bold;">' + info.firstname + ' ' + info.lastname + '</p>';
                        if (info.priority.trim() != "") {
                            result += '<span style="font-size:8pt;">(Contact Priority #' + info.priority + ')</span><br />';
                        }
                        result += '<span style="font-size:8pt;">(' + info.relation + ')</span>';
                        return result;
                    },
                    "aTargets": [1]
                },
                {
                    "fnRender": function (oObj) {
                        var result = '';
                        var info = oObj.aData[2];
                        if ($.isEmptyObject(info) || info == "") {
                            return '';
                        }
                        var address = info.street.trim() == '' ? '' : info.street + '<br />';
                        address += info.city.trim() == '' ? '' : info.city + ',';
                        address += info.state + ' ' + info.zip;
                        if (info.street.trim() != '') {
                            result += '<a href="http://maps.google.com/?z=14&q=' + info.street + ', ' + info.city + ', ' + info.state + ', ' + info.zip + ' (' + oObj.aData[1].firstname + ' ' + oObj.aData[1].lastname + ')&output" target="_blank">' + address + '</a><br />';
                        }
                        else {
                            result += address;
                        }
                        if (info.mailto == "1") {
                            result += "*Receives mailings";
                        }
                        return result;
                    },
                    "aTargets": [2]
                },
                {
                    "fnRender": function (oObj) {
                        var result = '';
                        var info = oObj.aData[3];
                        if ($.isEmptyObject(info) || info == "") {
                            return "";
                        }
                        result += '<p>';
                        if (info.email.trim() != "") {
                            result += '<span class="infoheader">Email: </span><a href="mailto:' + info.email + '">' + info.email + '</a><br/><span class="button" onclick="copyEmail(\'' + info.email + '\');" >+Add to automated emails</span><br />';
                        }
                        if (info.homephone.trim() != "") {
                            result += '<span class="infoheader">Home: </span>' + info.homephone + '<br />';
                        }
                        if (info.cellphone.trim() != "") {
                            result += '<span class="infoheader">Cell: </span>' + info.cellphone + '<br />';
                        }
                        if (info.workphone.trim() != "") {
                            result += '<span class="infoheader">Work: </span>' + info.workphone + '<br />';
                        }
                        if (info.employer.trim() != "") {
                            result += '<span class="infoheader">Employer: </span>' + info.employer + '<br />';
                        }
                        result += '</p>';
                        return result;
                    },
                    "aTargets": [3]
                }
            ],
            "fnDrawCallback": function () {
                $('#holder td').removeClass('sorting_1 sorting_2 sorting_3');
            }
        });

        //create add contact button, and bind click event handler
        $('.addcontact').append('<button>Add Contact</button>');
        $('.addcontact button').button({
            icons: {
                primary: 'ui-icon-plus'
            }
        });
        $('body').on('click', '.addcontact', function (e) {
            e.preventDefault();
            $('.addcontact').hide();
            var ridx = m_table.fnAddData(["", "", "", "", "", "", ""]);
            var sourcerow = m_table.fnSettings().aoData[ridx].nTr;
            $.get('/guardian/data/getEditor.html')
                .done(function (editForm) {

                    var editrow = m_table.fnOpen(sourcerow, editForm, "edit_row");
                    /*
                    $('form', editrow).submit(function () {
                        //copy mother/father to fields.txt in students table
                        if ($("#contact" + n + "_rel").val() == "Father") {
                            syncParent('father', n);
                        }
                        else if ($("#contact" + n + "_rel").val() == "Mother") {
                            syncParent('mother', n);
                        }
                        $.post('/admin/changesrecorded.white.html', $(this).serialize())
                            .success(function (data) {
                                m_table.fnClose(sourcerow);
                                refreshContact(n, sourcerow);
                            });
                        $('.addcontact').show();
                        return false;//prevent normal form submission
                    });
                    */
                    $('.edit_cancel', editrow).click(function () {
                        m_table.fnClose(sourcerow);
                        m_table.fnDeleteRow(sourcerow);
                        $('.addcontact').show();
                    });

                });

        });
        //bind click event on all edit icons
        $('body').on('click', '.editcontact', function (e) {
            e.preventDefault();
            var row = $(this).parents('tr')[0];
            if (row) {
                var sourcerow = row;
                var n = m_table.fnGetData(row)[m_keyindex];<commit_msg>Remove unneeded functions, use config object to store server, dbe table name (unfinished).<commit_after>/*global $,psData,confirm*/

String.prototype.trim = function () {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

function copyEmail(email) {
    if (email.trim().length == 0) {
        return;
    }
    var data = email.trim();
    var current = $("#auto_emails").val();
    if (current.length > 0) {
        data = current + "," + email.trim();
    }
    $("#auto_emails").val(data);
}

function cleanEmailList() {
    var autoEmailsSelector = $('#auto_emails');
    var emails = autoEmailsSelector.val().replace(/\s+/g, ''); //clean all white space
    emails = emails.replace(/;+/g, ',').replace(/,+$/, ''); //all semi-colons to commas, remove trailing comma
    autoEmailsSelector.val(emails); //update field with clean value
}

var $ = jQuery.noConflict();
var config = {
    // PowerSchool Point of Contact server, which will talk with the PS REST API.
    "psPoc": "https://psit.irondistrict.org"
};

(function () {
    'use strict';
    var m_table;
    var m_keyindex = 0;
    // Use PS POC server
    var m_requestURL = '/guardian/data/getContacts.html';
    $(document).ready(function () {
        $.ajaxSetup({
            url: m_requestURL
        });
        $('#error_container').ajaxError(function (e, jqxhr, settings, err) {
            clearError();
            displayError("AJAX Error.  Page=" + settings.url + " Error=" + jqxhr.statusText);
        });
        m_table = $('#holder').addClass('display').dataTable({
            "bPaginate": false,
            "bFilter": false,
            "bJQueryUI": true,
            "sDom": '<"H"lfr<"addcontact">>t<"F"ip>',
            "aaSorting": [
                [5, 'asc'],
                [6, 'asc']
            ],
            "aoColumnDefs": [
                {"bSortable": false, "aTargets": ['_all']},
                {"bVisible": false, "aTargets": [m_keyindex, 5, 6]},
                {"sWidth": "100px", "aTargets": [4]},
                {
                    "fnRender": function (oObj) {
                        var result = '';
                        var info = oObj.aData[1];
                        if ($.isEmptyObject(info) || info == "") {
                            return "";
                        }
                        result += '<p style="font-weight:bold;">' + info.firstname + ' ' + info.lastname + '</p>';
                        if (info.priority.trim() != "") {
                            result += '<span style="font-size:8pt;">(Contact Priority #' + info.priority + ')</span><br />';
                        }
                        result += '<span style="font-size:8pt;">(' + info.relation + ')</span>';
                        return result;
                    },
                    "aTargets": [1]
                },
                {
                    "fnRender": function (oObj) {
                        var result = '';
                        var info = oObj.aData[2];
                        if ($.isEmptyObject(info) || info == "") {
                            return '';
                        }
                        var address = info.street.trim() == '' ? '' : info.street + '<br />';
                        address += info.city.trim() == '' ? '' : info.city + ',';
                        address += info.state + ' ' + info.zip;
                        if (info.street.trim() != '') {
                            result += '<a href="http://maps.google.com/?z=14&q=' + info.street + ', ' + info.city + ', ' + info.state + ', ' + info.zip + ' (' + oObj.aData[1].firstname + ' ' + oObj.aData[1].lastname + ')&output" target="_blank">' + address + '</a><br />';
                        }
                        else {
                            result += address;
                        }
                        if (info.mailto == "1") {
                            result += "*Receives mailings";
                        }
                        return result;
                    },
                    "aTargets": [2]
                },
                {
                    "fnRender": function (oObj) {
                        var result = '';
                        var info = oObj.aData[3];
                        if ($.isEmptyObject(info) || info == "") {
                            return "";
                        }
                        result += '<p>';
                        if (info.email.trim() != "") {
                            result += '<span class="infoheader">Email: </span><a href="mailto:' + info.email + '">' + info.email + '</a><br/><span class="button" onclick="copyEmail(\'' + info.email + '\');" >+Add to automated emails</span><br />';
                        }
                        if (info.homephone.trim() != "") {
                            result += '<span class="infoheader">Home: </span>' + info.homephone + '<br />';
                        }
                        if (info.cellphone.trim() != "") {
                            result += '<span class="infoheader">Cell: </span>' + info.cellphone + '<br />';
                        }
                        if (info.workphone.trim() != "") {
                            result += '<span class="infoheader">Work: </span>' + info.workphone + '<br />';
                        }
                        if (info.employer.trim() != "") {
                            result += '<span class="infoheader">Employer: </span>' + info.employer + '<br />';
                        }
                        result += '</p>';
                        return result;
                    },
                    "aTargets": [3]
                }
            ],
            "fnDrawCallback": function () {
                $('#holder td').removeClass('sorting_1 sorting_2 sorting_3');
            }
        });

        //create add contact button, and bind click event handler
        $('.addcontact').append('<button>Add Contact</button>');
        $('.addcontact button').button({
            icons: {
                primary: 'ui-icon-plus'
            }
        });
        $('body').on('click', '.addcontact', function (e) {
            e.preventDefault();
            $('.addcontact').hide();
            var ridx = m_table.fnAddData(["", "", "", "", "", "", ""]);
            var sourcerow = m_table.fnSettings().aoData[ridx].nTr;
            $.get(config['ps'] + '/guardian/data/getEditor.html')
                .done(function (editForm) {
                    var editrow = m_table.fnOpen(sourcerow, editForm, "edit_row");
                    $('form', editrow).submit(function () {
                        $.post(config['psPoc'] + '/' + config[''])
                            .success(function (data) {
                                m_table.fnClose(sourcerow);
                                refreshContact(n, sourcerow);
                            });
                        $('.addcontact').show();
                        return false;//prevent normal form submission
                    });
                    $('.edit_cancel', editrow).click(function () {
                        m_table.fnClose(sourcerow);
                        m_table.fnDeleteRow(sourcerow);
                        $('.addcontact').show();
                    });

                });

        });
        //bind click event on all edit icons
        $('body').on('click', '.editcontact', function (e) {
            e.preventDefault();
            var row = $(this).parents('tr')[0];
            if (row) {
                var sourcerow = row;
                var n = m_table.fnGetData(row)[m_keyindex];
{'fraction_non_alphanumeric': 0.17246131679508864, 'fraction_numerical': 0.0035081125101797906, 'mean_word_length': 1.226188816064705, 'pattern_counts': {'":': 39, '<': 79, '<?xml version=': 0, '>': 81, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '924424', 'n_tokens_mistral': 4329, 'n_tokens_neox': 4116, 'n_words': 800}