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

src/admin/views/user-route/_script.js   A

Complexity

Total Complexity 16
Complexity/F 1.23

Size

Lines of Code 70
Function Count 13

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 70
rs 10
c 1
b 0
f 0
wmc 16
mnd 1
bc 16
fnc 13
bpm 1.2306
cpm 1.2306
noi 2

6 Functions

Rating   Name   Duplication   Size   Complexity  
A _script.js ➔ updateRoutes 0 6 1
A _script.js ➔ search 0 11 1
A $(ꞌ#btn-newꞌ).click 0 14 2
A $(ꞌ#btn-refreshꞌ).click 0 10 1
A $(ꞌ.btn-assignꞌ).click 0 16 2
A $(ꞌ.search[data-target]ꞌ).keyup 0 3 1
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