<commit_before> //Scripts for utilities page

var oTable;

$(document).ready(function() {

    //set header widget
    $('#utilities_nav').addClass('ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr');

    //Add navigation buttons
    $('.utilities_nav_choices').buttonset();

    //Add navigation actions
    target = $('div#utilities_panel');

    //User clicks reports button
    $('#reports_button').click(function() {

        //Show the report chooser
        $('#report_chooser').appendTo('#utilities_panel').show();

        //Add chosen
        $('select[name="type"]').chosen();

        //Add datepickers
        $('input[name="date_start_display"]').datepicker({
            dateFormat : "DD, MM d, yy",
            altField:$('input[name = "date_start"]'),
            altFormat: "yy-mm-dd"
            });

        $('input[name="date_start_display"]').datepicker('setDate', '-7');

        $('input[name="date_end_display"]').datepicker({
            dateFormat : "DD, MM d, yy",
            altField:$('input[name = "date_end"]'),
            altFormat: "yy-mm-dd"
            });

        $('input[name="date_end_display"]').datepicker('setDate', new Date());

        //Create a table
        $('#report_chooser').after( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="table_reports"><tfoot><tr></tr></tfoot></table>' );

        //Dynamically create dataTable, load data
        $('button.report_submit').click(function(event){
            event.preventDefault();

            var tableHeight = $('#utilities_panel').height() - $('#report_chooser').height() - 150;

            if ($('tfoot th').length)
            {
                $('tfoot th').remove();
            }

            if ($('thead th').length)
            {
                $('thead th').remove();
            }

            var q_type =$('select[name="type"]').val();

            var start = $('input[name="date_start"]').val();

            var end = $('input[name="date_end"]').val();

            var detail = $('input[name="detail"]').val();

            var query = [];

            if (q_type.indexOf("_grp_") != -1) //user groups
            {
                query.push('grp',q_type);
            }
            else if (q_type.indexOf("_spv_") != -1) //supervisor groups
            {
                query.push('supvsr_grp',q_type);
            }
            else if(q_type.indexOf("_cse_") != -1) //case
            {
                query.push('case',q_type);
            }
            else
            {
                query.push('user',q_type);//single user
            }

            //Load data from server
            $.ajax({
                url:'lib/php/data/utilities_reports_load.php?type=' + query[0] +
                            '&columns_only=true',
                dataType: 'json',
                type: 'get',
                error: function() {
                    return true;
                },
                success: function(data) {

                    if( data )
                    {
                        oTable = $('#table_reports').dataTable({
                            "sAjaxSource": 'lib/php/data/utilities_reports_load.php?type=' + query[0] +
                            '&val=' + query[1] + '&date_start=' + start + '&date_end=' + end,
                            "aoColumns": data.aoColumns,
                            "bAutoWidth":false,
                            "bProcessing": true,
                            "bScrollInfinite": true,
                            "sScrollY":tableHeight,
                            "iDisplayLength": 150,
                            "bSortCellsTop": true,
                            "bDestroy": true,
                            "oLanguage": {
                                "sEmptyTable": "No data found."
                            },
                            "oTableTools":
                            {
                                "sSwfPath": "lib/DataTables-1.8.2/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf",
                                "aButtons": [
                                    {
                                        "sExtends": "collection",
                                        "sButtonText": "Print/Export",
                                        "aButtons": [
                                            {"sExtends": "copy",
                                                "mColumns": "visible"
                                            },

                                            {"sExtends": "csv",
                                                "mColumns": "visible"
                                            },

                                            {"sExtends": "xls",
                                                "mColumns": "visible"
                                            },

                                            {"sExtends": "pdf",
                                                "mColumns": "visible",
                                                "sTitle": "Report"

                                            },

                                            {"sExtends": "print",
                                                "mColumns": "visible"
                                            }
                                        ]
                                    }
                                ]
                            },
                            "sDom": 'frTt',
                            "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
                                //Note that this function gets called on each draw; there are
                                //two draws with each dataTable. So, on the first one we add
                                //the th elements to the foot, the second we work on the data
                                if ($('tfoot th').length < 1)//th hasn't already been put in
                                {
                                    for (var i = data.aoColumns.length - 1; i >= 0; i--) {
                                        $('tfoot tr').append('<th></th>');
                                    }
                                }
                                else
                                {
                                    if (aaData.length > 0) //no need for footer if no data.
                                    {
                                        var totalTime = 0;

                                        colIndex = oTable.fnGetColumnIndex('Time (hours)');

                                        for ( var a=0 ; a<aaData.length ; a++ )
                                        {
                                            totalTime += parseInt(aaData[a][colIndex]);
                                        }

                                        var nCells = nRow.getElementsByTagName('th');

                                        var previousCell = colIndex - 1;

                                        nCells[previousCell].innerHTML = 'Total Hours';

                                        nCells[colIndex].innerHTML = totalTime;
                                    }

                                }


                            }

                        });
                    }}
                });

        });

        //Create toolbar
        $('div.toolbar').html('toolbar here');
    });

    //User clicks configuration button
    $('#config_button').click(function() {
        target.load('lib/php/data/utilities_configuration_load.php');

    });

    //Set default load
    $('#reports_button').trigger('click');
});

//
//Listeners<commit_msg>Fix to ensure display of footer in reports when printing.  Thanks, <NAME><commit_after> //Scripts for utilities page

var oTable;

