Add controllers and web interface
[infos-pratiques:etalage.git] / poiscasse / static / js / poiscasse.js
1 $(function () {
2     territoryAutocompleterUrl = "http://127.0.0.1:5002/api/v1/autocomplete-territory";
3     $('#territory').autocomplete({
4         source: function(request, response) {
5             $.ajax({
6                 url: territoryAutocompleterUrl + '?jsonp=?',
7                 dataType: 'jsonp',
8                 data: {
9                     term: request.term
10                 },
11                 success: function (data) {
12                     response($.map(data.data.items, function(item) {
13                         var label = item.main_postal_distribution;
14                         if (item.main_postal_distribution != item.nearest_postal_distribution) {
15                             label += ' (' + item.nearest_postal_distribution + ')';
16                         }
17                         if (item.type_name != 'Arrondissement municipal' && item.type_name != 'Commune'
18                                 && item.type_name != 'Commune associĆ©e') {
19                             label += ' (' + item.type_name + ')';
20                         }
21                         return {
22                             label: label,
23                             value: item.main_postal_distribution
24                         };
25                     }));
26                 }
27             });
28         }
29     });
30 });
31