View | Details | Raw Unified | Return to bug 41797
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-399 / +387 lines)
Lines 1814-2048 Link Here
1814
1814
1815
        const tables = [% To.json(tables || []) | $raw %];
1815
        const tables = [% To.json(tables || []) | $raw %];
1816
    </script>
1816
    </script>
1817
1818
    <script>
1817
    <script>
1819
        //  if the report param form has multiselects override default form submission
1818
        //  if the report param form has multiselects override default form submission
1820
        if( $('#report_param_form').find('select[multiple]').length ) {
1819
        if ($("#report_param_form").find("select[multiple]").length) {
1821
            $('#report_param_form').on('submit', function(e) {
1820
            $("#report_param_form").on("submit", function (e) {
1822
                $('#report_param_form').find('select[multiple]').each( function (i) {
1821
                $("#report_param_form")
1823
                    $(this).find('option:first').prop('disabled', false);
1822
                    .find("select[multiple]")
1824
                    var selection;
1823
                    .each(function (i) {
1825
                    if( $(this).find('option:selected').length === 0 ) {
1824
                        $(this).find("option:first").prop("disabled", false);
1826
                        selection = $(this).find('option:first').val();
1825
                        var selection;
1827
                        $(this).val(selection);
1826
                        if ($(this).find("option:selected").length === 0) {
1828
                    } else if( $(this).find('option:selected').length > 1 ) {
1827
                            selection = $(this).find("option:first").val();
1829
                        selection = $(this).val().join('\n');
1828
                            $(this).val(selection);
1830
                        $(this).find('option:selected').prop('selected', false);
1829
                        } else if ($(this).find("option:selected").length > 1) {
1831
                        $(this).find('option:first').val(selection);
1830
                            selection = $(this).val().join("\n");
1832
                        $(this).find('option:first').prop('selected', 'selected');
1831
                            $(this).find("option:selected").prop("selected", false);
1833
                    }
1832
                            $(this).find("option:first").val(selection);
1834
                });
1833
                            $(this).find("option:first").prop("selected", "selected");
1834
                        }
1835
                    });
1835
            });
1836
            });
1836
        }
1837
        }
1837
1838
1838
        function hide_bar_element() {
1839
        function hide_bar_element() {
1839
            $('#chart-column-horizontal').hide()
1840
            $("#chart-column-horizontal").hide();
1840
            $('.chart-column-group').each(function( index ) {
1841
            $(".chart-column-group").each(function (index) {
1841
                $( this ).hide();
1842
                $(this).hide();
1842
            });
1843
            });
1843
            $('.chart-column-line').each(function( index ) {
1844
            $(".chart-column-line").each(function (index) {
1844
                $( this ).hide()
1845
                $(this).hide();
1845
            });
1846
            });
1846
        }
1847
        }
1847
1848
1848
        function show_bar_element() {
1849
        function show_bar_element() {
1849
            $('#chart-column-horizontal').show()
1850
            $("#chart-column-horizontal").show();
1850
            $('.chart-column-group').each(function( index ) {
1851
            $(".chart-column-group").each(function (index) {
1851
                $( this ).show()
1852
                $(this).show();
1852
            });
1853
            });
1853
            $('.chart-column-line').each(function( index ) {
1854
            $(".chart-column-line").each(function (index) {
1854
                $( this ).show()
1855
                $(this).show();
1855
            });
1856
            });
1856
        }
1857
        }
1857
1858
1858
        function removeColumn(id) {
1859
        function removeColumn(id) {
1859
            $('#'+id).remove();
1860
            $("#" + id).remove();
1860
1861
1861
            if ( $('.chart-column-conf').length == 1 ) {
1862
            if ($(".chart-column-conf").length == 1) {
1862
                $('.chart-column-delete').remove();
1863
                $(".chart-column-delete").remove();
1863
            }
1864
            }
1864
        }
1865
        }
1865
1866
1866
        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
1867
        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
1867
1868
1868
        if (op == "create" || op == "editsql" || op == "save" ) {
1869
        if (op == "create" || op == "editsql" || op == "save") {
1869
1870
            var editor = CodeMirror.fromTextArea(sql, {
1870
            var editor = CodeMirror.fromTextArea(sql, {
1871
                lineNumbers: true,
1871
                lineNumbers: true,
1872
                mode: "text/x-sql",
1872
                mode: "text/x-sql",
1873
                lineWrapping: true,
1873
                lineWrapping: true,
1874
                smartIndent: false,
1874
                smartIndent: false,
1875
                keyword: { // Custom highlighting for items bounded in [[ ]] or << >>.
1875
                keyword: {
1876
                    "\\[\\[(.*?)\\]\\]":"style1",
1876
                    // Custom highlighting for items bounded in [[ ]] or << >>.
1877
                    "<<(.*?)>>":"style1"
1877
                    "\\[\\[(.*?)\\]\\]": "style1",
1878
                    "<<(.*?)>>": "style1",
1878
                },
1879
                },
1879
                hint: CodeMirror.hint.sql,
1880
                hint: CodeMirror.hint.sql,
1880
                hintOptions: {
1881
                hintOptions: {
1881
                    tables
1882
                    tables,
1882
                }
1883
                },
1883
            });
1884
            });
1884
            var ExcludedTriggerKeys = { //key-code combinations of keys that will not fire the auto-complete script
1885
            var ExcludedTriggerKeys = {
1885
                "8": "backspace",
1886
                //key-code combinations of keys that will not fire the auto-complete script
1886
                "9": "tab",
1887
                8: "backspace",
1887
                "13": "enter",
1888
                9: "tab",
1888
                "16": "shift",
1889
                13: "enter",
1889
                "17": "ctrl",
1890
                16: "shift",
1890
                "18": "alt",
1891
                17: "ctrl",
1891
                "19": "pause",
1892
                18: "alt",
1892
                "20": "capslock",
1893
                19: "pause",
1893
                "27": "escape",
1894
                20: "capslock",
1894
                "33": "pageup",
1895
                27: "escape",
1895
                "32": "spacebar",
1896
                33: "pageup",
1896
                "34": "pagedown",
1897
                32: "spacebar",
1897
                "35": "end",
1898
                34: "pagedown",
1898
                "36": "home",
1899
                35: "end",
1899
                "37": "left",
1900
                36: "home",
1900
                "38": "up",
1901
                37: "left",
1901
                "39": "right",
1902
                38: "up",
1902
                "40": "down",
1903
                39: "right",
1903
                "45": "insert",
1904
                40: "down",
1904
                "46": "delete",
1905
                45: "insert",
1905
                "56": "asterisk",
1906
                46: "delete",
1906
                "59": "semicolon",
1907
                56: "asterisk",
1907
                "91": "left window key",
1908
                59: "semicolon",
1908
                "92": "right window key",
1909
                91: "left window key",
1909
                "93": "select",
1910
                92: "right window key",
1910
                "106": "asterisk",
1911
                93: "select",
1911
                "107": "add",
1912
                106: "asterisk",
1912
                "109": "subtract",
1913
                107: "add",
1913
                "110": "decimal point",
1914
                109: "subtract",
1914
                "111": "divide",
1915
                110: "decimal point",
1915
                "112": "f1",
1916
                111: "divide",
1916
                "113": "f2",
1917
                112: "f1",
1917
                "114": "f3",
1918
                113: "f2",
1918
                "115": "f4",
1919
                114: "f3",
1919
                "116": "f5",
1920
                115: "f4",
1920
                "117": "f6",
1921
                116: "f5",
1921
                "118": "f7",
1922
                117: "f6",
1922
                "119": "f8",
1923
                118: "f7",
1923
                "120": "f9",
1924
                119: "f8",
1924
                "121": "f10",
1925
                120: "f9",
1925
                "122": "f11",
1926
                121: "f10",
1926
                "123": "f12",
1927
                122: "f11",
1927
                "144": "numlock",
1928
                123: "f12",
1928
                "145": "scrolllock",
1929
                144: "numlock",
1929
                "186": "semicolon",
1930
                145: "scrolllock",
1930
                "187": "equalsign",
1931
                186: "semicolon",
1931
                "188": "comma",
1932
                187: "equalsign",
1932
                "189": "dash",
1933
                188: "comma",
1933
                "191": "slash",
1934
                189: "dash",
1934
                "192": "graveaccent",
1935
                191: "slash",
1935
                "220": "backslash",
1936
                192: "graveaccent",
1936
                "222": "quote"
1937
                220: "backslash",
1937
            }
1938
                222: "quote",
1939
            };
1938
            //Trigger auto-complete on all keys not in dictionary of exclusions above.
1940
            //Trigger auto-complete on all keys not in dictionary of exclusions above.
1939
            editor.on("keyup", function(cm, e) {
1941
            editor.on("keyup", function (cm, e) {
1940
                if (ExcludedTriggerKeys[e.keyCode] == undefined) {
1942
                if (ExcludedTriggerKeys[e.keyCode] == undefined) {
1941
                         CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
1943
                    CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
1942
                }
1944
                }
1943
            })
1945
            });
1944
1946
1945
           // https://stackoverflow.com/questions/2086287/how-to-clear-jquery-validation-error-messages#answer-16025232
1947
            // https://stackoverflow.com/questions/2086287/how-to-clear-jquery-validation-error-messages#answer-16025232
1946
            function clearValidation( formElement ){
1948
            function clearValidation(formElement) {
1947
                // formElement should be a jQuery object
1949
                // formElement should be a jQuery object
1948
                var validator = formElement.validate();
1950
                var validator = formElement.validate();
1949
                // Iterate through named elements inside of the form, and mark them as error free
1951
                // Iterate through named elements inside of the form, and mark them as error free
1950
                $('[name]',formElement).each(function(){
1952
                $("[name]", formElement).each(function () {
1951
                    validator.successList.push(this);//mark as error free
1953
                    validator.successList.push(this); //mark as error free
1952
                    validator.showErrors();//remove error messages if present
1954
                    validator.showErrors(); //remove error messages if present
1953
                });
1955
                });
1954
                validator.resetForm();//remove error class on name elements and clear history
1956
                validator.resetForm(); //remove error class on name elements and clear history
1955
                validator.reset();//remove all error and success data
1957
                validator.reset(); //remove all error and success data
1956
            }
1958
            }
1957
        }
1959
        }