$(document).ready(function() {

    //set header widget
    $('#utilities_nav').addClass('ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr');

    //Add navigation buttons
    $('.utilities_nav_choices').buttonset();

    //Add navigation actions
    target = $('div#utilities_panel');

    //User clicks reports button
    $('#reports_button').click(function() {

        //Show the report chooser
        $('#report_chooser').appendTo('#utilities_panel').show();

        //Add chosen
        $('select[name="type"]').chosen();

        //Add datepickers
        $('input[name="date_start_display"]').datepicker({
            dateFormat : "DD, MM d, yy",
            altField:$('input[name = "date_start"]'),
            altFormat: "yy-mm-dd"
            });

        $('input[name="date_start_display"]').datepicker('setDate', '-7');

        $('input[name="date_end_display"]').datepicker({
            dateFormat : "DD, MM d, yy",
            altField:$('input[name = "date_end"]'),
            altFormat: "yy-mm-dd"
            });

        $('input[name="date_end_display"]').datepicker('setDate', new Date());

        //Create a table
        $('#report_chooser').after( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="table_reports"><tfoot><tr></tr></tfoot></table>' );

        //Dynamically create dataTable, load data
        $('button.report_submit').click(function(event){
            event.preventDefault();

            var tableHeight = $('#utilities_panel').height() - $('#report_chooser').height() - 150;

            if ($('tfoot th').length)
            {
                $('tfoot th').remove();
            }

            if ($('thead th').length)
            {
                $('thead th').remove();
            }

            var q_type =$('select[name="type"]').val();

            var start = $('input[name="date_start"]').val();

            var end = $('input[name="date_end"]').val();

            var detail = $('input[name="detail"]').val();

            var query = [];

            if (q_type.indexOf("_grp_") != -1) //user groups
            {
                query.push('grp',q_type);
            }
            else if (q_type.indexOf("_spv_") != -1) //supervisor groups
            {
                query.push('supvsr_grp',q_type);
            }
            else if(q_type.indexOf("_cse_") != -1) //case
            {
                query.push('case',q_type);
            }
            else
            {
                query.push('user',q_type);//single user
            }

            //Load data from server
            $.ajax({
                url:'lib/php/data/utilities_reports_load.php?type=' + query[0] +
                            '&columns_only=true',
                dataType: 'json',
                type: 'get',
                error: function() {
                    return true;
                },
                success: function(data) {

                    if( data )
                    {
                        //Add footer to html
                        for (var i = 0; i < data.aoColumns.length; i++) {
                            $('tfoot tr').append('<th></th>');
                        }

                        oTable = $('#table_reports').dataTable({
                            "sAjaxSource": 'lib/php/data/utilities_reports_load.php?type=' + query[0] +
                            '&val=' + query[1] + '&date_start=' + start + '&date_end=' + end,
                            "aoColumns": data.aoColumns,
                            "bAutoWidth":false,
                            "bProcessing": true,
                            "bScrollInfinite": true,
                            "sScrollY":tableHeight,
                            "iDisplayLength": 150,
                            "bSortCellsTop": true,
                            "bDestroy": true,
                            "oLanguage": {
                                "sEmptyTable": "No data found."
                            },
                            "oTableTools":
                            {
                                "sSwfPath": "lib/DataTables-1.8.2/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf",
                                "aButtons": [
                                    {
                                        "sExtends": "collection",
                                        "sButtonText": "Print/Export",
                                        "aButtons": [
                                            {"sExtends": "copy",
                                                "mColumns": "visible"
                                            },

                                            {"sExtends": "csv",
                                                "mColumns": "visible"
                                            },

                                            {"sExtends": "xls",
                                                "mColumns": "visible"
                                            },

                                            {"sExtends": "pdf",
                                                "mColumns": "visible",
                                                "sTitle": "Report",
                                                "bFooter":"visible"

                                            },

                                            {"sExtends": "print",
                                                "mColumns": "visible"
                                            }
                                        ]
                                    }
                                ]
                            },
                            "sDom": 'frTt',
                            "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
                                //Note that this function gets called on each draw; there are
                                //two draws with each dataTable. So, on the first one we add
                                //the th elements to the foot, the second we work on the data
                                // if ($('tfoot th').length < 1)//th hasn't already been put in
                                // {
                                //     for (var i = data.aoColumns.length - 1; i >= 0; i--) {
                                //         $('tfoot tr').append('<th></th>');
                                //     }
                                // }
                                // else
                                // {
                                    if (aaData.length > 0) //no need for footer if no data.
                                    {
                                        var totalTime = 0;

                                        colIndex = oTable.fnGetColumnIndex('Time (hours)');

                                        for ( var a=0 ; a<aaData.length ; a++ )
                                        {
                                            totalTime += parseInt(aaData[a][colIndex]);
                                        }

                                        var nCells = nRow.getElementsByTagName('th');

                                        var previousCell = colIndex - 1;

                                        nCells[previousCell].innerHTML = 'Total Hours';

                                        nCells[colIndex].innerHTML = totalTime;
                                    }

                               // }


                            }

                        });
                    }}
                });

        });

        //Create toolbar
        $('div.toolbar').html('toolbar here');
    });

    //User clicks configuration button
    $('#config_button').click(function() {
        target.load('lib/php/data/utilities_configuration_load.php');

    });

    //Set default load
    $('#reports_button').trigger('click');
});

//
//Listeners
{'fraction_non_alphanumeric': 0.12441284753078584, 'fraction_numerical': 0.003364224958740637, 'mean_word_length': 0.8695858549899134, 'pattern_counts': {'":': 61, '<': 27, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 125, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7618538', 'n_tokens_mistral': 3650, 'n_tokens_neox': 3415, 'n_words': 678}