Passed
Push — master ( cddcf6...1d3855 )
by Alexander
01:59
created

tcms/testplans/static/testplans/js/search.js (7 issues)

1
function pre_process_data(data) {
2
    var tags_cache = {};
3
4
    data.forEach(function(element) {
5
        addResourceToData(element, 'tag', 'Tag.filter', tags_cache);
6
    });
7
}
8
9
10
$(document).ready(function() {
11
    var table = $("#resultsTable").DataTable({
12
        ajax: function(data, callback, settings) {
0 ignored issues
show
The parameter settings is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
13
            var params = {};
14
15
            if ($('#id_name').val()) {
16
                params['name__icontains'] = $('#id_name').val();
17
            }
18
19
            if ($('#id_before').val()) {
20
                params['create_date__lte'] = $('#id_before').data('DateTimePicker').date().format('YYYY-MM-DD 23:59:59');
21
            }
22
23
            if ($('#id_after').val()) {
24
                params['create_date__gte'] = $('#id_after').data('DateTimePicker').date().format('YYYY-MM-DD 00:00:00');
25
            }
26
27
            if ($('#id_product').val()) {
28
                params['product'] = $('#id_product').val();
29
            };
30
31
            if ($('#id_version').val()) {
32
                params['product_version'] = $('#id_version').val();
33
            };
34
35
            if ($('#id_type').val()) {
36
                params['type'] = $('#id_type').val();
37
            };
38
39
            if ($('#id_author').val()) {
40
                params['author__username__startswith'] = $('#id_author').val();
41
            };
42
43
            if ($('#id_default_tester').val()) {
44
                params['case__default_tester__username__startswith'] = $('#id_default_tester').val();
45
            };
46
47
            updateParamsToSearchTags('#id_tag', params);
48
49
            params['is_active'] = $('#id_active').is(':checked');
50
51
            dataTableJsonRPC('TestPlan.filter', params, callback, pre_process_data);
52
        },
53
        columns: [
54
            { data: "plan_id" },
55
            {
56
                data: null,
57
                render: function (data, type, full, meta) {
0 ignored issues
show
The parameter type is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter meta is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter full is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
58
                    result = '<a href="/plan/'+ data.plan_id + '/">' + escapeHTML(data.name) + '</a>';
0 ignored issues
show
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
59
                    if (! data.is_active) {
60
                        result = '<strike>' + result + '</strike>';
61
                    }
62
                    return result;
63
                }
64
            },
65
            { data: "create_date" },
66
            { data: "product" },
67
            { data: "product_version" },
68
            { data: "type"},
69
            { data: "author" },
70
            {
71
                data: "tag",
72
                render: renderFromCache,
0 ignored issues
show
The variable renderFromCache seems to be never declared. If this is a global, consider adding a /** global: renderFromCache */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
73
            },
74
        ],
75
        dom: "t",
76
        language: {
77
            loadingRecords: '<div class="spinner spinner-lg"></div>',
78
            processing: '<div class="spinner spinner-lg"></div>',
79
            zeroRecords: "No records found"
80
        },
81
        order: [[ 0, 'asc' ]],
82
    });
83
84
    hookIntoPagination('#resultsTable', table);
85
86
    $('#btn_search').click(function() {
87
        table.ajax.reload();
88
        return false; // so we don't actually send the form
89
    });
90
91
    $('#id_product').change(update_version_select_from_product);
0 ignored issues
show
The variable update_version_select_from_product seems to be never declared. If this is a global, consider adding a /** global: update_version_select_from_product */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
92
93
    $('.bootstrap-switch').bootstrapSwitch();
94
95
    $('.selectpicker').selectpicker();
96
});
97