<commit_before>// vim: set ts=4 sts=4 et sw=4:

jQuery.autocompletetable = {
    refreshtable: function(properties, term, showall) {
        var tbl = $("<table></table>")
            .addClass("autocompletetable-result")
            .addClass("horizontal_ordered_table");
        var headrow = $("<tr></tr>");
        $("<th>&nbsp;</th>").appendTo(headrow);
        $.each(properties.headings, function(i, heading) {
            $("<th>" + heading + "</th>").appendTo(headrow);
        });
        $("<th>&nbsp;</th>").appendTo(headrow);
        $("<thead></thead>").append(headrow).appendTo(tbl);
        var result = $("<tbody></tbody>").appendTo(tbl);
        var idprefix = properties.searchfield.parent().parent().attr("id") + "-cb";

        var postdata = {
            "term": properties.term,
            "all": properties.showall
        };
        if(properties.filters) {
            $.each(properties.filters, function(key, f) {
                postdata[key] = f.enabled?"yes": "";
            });
        }

        $.getJSON(properties.jsonurl, postdata, function(data) {
            $.each(data.result, function(i, item) {
                var id = idprefix + "-" + i;
                var tr = $("<tr></tr>");
                $("<td></td>")
                    .append($("<input />")
                        .attr("type", "checkbox")
                        .attr("value", item.id)
                        .attr("id", id)
                        .attr("name", id))
                .appendTo(tr);
                $.each(item.path, function(index, part) {
                    var p = part.replace(properties.term,
                            "<strong>" + properties.term + "</strong>");
                    $("<td></td>")
                        .append($("<label>" + p + "</label>").attr("for", id))
                    .appendTo(tr);
                });
                $("<td></td>").append($("<a>" + properties.editlabel + "</a>")
                    .attr("href", item.editurl))
                .appendTo(tr);
                tr.appendTo(result);
            });

            properties.searchfield.next("button").remove();
            if(data.allcount > data.result.length) {
                var showallbutton =
                    $("<button></button>")
                        .html(properties.showall_label + " (" + data.allcount + ")")
                        .button();
                properties.searchfield.after(showallbutton);
                showallbutton.click(function(e) {
                    var term = properties.searchfield.val();
                    properties.term = term;
                    properties.showall = 'yes';
                    jQuery.autocompletetable.refreshtable(properties);
                    return false;
                });
            }
        });

        if(properties.searchfield.parent().children("table").length == 0) {
            properties.searchfield.parent().append(tbl);
        } else {
            properties.searchfield.parent().children("table").first().replaceWith(tbl);
        }
    },
}


jQuery.fn.autocompletetable = function(jsonurl, headings, editlabel,
        showall_label, args) {

    return this.each(function(){
        this.properties = {};
        this.properties.jsonurl = jsonurl;
        this.properties.headings = headings;
        this.properties.editlabel = editlabel;
        this.properties.showall_label = showall_label;
        this.properties.showall = 'no';
        this.properties.term = '';<commit_msg>Added check all to filter table<commit_after>// vim: set ts=4 sts=4 et sw=4:

jQuery.autocompletetable = {
    refreshtable: function(properties, term, showall) {
        var tbl = $("<table></table>")
            .addClass("autocompletetable-result")
            .addClass("horizontal_ordered_table");
        var headrow = $("<tr></tr>");
        var checkall = $("<input/>")
            .attr("type", "checkbox");
        $("<th></th>")
            .append(checkall)
            .appendTo(headrow);
        $.each(properties.headings, function(i, heading) {
            $("<th>" + heading + "</th>").appendTo(headrow);
        });
        $("<th>&nbsp;</th>").appendTo(headrow);
        $("<thead></thead>").append(headrow).appendTo(tbl);
        var result = $("<tbody></tbody>").appendTo(tbl);
        var idprefix = properties.searchfield.parent().parent().attr("id") + "-cb";

        var postdata = {
            "term": properties.term,
            "all": properties.showall
        };
        if(properties.filters) {
            $.each(properties.filters, function(key, f) {
                postdata[key] = f.enabled?"yes": "";
            });
        }

        $.getJSON(properties.jsonurl, postdata, function(data) {
            $.each(data.result, function(i, item) {
                var id = idprefix + "-" + i;
                var tr = $("<tr></tr>");
                $("<td></td>")
                    .append($("<input />")
                        .attr("type", "checkbox")
                        .attr("value", item.id)
                        .attr("id", id)
                        .attr("name", id))
                .appendTo(tr);
                $.each(item.path, function(index, part) {
                    var p = part.replace(properties.term,
                            "<strong>" + properties.term + "</strong>");
                    $("<td></td>")
                        .append($("<label>" + p + "</label>").attr("for", id))
                    .appendTo(tr);
                });
                $("<td></td>").append($("<a>" + properties.editlabel + "</a>")
                    .attr("href", item.editurl))
                .appendTo(tr);
                tr.appendTo(result);
            });

            properties.searchfield.next("button").remove();
            if(data.allcount > data.result.length) {
                var showallbutton =
                    $("<button></button>")
                        .html(properties.showall_label + " (" + data.allcount + ")")
                        .button();
                properties.searchfield.after(showallbutton);
                showallbutton.click(function(e) {
                    var term = properties.searchfield.val();
                    properties.term = term;
                    properties.showall = 'yes';
                    jQuery.autocompletetable.refreshtable(properties);
                    return false;
                });
            }
        });

        if(properties.searchfield.parent().children("table").length == 0) {
            properties.searchfield.parent().append(tbl);
        } else {
            properties.searchfield.parent().children("table").first().replaceWith(tbl);
        }


        // Check all checkboxes when clicking checkall
        checkall.click(function() {
            var qry ="#" + properties.id + " input:checkbox";
            var checked = checkall.is(":checked");
            //$.log(qry);
            //$.log(checked);
            $(qry).attr("checked", checked);
        });
    },
}


jQuery.fn.autocompletetable = function(jsonurl, headings, editlabel,
        showall_label, args) {

    return this.each(function(){
        this.properties = {};
        this.properties.id = $(this).attr("id");
        this.properties.jsonurl = jsonurl;
        this.properties.headings = headings;
        this.properties.editlabel = editlabel;
        this.properties.showall_label = showall_label;
        this.properties.showall = 'no';
        this.properties.term = '';
{'fraction_non_alphanumeric': 0.16704348982577472, 'fraction_numerical': 0.0010639712727756351, 'mean_word_length': 1.5726992815600411, 'pattern_counts': {'":': 7, '<': 66, '<?xml version=': 0, '>': 68, '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': '1210967', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1971, 'n_words': 312}