Passed
Push — master ( f709bb...0fb35a )
by Markus
03:20
created

chaoswg/static/js/tasks.js   A

Complexity

Total Complexity 7
Complexity/F 1

Size

Lines of Code 43
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

5 Functions

Rating   Name   Duplication   Size   Complexity  
A $(ꞌ.popover .closeꞌ).click 0 3 1
A $(ꞌ.btn-backlogꞌ).click 0 3 1
A $(ꞌ.btn-todoꞌ).click 0 3 1
A popovers.click 0 3 1
A $(ꞌ.btn-doneꞌ).click 0 3 1
1
/* global $ */
2
function process_btn_press(element, state) {
3
    var popover = element.parents('.popover');
4
    var taskid = popover.prev().data('taskid');
5
    var data = {id: taskid, state: state};
6
    // send actual HTTP POST request to app
7
    $.post('/set_task_state', data)
8
        .done(function() {
9
            // Reload page after new state was set
10
            // TODO reloading the whole page is bad but whatever...
11
            location.reload();
12
        });
13
    // TODO error handling?
14
    popover.popover('hide');
15
}
16
17
// Init popovers
18
var popovers = $('[data-toggle="popover"]');
19
popovers.popover({
20
    placement: 'bottom auto',
21
    html: true,
22
    content: '<div class="btn-group">' +
23
             '<button type="button" class="btn btn-warning btn-backlog">Backlog</button>' +
24
             '<button type="button" class="btn btn-danger btn-todo">ToDo</button>' +
25
             '<button type="button" class="btn btn-success btn-done">Done</button>' +
26
             '</div>'
27
});
28
// Only one popover at a time
29
popovers.click(function(){
30
    popovers.not(this).popover('hide');
31
});
32
// Button events
33
$(document).on('click', '.popover .close', function(){
34
    $(this).parents('.popover').popover('hide');
35
});
36
$(document).on('click', '.btn-backlog', function(){
37
    process_btn_press($(this), 0);
38
});
39
$(document).on('click', '.btn-todo', function(){
40
    process_btn_press($(this), 1);
41
});
42
$(document).on('click', '.btn-done', function(){
43
    process_btn_press($(this), 2);
44
});
45