Completed
Pull Request — master (#48)
by Patrick
02:22
created

js/viewDept.js   A

Complexity

Total Complexity 10
Complexity/F 2.5

Size

Lines of Code 65
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 65
rs 10
wmc 10
mnd 1
bc 11
fnc 4
bpm 2.75
cpm 2.5
noi 1

4 Functions

Rating   Name   Duplication   Size   Complexity  
A viewDept.js ➔ publicChanged 0 11 2
B viewDept.js ➔ getDepartmentDone 0 22 5
A viewDept.js ➔ viewShifts 0 5 1
A viewDept.js ➔ initPage 0 20 2
1
var deptData = null;
2
3
function getDepartmentDone(jqXHR)
4
{
5
    if(jqXHR.status !== 200 || jqXHR.responseJSON === undefined)
6
    {
7
        alert('Unable to obtain department!');
8
        return;
9
    }
10
    var data = jqXHR.responseJSON;
11
    deptData = data;
12
    $('#departmentNameRO').append(data.departmentName);
13
    $('#departmentName').val(data.departmentName);
14
    if(data.description !== undefined)
15
    {
16
        $('#description').val(data.description);
17
    }
18
    if(data.public)
19
    {
20
        $('#public').prop('checked', true);
21
        $('#privateDept').hide();
22
    }
23
    console.log(data);
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...
24
}
25
26
function publicChanged()
27
{
28
    if($('#public').prop('checked'))
29
    {
30
        $('#privateDept').hide();
31
    }
32
    else
33
    {
34
        $('#privateDept').show();
35
    }
36
}
37
38
function viewShifts()
39
{
40
    window.location = 'shifts.php?id='+deptData.departmentID;
41
    return false;
42
}
43
44
function initPage()
45
{
46
    var id = getParameterByName('id');
47
    if(id === null)
48
    {
49
        $.ajax({
50
            url: 'api/v1/departments?$top=1',
51
            type: 'GET',
52
            dataType: 'json',
53
            complete: getDepartmentDone});
54
    }
55
    else
56
    {
57
        $.ajax({
58
            url: 'api/v1/departments/'+id,
59
            type: 'GET',
60
            dataType: 'json',
61
            complete: getDepartmentDone});
62
    }
63
}
64
65
$(initPage);
66