Passed
Push — master ( fa1fe5...e0e732 )
by Tim
08:43
created

public/assets/js/consentAdmin.js   A

Complexity

Total Complexity 14
Complexity/F 2.8

Size

Lines of Code 79
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 79
rs 10
c 0
b 0
f 0
wmc 14
mnd 9
bc 9
fnc 5
bpm 1.8
cpm 2.8
noi 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A consentAdmin.js ➔ checkConsent 0 25 4
A consentAdmin.js ➔ toggleShowAttributes 0 12 4
A consentAdmin.js ➔ GetXmlHttpObject 0 16 3
1
var xmlHttp;
2
3
function checkConsent()
4
{
5
    var show_spid = this.id.charAt(this.id.length - 1);
6
    var checkbox = document.getElementById("checkbox_" + show_spid);
7
8
    xmlHttp = GetXmlHttpObject()
9
    if (xmlHttp === null) {
10
        alert("Browser does not support HTTP Request")
0 ignored issues
show
Debugging Code Best Practice introduced by
The alert UI element is often considered obtrusive and is generally only used as a temporary measure. Consider replacing it with another UI element.
Loading history...
11
        return
12
    }
13
14
    var url = "consentAdmin.php"
15
    url = url + "?cv=" + checkbox.value
16
    url = url + "&action=" + checkbox.checked
17
    url = url + "&sid=" + Math.random()
18
19
    xmlHttp.onreadystatechange = function () {
20
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
21
            document.getElementById("consentText_" + show_spid).innerHTML = xmlHttp.responseText;
22
        }
23
    }
24
25
    xmlHttp.open("GET", url, true)
26
    xmlHttp.send(null)
27
}
28
29
// This function creates an XMLHttpRequest
30
function GetXmlHttpObject()
31
{
32
    var xmlHttp = null;
0 ignored issues
show
Unused Code introduced by
The assignment to xmlHttp seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
33
    try {
34
        // Firefox, Opera 8.0+, Safari
35
        xmlHttp = new XMLHttpRequest();
36
    } catch (e) {
37
        //Internet Explorer
38
        try {
39
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
0 ignored issues
show
Bug introduced by
The variable ActiveXObject seems to be never declared. If this is a global, consider adding a /** global: ActiveXObject */ 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...
40
        } catch (e) {
41
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
42
        }
43
    }
44
    return xmlHttp;
45
}
46
47
function toggleShowAttributes()
48
{
49
    var show_spid = this.id.charAt(this.id.length - 1);
50
51
    var disp = document.getElementById('attributes_' + show_spid);
52
    var showing = document.getElementById('showing_' + show_spid);
53
    var hiding = document.getElementById('hiding_' + show_spid);
54
55
    disp.style.display = (disp.style.display == 'none' ? 'block' : 'none');
56
    showing.style.display = (disp.style.display == 'none' ? 'inline' : 'none');
57
    hiding.style.display = (disp.style.display == 'none' ? 'none' : 'inline');
58
}
59
60
document.addEventListener(
61
    'DOMContentLoaded',
62
    function () {
63
        var show_hide = document.getElementsByClassName("show_hide");
64
        for (var i = 0; i < show_hide.length; i++) {
65
            show_hide[i].addEventListener(
66
                'click',
67
                toggleShowAttributes
68
            );
69
        }
70
71
        var checkbox = document.getElementsByClassName("checkbox");
72
        for (var j = 0; j < checkbox.length; j++) {
73
            checkbox[j].addEventListener(
74
                'click',
75
                checkConsent
76
            );
77
        }
78
    }
79
);
80