Completed
Push — master ( e8947e...dc23b0 )
by Andreas
15:04
created

static/org.openpsa.mypage/mypage.js   A

Complexity

Total Complexity 11
Complexity/F 1.22

Size

Lines of Code 71
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 71
rs 10
c 1
b 0
f 0
wmc 11
mnd 1
bc 13
fnc 9
bpm 1.4443
cpm 1.2222
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A org_openpsa_workingon.select 0 12 2
B org_openpsa_workingon.setup_widget 0 25 2
A mypage.js ➔ send_working_on 0 23 1
1
2
function show_loading()
3
{
4
    $('#org_openpsa_mypage_workingon_widget .org_openpsa_mypage_workingon').hide();
5
    $('#org_openpsa_mypage_workingon_loading').show();
6
}
7
8
function send_working_on(action)
9
{
10
    var description = $("#working_description").serialize(),
11
    task = $("#working_task_selection").val().replace(/[\[|"|\]]/g, ''),
12
    invoiceable = $('#working_invoiceable').is(':checked'),
13
    send_url = MIDCOM_PAGE_PREFIX + "workingon/set/";
14
15
    $.ajax({
16
        type: "POST",
17
        url: send_url,
18
        data: description + "&task=" + task + "&invoiceable=" + invoiceable + '&action=' + action,
19
        success: function(msg)
20
        {
21
            $("#org_openpsa_mypage_workingon_widget").html(msg);
22
        },
23
        error: function() {
24
            location.href = location.href;
25
        },
26
        beforeSend: function() {
27
            show_loading();
28
        }
29
    });
30
}
31
32
var org_openpsa_workingon =
33
{
34
    setup_widget: function()
35
    {
36
        $('#org_openpsa_mypage_workingon_loading').hide();
37
        $('#org_openpsa_mypage_workingon_start')
38
            .prop("disabled", true)
39
            .bind('click', function()
40
            {
41
                send_working_on('start');
42
            });
43
44
        $('#org_openpsa_mypage_workingon_stop')
45
            .bind('click', function()
46
            {
47
                send_working_on('stop');
48
            });
49
50
        if ($('#working_task_selection').val() === '')
51
        {
52
            $('#org_openpsa_mypage_workingon_stop').hide();
53
        }
54
        else
55
        {
56
            $('#org_openpsa_mypage_workingon_start').hide();
57
        }
58
    },
59
    select: function(event, ui)
60
    {
61
        midcom_helper_datamanager2_autocomplete.select(event, ui);
62
        if ($('#working_task_selection').val() !== '')
63
        {
64
            $('#org_openpsa_mypage_workingon_start').prop("disabled", false);
65
        }
66
        else
67
        {
68
            $('#org_openpsa_mypage_workingon_start').prop("disabled", true);
69
        }
70
    }
71
72
}
73