Completed
Pull Request — FVSv2 (#49)
by Patrick
02:16
created

js/viewDept.js   A

Complexity

Total Complexity 13
Complexity/F 2.6

Size

Lines of Code 79
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 79
rs 10
wmc 13
mnd 1
bc 13
fnc 5
bpm 2.6
cpm 2.6
noi 1

5 Functions

Rating   Name   Duplication   Size   Complexity  
A viewDept.js ➔ publicChanged 0 11 2
B viewDept.js ➔ getDepartmentDone 0 26 5
A viewDept.js ➔ viewShifts 0 5 1
A viewDept.js ➔ getRoleDone 0 9 3
A viewDept.js ➔ initPage 0 20 2
1
var deptData = null;
2
3
function getRoleDone(jqXHR)
4
{
5
    if(jqXHR.status !== 200 || jqXHR.responseJSON === undefined)
6
    {
7
        alert('Unable to obtain roles!');
8
        return;
9
    }
10
    console.log(jqXHR);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
11
}
12
13
function getDepartmentDone(jqXHR)
14
{
15
    if(jqXHR.status !== 200 || jqXHR.responseJSON === undefined)
16
    {
17
        alert('Unable to obtain department!');
18
        return;
19
    }
20
    var data = jqXHR.responseJSON;
21
    deptData = data[0];
22
    $('#departmentNameRO').append(deptData.departmentName);
23
    $('#departmentName').val(deptData.departmentName);
24
    if(deptData.description !== undefined)
25
    {
26
        $('#description').val(deptData.description);
27
    }
28
    if(deptData.public)
29
    {
30
        $('#public').prop('checked', true);
31
        $('#privateDept').hide();
32
    }
33
    $.ajax({
34
        url: 'api/v1/departments/'+deptData.departmentID+'/roles',
35
        type: 'GET',
36
        dataType: 'json',
37
        complete: getRoleDone});
38
}
39
40
function publicChanged()
41
{
42
    if($('#public').prop('checked'))
43
    {
44
        $('#privateDept').hide();
45
    }
46
    else
47
    {
48
        $('#privateDept').show();
49
    }
50
}
51
52
function viewShifts()
53
{
54
    window.location = 'shifts.php?id='+deptData.departmentID;
55
    return false;
56
}
57
58
function initPage()
59
{
60
    var id = getParameterByName('id');
61
    if(id === null)
62
    {
63
        $.ajax({
64
            url: 'api/v1/departments?$top=1',
65
            type: 'GET',
66
            dataType: 'json',
67
            complete: getDepartmentDone});
68
    }
69
    else
70
    {
71
        $.ajax({
72
            url: 'api/v1/departments/'+id,
73
            type: 'GET',
74
            dataType: 'json',
75
            complete: getDepartmentDone});
76
    }
77
}
78
79
$(initPage);
80