Completed
Push — master ( b0bf1d...042f37 )
by Andreas
14:04
created

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

Complexity

Total Complexity 10
Complexity/F 1.11

Size

Lines of Code 52
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 10
mnd 1
bc 1
fnc 9
bpm 0.1111
cpm 1.1111
noi 0

1 Function

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