web/admin/js/nro.js   A
last analyzed

Complexity

Total Complexity 18
Complexity/F 2

Size

Lines of Code 93
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 18
eloc 60
mnd 9
bc 9
fnc 9
dl 0
loc 93
rs 10
bpm 1
cpm 2
noi 5
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A nro.js ➔ filter_action 0 4 1
1
/*
2
 * *****************************************************************************
3
 * Contributions to this work were made on behalf of the GÉANT project, a 
4
 * project that has received funding from the European Union’s Framework 
5
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
6
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
7
 * 691567 (GN4-1) and No. 731122 (GN4-2).
8
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
9
 * of the copyright in all material which was developed by a member of the GÉANT
10
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
11
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
12
 * UK as a branch of GÉANT Vereniging.
13
 * 
14
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
15
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
16
 *
17
 * License: see the web/copyright.inc.php file in the file structure or
18
 *          <base_url>/copyright.php after deploying the software
19
 */
20
21
/* various jquery scripts for the NRO admin page */
22
23
function row_filter(tbody) {
24
    var linked = tbody.find('[id^="unlinked_ck_"]').is(':checked');
25
    var broken_cert = tbody.find('[id^="brokencert_ck_"]').is(':checked');
26
    var or_warn = tbody.find('[id^="or_ck_"]').is(':checked');
27
    var profile_warn = tbody.find('[id^="profile_ck_"]').is(':checked');
28
    var input = tbody.find('[id^="qsearch_"]').val().toLowerCase();
29
    var tr_visible;
30
    var inp_found;
31
    tbody.children("tr.idp_tr").each(function() {
32
        tr_visible = true;
33
        if (linked && $(this).hasClass('linked')) {
34
            tr_visible = false;
35
        }
36
        if (tr_visible && broken_cert && $(this).hasClass('certok')) {
37
            tr_visible = false;
38
        }
39
        if (tr_visible && or_warn && $(this).hasClass('orok')) {
40
            tr_visible = false;
41
        }        
42
        if (tr_visible && profile_warn && $(this).hasClass('profileok')) {
43
            tr_visible = false;
44
        }         
45
        if (tr_visible && input !== '') {
46
            inp_found = $(this).find("span.inst_name:contains('"+input+"')").length;
47
            if (inp_found == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing inp_found to 0 using the == operator is not safe. Consider using === instead.
Loading history...
48
                tr_visible = false;
49
            }
50
        }
51
        if (tr_visible) {
52
            $(this).show();
53
        } else {
54
            $(this).hide();            
55
        }
56
    });
57
}
58
59
function filter_action() {
60
    var this_tbody = $(this).parent().parent().parent();
61
    row_filter(this_tbody);
62
}
63
64
$(document).ready(function() {
65
    // realm diagnostics
66
    $("#realmcheck").on('click', function() {
67
        event.preventDefault();
0 ignored issues
show
Bug introduced by
The variable event seems to be never declared. If this is a global, consider adding a /** global: event */ 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...
68
        document.location.href = '../diag/diag.php?admin=1&sp=1&realm=';
69
    });
70
71
    // this gets the maximum width of the Organisation column and then sets this to all
72
    // thanks to this the width does not change as we filter out some, possibly wide names
73
    var instTdWidth = 0;
74
    $("td.inst_td").each(function() {
75
        instTdWidth = Math.max(instTdWidth, $(this).width());
76
    });
77
    $("td.inst_td").width(instTdWidth);
78
    
79
    // show/hide download statistics part of the window
80
    $("button.stat-button").on('click', function() {
81
        var stat_downloads = $(this).siblings("table").find(".stat-downloads");
82
        if (stat_downloads.is(":visible")) {
83
            stat_downloads.hide();
84
            $(this).css('position', 'absolute');
85
            $(this).text(show_downloads);                
0 ignored issues
show
Bug introduced by
The variable show_downloads seems to be never declared. If this is a global, consider adding a /** global: show_downloads */ 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...
86
        } else {
87
            stat_downloads.show();
88
            $(this).css('position', 'static');
89
            $(this).text(hide_downloads);
0 ignored issues
show
Bug introduced by
The variable hide_downloads seems to be never declared. If this is a global, consider adding a /** global: hide_downloads */ 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...
90
        }
91
    });
92
93
    // handler for the text filter (must take into account possible filtering 
94
    // on linked status
95
    $('[id^="qsearch_"]').keyup(filter_action);
96
97
    // the linked filter checkbox handler
98
    $(":checkbox").on('click', filter_action);
99
    
100
    $("#fed_selection").on('change', function() {
101
        fed = $("#fed_selection option:selected").val();
0 ignored issues
show
Bug introduced by
The variable fed 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.fed.
Loading history...
102
        if (fed === "XX") {
103
            return;
104
        }
105
        $("#main_content").hide();
106
        $("#loading_gif").show();
107
        document.location.href = "overview_federation.php?fed_id="+fed;
108
    });
109
    
110
    $("img.cat-icon").tooltip();
111
    $("#loading_gif").hide();
112
    $("tbody.fedlist").each(function() {
113
        row_filter($(this));
114
    });
115
});
116
117
118
    
119