<commit_before>var HQReport = function (options) {
    'use strict';
    var self = this;
    self.domain = options.domain;
    self.datespan = options.datespan;
    self.filterSet = options.filterSet || false;
    self.needsFilters = options.needsFilters || false;
    self.filterAccordion = options.filterAccordion || "#reportFilters";
    self.filterSubmitButton = options.filterSubmitButton || $('#paramSelectorForm button[type="submit"]');
    self.toggleFiltersButton = options.toggleFiltersButton || "#toggle-report-filters";
    self.exportReportButton = options.exportReportButton || "#export-report-excel";
    self.emailReportButton = options.emailReportButton || "#email-report";
    self.urlRoot = options.urlRoot;
    self.slug = options.slug;
    self.subReportSlug = options.subReportSlug;
    self.type = options.type;

    self.toggleFiltersCookie = self.domain+'.hqreport.toggleFilterState';
    self.datespanCookie = self.domain+".hqreport.filterSetting.test.datespan";

    self.initialLoad = true;

    self.init = function () {
        $(function () {
            checkFilterAccordionToggleState();

            $(self.exportReportButton).click(function (e) {
                var params = window.location.search.substr(1);
                var exportURL;
                e.preventDefault();
                if (params.length <= 1) {
                    if (self.loadDatespanFromCookie()) {
                        params = "startdate="+self.datespan.startdate+
                            "&enddate="+self.datespan.enddate;
                    }
                }
                window.location.href = window.location.pathname.replace(self.urlRoot,
                    self.urlRoot+'export/')+"?"+params;
            });

            $(self.emailReportButton).click(function (e) {
                var params = window.location.search.substr(1);
                e.preventDefault();
                if (params.length <= 1) {
                    if (self.loadDatespanFromCookie()) {
                        params = "startdate="+self.datespan.startdate+
                            "&enddate="+self.datespan.enddate;
                    }
                }
                window.location.href = window.location.pathname.replace(self.urlRoot,
                    self.urlRoot+'email_onceoff/')+"?"+params;
            });

            self.resetFilterState();
            if (self.needsFilters) {
                self.filterSubmitButton.button('reset').addClass('btn-primary');
            }
        });
    };

    self.handleTabularReportCookies = function (reportDatatable) {
        var defaultRowsCookieName = self.domain+'.hqreport.tabularSetting.defaultRows',
            savedPath = window.location.pathname;
        var defaultRowsCookie = ''+$.cookie(defaultRowsCookieName);
        reportDatatable.defaultRows = parseInt(defaultRowsCookie) || reportDatatable.defaultRows;

        $(reportDatatable.dataTableElem).on('hqreport.tabular.lengthChange', function (event, value) {
            $.cookie(defaultRowsCookieName, value,
                {path: savedPath, expires: 2});
        });
    };

    self.saveDatespanToCookie = function () {
        if (self.datespan) {
            $.cookie(self.datespanCookie+'.startdate', self.datespan.startdate,<commit_msg>extract common handler to closure<commit_after>var HQReport = function (options) {
    'use strict';
    var self = this;
    self.domain = options.domain;
    self.datespan = options.datespan;
    self.filterSet = options.filterSet || false;
    self.needsFilters = options.needsFilters || false;
    self.filterAccordion = options.filterAccordion || "#reportFilters";
    self.filterSubmitButton = options.filterSubmitButton || $('#paramSelectorForm button[type="submit"]');
    self.toggleFiltersButton = options.toggleFiltersButton || "#toggle-report-filters";
    self.exportReportButton = options.exportReportButton || "#export-report-excel";
    self.emailReportButton = options.emailReportButton || "#email-report";
    self.urlRoot = options.urlRoot;
    self.slug = options.slug;
    self.subReportSlug = options.subReportSlug;
    self.type = options.type;

    self.toggleFiltersCookie = self.domain+'.hqreport.toggleFilterState';
    self.datespanCookie = self.domain+".hqreport.filterSetting.test.datespan";

    self.initialLoad = true;

    self.init = function () {
        $(function () {
            checkFilterAccordionToggleState();

            $(self.exportReportButton).click(button_click_handler("export/"));

            $(self.emailReportButton).click(button_click_handler("email_onceoff/"));

            self.resetFilterState();
            if (self.needsFilters) {
                self.filterSubmitButton.button('reset').addClass('btn-primary');
            }

            function button_click_handler(path) {
                return function (e) {
                    var params = window.location.search.substr(1);
                    var exportURL;
                    e.preventDefault();
                    if (params.length <= 1) {
                        if (self.loadDatespanFromCookie()) {
                            params = "startdate="+self.datespan.startdate+
                                "&enddate="+self.datespan.enddate;
                        }
                    }
                    window.location.href = window.location.pathname.replace(self.urlRoot,
                        self.urlRoot+path)+"?"+params;
                }
            }
        });
    };

    self.handleTabularReportCookies = function (reportDatatable) {
        var defaultRowsCookieName = self.domain+'.hqreport.tabularSetting.defaultRows',
            savedPath = window.location.pathname;
        var defaultRowsCookie = ''+$.cookie(defaultRowsCookieName);
        reportDatatable.defaultRows = parseInt(defaultRowsCookie) || reportDatatable.defaultRows;

        $(reportDatatable.dataTableElem).on('hqreport.tabular.lengthChange', function (event, value) {
            $.cookie(defaultRowsCookieName, value,
                {path: savedPath, expires: 2});
        });
    };

    self.saveDatespanToCookie = function () {
        if (self.datespan) {
            $.cookie(self.datespanCookie+'.startdate', self.datespan.startdate,
{'fraction_non_alphanumeric': 0.12104253277902143, 'fraction_numerical': 0.0012791813239526704, 'mean_word_length': 2.266318537859008, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2768622', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1641, 'n_words': 237}