Completed
Push — master ( 7d66c7...f9ab04 )
by Xu
113:31 queued 73:35
created

$(ꞌ#btn-refreshꞌ).click   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
$('i.glyphicon-refresh-animate').hide();
2
function updateRoutes(r) {
3
    _opts.routes.avaliable = r.avaliable;
0 ignored issues
show
Bug introduced by
The variable _opts seems to be never declared. If this is a global, consider adding a /** global: _opts */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
4
    _opts.routes.assigned = r.assigned;
5
    search('avaliable');
6
    search('assigned');
7
}
8
9
$('#btn-new').click(function () {
10
    var $this = $(this);
11
    var route = $('#inp-route').val().trim();
12
    if (route != '') {
13
        $this.children('i.glyphicon-refresh-animate').show();
14
        $.post($this.attr('href'), {route: route}, function (r) {
15
            $('#inp-route').val('').focus();
16
            updateRoutes(r);
17
        }).always(function () {
18
            $this.children('i.glyphicon-refresh-animate').hide();
19
        });
20
    }
21
    return false;
22
});
23
24
$('.btn-assign').click(function (e) {
25
    e.preventDefault();
26
    var $this = $(this);
27
    var target = $this.data('target');
28
    var routes = $('select.list[data-target="' + target + '"]').val();
29
30
    if (routes.length) {
31
        $this.children('i.glyphicon-refresh-animate').show();
32
        $.post($this.attr('href'), {routes: routes}, function (r) {
33
            updateRoutes(r);
34
        }).always(function () {
35
            $this.children('i.glyphicon-refresh-animate').hide();
36
        });
37
    }
38
    return false;
39
});
40
41
$('#btn-refresh').click(function () {
42
    var $icon = $(this).children('span.glyphicon');
43
    $icon.addClass('glyphicon-refresh-animate');
44
    $.post($(this).attr('href'), function (r) {
45
        updateRoutes(r);
46
    }).always(function () {
47
        $icon.removeClass('glyphicon-refresh-animate');
48
    });
49
    return false;
50
});
51
52
$('.search[data-target]').keyup(function () {
53
    search($(this).data('target'));
54
});
55
56
function search(target) {
57
    var $list = $('select.list[data-target="' + target + '"]');
58
    $list.html('');
59
    var q = $('.search[data-target="' + target + '"]').val();
60
    $.each(_opts.routes[target], function () {
0 ignored issues
show
Bug introduced by
The variable _opts seems to be never declared. If this is a global, consider adding a /** global: _opts */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
61
        var r = this;
62
        if (r.indexOf(q) >= 0) {
63
            $('<option>').text(r).val(r).appendTo($list);
64
        }
65
    });
66
}
67
68
// initial
69
search('avaliable');
70
search('assigned');
71