<commit_before>/*
    jcclient.js  -  <NAME>

    https://github.com/cosinekitty/jcadmin
*/

(function(){
    function ApiGet(path, onSuccess, onFailure) {
        var request = new XMLHttpRequest();
        request.onreadystatechange = function(){
            if (request.readyState === XMLHttpRequest.DONE) {
                if (request.status === 200) {
                    var responseJson = JSON.parse(request.responseText);
                    if (!responseJson.error) {
                        onSuccess && onSuccess(responseJson);
                    } else {
                        console.log('ApiGet returned error object for %s :', path);
                        console.log(responseJson.error);
                        onFailure && onFailure(request);
                    }
                } else {
                    console.log('ApiGet failure for %s :', path);
                    console.log(request);
                    onFailure && onFailure(request);
                }
            }
        };
        request.open('GET', path);
        request.send(null);
    }

    // A list of all mutually-exclusive elements (only one is visible at a time):
    var ModalDivList = ['RecentCallsDiv', 'TargetCallDiv'];

    var PollTimer = null;
    var PrevPoll = {
        'callerid':  {
            'modified': '',
            'data': {
                'calls': [],
                'limit': 0,
                'start': 0,
                'total': 0,
            }
        },

        'whitelist': {
            'modified': '',
            'data': {
                'table': {}
            }
        },

        'blacklist': {
            'modified':'',
            'data':{
                'table': {}
            }
        }
    };

    function SetActiveDiv(activeDivId) {
        ModalDivList.forEach(function(divId){
            var div = document.getElementById(divId);
            if (divId === activeDivId) {
                div.style.display = '';
            } else {
                div.style.display = 'none';
            }
        });
    }

    function SetTargetCall(call) {
        var safeButton    = document.getElementById('TargetRadioButtonSafe');
        var neutralButton = document.getElementById('TargetRadioButtonNeutral');
        var blockButton   = document.getElementById('TargetRadioButtonBlocked');

        var numberDiv = document.getElementById('TargetNumberDiv');
        numberDiv.textContent = call.number;

        var nameDiv = document.getElementById('TargetNameDiv');
        nameDiv.textContent = call.name;

        var searchButton = document.getElementById('SearchNumberButton');
        searchButton.innerHTML = '<a href="http://www.google.com/search?q=' + call.number + '" target="_blank">Search Google</a>';

        var status = PhoneCallStatus(call);
        numberDiv.className = BlockStatusClassName(status);

        switch (status) {
            case 'B':
                blockButton.checked = true;
                break;

            case 'W':
                safeButton.checked = true;
                break;

            default:
                neutralButton.checked = true;
                break;
        }

        function Classify(status, phonenumber, comment) {
            var url = '/api/classify/' +
                status + '/' +
                encodeURIComponent(phonenumber) + '/' +
                encodeURIComponent(comment);

            ApiGet(url, function(data) {
                numberDiv.className = BlockStatusClassName(data.status);
            });
        }

        safeButton.onclick = function() {
            Classify('safe', call.number, call.name);
        }

        neutralButton.onclick = function() {
            Classify('neutral', call.number, call.name);
        }

        blockButton.onclick = function() {
            Classify('blocked', call.number, call.name);
        }

        SetActiveDiv('TargetCallDiv');
    }

    function CreatePhoneNumberCell(call, status) {
        var numberCell = document.createElement('td');
        if (call.number !== '') {<commit_msg>Disable radio buttons while waiting for state change response to come back from server.<commit_after>/*
    jcclient.js  -  <NAME>

    https://github.com/cosinekitty/jcadmin
*/

(function(){
    function ApiGet(path, onSuccess, onFailure) {
        var request = new XMLHttpRequest();
        request.onreadystatechange = function(){
            if (request.readyState === XMLHttpRequest.DONE) {
                if (request.status === 200) {
                    var responseJson = JSON.parse(request.responseText);
                    if (!responseJson.error) {
                        onSuccess && onSuccess(responseJson);
                    } else {
                        console.log('ApiGet returned error object for %s :', path);
                        console.log(responseJson.error);
                        onFailure && onFailure(request);
                    }
                } else {
                    console.log('ApiGet failure for %s :', path);
                    console.log(request);
                    onFailure && onFailure(request);
                }
            }
        };
        request.open('GET', path);
        request.send(null);
    }

    // A list of all mutually-exclusive elements (only one is visible at a time):
    var ModalDivList = ['RecentCallsDiv', 'TargetCallDiv'];

    var PollTimer = null;
    var PrevPoll = {
        'callerid':  {
            'modified': '',
            'data': {
                'calls': [],
                'limit': 0,
                'start': 0,
                'total': 0,
            }
        },

        'whitelist': {
            'modified': '',
            'data': {
                'table': {}
            }
        },

        'blacklist': {
            'modified':'',
            'data':{
                'table': {}
            }
        }
    };

    function SetActiveDiv(activeDivId) {
        ModalDivList.forEach(function(divId){
            var div = document.getElementById(divId);
            if (divId === activeDivId) {
                div.style.display = '';
            } else {
                div.style.display = 'none';
            }
        });
    }

    function EnableDisableControls(enabled) {
        var disabled = !enabled;
        document.getElementById('TargetRadioButtonSafe').disabled = disabled;
        document.getElementById('TargetRadioButtonNeutral').disabled = disabled;
        document.getElementById('TargetRadioButtonBlocked').disabled = disabled;
    }

    function SetTargetCall(call) {
        var safeButton    = document.getElementById('TargetRadioButtonSafe');
        var neutralButton = document.getElementById('TargetRadioButtonNeutral');
        var blockButton   = document.getElementById('TargetRadioButtonBlocked');

        var numberDiv = document.getElementById('TargetNumberDiv');
        numberDiv.textContent = call.number;

        var nameDiv = document.getElementById('TargetNameDiv');
        nameDiv.textContent = call.name;

        var searchButton = document.getElementById('SearchNumberButton');
        searchButton.innerHTML = '<a href="http://www.google.com/search?q=' + call.number + '" target="_blank">Search Google</a>';

        var status = PhoneCallStatus(call);
        numberDiv.className = BlockStatusClassName(status);

        switch (status) {
            case 'B':
                blockButton.checked = true;
                break;

            case 'W':
                safeButton.checked = true;
                break;

            default:
                neutralButton.checked = true;
                break;
        }

        function Classify(status, phonenumber, comment) {
            EnableDisableControls(false);

            var url = '/api/classify/' +
                status + '/' +
                encodeURIComponent(phonenumber) + '/' +
                encodeURIComponent(comment);

            ApiGet(url, function(data) {
                numberDiv.className = BlockStatusClassName(data.status);
                EnableDisableControls(true);
            });
        }

        safeButton.onclick = function() {
            Classify('safe', call.number, call.name);
        }

        neutralButton.onclick = function() {
            Classify('neutral', call.number, call.name);
        }

        blockButton.onclick = function() {
            Classify('blocked', call.number, call.name);
        }

        EnableDisableControls(true);
        SetActiveDiv('TargetCallDiv');
    }

    function CreatePhoneNumberCell(call, status) {
        var numberCell = document.createElement('td');
        if (call.number !== '') {
{'fraction_non_alphanumeric': 0.11707148612869805, 'fraction_numerical': 0.0013813744675952573, 'mean_word_length': 1.5973094170403588, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4695289', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2117, 'n_words': 413}