Completed
Push — master ( f480bf...21d5d4 )
by Patrick
03:35
created

themes/js/add.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 47
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 6
mnd 1
bc 8
fnc 3
bpm 2.6666
cpm 2
noi 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A add.js ➔ init_page 0 4 1
B add.js ➔ submit_page 0 27 3
1
function post_done(jqXHR)
2
{
3
    if(jqXHR.status === 200)
4
    {
5
        alert('Success!');
6
        location = 'index.php';
7
    }
8
    else
9
    {
10
        alert('Error! '+jqXHR.responseText);
11
    }
12
}
13
14
function submit_page(e)
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
15
{
16
    var obj = {};
17
    obj.name = $('#name').val();
18
    if(obj.name.length === 0)
19
    {
20
        $('#name').parent().addClass('has-error')
21
        return;
22
    }
23
    $('#name').parent().removeClass('has-error')
24
    if($('#presenting:checked').length > 0)
25
    {
26
        obj.presenting = true;
27
    }
28
    else
29
    {
30
        obj.presenting = false;
31
    }
32
    $.ajax({
33
        url: 'api/v1/themes',
34
        type: 'post',
35
        dataType: 'json',
36
        data: JSON.stringify(obj),
37
        processData: false,
38
        complete: post_done
39
    });
40
}
41
42
function init_page()
43
{
44
    $('[name=submit]').on('click', submit_page);
45
}
46
47
$(init_page);
48