1958
1960
1959
        if (op == "showsql" || op == "showreport") {
1961
        if (op == "showsql" || op == "showreport") {
1960
1961
            var editor = CodeMirror.fromTextArea(sql, {
1962
            var editor = CodeMirror.fromTextArea(sql, {
1962
                lineNumbers: false,
1963
                lineNumbers: false,
1963
                mode: "text/x-sql",
1964
                mode: "text/x-sql",
1964
                lineWrapping: true,
1965
                lineWrapping: true,
1965
                readOnly: true,
1966
                readOnly: true,
1966
                keyword: { // Custom highlighting for items bounded in [[ ]] or << >>.
1967
                keyword: {
1967
                    "\\[\\[(.*?)\\]\\]":"style2",
1968
                    // Custom highlighting for items bounded in [[ ]] or << >>.
1968
                    "<<(.*?)>>":"style1"
1969
                    "\\[\\[(.*?)\\]\\]": "style2",
1969
               },
1970
                    "<<(.*?)>>": "style1",
1971
                },
1970
            });
1972
            });
1971
        }
1973
        }
1972
1974
1973
        function showParamModal( category ){
1975
        function showParamModal(category) {
1974
            var modal = $("#runtime_parameters");
1976
            var modal = $("#runtime_parameters");
1975
            var modalTitle = $("#runtime_parametersLabel");
1977
            var modalTitle = $("#runtime_parametersLabel");
1976
            switch ( category ){
1978
            switch (category) {
1977
                case "insertAuthVal":
1979
                case "insertAuthVal":
1978
                    modalTitle.text( _("Insert authorized value parameter") );
1980
                    modalTitle.text(_("Insert authorized value parameter"));
1979
                    $("#paramLabel").val( _("Authorized value") );
1981
                    $("#paramLabel").val(_("Authorized value"));
1980
                    $("#authorised_value_category").show();
1982
                    $("#authorised_value_category").show();
1981
                    $("label[for='authorised_value']").addClass("required");
1983
                    $("label[for='authorised_value']").addClass("required");
1982
                    $("#authorised_value").prop("required", true ).attr("required", "required").addClass("required");
1984
                    $("#authorised_value").prop("required", true).attr("required", "required").addClass("required");
1983
                    $("#runtime_param_options").show();
1985
                    $("#runtime_param_options").show();
1984
                    break;
1986
                    break;
1985
                case "insertCnSource":
1987
                case "insertCnSource":
1986
                    modalTitle.text( _("Insert classification source parameter") );
1988
                    modalTitle.text(_("Insert classification source parameter"));
1987
                    $("#paramLabel").val( _("Source of classification or shelving scheme") );
1989
                    $("#paramLabel").val(_("Source of classification or shelving scheme"));
1988
                    $("#param_category").val("cn_source");
1990
                    $("#param_category").val("cn_source");
1989
                    $("#runtime_param_options").show();
1991
                    $("#runtime_param_options").show();
1990
                    break;
1992
                    break;
1991
                case "insertFramework":
1993
                case "insertFramework":
1992
                    modalTitle.text( _("Insert bibliographic framework parameter") );
1994
                    modalTitle.text(_("Insert bibliographic framework parameter"));
1993
                    $("#paramLabel").val( _("Framework") );
1995
                    $("#paramLabel").val(_("Framework"));
1994
                    $("#param_category").val("biblio_framework");
1996
                    $("#param_category").val("biblio_framework");
1995
                    $("#runtime_param_options").show();
1997
                    $("#runtime_param_options").show();
1996
                    break;
1998
                    break;
1997
                case "insertDate":
1999
                case "insertDate":
1998
                    modalTitle.text( _("Insert date parameter") );
2000
                    modalTitle.text(_("Insert date parameter"));
1999
                    $("#paramLabel").val( _("Date") );
2001
                    $("#paramLabel").val(_("Date"));
2000
                    $("#param_category").val("date");
2002
                    $("#param_category").val("date");
2001
                    break;
2003
                    break;
2002
                case "insertItemtypes":
2004
                case "insertItemtypes":
2003
                    modalTitle.text( _("Insert item types parameter") );
2005
                    modalTitle.text(_("Insert item types parameter"));
2004
                    $("#paramLabel").val( _("Item type") );
2006
                    $("#paramLabel").val(_("Item type"));
2005
                    $("#param_category").val("itemtypes");
2007
                    $("#param_category").val("itemtypes");
2006
                    $("#runtime_param_options").show();
2008
                    $("#runtime_param_options").show();
2007
                    break;
2009
                    break;
2008
                case "insertBranches":
2010
                case "insertBranches":
2009
                    modalTitle.text( _("Insert libraries parameter") );
2011
                    modalTitle.text(_("Insert libraries parameter"));
2010
                    $("#paramLabel").val( _("Library") );
2012
                    $("#paramLabel").val(_("Library"));
2011
                    $("#param_category").val("branches");
2013
                    $("#param_category").val("branches");
2012
                    $("#runtime_param_options").show();
2014
                    $("#runtime_param_options").show();
2013
                    break;
2015
                    break;
2014
                case "insertCategorycode":
2016
                case "insertCategorycode":
2015
                    modalTitle.text( _("Insert patron category parameter") );
2017
                    modalTitle.text(_("Insert patron category parameter"));
2016
                    $("#paramLabel").val( _("Patron category") );
2018
                    $("#paramLabel").val(_("Patron category"));
2017
                    $("#param_category").val("categorycode");
2019
                    $("#param_category").val("categorycode");
2018
                    $("#runtime_param_options").show();
2020
                    $("#runtime_param_options").show();
2019
                    break;
2021
                    break;
2020
                case "insertCashregister":
2022
                case "insertCashregister":
2021
                    modalTitle.text( _("Insert cash register parameter") );
2023
                    modalTitle.text(_("Insert cash register parameter"));
2022
                    $("#paramLabel").val( _("Cash register") );
2024
                    $("#paramLabel").val(_("Cash register"));
2023
                    $("#param_category").val("cash_registers");
2025
                    $("#param_category").val("cash_registers");
2024
                    $("#runtime_param_options").show();
2026
                    $("#runtime_param_options").show();
2025
                    break;
2027
                    break;
2026
                case "insertDebittypes":
2028
                case "insertDebittypes":
2027
                    modalTitle.text( _("Insert debit type parameter") );
2029
                    modalTitle.text(_("Insert debit type parameter"));
2028
                    $("#paramLabel").val( _("Debit type") );
2030
                    $("#paramLabel").val(_("Debit type"));
2029
                    $("#param_category").val("debit_types");
2031
                    $("#param_category").val("debit_types");
2030
                    $("#runtime_param_options").show();
2032
                    $("#runtime_param_options").show();
2031
                    break;
2033
                    break;
2032
                case "insertCredittypes":
2034
                case "insertCredittypes":
2033
                    modalTitle.text( _("Insert credit type parameter") );
2035
                    modalTitle.text(_("Insert credit type parameter"));
2034
                    $("#paramLabel").val( _("Credit type") );
2036
                    $("#paramLabel").val(_("Credit type"));
2035
                    $("#param_category").val("credit_types");
2037
                    $("#param_category").val("credit_types");
2036
                    $("#runtime_param_options").show();
2038
                    $("#runtime_param_options").show();
2037
                    break;
2039
                    break;
2038
                case "insertList":
2040
                case "insertList":
2039
                    modalTitle.text( _("Insert list parameter") );
2041
                    modalTitle.text(_("Insert list parameter"));
2040
                    $("#paramLabel").val( _("List of values") );
2042
                    $("#paramLabel").val(_("List of values"));
2041
                    $("#param_category").val("list");
2043
                    $("#param_category").val("list");
2042
                    break;
2044
                    break;
2043
                case "insertText":
2045
                case "insertText":
2044
                    modalTitle.text( _("Insert text parameter") );
2046
                    modalTitle.text(_("Insert text parameter"));
2045
                    $("#paramLabel").val( _("Text") );
2047
                    $("#paramLabel").val(_("Text"));
2046
                    $("#param_category").val("");
2048
                    $("#param_category").val("");
2047
                    break;
2049
                    break;
2048
            }
2050
            }
Lines 2050-2086 Link Here
2050
            modal.modal("show");
2052
            modal.modal("show");
2051
        }
2053
        }
