Add config for territoria URL. Add "etalage" namespace.
[infos-pratiques:etalage.git] / poiscasse / static / js / poiscasse.js
1 /*
2  * PoisCasse -- Open Data POIs portal
3  * By: Emmanuel Raviart <eraviart@easter-eggs.com>
4  *     Romain Soufflet <rsoufflet@easter-eggs.com>
5  *
6  * Copyright (C) 2011 Easter-eggs
7  * http://gitorious.org/infos-pratiques/poiscasse
8  *
9  * This file is part of PoisCasse.
10  *
11  * PoisCasse is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Affero General Public License as
13  * published by the Free Software Foundation, either version 3 of the
14  * License, or (at your option) any later version.
15  *
16  * PoisCasse is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Affero General Public License for more details.
20  *
21  * You should have received a copy of the GNU Affero General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 */
24
25
26 var etalage = etalage || {};
27
28
29 $(function () {
30     $('#territory').autocomplete({
31         source: function(request, response) {
32             $.ajax({
33                 url: etalage.territoryAutocompleterUrl + '?jsonp=?',
34                 dataType: 'jsonp',
35                 data: {
36                     term: request.term
37                 },
38                 success: function (data) {
39                     response($.map(data.data.items, function(item) {
40                         var label = item.main_postal_distribution;
41                         if (item.main_postal_distribution != item.nearest_postal_distribution) {
42                             label += ' (' + item.nearest_postal_distribution + ')';
43                         }
44                         if (item.type_name != 'Arrondissement municipal' && item.type_name != 'Commune'
45                                 && item.type_name != 'Commune associĆ©e') {
46                             label += ' (' + item.type_name + ')';
47                         }
48                         return {
49                             label: label,
50                             value: item.main_postal_distribution
51                         };
52                     }));
53                 }
54             });
55         }
56     });
57 });
58