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

viewAll.js ➔ initPage   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
function getDepartmentsDone(jqXHR)
2
{
3
    if(jqXHR.status !== 200 || jqXHR.responseJSON === undefined)
4
    {
5
        alert('Unable to obtain departments!');
6
        return;
7
    }
8
    var div = $('#departments');
9
    var data = jqXHR.responseJSON;
10
    for(var i = 0; i < data.length; i++)
11
    {
12
         div.prepend('<a href="viewDept.php?id='+data[i].departmentID+'" class="list-group-item">'+data[i].departmentName+'<span class="label label-success pull-right">0</span><span class="label label-danger pull-right">0</span></a>');
13
    }
14
}
15
16
function initPage()
17
{
18
    $.ajax({
19
        url: 'api/v1/departments',
20
        type: 'GET',
21
        dataType: 'json',
22
        complete: getDepartmentsDone});
23
}
24
25
$(initPage);
26