2052
2054
2053
        function load_group_subgroups () {
2055
        function load_group_subgroups() {
2054
            var group = $("#group_select").val();
2056
            var group = $("#group_select").val();
2055
            var subgroup = $("#subgroup_select").val();
2057
            var subgroup = $("#subgroup_select").val();
2056
            var sg = $("#subgroup");
2058
            var sg = $("#subgroup");
2057
            $(sg).find('option[value!=""]').each(function() {
2059
            $(sg)
2058
                $(this).remove();
2060
                .find('option[value!=""]')
2059
            });
2061
                .each(function () {
2062
                    $(this).remove();
2063
                });
2060
            $(sg).hide();
2064
            $(sg).hide();
2061
            if (group) {
2065
            if (group) {
2062
                var select = $(sg).find('select')[0];
2066
                var select = $(sg).find("select")[0];
2063
                $.each( group_subgroups[group], function(index, value) {
2067
                $.each(group_subgroups[group], function (index, value) {
2064
                    if ( value[0] == subgroup ) {
2068
                    if (value[0] == subgroup) {
2065
                        $('<option selected="selected" value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
2069
                        $('<option selected="selected" value="' + value[0] + '">' + value[1] + "</option>").appendTo(select);
2066
                    } else {
2070
                    } else {
2067
                        $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
2071
                        $('<option value="' + value[0] + '">' + value[1] + "</option>").appendTo(select);
2068
                    }
2072
                    }
2069
                } );
2073
                });
2070
                $("#subgroup, #subgroup *").show();
2074
                $("#subgroup, #subgroup *").show();
2071
            }
2075
            }
2072
        }
2076
        }
2073
2077
2074
        $(document).ready(function(){
2078
        $(document).ready(function () {
2075
2076
            var activeTab = localStorage.getItem("sql_reports_activetab");
2079
            var activeTab = localStorage.getItem("sql_reports_activetab");
2077
            if( activeTab == 0 ){
2080
            if (activeTab == 0) {
2078
                $("#subgroup_filter_block").hide();
2081
                $("#subgroup_filter_block").hide();
2079
            }
2082
            }
2080
2083
2081
            $("body").on('click',".fetch_chart_data",function(){
2084
            $("body").on("click", ".fetch_chart_data", function () {
2082
                if( unlimited_total > 1000 ){
2085
                if (unlimited_total > 1000) {
2083
                    if( confirm( _("Fetching full chart data for reports with many rows can cause performance issues. Are you sure you want to chart this report?") ) ){
2086
                    if (confirm(_("Fetching full chart data for reports with many rows can cause performance issues. Are you sure you want to chart this report?"))) {
2084
                        return true;
2087
                        return true;
2085
                    } else {
2088
                    } else {
2086
                        return false;
2089
                        return false;
Lines 2091-2126 Link Here
2091
            var showsql;
2094
            var showsql;
2092
            hide_bar_element();
2095
            hide_bar_element();
2093
2096
2094
            if ( $('.chart-column-conf').length == 1 ) {
2097
            if ($(".chart-column-conf").length == 1) {
2095
                $('.chart-column-delete').remove();
2098
                $(".chart-column-delete").remove();
2096
            }
2099
            }
2097
2100
2098
            $(".chart-column-delete").on('click', function(e){
2101
            $(".chart-column-delete").on("click", function (e) {
2099
                e.preventDefault();
2102
                e.preventDefault();
2100
                removeColumn('column_' + $(this).data('column'));
2103
                removeColumn("column_" + $(this).data("column"));
2101
            })
2104
            });
2102
2105
2103
            $('#download-chart').click(function() {
2106
            $("#download-chart").click(function () {
2104
                var svg = '<svg>' + $('#chart svg').html() + '</svg>';
2107
                var svg = "<svg>" + $("#chart svg").html() + "</svg>";
2105
                this.href = 'data:application/octet-stream;base64,' + btoa(svg);
2108
                this.href = "data:application/octet-stream;base64," + btoa(svg);
2106
                this.setAttribute('download', 'chart.svg');
2109
                this.setAttribute("download", "chart.svg");
2107
            });
2110
            });
2108
2111
2109
            $('#chart-type').change(function() {
2112
            $("#chart-type").change(function () {
2110
                if ($(this).val() == 'bar') {
2113
                if ($(this).val() == "bar") {
2111
                    show_bar_element();
2114
                    show_bar_element();
2112
                }
2115
                } else {
2113
                else {
2114
                    hide_bar_element();
2116
                    hide_bar_element();
2115
                }
2117
                }
2116
            });
2118
            });
2117
2119
2118
            $('#download-chart').hide();
2120
            $("#download-chart").hide();
2119
            var chart;
2121
            var chart;
2120
2122
2121
            if ( original_results && !has_errors ) {
2123
            if (original_results && !has_errors) {
2122
                $('#draw-chart').click(function() {
2124
                $("#draw-chart").click(function () {
2123
2124
                    var x_elements = $('select[name="x"]').val();
2125
                    var x_elements = $('select[name="x"]').val();
2125
                    var y_elements = [];
2126
                    var y_elements = [];
2126
                    var groups = [];
2127
                    var groups = [];
Lines 2130-2190 Link Here
2130
                    headers = header_row;
2131
                    headers = header_row;
2131
2132
2132
                    var results;
2133
                    var results;
2133
                    if (all_results.length){
2134
                    if (all_results.length) {
2134
                        if ($('input[name="chart-include-all"]').prop('checked')) {
2135
                        if ($('input[name="chart-include-all"]').prop("checked")) {
2135
                            results = all_results;
2136
                            results = all_results;
2136
                        }
2137
                        } else {
2137
                        else {
2138
                            results = original_results;
2138
                            results = original_results;
2139
                        }
2139
                        }
2140
                    } else {
2140
                    } else {
2141
                        results = original_results;
2141
                        results = original_results;
2142
                    }
2142
                    }
2143
2143
2144
                    if ($('input[name="chart-exclude-last"]').prop('checked')) {
2144
                    if ($('input[name="chart-exclude-last"]').prop("checked")) {
2145
                        results.splice(-1, 1);
2145
                        results.splice(-1, 1);
2146
                    }
2146
                    }
2147
2147
2148
                    $('select[name="y"]').each(function( index ) {
2148
                    $('select[name="y"]').each(function (index) {
2149
                        y_elements.push( $(this).val() );
2149
                        y_elements.push($(this).val());
2150
                    });
2150
                    });
2151
                    $('select[name="group"]').each(function( index ) {
2151
                    $('select[name="group"]').each(function (index) {
2152
                        groups.push( $(this).val() );
2152
                        groups.push($(this).val());
2153
                    });
2153
                    });
2154
                    $('.column-line').each(function( index ) {
2154
                    $(".column-line").each(function (index) {
2155
                        if ($(this).prop('checked')) {
2155
                        if ($(this).prop("checked")) {
2156
                            lines.push( $(this).attr('name') );
2156
                            lines.push($(this).attr("name"));
2157
                        }
2157
                        }
2158
                    });
2158
                    });
2159
2159
2160
                    // Remove deleted columns from headers and results.
2160
                    // Remove deleted columns from headers and results.
2161
                    var deleted_indexes = [];
2161
                    var deleted_indexes = [];
2162
                    var kept_headers = [];
2162
                    var kept_headers = [];
2163
                    $.each(headers, function(index, value) {
2163
                    $.each(headers, function (index, value) {
2164
                        if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
2164
                        if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
2165
                            // This header is neither a x element nor in y elements. Don't need it.
2165
                            // This header is neither a x element nor in y elements. Don't need it.
2166
                            deleted_indexes.push(index);
2166
                            deleted_indexes.push(index);
2167
                        }
2167
                        } else {
2168
                        else {
2168
                            kept_headers.push({ cell: value.cell });
2169
                            kept_headers.push({cell: value.cell});
2170
                        }
2169
                        }
2171
                    });
2170
                    });
2172
2171
2173
                    // Remove corresponding cells.
2172
                    // Remove corresponding cells.
2174
                    var kept_results = [];
2173
                    var kept_results = [];
2175
                    $.each(results, function(index, value) {
2174
                    $.each(results, function (index, value) {
2176
                        var line = {};
2175
                        var line = {};
2177
                        line['cells'] = [];
2176
                        line["cells"] = [];
2178
                        $.each(value.cells, function(i, val) {
2177
                        $.each(value.cells, function (i, val) {
2179
                            if ($.inArray(i, deleted_indexes) === -1) {
2178
                            if ($.inArray(i, deleted_indexes) === -1) {
2180
                                line['cells'].push({cell: val.cell});
2179
                                line["cells"].push({ cell: val.cell });
2181
                            }
2180
                            }
2182
                        });
2181
                        });
2183
                        kept_results.push(line);
2182
                        kept_results.push(line);
2184
                    });
2183
                    });
2185
2184
2186
                    options.type = $('select[name="chart-type"]').val();
2185
                    options.type = $('select[name="chart-type"]').val();
2187
                    options.horizontal = $('input[name="column-horizontal"]').prop('checked');
2186
                    options.horizontal = $('input[name="column-horizontal"]').prop("checked");
2188
                    options.lines = lines;
2187
                    options.lines = lines;
2189
2188
2190
                    chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
2189
                    chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
Lines 2193-2227 Link Here
2193
                    $("#chartModal").modal("hide");
2192
                    $("#chartModal").modal("hide");
2194
                });
2193
                });
2195
            }
2194
            }
2196
            if (op == "create"){
2195
            if (op == "create") {
2197
                load_group_subgroups();
2196
                load_group_subgroups();
2198
            }
2197
            }
2199
2198
2200
            $('#limit').change(function() {
2199
            $("#limit").change(function () {
2201
                $('#limitselect').submit();
2200
                $("#limitselect").submit();
2202
            });
2201
            });
2203
2202
2204
            $(document).click(function() {
2203
            $(document).click(function () {
2205
                $('#report_updated').hide();
2204
                $("#report_updated").hide();
2206
            });
2205
            });
2207
2206
2208
            $(".goback").on("click",function(e){
2207
            $(".goback").on("click", function (e) {
2209
                e.preventDefault();
2208
                e.preventDefault();
2210
                window.history.back();
2209
                window.history.back();
2211
            });
2210
            });
2212
2211
2213
            $("body").on("click", ".mana_search_button", function(){
2212
            $("body").on("click", ".mana_search_button", function () {
2214
                $("#mana-loading").show();
2213
                $("#mana-loading").show();
2215
                mana_search($("#mana_search_field").val());
2214
                mana_search($("#mana_search_field").val());
2216
            });
2215
            });
2217
2216
2218
            $(".ShareButton").on("click", function(){
2217
            $(".ShareButton").on("click", function () {
2219
                $("#note-error").hide();
2218
                $("#note-error").hide();
2220
                if($(this).closest("tr").find(".report_notes").text().length < 20 || $(this).closest("tr").find(".report_name").text().length < 20){
2219
                if ($(this).closest("tr").find(".report_notes").text().length < 20 || $(this).closest("tr").find(".report_name").text().length < 20) {
2221
                    $(".shared_infos").hide();
2220
                    $(".shared_infos").hide();
2222
                    $("#note-error").show();
2221
                    $("#note-error").show();
2223
                }
2222
                } else {
2224
                else{
2225
                    $("#reportid").val($(this).closest("tr").find(".report_id").text());
2223
                    $("#reportid").val($(this).closest("tr").find(".report_id").text());
2226
                    $("#shared_id").html($(this).closest("tr").find(".report_id").text());
2224
                    $("#shared_id").html($(this).closest("tr").find(".report_id").text());
2227
                    $("#shared_name").html($(this).closest("tr").find(".report_name").text());
2225
                    $("#shared_name").html($(this).closest("tr").find(".report_name").text());
Lines 2232-2250 Link Here
2232
                }
2230
                }
2233
            });
2231
            });
2234
2232
2235
            $("#mana_share_report").on("hidden.bs.modal", function(){
2233
            $("#mana_share_report").on("hidden.bs.modal", function () {
2236
                $(".shared_infos").show();
2234
                $(".shared_infos").show();
2237
            });
2235
            });
2238
2236
2239
            $("#addColumn").on("click",function(){
2237
            $("#addColumn").on("click", function () {
2240
                addColumn();
2238
                addColumn();
2241
            });
2239
            });
2242
2240
2243
            $("#delColumn").on("click",function(){
2241
            $("#delColumn").on("click", function () {
2244
                delColumn();
2242
                delColumn();
2245
            });
2243
            });
2246
2244
2247
            if (saved1){
2245
            if (saved1) {
2248
                var rtable = $("#table_reports").kohaTable(
2246
                var rtable = $("#table_reports").kohaTable(
2249
                    {
2247
                    {
2250
                        autoWidth: false,
2248
                        autoWidth: false,
Lines 2259-2374 Link Here
2259
                let table_dt = rtable.DataTable();
2257
                let table_dt = rtable.DataTable();
2260
2258
2261
                $("#tabs a[data-bs-toggle='tab']").on("shown.bs.tab", function (e) {
2259
                $("#tabs a[data-bs-toggle='tab']").on("shown.bs.tab", function (e) {
2262
                    tabsInit( $(e.target).parent(), rtable );
2260
                    tabsInit($(e.target).parent(), rtable);
2263
                });
2261
                });
2264
2262
2265
                if( activeTab ){
2263
                if (activeTab) {
2266
                    $("#tabs li:eq(" + activeTab + ") a").tab("show");
2264
                    $("#tabs li:eq(" + activeTab + ") a").tab("show");
2267
                }
2265
                }
2268
2266
2269
                $("#subgroup_filter").change(function() {
2267
                $("#subgroup_filter").change(function () {
2270
                    var selected = $(this).find('option:selected');
2268
                    var selected = $(this).find("option:selected");
2271
                    var sg_id = $(selected).val();
2269
                    var sg_id = $(selected).val();
2272
                    let col = table_dt.columns(5);
2270
                    let col = table_dt.columns(5);
2273
                    if (sg_id.length > 0) {
2271
                    if (sg_id.length > 0) {
2274
                        col.search(sg_id, {exact:true}).visible(false).draw();
2272
                        col.search(sg_id, { exact: true }).visible(false).draw();
2275
                    } else {
2273
                    } else {
2276
                        col.search("").visible(true).draw();
2274
                        col.search("").visible(true).draw();
2277
                    }
2275
                    }
2278
                });
2276
                });
2279
2277
2280
                $("#reports_form").submit(function(){
2278
                $("#reports_form").submit(function () {
2281
                    var checkedItems = $("input[name=id]:checked");
2279
                    var checkedItems = $("input[name=id]:checked");
2282
                    if ($(checkedItems).size() == 0) {
2280
                    if ($(checkedItems).size() == 0) {
2283
                        alert(_("You must select one or more reports to delete"));
2281
                        alert(_("You must select one or more reports to delete"));
2284
                        return false;
2282
                        return false;
2285
                    }
2283
                    }
2286
                    $(checkedItems).parents('tr').addClass("warn");
2284
                    $(checkedItems).parents("tr").addClass("warn");
2287
                    if( confirm(_("Are you sure you want to delete the selected reports?")) ) {
2285
                    if (confirm(_("Are you sure you want to delete the selected reports?"))) {
2288
                        return true;
2286
                        return true;
2289
                    } else {
2287
                    } else {
2290
                        $(checkedItems).parents('tr').removeClass("warn");
2288
                        $(checkedItems).parents("tr").removeClass("warn");
2291
                        return false;
2289
                        return false;
2292
                    }
2290
                    }
2293
                });
2291
                });
2294
2292
2295
                $("body").on("click", ".update_sql", function(e){
2293
                $("body").on("click", ".update_sql", function (e) {
2296
                    e.preventDefault();
2294
                    e.preventDefault();
2297
                    var ltitle = $(this).text();
2295
                    var ltitle = $(this).text();
2298
                    var report_id = $(this).data("report_id");
2296
                    var report_id = $(this).data("report_id");
2299
                    var page = $(this).attr("href");
2297
                    var page = $(this).attr("href");
2300
                    $("#update_sql .modal-body").load(page + " div", function(){
2298
                    $("#update_sql .modal-body").load(page + " div", function () {
2301
                        var diff1 = $("#col1 .show_sql").text();
2299
                        var diff1 = $("#col1 .show_sql").text();
2302
                        var diff2 = $("#col2 .show_sql").text();
2300
                        var diff2 = $("#col2 .show_sql").text();
2303
                        var diffs = diffString( escape(diff1), escape(diff2) );
2301
                        var diffs = diffString(escape(diff1), escape(diff2));
2304
                        $("#col1 .show_sql,#col2 .show_sql").html(diffs);
2302
                        $("#col1 .show_sql,#col2 .show_sql").html(diffs);
2305
                    });
2303
                    });
2306
                    $('#update_sql').modal('show');
2304
                    $("#update_sql").modal("show");
2307
                    $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?op=convert&id=" + report_id);
2305
                    $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?op=convert&id=" + report_id);
2308
                });
2306
                });
2309
2307
2310
                $("#update_sql").on("hidden.bs.modal", function(){
2308
                $("#update_sql").on("hidden.bs.modal", function () {
2311
                    $("#update_sql_label").html("");
2309
                    $("#update_sql_label").html("");
2312
                    $("#update_sql .modal-body").html('<div id="loading"><img src="' + interface + "/" + theme + '/img/spinner-small.gif" alt="" /> ' + _("Loading") + "</div>");
2310
                    $("#update_sql .modal-body").html('<div id="loading"><img src="' + interface + "/" + theme + '/img/spinner-small.gif" alt="" /> ' + _("Loading") + "</div>");
2313
                });
2311
                });
2314
            }
2312
            }
2315
2313
2316
            if (op == "showsql"){
2314
            if (op == "showsql") {
2317
                $("#sql").focus(function() {
2315
                $("#sql").focus(function () {
2318
                    $(this).select();
2316
                    $(this).select();
2319
                });
2317
                });
2320
            }
2318
            }
2321
2319
2322
            $("#toggle_sql").click(function(){
2320
            $("#toggle_sql").click(function () {
2323
                var sql_output = $("#sql_output");
2321
                var sql_output = $("#sql_output");
2324
                sql_output.toggle();
2322
                sql_output.toggle();
2325
                if( sql_output.is(":visible") ){
2323
                if (sql_output.is(":visible")) {
2326
                    $(this).button('complete');
2324
                    $(this).button("complete");
2327
                } else {
2325
                } else {
2328
                    $(this).button('reset');
2326
                    $(this).button("reset");
2329
                }
2327
                }
2330
                if( !showsql ){
2328
                if (!showsql) {
2331
                    showsql = CodeMirror.fromTextArea(sql, {
2329
                    showsql = CodeMirror.fromTextArea(sql, {
2332
                        lineNumbers: false,
2330
                        lineNumbers: false,
2333
                        mode: "text/x-sql",
2331
                        mode: "text/x-sql",
2334
                        lineWrapping: true,
2332
                        lineWrapping: true,
2335
                        readOnly: true
2333
                        readOnly: true,
2336
                    });
2334
                    });
2337
                }
2335
                }
2338
            });
2336
            });
2339
2337
2340
            $(".toggle_chart_settings").click(function(){
2338
            $(".toggle_chart_settings").click(function () {
2341
                $("#chart, #toggle_chart_settings_hid, #toggle_chart_settings_vis").toggle();
2339
                $("#chart, #toggle_chart_settings_hid, #toggle_chart_settings_vis").toggle();
2342
            });
2340
            });
2343
2341
2344
            if (op == "create" || op == "editsql" || op == "save"){
2342
            if (op == "create" || op == "editsql" || op == "save") {
2345
2346
                var validated_form = $("#sql_report_form").validate({
2343
                var validated_form = $("#sql_report_form").validate({
2347
                    reportname: "required",
2344
                    reportname: "required",
2348
                    group_input: {
2345
                    group_input: {
2349
                        required: {
2346
                        required: {
2350
                            depends: function(element) {
2347
                            depends: function (element) {
2351
                                return $("#create_group").prop("checked") && $("#groupdesc_input").val() != '';
2348
                                return $("#create_group").prop("checked") && $("#groupdesc_input").val() != "";
2352
                            }
2349
                            },
2353
                        }
2350
                        },
2354
                    },
2351
                    },
2355
                    groupdesc_input: {
2352
                    groupdesc_input: {
2356
                        required: {
2353
                        required: {
2357
                            depends: function(element) {
2354
                            depends: function (element) {
2358
                                return $("#create_group").prop("checked") && $("#group_input").val() != '';
2355
                                return $("#create_group").prop("checked") && $("#group_input").val() != "";
2359
                            }
2356
                            },
2360
                        }
2357
                        },
2361
                    }
2358
                    },
2362
                });
2359
                });
2363
2360
2364
                $("#select_group").change(function() {
2361
                $("#select_group").change(function () {
2365
                    if($(this).prop('checked')) {
2362
                    if ($(this).prop("checked")) {
2366
                        $("#group_input").attr("class","").prop('disabled', true).prop("required", false);
2363
                        $("#group_input").attr("class", "").prop("disabled", true).prop("required", false);
2367
                        $("#groupdesc_input").attr("class","").prop('disabled', true).prop("required", false);
2364
                        $("#groupdesc_input").attr("class", "").prop("disabled", true).prop("required", false);
2368
                        $("#group_select").prop('disabled', false);
2365
                        $("#group_select").prop("disabled", false);
2369
                        clearValidation( $("#sql_report_form") );
2366
                        clearValidation($("#sql_report_form"));
2370
                        if ($("#group_select").val().length > 0) {
2367
                        if ($("#group_select").val().length > 0) {
2371
                            $("#select_subgroup").prop('checked', true);
2368
                            $("#select_subgroup").prop("checked", true);
2372
                            $("#select_subgroup").change();
2369
                            $("#select_subgroup").change();
2373
                            $("#subgroup, #subgroup *").show();
2370
                            $("#subgroup, #subgroup *").show();
2374
                        } else {
2371
                        } else {
Lines 2376-2450 Link Here
2376
                        }
2373
                        }
2377
                    }
2374
                    }
2378
                });
2375
                });
2379
                $("#create_group").change(function() {
2376
                $("#create_group").change(function () {
2380
                    if($(this).prop('checked')) {
2377
                    if ($(this).prop("checked")) {
2381
                        $("#group_input").prop('disabled', false).prop("required", true );
2378
                        $("#group_input").prop("disabled", false).prop("required", true);
2382
                        $("#groupdesc_input").prop('disabled', false).prop("required", true );
2379
                        $("#groupdesc_input").prop("disabled", false).prop("required", true);
2383
                        $("#group_select").prop('disabled', true);
2380
                        $("#group_select").prop("disabled", true);
2384
                        // $("#create_subgroup").prop('checked', true).change();
2381
                        // $("#create_subgroup").prop('checked', true).change();
2385
                        $("#subgroup_select").hide();
2382
                        $("#subgroup_select").hide();
2386
                        $("#subgroup input[type='radio']").hide();
2383
                        $("#subgroup input[type='radio']").hide();
2387
                        $("#subgroup label[for]").hide();
2384
                        $("#subgroup label[for]").hide();
2388
                        $("#subgroup_input").prop("required", false ).prop("disabled", false).show();
2385
                        $("#subgroup_input").prop("required", false).prop("disabled", false).show();
2389
                        $("#subgroupdesc_input").prop("required", false ).prop("disabled", false).show();
2386
                        $("#subgroupdesc_input").prop("required", false).prop("disabled", false).show();
2390
                        $("#subgroup").show();
2387
                        $("#subgroup").show();
2391
                        // Add validation rules for fields which were previously hidden
2388
                        // Add validation rules for fields which were previously hidden
2392
                        $("#subgroup_input").rules("add", {
2389
                        $("#subgroup_input").rules("add", {
2393
                            required: {
2390
                            required: {
2394
                                depends: function(element) {
2391
                                depends: function (element) {
2395
                                    return $("#create_group").prop("checked") &&  $("#subgroupdesc_input").val() != '';
2392
                                    return $("#create_group").prop("checked") && $("#subgroupdesc_input").val() != "";
2396
                                }
2393
                                },
2397
                            }
2394
                            },
2398
                        });
2395
                        });
2399
                        $("#subgroupdesc_input").rules("add", {
2396
                        $("#subgroupdesc_input").rules("add", {
2400
                            required: {
2397
                            required: {
2401
                                depends: function(element) {
2398
                                depends: function (element) {
2402
                                    return $("#create_group").prop("checked") &&  $("#subgroup_input").val() != '';
2399
                                    return $("#create_group").prop("checked") && $("#subgroup_input").val() != "";
2403
                                }
2400
                                },
2404
                            }
2401
                            },
2405
                        });
2402
                        });
2406
                    }
2403
                    }
2407
                });
2404
                });
2408
                $("#select_subgroup").change(function() {
2405
                $("#select_subgroup").change(function () {
2409
                    if($(this).prop('checked')) {
2406
                    if ($(this).prop("checked")) {
2410
                        $("#subgroup_select").prop('disabled', false);
2407
                        $("#subgroup_select").prop("disabled", false);
2411
                        $("#subgroup_input").prop('disabled', true).prop("required", false );
2408
                        $("#subgroup_input").prop("disabled", true).prop("required", false);
2412
                        $("#subgroupdesc_input").prop('disabled', true).prop("required", false );
2409
                        $("#subgroupdesc_input").prop("disabled", true).prop("required", false);
2413
                        clearValidation( $("#sql_report_form") );
2410
                        clearValidation($("#sql_report_form"));
2414
                    }
2411
                    }
2415
                });
2412
                });
2416
                $("#create_subgroup").change(function() {
2413
                $("#create_subgroup").change(function () {
2417
                    if($(this).prop('checked')) {
2414
                    if ($(this).prop("checked")) {
2418
                        $("#subgroup_input").prop('disabled', false).prop("required", true );
2415
                        $("#subgroup_input").prop("disabled", false).prop("required", true);
2419
                        $("#subgroupdesc_input").prop('disabled', false).prop("required", true );
2416
                        $("#subgroupdesc_input").prop("disabled", false).prop("required", true);
2420
                        $("#subgroup_select").val("").prop('disabled', true);
2417
                        $("#subgroup_select").val("").prop("disabled", true);
2421
                    }
2418
                    }
2422
                });
2419
                });
2423
                $("#select_group").change();
2420
                $("#select_group").change();
2424
                $("#select_subgroup").change();
2421
                $("#select_subgroup").change();
2425
                $("#group_select").on("change",function(){
2422
                $("#group_select").on("change", function () {
2426
                    load_group_subgroups();
2423
                    load_group_subgroups();
2427
                });
2424
                });
2428
2425
2429
                $(".insertParam").on("click", function(e){
2426
                $(".insertParam").on("click", function (e) {
2430
                    e.preventDefault();
2427
                    e.preventDefault();
2431
                    var category = this.id;
2428
                    var category = this.id;
2432
                    showParamModal( category );
2429
                    showParamModal(category);
2433
                });
2430
                });
2434
2431
2435
                $("#runtime_parameters").on("shown.bs.modal", function(){
2432
                $("#runtime_parameters").on("shown.bs.modal", function () {
2436
                    $("#paramLabel").focus();
2433
                    $("#paramLabel").focus();
2437
                });
2434
                });
2438
2435
2439
                $("#runtime_parameters").on("hide.bs.modal", function(){
2436
                $("#runtime_parameters").on("hide.bs.modal", function () {
2440
                    $("#send_runtime_parameter")[0].reset();
2437
                    $("#send_runtime_parameter")[0].reset();
2441
                    $("#authorised_value_category").val("").hide();
2438
                    $("#authorised_value_category").val("").hide();
2442
                    $("#runtime_param_options").val("").hide();
2439
                    $("#runtime_param_options").val("").hide();
2443
                    $("label[for='authorised_value']").removeClass("required");
2440
                    $("label[for='authorised_value']").removeClass("required");
2444
                    $("#authorised_value").prop("required", false ).removeAttr("required").removeClass("required");
2441
                    $("#authorised_value").prop("required", false).removeAttr("required").removeClass("required");
2445
                });
2442
                });
2446
2443
2447
                $("#send_runtime_parameter").on("submit", function(e){
2444
                $("#send_runtime_parameter").on("submit", function (e) {
2448
                    e.preventDefault();
2445
                    e.preventDefault();
2449
                    /* Get form values */
2446
                    /* Get form values */
2450
                    var paramLabel = $("#paramLabel").val();
2447
                    var paramLabel = $("#paramLabel").val();
Lines 2457-2479 Link Here
2457
                    var cursor = doc.getCursor();
2454
                    var cursor = doc.getCursor();
2458
                    var pos = {
2455
                    var pos = {
2459
                        line: cursor.line,
2456
                        line: cursor.line,
2460
                        ch: cursor.ch
2457
                        ch: cursor.ch,
2461
                    }
2458
                    };
2462
                    /* Build runtime parameter text string */
2459
                    /* Build runtime parameter text string */
2463
                    var text = "";
2460
                    var text = "";
2464
                    if( paramLabel && param_category ){
2461
                    if (paramLabel && param_category) {
2465
                        text += paramLabel + "|" + param_category;
2462
                        text += paramLabel + "|" + param_category;
2466
                    } else if( paramLabel ) {
2463
                    } else if (paramLabel) {
2467
                        text += paramLabel;
2464
                        text += paramLabel;
2468
                    } else if( param_category ){
2465
                    } else if (param_category) {
2469
                        text += param_category;
2466
                        text += param_category;
2470
                    }
2467
                    }
2471
                    if( param_option ){
2468
                    if (param_option) {
2472
                        text += param_option;
2469
                        text += param_option;
2473
                    }
2470
                    }
2474
                    if( text != "" ){
2471
                    if (text != "") {
2475
                        text = " <<" + text + ">> ";
2472
                        text = " <<" + text + ">> ";
2476
                        if( selection.length > 0){
2473
                        if (selection.length > 0) {
2477
                            editor.replaceSelection(text);
2474
                            editor.replaceSelection(text);
2478
                        } else {
2475
                        } else {
2479
                            doc.replaceRange(text, pos);
2476
                            doc.replaceRange(text, pos);
Lines 2482-2556 Link Here
2482
                    $("#runtime_parameters").modal("hide");
2479
                    $("#runtime_parameters").modal("hide");
2483
                });
2480
                });
2484
2481
2485
                $("#authorised_value").on("change", function(){
2482
                $("#authorised_value").on("change", function () {
2486
                    $("#param_category").val( $(this).val() );
2483
                    $("#param_category").val($(this).val());
2487
                });
2484
                });
2488
2489
            }
2485
            }
2490
2486
2491
            $("#mana_search_form").submit(function(e){
2487
            $("#mana_search_form").submit(function (e) {
2492
                e.preventDefault();
2488
                e.preventDefault();
2493
            });
2489
            });
2494
2490
2495
            $("#column_submit").submit(function() {
2491
            $("#column_submit").submit(function () {
2496
                if ($("#selectedColumns option").size() < 1) {
2492
                if ($("#selectedColumns option").size() < 1) {
2497
                    alert(_("No columns selected!"));
2493
                    alert(_("No columns selected!"));
2498
                    return false;
2494
                    return false;
2499
                }
2495
                }
2500
                $("#selectedColumns option").attr("selected", "selected");  // Select everything still in #selectedColumns
2496
                $("#selectedColumns option").attr("selected", "selected"); // Select everything still in #selectedColumns
2501
                return true;
2497
                return true;
2502
            });
2498
            });
2503
2499
2504
            // Mana KB
2500
            // Mana KB
2505
            $("body").on("click", ".mana-use", function(e) {
2501
            $("body").on("click", ".mana-use", function (e) {
2506
                e.preventDefault();
2502
                e.preventDefault();
2507
                $(this).find("i").attr("class","fa-solid fa-rotate fa-spin");
2503
                $(this).find("i").attr("class", "fa-solid fa-rotate fa-spin");
2508
                mana_use( $(this).data("report_id") );
2504
                mana_use($(this).data("report_id"));
2509
            });
2505
            });
2510
2506
2511
            $("#mana_search_result").on("shown.bs.modal", function(){
2507
            $("#mana_search_result").on("shown.bs.modal", function () {
2512
                $("#mana_search_field").focus();
2508
                $("#mana_search_field").focus();
2513
            });
2509
            });
2514
2510
2515
            $("#mana_search_result").on("hide.bs.modal", function(){
2511
            $("#mana_search_result").on("hide.bs.modal", function () {
2516
                $("#mana_result_content").html("");
2512
                $("#mana_result_content").html("");
2517
                $("#mana_search_field").val("");
2513
                $("#mana_search_field").val("");
2518
            });
2514
            });
2519
2515
2520
            $(".batch_op").on("click", function(e){
2516
            $(".batch_op").on("click", function (e) {
2521
                e.preventDefault();
2517
                e.preventDefault();
2522
                var target_form = $(this).data("submit");
2518
                var target_form = $(this).data("submit");
2523
                $("#" + target_form ).submit();
2519
                $("#" + target_form).submit();
2524
            });
2520
            });
2525
2521
2526
            $("#batch_add_to_list").on("submit", function(e){
2522
            $("#batch_add_to_list").on("submit", function (e) {
2527
                e.preventDefault();
2523
                e.preventDefault();
2528
                addToList();
2524
                addToList();
2529
            });
2525
            });
2530
2526
2531
            $("body").on("click", ".preview_sql", function(e){
2527
            $("body").on("click", ".preview_sql", function (e) {
2532
                e.preventDefault();
2528
                e.preventDefault();
2533
                var reportid = $(this).data("reportid");
2529
                var reportid = $(this).data("reportid");
2534
                previewSql( reportid );
2530
                previewSql(reportid);
2535
            });
2531
            });
2536
            $(".limitselect").on("click", function(){
2532
            $(".limitselect").on("click", function () {
2537
                var limit = $(this).data("limit");
2533
                var limit = $(this).data("limit");
2538
                $("#limit").val( limit );
2534
                $("#limit").val(limit);
2539
                $("#limitselect").submit();
2535
                $("#limitselect").submit();
2540
            });
2536
            });
2541
2537
2542
            // Apply select2 to all select fields having a "multiple" attribute
2538
            // Apply select2 to all select fields having a "multiple" attribute
2543
            let selectFields = document.querySelectorAll('#report_param_form select[multiple]');
2539
            let selectFields = document.querySelectorAll("#report_param_form select[multiple]");
2544
            selectFields.forEach((selectField) => {
2540
            selectFields.forEach(selectField => {
2545
                selectField.style.minWidth = '320px';
2541
                selectField.style.minWidth = "320px";
2546
                $(selectField).select2();
2542
                $(selectField).select2();
2547
            });
2543
            });
2548
2549
        });
2544
        });
2550
2545
2551
        $("#toggle_auto_links").on("click", function(e){
2546
        $("#toggle_auto_links").on("click", function (e) {
2552
            e.preventDefault();
2547
            e.preventDefault();
2553
            if( $(".data-plain").is(":visible") ){
2548
            if ($(".data-plain").is(":visible")) {
2554
                /* if a data-plain element is visible, this click hides it and shows auto-links */
2549
                /* if a data-plain element is visible, this click hides it and shows auto-links */
2555
                localStorage.removeItem("reports_auto_link_off");
2550
                localStorage.removeItem("reports_auto_link_off");
2556
            } else {
2551
            } else {
Lines 2559-2574 Link Here
2559
            }
2554
            }
2560
            $(".data-plain,.autolink").toggle();
2555
            $(".data-plain,.autolink").toggle();
2561
        });
2556
        });
2562
        if ( localStorage.getItem("reports_auto_link_off") == 1 ){
2557
        if (localStorage.getItem("reports_auto_link_off") == 1) {
2563
            $("#toggle_auto_links").click();
2558
            $("#toggle_auto_links").click();
2564
        }
2559
        }
2565
2560
2566
        function tabsInit( tab, rtable ){
2561
        function tabsInit(tab, rtable) {
2567
            var activeTab = tab.index();
2562
            var activeTab = tab.index();
2568
            localStorage.setItem("sql_reports_activetab", activeTab );
2563
            localStorage.setItem("sql_reports_activetab", activeTab);
2569
2564
2570
            $("#subgroup_filter option").each(function() {
2565
            $("#subgroup_filter option").each(function () {
2571
                if($(this).val().length > 0) {
2566
                if ($(this).val().length > 0) {
2572
                    $(this).remove();
2567
                    $(this).remove();
2573
                }
2568
                }
2574
            });
2569
            });
Lines 2579-2596 Link Here
2579
            col5.search("").visible(true);
2574
            col5.search("").visible(true);
2580
2575
2581
            var g_id = tab.find("a").data("tabname");
2576
            var g_id = tab.find("a").data("tabname");
2582
            if (g_id === 'reports') {
2577
            if (g_id === "reports") {
2583
                g_id = '';
2578
                g_id = "";
2584
            }
2579
            }
2585
2580
2586
            if (g_id !== null && g_id !== undefined && g_id.toString().length > 0) {
2581
            if (g_id !== null && g_id !== undefined && g_id.toString().length > 0) {
2587
                col4.search(g_id, {exact:true}).visible(false);
2582
                col4.search(g_id, { exact: true }).visible(false);
2588
                if( group_subgroups[g_id] && group_subgroups[g_id].length > 0 ){
2583
                if (group_subgroups[g_id] && group_subgroups[g_id].length > 0) {
2589
                    for(var i in group_subgroups[g_id]) {
2584
                    for (var i in group_subgroups[g_id]) {
2590
                        $("#subgroup_filter").append(
2585
                        $("#subgroup_filter").append('<option value="' + group_subgroups[g_id][i][0] + '">' + group_subgroups[g_id][i][1] + "</option>");
2591
                            '<option value="' + group_subgroups[g_id][i][0] + '">'
2592
                            + group_subgroups[g_id][i][1] + '</option>'
2593
                        );
2594
                    }
2586
                    }
2595
                    $("#subgroup_filter_block").show();
2587
                    $("#subgroup_filter_block").show();
2596
                } else {
2588
                } else {
Lines 2610-2735 Link Here
2610
        }
2602
        }
2611
2603
2612
        // Mana KB
2604
        // Mana KB
2613
        function mana_use( mana_id ){
2605
        function mana_use(mana_id) {
2614
            $.ajax( {
2606
            $.ajax({
2615
                type:"POST",
2607
                type: "POST",
2616
                url: "/cgi-bin/koha/svc/mana/use",
2608
                url: "/cgi-bin/koha/svc/mana/use",
2617
                data: {id:mana_id, resource: 'report', saveinbase: 1, csrf_token: $('meta[name="csrf-token"]').attr('content')},
2609
                data: { id: mana_id, resource: "report", saveinbase: 1, csrf_token: $('meta[name="csrf-token"]').attr("content") },
2618
                dataType: "json",
2610
                dataType: "json",
2619
            })
2611
            })
2620
            .done( function (result){
2612
                .done(function (result) {
2621
                if ( result.errmsg ){
2613
                    if (result.errmsg) {
2622
                    alert( result.errmsg );
2614
                        alert(result.errmsg);
2623
                }
2615
                    } else {
2624
                else{
2616
                        window.location = "/cgi-bin/koha/reports/guided_reports.pl?id=".concat(result.id).concat("&op=show&mana_success=1");
2625
                    window.location = ("/cgi-bin/koha/reports/guided_reports.pl?id=").concat(result.id).concat("&op=show&mana_success=1");
2617
                    }
2626
                }
2618
                })
2627
            })
2619
                .fail(function (error) {
2628
            .fail(function( error ) {
2620
                    $(".mana_use_status").hide();
2629
                $(".mana_use_status").hide();
2621
                    $("#mana_use_errortext").html(error.status + " " + error.statusText);
2630
                $("#mana_use_errortext").html( error.status + " " + error.statusText );
2622
                    $("#mana_use_failed").show();
2631
                $("#mana_use_failed").show();
2623
                    $(".mana-use i").attr("class", "fa fa-download");
2632
                $(".mana-use i").attr("class","fa fa-download");
2624
                });
2633
            });
2634
        }
2625
        }
2635
2626
2636
        function mana_search( textquery ){
2627
        function mana_search(textquery) {
2637
            $(".mana_search_status").hide();
2628
            $(".mana_search_status").hide();
2638
            $("#mana_result_content").load("/cgi-bin/koha/svc/mana/search #mana_results", "resource=report&usecomments=1&id=" + textquery, function( response, status, xhr ) {
2629
            $("#mana_result_content").load("/cgi-bin/koha/svc/mana/search #mana_results", "resource=report&usecomments=1&id=" + textquery, function (response, status, xhr) {
2639
2630
                if (status == "error") {
2640
                    if ( status == "error" ) {
2631
                    $("#mana_search_errortext").html(xhr.status + " " + xhr.statusText);
2641
                        $("#mana_search_errortext").html( xhr.status + " " + xhr.statusText );
2632
                    $("#mana_search_failed").show();
2642
                        $("#mana_search_failed").show();
2633
                    $("#mana-loading").hide();
2643
                        $("#mana-loading").hide();
2634
                } else {
2644
                    } else {
2635
                    $(".mana_search_status").hide();
2645
                        $(".mana_search_status").hide();
2636
                    $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
2646
                        $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
2637
                    $("#mana-loading").hide();
2647
                        $("#mana-loading").hide();
2638
                    $("#mana_results_datatable").kohaTable({
2648
                        $("#mana_results_datatable").kohaTable({
2639
                        pagingType: "full",
2649
                            pagingType: "full",
2640
                        autoWidth: false,
2650
                            autoWidth: false,
2641
                        columnDefs: [{ width: "35%", targets: 1 }],
2651
                            columnDefs: [
2642
                    });
2652
                                { "width": "35%", targets: 1 }
2653
                            ],
2654
                        });
2655
2643
2656
                        $(".showbutton").on("click", function(e){
2644
                    $(".showbutton").on("click", function (e) {
2657
                            e.preventDefault();
2645
                        e.preventDefault();
2658
                            $(this).parent().hide();
2646
                        $(this).parent().hide();
2659
                            $(this).parent().next().show();
2647
                        $(this).parent().next().show();
2660
                        });
2648
                    });
2661
2649
2662
                        $(".hidebutton").on("click", function(e){
2650
                    $(".hidebutton").on("click", function (e) {
2663
                            e.preventDefault();
2651
                        e.preventDefault();
2664
                            $(this).parent().hide();
2652
                        $(this).parent().hide();
2665
                            $(this).parent().prev().show();
2653
                        $(this).parent().prev().show();
2666
                        });
2654
                    });
2667
2655
2668
                        if($("td.dataTables_empty").length == 0){
2656
                    if ($("td.dataTables_empty").length == 0) {
2669
                            $("#mana_search_message").show();
2657
                        $("#mana_search_message").show();
2670
                        }
2671
                    }
2658
                    }
2672
                });
2659
                }
2660
            });
2673
        }
2661
        }
2674
2662
2675
        function addToList() {
2663
        function addToList() {
2676
            var biblionumbers = [];
2664
            var biblionumbers = [];
2677
            $(".bib_to_list").each(function() {
2665
            $(".bib_to_list").each(function () {
2678
                var biblionumber = Number( $(this).val() );
2666
                var biblionumber = Number($(this).val());
2679
                if( biblionumbers.indexOf( biblionumber ) < 0 ){
2667
                if (biblionumbers.indexOf(biblionumber) < 0) {
2680
                    biblionumbers.push( biblionumber );
2668
                    biblionumbers.push(biblionumber);
2681
                }
2669
                }
2682
            });
2670
            });
2683
            bibs = biblionumbers.join("/");
2671
            bibs = biblionumbers.join("/");
2684
            var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
2672
            var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
2685
            window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
2673
            window.open(url, "Add_to_virtualshelf", "width=500, height=400, toolbar=false, scrollbars=yes");
2686
            return false;
2674
            return false;
2687
        }
2675
        }
2688
2676
2689
        // Adapted from https://gist.github.com/jnormore/7418776
2677
        // Adapted from https://gist.github.com/jnormore/7418776
2690
        function previewSql(reportid) {
2678
        function previewSql(reportid) {
2691
            var message = $("#previewSql" + reportid ).val();
2679
            var message = $("#previewSql" + reportid).val();
2692
            var title = $("#previewSql" + reportid ).data("title");
2680
            var title = $("#previewSql" + reportid).data("title");
2693
            if( $("#preview-sql-modal").length > 0) {
2681
            if ($("#preview-sql-modal").length > 0) {
2694
                $("#preview-sql-modal").remove();
2682
                $("#preview-sql-modal").remove();
2695
            }
2683
            }
2696
2684
2697
            // Clone the template content
2685
            // Clone the template content
2698
            var template = document.getElementById('preview-sql-modal-template');
2686
            var template = document.getElementById("preview-sql-modal-template");
2699
            var clone = document.importNode(template.content, true);
2687
            var clone = document.importNode(template.content, true);
2700
2688
2701
            // Fill in the placeholders
2689
            // Fill in the placeholders
2702
            clone.querySelector('[data-placeholder="title"]').textContent = title;
2690
            clone.querySelector('[data-placeholder="title"]').textContent = title;
2703
2691
2704
            Object.assign(clone.querySelector('[data-placeholder="code"]'), {
2692
            Object.assign(clone.querySelector('[data-placeholder="code"]'), {
2705
                id: 'code' + reportid,
2693
                id: "code" + reportid,
2706
                textContent: message
2694
                textContent: message,
2707
            });
2695
            });
2708
2696
2709
            clone.querySelector('[data-placeholder="edit-href"]').href = '/cgi-bin/koha/reports/guided_reports.pl?id=' + encodeURIComponent(reportid) + '&op=edit_form';
2697
            clone.querySelector('[data-placeholder="edit-href"]').href = "/cgi-bin/koha/reports/guided_reports.pl?id=" + encodeURIComponent(reportid) + "&op=edit_form";
2710
            clone.querySelector('[data-placeholder="duplicate-href"]').href = '/cgi-bin/koha/reports/guided_reports.pl?op=duplicate&id=' + encodeURIComponent(reportid);
2698
            clone.querySelector('[data-placeholder="duplicate-href"]').href = "/cgi-bin/koha/reports/guided_reports.pl?op=duplicate&id=" + encodeURIComponent(reportid);
2711
            clone.querySelector('[data-placeholder="schedule-href"]').href = '/cgi-bin/koha/tools/scheduler.pl?id=' + encodeURIComponent(reportid);
2699
            clone.querySelector('[data-placeholder="schedule-href"]').href = "/cgi-bin/koha/tools/scheduler.pl?id=" + encodeURIComponent(reportid);
2712
2700
2713
            Object.assign(clone.querySelector('[data-placeholder="delete-attrs"]').dataset, {
2701
            Object.assign(clone.querySelector('[data-placeholder="delete-attrs"]').dataset, {
2714
                id: reportid,
2702
                id: reportid,
2715
                action: 'guided_reports.pl',
2703
                action: "guided_reports.pl",
2716
                method: 'post',
2704
                method: "post",
2717
                op: 'cud-delete'
2705
                op: "cud-delete",
2718
            });
2706
            });
2719
2707
2720
            clone.querySelector('[data-placeholder="run-href"]').href = '/cgi-bin/koha/reports/guided_reports.pl?id=' + encodeURIComponent(reportid) + '&op=run';
2708
            clone.querySelector('[data-placeholder="run-href"]').href = "/cgi-bin/koha/reports/guided_reports.pl?id=" + encodeURIComponent(reportid) + "&op=run";
2721
2709
2722
            document.body.appendChild(clone);
2710
            document.body.appendChild(clone);
2723
2711
2724
            $("#preview-sql-modal").on("shown.bs.modal", function(){
2712
            $("#preview-sql-modal")
2725
                CodeMirror.fromTextArea( document.getElementById("code" + reportid ), {
2713
                .on("shown.bs.modal", function () {
2726
                    lineNumbers: false,
2714
                    CodeMirror.fromTextArea(document.getElementById("code" + reportid), {
2727
                    mode: "text/x-sql",
2715
                        lineNumbers: false,
2728
                    lineWrapping: true,
2716
                        mode: "text/x-sql",
2729
                    readOnly: true
2717
                        lineWrapping: true,
2730
                });
2718
                        readOnly: true,
2731
            })
2719
                    });
2732
            .modal('show');
2720
                })
2721
                .modal("show");
2733
        }
2722
        }
2734
    </script>
2723
    </script>
2735
[% END %]
2724
[% END %]
2736
- 

Return to bug 41797