Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1375 aurelien 1
//+---------------------------------------------------------------------------------------------------------+
2
// AUTO-COMPLÉTION Noms Scientifiques
3
 
4
function ajouterAutocompletionCommunes() {
5
	$('#commune').autocomplete({
6
		source: function(requete, add){
7
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
8
			requete = "";
9
			var url = getUrlAutocompletionCommunes()+"/"+$('#commune').val();
10
			$.getJSON(url, requete, function(data) {
11
				var suggestions = traiterRetourCommune(data);
12
				add(suggestions);
13
            });
14
        },
15
        html: true
16
	});
17
 
18
	$( "#commune" ).bind("autocompleteselect", function(event, ui) {
19
		console.log(ui.item);
20
		$("#commune").data(ui.item.value);
21
		$("#dept").data(ui.item.code);
22
		$("#dept").val(ui.item.code);
23
	});
24
}
25
 
26
function separerCommuneDepartement(chaine) {
27
	var deptCommune = chaine.split(' (');
28
	if(deptCommune[1] != null && deptCommune[1] != undefined) {
29
		deptCommune[1] = deptCommune[1].replace(')', '');
30
	} else {
31
		deptCommune[1] = '';
32
	}
33
	return deptCommune;
34
}
35
 
36
function traiterRetourCommune(data) {
37
	var suggestions = [];
38
	if (data != undefined) {
39
		$.each(data, function(i, val) {
40
			var nom = {label : '', value : ''};
41
			if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
42
				nom.label = "...";
43
				nom.value = val[0];
44
				suggestions.push(nom);
45
				return false;
46
			} else {
47
				nom.label = val[0];
48
				var deptCommune = separerCommuneDepartement(val[0]);
49
				nom.value = deptCommune[0];
50
				nom.code = deptCommune[1];
51
				suggestions.push(nom);
52
			}
53
		});
54
	}
55
 
56
	return suggestions;
57
}
58
 
59
function getUrlAutocompletionCommunes() {
60
	var url = SERVICE_AUTOCOMPLETION_COMMUNE_URL;
61
	return url;
62
}
63
 
64
$(document).ready(function() {
65
	ajouterAutocompletionCommunes();
1377 aurelien 66
	$("#date_debut").datepicker($.datepicker.regional['fr']);
67
	$("#date_fin").datepicker($.datepicker.regional['fr']);
1375 aurelien 68
});