1
|
|
|
$('i.glyphicon-refresh-animate').hide(); |
2
|
|
|
function updateRoutes(r) { |
3
|
|
|
_opts.routes.avaliable = r.avaliable; |
|
|
|
|
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 () { |
|
|
|
|
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
|
|
|
|
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.