Subversion Repositories eFlore/Applications.cel

Rev

Rev 2904 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2904 Rev 2909
1
// Héritage !!
1
// Héritage !!
2
function WidgetSaisieSauvages() {
2
function WidgetSaisieSauvages() {
3
	this.markerDeb = undefined;
3
	this.markerDeb = undefined;
4
	this.latLngDeb = undefined;
4
	this.latLngDeb = undefined;
5
	this.markerFin = undefined;
5
	this.markerFin = undefined;
6
	this.latLngCentre = undefined;
6
	this.latLngCentre = undefined;
7
	this.latLngFin = undefined;
7
	this.latLngFin = undefined;
8
	this.ligneRue = undefined;
8
	this.ligneRue = undefined;
9
	this.premierDeplacement = true;
9
	this.premierDeplacement = true;
10
	this.valeurChamp = "";
10
	this.valeurChamp = "";
11
	this.avertissementDeuxPhotosAffiche = false;
11
	this.avertissementDeuxPhotosAffiche = false;
12
	this.googleMapMarqueurDebutUrl = null;
12
	this.googleMapMarqueurDebutUrl = null;
13
	this.googleMapMarqueurFinUrl = null;
13
	this.googleMapMarqueurFinUrl = null;
14
	this.ville = null;
14
	this.ville = null;
15
	this.supprimerIconeUrl = null;
15
	this.supprimerIconeUrl = null;
16
	this.serviceTraceRueUrl = null;
16
	this.serviceTraceRueUrl = null;
17
	this.taxons = {};
17
	this.taxons = {};
18
	this.listeRues = {};
18
	this.listeRues = {};
19
	this.indexRueSelectionnee = 0;
19
	this.indexRueSelectionnee = 0;
20
	this.requeteRechercheRue = null;
20
	this.requeteRechercheRue = null;
21
	this.aucuneRueSelectionnee = "Aucune rue sélectionnée";
21
	this.aucuneRueSelectionnee = "Aucune rue sélectionnée";
22
	this.nomDeRueInconnue = "Nom de rue inconnu";
22
	this.nomDeRueInconnue = "Nom de rue inconnu";
23
}	
23
}	
24
WidgetSaisieSauvages.prototype = new WidgetSaisie();
24
WidgetSaisieSauvages.prototype = new WidgetSaisie();
25
 
25
 
26
// surcharge
26
// surcharge
27
WidgetSaisieSauvages.prototype.initCarto = function() {
27
WidgetSaisieSauvages.prototype.initCarto = function() {
28
	this.initialiserGoogleMap();
28
	this.initialiserGoogleMap();
29
	this.afficherEtapeGeolocalisation(1);
29
	this.afficherEtapeGeolocalisation(1);
30
	this.latLng = true; // patch cracra pour éviter de surcharger trouvercommune()
30
	this.latLng = true; // patch cracra pour éviter de surcharger trouvercommune()
31
 
31
 
32
	var lthis = this;
32
	var lthis = this;
33
	$('#carte-recherche').autocomplete({
33
	$('#carte-recherche').autocomplete({
34
		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
34
		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
35
		source: function(request, response) {
35
		source: function(request, response) {
36
			lthis.geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
36
			lthis.geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
37
				if (status == google.maps.GeocoderStatus.OK) {
37
				if (status == google.maps.GeocoderStatus.OK) {
38
					response($.map(results, function(item) {
38
					response($.map(results, function(item) {
39
						var rue = "";
39
						var rue = "";
40
						$.each(item.address_components, function(){
40
						$.each(item.address_components, function(){
41
							if (this.types[0] == "route" || this.types[0] == "street_address" ) {
41
							if (this.types[0] == "route" || this.types[0] == "street_address" ) {
42
								rue = this.short_name;
42
								rue = this.short_name;
43
							}
43
							}
44
						});
44
						});
45
						var retour = {
45
						var retour = {
46
							label: item.formatted_address,
46
							label: item.formatted_address,
47
							value: rue,
47
							value: rue,
48
							latitude: item.geometry.location.lat(),
48
							latitude: item.geometry.location.lat(),
49
							longitude: item.geometry.location.lng()
49
							longitude: item.geometry.location.lng()
50
						};
50
						};
51
						return retour;
51
						return retour;
52
					}));
52
					}));
53
				} else {
53
				} else {
54
					lthis.afficherErreurGoogleMap(status);
54
					lthis.afficherErreurGoogleMap(status);
55
				}
55
				}
56
			});
56
			});
57
		},
57
		},
58
		// Cette partie est executee a la selection d'une adresse
58
		// Cette partie est executee a la selection d'une adresse
59
		select: function(event, ui) {
59
		select: function(event, ui) {
60
			var nouvellePosition = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
60
			var nouvellePosition = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
61
			lthis.initialiserMarkerDeb();
61
			lthis.initialiserMarkerDeb();
62
			lthis.deplacerMarkerDeb(nouvellePosition);
62
			lthis.deplacerMarkerDeb(nouvellePosition);
63
			lthis.map.setZoom(16);
63
			lthis.map.setZoom(16);
64
			lthis.afficherEtapeGeolocalisation(2);
64
			lthis.afficherEtapeGeolocalisation(2);
65
		}
65
		}
66
	});
66
	});
67
};
67
};
68
 
68
 
69
//surcharge
69
//surcharge
70
WidgetSaisieSauvages.prototype.initForm = function() {
70
WidgetSaisieSauvages.prototype.initForm = function() {
71
	// super() à la main - toute autre manière de faire est über-komplex
71
	// super() à la main - toute autre manière de faire est über-komplex
72
	WidgetSaisie.prototype.initForm.call(this);
72
	WidgetSaisie.prototype.initForm.call(this);
73
 
73
 
74
	this.surChangementTaxonListe();
74
	this.surChangementTaxonListe();
75
	$('#taxon-liste').on('change', this.surChangementTaxonListe);
75
	$('#taxon-liste').on('change', this.surChangementTaxonListe);
76
	if (this.debug) {
76
	if (this.debug) {
77
		console.log('Selected taxon:'+$('#taxon-liste option:selected').val());
77
		console.log('Selected taxon:'+$('#taxon-liste option:selected').val());
78
	}
78
	}
79
	$('#taxon-liste').on('blur', this.surChangementValeurTaxon);
79
	$('#taxon-liste').on('blur', this.surChangementValeurTaxon);
80
	$('#taxon').on('blur', this.surChangementValeurTaxon);
80
	$('#taxon').on('blur', this.surChangementValeurTaxon);
81
};
81
};
82
 
82
 
83
//surcharge
83
//surcharge
84
WidgetSaisieSauvages.prototype.initEvts = function() {
84
WidgetSaisieSauvages.prototype.initEvts = function() {
85
	var lthis = this;
85
	var lthis = this;
86
	// super() à la main - toute autre manière de faire est über-komplex
86
	// super() à la main - toute autre manière de faire est über-komplex
87
	WidgetSaisie.prototype.initEvts.call(this);
87
	WidgetSaisie.prototype.initEvts.call(this);
88
 
88
 
89
	$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
89
	$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
90
		event.stopPropagation();
90
		event.stopPropagation();
91
	});
91
	});
92
	$('#fichier').off(); // elever l'écouteur d'événements de base
92
	$('#fichier').off(); // elever l'écouteur d'événements de base
93
	$('#fichier').on('click change', function(event) {
93
	$('#fichier').on('click change', function(event) {
94
		
94
		
95
		if($("#photos-conteneur #miniatures .miniature").length == 1 && ! lthis.avertissementDeuxPhotosAffiche) {
95
		if($("#photos-conteneur #miniatures .miniature").length == 1 && ! lthis.avertissementDeuxPhotosAffiche) {
96
			messageAvertissement = "Attention: \n"+
96
			messageAvertissement = "Attention: \n"+
97
			"Sélectionnez uniquement les photos correspondantes à une seule plante \n"+
97
			"Sélectionnez uniquement les photos correspondantes à une seule plante \n"+
98
			"(c'est à dire correspondant à un seul individu d'une espèce donnée) \n"+
98
			"(c'est à dire correspondant à un seul individu d'une espèce donnée) \n"+
99
			"vue dans le tronçon de rue inventoriée ";
99
			"vue dans le tronçon de rue inventoriée ";
100
			if(window.confirm(messageAvertissement)) {
100
			if(window.confirm(messageAvertissement)) {
101
				lthis.avertissementDeuxPhotosAffiche = true;
101
				lthis.avertissementDeuxPhotosAffiche = true;
102
				return true;
102
				return true;
103
			} else {
103
			} else {
104
				return false;
104
				return false;
105
			}
105
			}
106
		}
106
		}
107
		if ($(this).val().length > 0) {
107
		if ($(this).val().length > 0) {
108
			arreter(event);
108
			arreter(event);
109
			var options = {
109
			var options = {
110
				success: lthis.afficherMiniature.bind(lthis), // post-submit callback
110
				success: lthis.afficherMiniature.bind(lthis), // post-submit callback
111
				dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
111
				dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
112
				resetForm: true // reset the form after successful submit
112
				resetForm: true // reset the form after successful submit
113
			};
113
			};
114
			$('#miniature').append(
114
			$('#miniature').append(
115
				'<img id="miniature-chargement" class="miniature" alt="chargement" src="'+ this.chargementImageIconeUrl +'"/>');
115
				'<img id="miniature-chargement" class="miniature" alt="chargement" src="'+ this.chargementImageIconeUrl +'"/>');
116
			$('#ajouter-obs').attr('disabled', 'disabled');
116
			$('#ajouter-obs').attr('disabled', 'disabled');
117
			if (lthis.verifierFormat($(this).val())) {
117
			if (lthis.verifierFormat($(this).val())) {
118
				$('#form-upload').ajaxSubmit(options);
118
				$('#form-upload').ajaxSubmit(options);
119
			} else {
119
			} else {
120
				$('#form-upload')[0].reset();
120
				$('#form-upload')[0].reset();
121
				window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+	$('#fichier').attr('accept'));
121
				window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+	$('#fichier').attr('accept'));
122
			}
122
			}
123
			return false;
123
			return false;
124
		}
124
		}
125
	});
125
	});
126
 
126
 
127
	$('.cb-milieux').on('click', function(event) {
127
	$('.cb-milieux').on('click', function(event) {
128
		$(this).valid();
128
		$(this).valid();
129
		event.stopPropagation();
129
		event.stopPropagation();
130
	});
130
	});
131
 
131
 
132
	// Défilement des photos
132
	// Défilement des photos
133
	$('body').on('click', '.defilement-control-zone', function(event) {
133
	$('body').on('click', '.defilement-control-zone', function(event) {
134
		lthis.defilerMiniatures($(this));
134
		lthis.defilerMiniatures($(this));
135
	});
135
	});
136
	$('body').on('mouseover', '.defilement-control-zone', function(event) {
136
	$('body').on('mouseover', '.defilement-control-zone', function(event) {
137
		$('.defilement-control', this).removeClass('hidden');
137
		$('.defilement-control', this).removeClass('hidden');
138
	});
138
	});
139
	$('body').on('mouseout', '.defilement-control-zone', function(event) {
139
	$('body').on('mouseout', '.defilement-control-zone', function(event) {
140
		$('.defilement-control', this).addClass('hidden');
140
		$('.defilement-control', this).addClass('hidden');
141
	});
141
	});
142
 
142
 
143
	$('#photo-placeholder').click(function(event) {
143
	$('#photo-placeholder').click(function(event) {
144
		$('#fichier').click();
144
		$('#fichier').click();
145
	});
145
	});
146
	$('#geolocaliser').on('click', this.geolocaliser.bind(this));
146
	$('#geolocaliser').on('click', this.geolocaliser.bind(this));
147
	
147
	
148
	$('.navigation-rue').on('click', this.surClicRueSuivantPrecedent.bind(this));
148
	$('.navigation-rue').on('click', this.surClicRueSuivantPrecedent.bind(this));
149
};
149
};
150
 
150
 
151
WidgetSaisieSauvages.prototype.montrerFormIdentite = function() {
151
WidgetSaisieSauvages.prototype.montrerFormIdentite = function() {
152
	$('#zone-courriel-confirmation, #zone-prenom-nom').css('display', 'block');
152
	$('#zone-courriel-confirmation, #zone-prenom-nom').css('display', 'block');
153
};
153
};
154
 
154
 
155
// surcharge
155
// surcharge
156
WidgetSaisieSauvages.prototype.initialiserGoogleMap = function() {
156
WidgetSaisieSauvages.prototype.initialiserGoogleMap = function() {
157
	var lthis = this;
157
	var lthis = this;
158
	this.latLngDeb = new google.maps.LatLng(48.8543, 2.3483);// Paris
158
	this.latLngDeb = new google.maps.LatLng(48.8543, 2.3483);// Paris par défaut
-
 
159
	
-
 
160
	// si param "zone_geo"
159
	if (this.ville == 'Marseille') {
161
	if (this.zoneGeo != "") {
160
		this.latLngDeb = new google.maps.LatLng(43.29545, 5.37458);
162
		var url = "http://api.tela-botanica.org/service:cel:coordSearch?zone=" + this.zoneGeo;
161
	} else if (this.ville == 'Montpellier') {
163
		$.getJSON(url, function(data) {
162
		this.latLngDeb = new google.maps.LatLng(43.61077, 3.87672);
164
			lthis.latLngDeb = new google.maps.LatLng(data.lat, data.lng);
-
 
165
			lthis.suiteInitialiserGoogleMap();
-
 
166
		});
-
 
167
		
163
	}
168
	}
-
 
169
	
-
 
170
	// si param "ville"
-
 
171
	else {
-
 
172
		if (this.ville == 'Marseille') {
-
 
173
			this.latLngDeb = new google.maps.LatLng(43.29545, 5.37458);
-
 
174
		} 
-
 
175
		if (this.ville == 'Montpellier') {
-
 
176
			this.latLngDeb = new google.maps.LatLng(43.61077, 3.87672);
-
 
177
		}
-
 
178
		this.suiteInitialiserGoogleMap();
-
 
179
	}
-
 
180
	
-
 
181
	
-
 
182
}
-
 
183
 
-
 
184
 
-
 
185
WidgetSaisieSauvages.prototype.suiteInitialiserGoogleMap = function() {
164
	var options = {
186
	var options = {
165
			zoom: 16,
187
			zoom: 16,
166
			center: this.latLngDeb,
188
			center: this.latLngDeb,
167
			mapTypeId: google.maps.MapTypeId.HYBRID,
189
			mapTypeId: google.maps.MapTypeId.HYBRID,
168
			mapTypeControlOptions: {
190
			mapTypeControlOptions: {
169
				mapTypeIds: ['OSM',
191
				mapTypeIds: ['OSM',
170
					google.maps.MapTypeId.ROADMAP,
192
					google.maps.MapTypeId.ROADMAP,
171
					google.maps.MapTypeId.HYBRID,
193
					google.maps.MapTypeId.HYBRID,
172
					google.maps.MapTypeId.SATELLITE,
194
					google.maps.MapTypeId.SATELLITE,
173
					google.maps.MapTypeId.TERRAIN]}
195
					google.maps.MapTypeId.TERRAIN]}
174
		};
196
		};
175
 
197
 
176
	// Ajout de la couche OSM à la carte
198
	// Ajout de la couche OSM à la carte
177
	osmMapType = new google.maps.ImageMapType({
199
	osmMapType = new google.maps.ImageMapType({
178
		getTileUrl: function(coord, zoom) {
200
		getTileUrl: function(coord, zoom) {
179
			return 'http://tile.openstreetmap.org/' + zoom + '/' + coord.x + '/' + coord.y + '.png';
201
			return 'http://tile.openstreetmap.org/' + zoom + '/' + coord.x + '/' + coord.y + '.png';
180
		},
202
		},
181
		tileSize: new google.maps.Size(256, 256),
203
		tileSize: new google.maps.Size(256, 256),
182
		isPng: true,
204
		isPng: true,
183
		alt: 'OpenStreetMap',
205
		alt: 'OpenStreetMap',
184
		name: 'OSM',
206
		name: 'OSM',
185
		maxZoom: 19
207
		maxZoom: 19
186
	});
208
	});
187
 
209
 
188
	// Création de la carte Google
210
	// Création de la carte Google
189
	this.map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
211
	this.map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
190
	this.map.mapTypes.set('OSM', osmMapType);
212
	this.map.mapTypes.set('OSM', osmMapType);
191
 
213
 
192
	// Ajout de l'évènment sur click dans Carte
214
	// Ajout de l'évènment sur click dans Carte
193
	google.maps.event.addListener(this.map, 'click', this.surClickDansCarte.bind(this));
215
	google.maps.event.addListener(this.map, 'click', this.surClickDansCarte.bind(this));
194
 
216
 
195
	// Lorsque la carte est chargée, on vérifie si on peut précharger des données
217
	// Lorsque la carte est chargée, on vérifie si on peut précharger des données
-
 
218
	var lthis = this;
196
	google.maps.event.addListenerOnce(this.map, 'idle', function(){
219
	google.maps.event.addListenerOnce(this.map, 'idle', function(){
197
		// Initialisation du marker de début de rue
220
		// Initialisation du marker de début de rue
198
		if (!lthis.obsId) {
221
		if (!lthis.obsId) {
199
			// Tentative de geocalisation si aucune obs à précharger
222
			// Tentative de geolocalisation si aucune obs à précharger
200
			lthis.initialiserMarkerDeb();
223
			lthis.initialiserMarkerDeb();
-
 
224
			if (this.zoneGeo == "" && this.ville == "") {
201
			lthis.tenterGeolocalisation();
225
				lthis.tenterGeolocalisation();
-
 
226
			}
202
		}
227
		}
203
	});
228
	});
204
 
229
 
205
	// Création du Geocoder
230
	// Création du Geocoder
206
	this.geocoder = new google.maps.Geocoder();
231
	this.geocoder = new google.maps.Geocoder();
207
};
232
};
208
 
233
 
209
WidgetSaisieSauvages.prototype.surClickDansCarte = function(event) {
234
WidgetSaisieSauvages.prototype.surClickDansCarte = function(event) {
210
	this.latLngDeb = event.latLng;
235
	this.latLngDeb = event.latLng;
211
	this.deplacerMarkerDeb(this.latLngDeb);
236
	this.deplacerMarkerDeb(this.latLngDeb);
212
};
237
};
213
 
238
 
214
// surcharge
239
// surcharge
215
WidgetSaisieSauvages.prototype.prechargerForm = function(data) {
240
WidgetSaisieSauvages.prototype.prechargerForm = function(data) {
216
 
241
 
217
    $('#carte-recherche').val(data.zoneGeo);
242
    $('#carte-recherche').val(data.zoneGeo);
218
	$('#commune-nom').text(data.zoneGeo);
243
	$('#commune-nom').text(data.zoneGeo);
219
 
244
 
220
	if(data.hasOwnProperty("codeZoneGeo")) {
245
	if(data.hasOwnProperty("codeZoneGeo")) {
221
		$('#commune-code-insee').text(data.codeZoneGeo.replace('INSEE-C:', ''));
246
		$('#commune-code-insee').text(data.codeZoneGeo.replace('INSEE-C:', ''));
222
	}
247
	}
223
 
248
 
224
    var pos = new google.maps.LatLng(data.latitude, data.longitude);
249
    var pos = new google.maps.LatLng(data.latitude, data.longitude);
225
 
250
 
226
    if(data.hasOwnProperty("extension")) {
251
    if(data.hasOwnProperty("extension")) {
227
    	// cas des obs florilèges qui apparaissent aussi comme des obs sauvages
252
    	// cas des obs florilèges qui apparaissent aussi comme des obs sauvages
228
    	// mais qui n'ont pas de coté de rue
253
    	// mais qui n'ont pas de coté de rue
229
    	if(data.extension.hasOwnProperty("coteRue")) {
254
    	if(data.extension.hasOwnProperty("coteRue")) {
230
    		$('#rue_cote option[value='+data.extension.coteRue.valeur+']').attr("selected", "selected");
255
    		$('#rue_cote option[value='+data.extension.coteRue.valeur+']').attr("selected", "selected");
231
    	}
256
    	}
232
 
257
 
233
    	var deb = new google.maps.LatLng(data.extension.latitudeDebutRue.valeur, data.extension.longitudeDebutRue.valeur);
258
    	var deb = new google.maps.LatLng(data.extension.latitudeDebutRue.valeur, data.extension.longitudeDebutRue.valeur);
234
	    var fin = new google.maps.LatLng(data.extension.latitudeFinRue.valeur, data.extension.longitudeFinRue.valeur);
259
	    var fin = new google.maps.LatLng(data.extension.latitudeFinRue.valeur, data.extension.longitudeFinRue.valeur);
235
	    
260
	    
236
	    this.mettreAJourMarkerPosition(pos);
261
	    this.mettreAJourMarkerPosition(pos);
237
 
262
 
238
	    this.latLngDeb = deb;
263
	    this.latLngDeb = deb;
239
		this.initialiserMarkerDebSimple();
264
		this.initialiserMarkerDebSimple();
240
		
265
		
241
		this.latLngFin = fin;
266
		this.latLngFin = fin;
242
	    this.initialiserMarkerFin(fin);
267
	    this.initialiserMarkerFin(fin);
243
	    
268
	    
244
	    this.rechercherRue();
269
	    this.rechercherRue();
245
 
270
 
246
	    var latlngbounds = new google.maps.LatLngBounds();
271
	    var latlngbounds = new google.maps.LatLngBounds();
247
	    latlngbounds.extend(deb);
272
	    latlngbounds.extend(deb);
248
	    latlngbounds.extend(fin);
273
	    latlngbounds.extend(fin);
249
	    this.map.setCenter(latlngbounds.getCenter());
274
	    this.map.setCenter(latlngbounds.getCenter());
250
	    this.map.fitBounds(latlngbounds);
275
	    this.map.fitBounds(latlngbounds);
251
    } else if(data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude")) {
276
    } else if(data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude")) {
252
    	this.deplacerMarkerDeb(pos);
277
    	this.deplacerMarkerDeb(pos);
253
    }
278
    }
254
};
279
};
255
 
280
 
256
WidgetSaisieSauvages.prototype.initialiserMarkerDebSimple = function() {
281
WidgetSaisieSauvages.prototype.initialiserMarkerDebSimple = function() {
257
	this.premierDeplacement = true;
282
	this.premierDeplacement = true;
258
	if (this.markerDeb == undefined) {
283
	if (this.markerDeb == undefined) {
259
		// Marqueur de début de Rue
284
		// Marqueur de début de Rue
260
		this.markerDeb = new google.maps.Marker({
285
		this.markerDeb = new google.maps.Marker({
261
			map: this.map,
286
			map: this.map,
262
			draggable: true,
287
			draggable: true,
263
			title: 'Début de la portion de rue étudiée',
288
			title: 'Début de la portion de rue étudiée',
264
			icon: this.googleMapMarqueurDebutUrl,
289
			icon: this.googleMapMarqueurDebutUrl,
265
			position: this.latLngDeb
290
			position: this.latLngDeb
266
		});
291
		});
267
		google.maps.event.addListener(this.markerDeb, 'dragend', this.surDeplacementMarkerDeb.bind(this));
292
		google.maps.event.addListener(this.markerDeb, 'dragend', this.surDeplacementMarkerDeb.bind(this));
268
	}
293
	}
269
}
294
}
270
 
295
 
271
 
296
 
272
WidgetSaisieSauvages.prototype.initialiserMarkerDeb = function() {
297
WidgetSaisieSauvages.prototype.initialiserMarkerDeb = function() {
273
	this.premierDeplacement = true;
298
	this.premierDeplacement = true;
274
	if (this.markerDeb == undefined) {
299
	if (this.markerDeb == undefined) {
275
		// Marqueur de début de Rue
300
		// Marqueur de début de Rue
276
		this.markerDeb = new google.maps.Marker({
301
		this.markerDeb = new google.maps.Marker({
277
			map: this.map,
302
			map: this.map,
278
			draggable: true,
303
			draggable: true,
279
			title: 'Début de la portion de rue étudiée',
304
			title: 'Début de la portion de rue étudiée',
280
			icon: this.googleMapMarqueurDebutUrl,
305
			icon: this.googleMapMarqueurDebutUrl,
281
			position: this.latLngDeb
306
			position: this.latLngDeb
282
		});
307
		});
283
		google.maps.event.addListener(this.markerDeb, 'dragend', this.surDeplacementMarkerDeb.bind(this));
308
		google.maps.event.addListener(this.markerDeb, 'dragend', this.surDeplacementMarkerDeb.bind(this));
284
	}
309
	}
285
 
310
 
286
	this.latLngFin = this.latLngDeb;
311
	this.latLngFin = this.latLngDeb;
287
	if (this.markerFin != undefined) {
312
	if (this.markerFin != undefined) {
288
		this.markerFin.setMap(null);
313
		this.markerFin.setMap(null);
289
	}
314
	}
290
	this.latLngCentre = this.latLngDeb;
315
	this.latLngCentre = this.latLngDeb;
291
	if (this.ligneRue != undefined) {
316
	if (this.ligneRue != undefined) {
292
		this.ligneRue.setMap(null);
317
		this.ligneRue.setMap(null);
293
	}
318
	}
294
};
319
};
295
 
320
 
296
WidgetSaisieSauvages.prototype.surDeplacementMarkerDeb = function() {
321
WidgetSaisieSauvages.prototype.surDeplacementMarkerDeb = function() {
297
	// Annulation d'une éventuelle recherche de rue déjà en cours
322
	// Annulation d'une éventuelle recherche de rue déjà en cours
298
	this.annulerRechercherRue();
323
	this.annulerRechercherRue();
299
	this.latLngDeb = this.markerDeb.getPosition();
324
	this.latLngDeb = this.markerDeb.getPosition();
300
	this.deplacerMarkerDeb(this.latLngDeb);
325
	this.deplacerMarkerDeb(this.latLngDeb);
301
};
326
};
302
 
327
 
303
WidgetSaisieSauvages.prototype.deplacerMarkerDeb = function(nouvellePosition) {
328
WidgetSaisieSauvages.prototype.deplacerMarkerDeb = function(nouvellePosition) {
304
	
329
	
305
	this.latLngDeb = nouvellePosition;
330
	this.latLngDeb = nouvellePosition;
306
	if (this.markerDeb == undefined) {
331
	if (this.markerDeb == undefined) {
307
		// Marqueur de début de Rue
332
		// Marqueur de début de Rue
308
		this.markerDeb = new google.maps.Marker({
333
		this.markerDeb = new google.maps.Marker({
309
			map: this.map,
334
			map: this.map,
310
			draggable: true,
335
			draggable: true,
311
			title: 'Début de la portion de rue étudiée',
336
			title: 'Début de la portion de rue étudiée',
312
			icon: this.googleMapMarqueurDebutUrl,
337
			icon: this.googleMapMarqueurDebutUrl,
313
			position: this.latLngDeb
338
			position: this.latLngDeb
314
		});
339
		});
315
		google.maps.event.addListener(this.markerDeb, 'dragend', this.surDeplacementMarkerDeb.bind(this));
340
		google.maps.event.addListener(this.markerDeb, 'dragend', this.surDeplacementMarkerDeb.bind(this));
316
	}
341
	}
317
	this.markerDeb.setPosition(this.latLngDeb);
342
	this.markerDeb.setPosition(this.latLngDeb);
318
	this.map.setCenter(this.latLngDeb);
343
	this.map.setCenter(this.latLngDeb);
319
	this.mettreAJourMarkerPosition(this.latLngDeb);
344
	this.mettreAJourMarkerPosition(this.latLngDeb);
320
	this.trouverCommune(this.latLngDeb);
345
	this.trouverCommune(this.latLngDeb);
321
 
346
 
322
	var nouvellePositionFin = new google.maps.LatLng(this.latLngDeb.lat(), this.latLngDeb.lng() + 0.0010);
347
	var nouvellePositionFin = new google.maps.LatLng(this.latLngDeb.lat(), this.latLngDeb.lng() + 0.0010);
323
	this.initialiserMarkerFin();
348
	this.initialiserMarkerFin();
324
	this.deplacerMarkerFin(nouvellePositionFin);
349
	this.deplacerMarkerFin(nouvellePositionFin);
325
	this.afficherEtapeGeolocalisation(3);
350
	this.afficherEtapeGeolocalisation(3);
326
};
351
};
327
 
352
 
328
WidgetSaisieSauvages.prototype.initialiserMarkerFin = function() {
353
WidgetSaisieSauvages.prototype.initialiserMarkerFin = function() {
329
	if (this.markerFin == undefined) {
354
	if (this.markerFin == undefined) {
330
		this.markerFin = new google.maps.Marker({
355
		this.markerFin = new google.maps.Marker({
331
			map: this.map,
356
			map: this.map,
332
			draggable: true,
357
			draggable: true,
333
			title: 'Fin de la portion de rue étudiée',
358
			title: 'Fin de la portion de rue étudiée',
334
			icon: this.googleMapMarqueurFinUrl,
359
			icon: this.googleMapMarqueurFinUrl,
335
			position: this.latLngFin
360
			position: this.latLngFin
336
		});
361
		});
337
		google.maps.event.addListener(this.markerFin, 'dragend', this.surDeplacementMarkerFin.bind(this));
362
		google.maps.event.addListener(this.markerFin, 'dragend', this.surDeplacementMarkerFin.bind(this));
338
	}
363
	}
339
};
364
};
340
 
365
 
341
WidgetSaisieSauvages.prototype.deplacerMarkerFin = function(nouvellePosition) {
366
WidgetSaisieSauvages.prototype.deplacerMarkerFin = function(nouvellePosition) {
342
	this.latLngFin = nouvellePosition;
367
	this.latLngFin = nouvellePosition;
343
	this.markerFin.setMap(this.map);
368
	this.markerFin.setMap(this.map);
344
	this.markerFin.setPosition(this.latLngFin);
369
	this.markerFin.setPosition(this.latLngFin);
345
	this.dessinerLigneRue(this.latLngDeb, this.latLngFin);
370
	this.dessinerLigneRue(this.latLngDeb, this.latLngFin);
346
};
371
};
347
 
372
 
348
WidgetSaisieSauvages.prototype.surDeplacementMarkerFin = function() {
373
WidgetSaisieSauvages.prototype.surDeplacementMarkerFin = function() {
349
	// Annulation d'une éventuelle recherche déjà en cours
374
	// Annulation d'une éventuelle recherche déjà en cours
350
	this.annulerRechercherRue();
375
	this.annulerRechercherRue();
351
	this.rechercherRue();
376
	this.rechercherRue();
352
};
377
};
353
 
378
 
354
WidgetSaisieSauvages.prototype.surClicRueSuivantPrecedent = function(event) {
379
WidgetSaisieSauvages.prototype.surClicRueSuivantPrecedent = function(event) {
355
	event.preventDefault();
380
	event.preventDefault();
356
	if($(event.target).hasClass("navigation-rue-suivant")) {
381
	if($(event.target).hasClass("navigation-rue-suivant")) {
357
		this.indexRueSelectionnee = this.indexRueSelectionnee < this.listeRues.length - 1 ? this.indexRueSelectionnee + 1 : 0;
382
		this.indexRueSelectionnee = this.indexRueSelectionnee < this.listeRues.length - 1 ? this.indexRueSelectionnee + 1 : 0;
358
	} else {
383
	} else {
359
		this.indexRueSelectionnee = this.indexRueSelectionnee > 0 ? this.indexRueSelectionnee - 1 : this.listeRues.length - 1;
384
		this.indexRueSelectionnee = this.indexRueSelectionnee > 0 ? this.indexRueSelectionnee - 1 : this.listeRues.length - 1;
360
	}
385
	}
361
	this.mettreRueEnValeur(this.listeRues[this.indexRueSelectionnee]);
386
	this.mettreRueEnValeur(this.listeRues[this.indexRueSelectionnee]);
362
}
387
}
363
 
388
 
364
WidgetSaisieSauvages.prototype.afficherChargementRechercheRue = function() {
389
WidgetSaisieSauvages.prototype.afficherChargementRechercheRue = function() {
365
	if(!!this.ligneRue) {
390
	if(!!this.ligneRue) {
366
		this.ligneRue.setMap(null);
391
		this.ligneRue.setMap(null);
367
	}
392
	}
368
	var img = '<img src="'+this.chargementImageIconeUrl+'" />';
393
	var img = '<img src="'+this.chargementImageIconeUrl+'" />';
369
	$('#indication-nom-rue-nom').html(img+" Recherche de la rue en cours");
394
	$('#indication-nom-rue-nom').html(img+" Recherche de la rue en cours");
370
	$('#indication-nom-rue').css('visibility','visible');
395
	$('#indication-nom-rue').css('visibility','visible');
371
	$('#indication-nom-rue').effect("highlight", {}, 500);
396
	$('#indication-nom-rue').effect("highlight", {}, 500);
372
	$(".navigation-rue").toggle(false);
397
	$(".navigation-rue").toggle(false);
373
}
398
}
374
 
399
 
375
WidgetSaisieSauvages.prototype.rechercherRue = function() {
400
WidgetSaisieSauvages.prototype.rechercherRue = function() {
376
	this.afficherChargementRechercheRue();
401
	this.afficherChargementRechercheRue();
377
	
402
	
378
	var params = "latitude_debut="+this.markerDeb.getPosition().lat()+"&longitude_debut="+this.markerDeb.getPosition().lng()+
403
	var params = "latitude_debut="+this.markerDeb.getPosition().lat()+"&longitude_debut="+this.markerDeb.getPosition().lng()+
379
	"&latitude_fin="+this.markerFin.getPosition().lat()+"&longitude_fin="+this.markerFin.getPosition().lng();
404
	"&latitude_fin="+this.markerFin.getPosition().lat()+"&longitude_fin="+this.markerFin.getPosition().lng();
380
	var lthis = this;
405
	var lthis = this;
381
 
406
 
382
	this.requeteRechercheRue = $.getJSON(this.serviceTraceRueUrl+'?'+params, function(data) {
407
	this.requeteRechercheRue = $.getJSON(this.serviceTraceRueUrl+'?'+params, function(data) {
383
		$('#indication-nom-rue-nom').html("");	
408
		$('#indication-nom-rue-nom').html("");	
384
		lthis.listeRues = data.elements;
409
		lthis.listeRues = data.elements;
385
		var coordDeb = {"lat" : lthis.markerDeb.getPosition().lat(), "lon" : lthis.markerDeb.getPosition().lng()};
410
		var coordDeb = {"lat" : lthis.markerDeb.getPosition().lat(), "lon" : lthis.markerDeb.getPosition().lng()};
386
		var coordFin = {"lat" : lthis.markerFin.getPosition().lat(), "lon" : lthis.markerFin.getPosition().lng()};
411
		var coordFin = {"lat" : lthis.markerFin.getPosition().lat(), "lon" : lthis.markerFin.getPosition().lng()};
387
		var tags = {"name" : lthis.aucuneRueSelectionnee};
412
		var tags = {"name" : lthis.aucuneRueSelectionnee};
388
		var pasDeRue = {"geometry" : [coordDeb, coordFin], "tags" : tags};
413
		var pasDeRue = {"geometry" : [coordDeb, coordFin], "tags" : tags};
389
		lthis.listeRues.push(pasDeRue);
414
		lthis.listeRues.push(pasDeRue);
390
		lthis.indexRueSelectionnee = 0;
415
		lthis.indexRueSelectionnee = 0;
391
		lthis.mettreRueEnValeur(lthis.listeRues[0]);	
416
		lthis.mettreRueEnValeur(lthis.listeRues[0]);	
392
	});
417
	});
393
}
418
}
394
 
419
 
395
WidgetSaisieSauvages.prototype.annulerRechercherRue = function() {
420
WidgetSaisieSauvages.prototype.annulerRechercherRue = function() {
396
	if(this.requeteRechercheRue != null) {
421
	if(this.requeteRechercheRue != null) {
397
		this.requeteRechercheRue.abort();
422
		this.requeteRechercheRue.abort();
398
		this.requeteRechercheRue = null;
423
		this.requeteRechercheRue = null;
399
		$('#indication-nom-rue').css('visibility','hidden');
424
		$('#indication-nom-rue').css('visibility','hidden');
400
	}
425
	}
401
}
426
}
402
 
427
 
403
 
428
 
404
WidgetSaisieSauvages.prototype.mettreRueEnValeur = function(rue) {
429
WidgetSaisieSauvages.prototype.mettreRueEnValeur = function(rue) {
405
	this.afficherIndicationRue(rue['tags']['name']);
430
	this.afficherIndicationRue(rue['tags']['name']);
406
	this.afficherTraceRue(rue['geometry']);
431
	this.afficherTraceRue(rue['geometry']);
407
	this.afficherEtapeGeolocalisation(4);
432
	this.afficherEtapeGeolocalisation(4);
408
}
433
}
409
 
434
 
410
WidgetSaisieSauvages.prototype.afficherIndicationRue = function(indication) {
435
WidgetSaisieSauvages.prototype.afficherIndicationRue = function(indication) {
411
	indication = !!indication ? indication : this.nomDeRueInconnue;
436
	indication = !!indication ? indication : this.nomDeRueInconnue;
412
	$('#indication-nom-rue-nom').html(indication);
437
	$('#indication-nom-rue-nom').html(indication);
413
	$('#indication-nom-rue').css('visibility','visible');
438
	$('#indication-nom-rue').css('visibility','visible');
414
	$('#indication-nom-rue').effect("highlight", {}, 500);
439
	$('#indication-nom-rue').effect("highlight", {}, 500);
415
	$(".navigation-rue").toggle(this.listeRues.length > 1);
440
	$(".navigation-rue").toggle(this.listeRues.length > 1);
416
}
441
}
417
 
442
 
418
WidgetSaisieSauvages.prototype.afficherTraceRue = function(rue) {
443
WidgetSaisieSauvages.prototype.afficherTraceRue = function(rue) {
419
 
444
 
420
	if (this.ligneRue != undefined) {
445
	if (this.ligneRue != undefined) {
421
		this.ligneRue.setMap(null);
446
		this.ligneRue.setMap(null);
422
	}
447
	}
423
 
448
 
424
	var cheminRue = new Array();
449
	var cheminRue = new Array();
425
	if(rue.length > 0) {
450
	if(rue.length > 0) {
426
		$.each(rue, function(index, value) {
451
		$.each(rue, function(index, value) {
427
			cheminRue.push(new google.maps.LatLng(value['lat'], value['lon']));
452
			cheminRue.push(new google.maps.LatLng(value['lat'], value['lon']));
428
		});
453
		});
429
		
454
		
430
		this.ligneRue = new google.maps.Polyline({
455
		this.ligneRue = new google.maps.Polyline({
431
			path: cheminRue,
456
			path: cheminRue,
432
			strokeColor: "#FF0000",
457
			strokeColor: "#FF0000",
433
			strokeOpacity: 1.0,
458
			strokeOpacity: 1.0,
434
			strokeWeight: 2
459
			strokeWeight: 2
435
		});
460
		});
436
	
461
	
437
		this.ligneRue.setMap(this.map);
462
		this.ligneRue.setMap(this.map);
438
	}
463
	}
439
};
464
};
440
 
465
 
441
WidgetSaisieSauvages.prototype.dessinerLigneRue = function(pointDebut, pointFin) {
466
WidgetSaisieSauvages.prototype.dessinerLigneRue = function(pointDebut, pointFin) {
442
	if (this.ligneRue != undefined) {
467
	if (this.ligneRue != undefined) {
443
		this.ligneRue.setMap(null);
468
		this.ligneRue.setMap(null);
444
	}
469
	}
445
 
470
 
446
	this.ligneRue = new google.maps.Polyline({
471
	this.ligneRue = new google.maps.Polyline({
447
		path: [pointDebut, pointFin],
472
		path: [pointDebut, pointFin],
448
		strokeColor: "#FF0000",
473
		strokeColor: "#FF0000",
449
		strokeOpacity: 1.0,
474
		strokeOpacity: 1.0,
450
		strokeWeight: 2
475
		strokeWeight: 2
451
	});
476
	});
452
 
477
 
453
	this.ligneRue.setMap(this.map);
478
	this.ligneRue.setMap(this.map);
454
};
479
};
455
 
480
 
456
WidgetSaisieSauvages.prototype.afficherCentreRue = function() {
481
WidgetSaisieSauvages.prototype.afficherCentreRue = function() {
457
	this.latLngDeb = this.markerDeb.getPosition();
482
	this.latLngDeb = this.markerDeb.getPosition();
458
	this.latLngFin = this.markerFin.getPosition();
483
	this.latLngFin = this.markerFin.getPosition();
459
	this.latLngCentre = new google.maps.LatLng((this.latLngFin.lat() + this.latLngDeb.lat())/2, (this.latLngFin.lng() + this.latLngDeb.lng())/2);
484
	this.latLngCentre = new google.maps.LatLng((this.latLngFin.lat() + this.latLngDeb.lat())/2, (this.latLngFin.lng() + this.latLngDeb.lng())/2);
460
	this.mettreAJourMarkerPosition(this.latLngCentre);
485
	this.mettreAJourMarkerPosition(this.latLngCentre);
461
};
486
};
462
 
487
 
463
WidgetSaisieSauvages.prototype.afficherEtapeGeolocalisation = function(numEtape) {
488
WidgetSaisieSauvages.prototype.afficherEtapeGeolocalisation = function(numEtape) {
464
	$('.liste_indication_geolocalisation').children().hide();
489
	$('.liste_indication_geolocalisation').children().hide();
465
	$('.liste_indication_geolocalisation :nth-child('+numEtape+')').show();
490
	$('.liste_indication_geolocalisation :nth-child('+numEtape+')').show();
466
};
491
};
467
 
492
 
468
// surcharge
493
// surcharge
469
WidgetSaisieSauvages.prototype.geolocaliser = function(event) {
494
WidgetSaisieSauvages.prototype.geolocaliser = function(event) {
470
	var latitude = $('#latitude').val(),
495
	var latitude = $('#latitude').val(),
471
		longitude = $('#longitude').val(),
496
		longitude = $('#longitude').val(),
472
		nouvellePosition = new google.maps.LatLng(latitude, longitude);
497
		nouvellePosition = new google.maps.LatLng(latitude, longitude);
473
	this.initialiserMarkerDeb();
498
	this.initialiserMarkerDeb();
474
	this.deplacerMarkerDeb(nouvellePosition);
499
	this.deplacerMarkerDeb(nouvellePosition);
475
	this.afficherEtapeGeolocalisation(2);
500
	this.afficherEtapeGeolocalisation(2);
476
	this.map.setZoom(16);
501
	this.map.setZoom(16);
477
	arreter(event);
502
	arreter(event);
478
};
503
};
479
 
504
 
480
WidgetSaisieSauvages.prototype.tenterGeolocalisation = function() {
505
WidgetSaisieSauvages.prototype.tenterGeolocalisation = function() {
481
	var lthis = this;
506
	var lthis = this;
482
	if (navigator.geolocation) {
507
	if (navigator.geolocation) {
483
		navigator.geolocation.getCurrentPosition(function(position) {
508
		navigator.geolocation.getCurrentPosition(function(position) {
484
			var latitude = position.coords.latitude,
509
			var latitude = position.coords.latitude,
485
				longitude = position.coords.longitude,
510
				longitude = position.coords.longitude,
486
				nouvellePosition = new google.maps.LatLng(latitude, longitude);
511
				nouvellePosition = new google.maps.LatLng(latitude, longitude);
487
			lthis.initialiserMarkerDeb();
512
			lthis.initialiserMarkerDeb();
488
			lthis.deplacerMarkerDeb(nouvellePosition);
513
			lthis.deplacerMarkerDeb(nouvellePosition);
489
			lthis.map.setZoom(16);
514
			lthis.map.setZoom(16);
490
		});
515
		});
491
	} else {
516
	} else {
492
		lthis.initialiserMarkerDeb();
517
		lthis.initialiserMarkerDeb();
493
	}
518
	}
494
};
519
};
495
 
520
 
496
/**
521
/**
497
 * AUTO-COMPLÉTION Noms Scientifiques => OK
522
 * AUTO-COMPLÉTION Noms Scientifiques => OK
498
 * sélectionne un nom et puis qu'on le remplacer par un nom non valide
523
 * sélectionne un nom et puis qu'on le remplacer par un nom non valide
499
 * Garder la trace de la valeur permet de vider le nn lorsqu'on
524
 * Garder la trace de la valeur permet de vider le nn lorsqu'on
500
 */
525
 */
501
WidgetSaisieSauvages.prototype.ajouterAutocompletionNoms = function() {
526
WidgetSaisieSauvages.prototype.ajouterAutocompletionNoms = function() {
502
	var lthis = this;
527
	var lthis = this;
503
	$('#taxon').autocomplete({
528
	$('#taxon').autocomplete({
504
		source: function(requete, add){
529
		source: function(requete, add){
505
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
530
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
506
 
531
 
507
			var url = lthis.getUrlAutocompletionNomsSci();
532
			var url = lthis.getUrlAutocompletionNomsSci();
508
			$.getJSON(url, function(data) {
533
			$.getJSON(url, function(data) {
509
				var suggestions = lthis.traiterRetourNomsSci(data);
534
				var suggestions = lthis.traiterRetourNomsSci(data);
510
				add(suggestions);
535
				add(suggestions);
511
			});
536
			});
512
		},
537
		},
513
		html: true
538
		html: true
514
	});
539
	});
515
 
540
 
516
	$('#taxon').bind('autocompleteselect', function(event, ui) {
541
	$('#taxon').bind('autocompleteselect', function(event, ui) {
517
		$('#taxon').data(ui.item);
542
		$('#taxon').data(ui.item);
518
		lthis.valeurChamp = $('#taxon').val();
543
		lthis.valeurChamp = $('#taxon').val();
519
		if (ui.item.retenu == true) {
544
		if (ui.item.retenu == true) {
520
			$('#taxon').addClass('ns-retenu');
545
			$('#taxon').addClass('ns-retenu');
521
		} else {
546
		} else {
522
			$('#taxon').removeClass('ns-retenu');
547
			$('#taxon').removeClass('ns-retenu');
523
		}
548
		}
524
	});
549
	});
525
	
550
	
526
	$('#taxon').bind('keypress', function() {
551
	$('#taxon').bind('keypress', function() {
527
		if(lthis.valeurChamp != $('#taxon').val()) {
552
		if(lthis.valeurChamp != $('#taxon').val()) {
528
			$('#taxon').data('numNomSel', '');
553
			$('#taxon').data('numNomSel', '');
529
		}
554
		}
530
		lthis.valeurChamp = $('#taxon').val();
555
		lthis.valeurChamp = $('#taxon').val();
531
	});
556
	});
532
};
557
};
533
 
558
 
534
WidgetSaisieSauvages.prototype.getUrlAutocompletionNomsSci = function() {
559
WidgetSaisieSauvages.prototype.getUrlAutocompletionNomsSci = function() {
535
	var mots = $('#taxon').val(),
560
	var mots = $('#taxon').val(),
536
		url = this.serviceAutocompletionNomSciUrlTpl.replace('{referentiel}', this.nomSciReferentiel);
561
		url = this.serviceAutocompletionNomSciUrlTpl.replace('{referentiel}', this.nomSciReferentiel);
537
	url = url.replace('{masque}', mots);
562
	url = url.replace('{masque}', mots);
538
	return url;
563
	return url;
539
};
564
};
540
 
565
 
541
WidgetSaisieSauvages.prototype.traiterRetourNomsSci = function(data) {
566
WidgetSaisieSauvages.prototype.traiterRetourNomsSci = function(data) {
542
	var suggestions = [];
567
	var suggestions = [];
543
	if (data.resultat != undefined) {
568
	if (data.resultat != undefined) {
544
		$.each(data.resultat, function(i, val) {
569
		$.each(data.resultat, function(i, val) {
545
			val.nn = i;
570
			val.nn = i;
546
			var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
571
			var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
547
				nomRet: '', numNomRet: '', famille: '', retenu: false
572
				nomRet: '', numNomRet: '', famille: '', retenu: false
548
			};
573
			};
549
			if (suggestions.length >= this.autocompletionElementsNbre) {
574
			if (suggestions.length >= this.autocompletionElementsNbre) {
550
				nom.label = '...';
575
				nom.label = '...';
551
				nom.value = $('#taxon').val();
576
				nom.value = $('#taxon').val();
552
				suggestions.push(nom);
577
				suggestions.push(nom);
553
				return false;
578
				return false;
554
			} else {
579
			} else {
555
				nom.label = val.nom_sci_complet;
580
				nom.label = val.nom_sci_complet;
556
				nom.value = val.nom_sci_complet;
581
				nom.value = val.nom_sci_complet;
557
				nom.nt = val.num_taxonomique;
582
				nom.nt = val.num_taxonomique;
558
				nom.nomSel = val.nom_sci;
583
				nom.nomSel = val.nom_sci;
559
				nom.nomSelComplet = val.nom_sci_complet;
584
				nom.nomSelComplet = val.nom_sci_complet;
560
				nom.numNomSel = val.nn;
585
				nom.numNomSel = val.nn;
561
				nom.nomRet = val.nom_retenu_complet;
586
				nom.nomRet = val.nom_retenu_complet;
562
				nom.numNomRet = val['nom_retenu.id'];
587
				nom.numNomRet = val['nom_retenu.id'];
563
				nom.famille = val.famille;
588
				nom.famille = val.famille;
564
				nom.retenu = (val.retenu == 'false') ? false : true;
589
				nom.retenu = (val.retenu == 'false') ? false : true;
565
 
590
 
566
				suggestions.push(nom);
591
				suggestions.push(nom);
567
			}
592
			}
568
		});
593
		});
569
	}
594
	}
570
	return suggestions;
595
	return suggestions;
571
};
596
};
572
 
597
 
573
// surcharge
598
// surcharge
574
WidgetSaisieSauvages.prototype.configurerFormValidator = function() {
599
WidgetSaisieSauvages.prototype.configurerFormValidator = function() {
575
	$.validator.addMethod(
600
	$.validator.addMethod(
576
		'dateCel',
601
		'dateCel',
577
		function (value, element) {
602
		function (value, element) {
578
			return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
603
			return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
579
		},
604
		},
580
		'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
605
		'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
581
 
606
 
582
	$.extend($.validator.defaults, {
607
	$.extend($.validator.defaults, {
583
		ignore: [],// Forcer Jquery Validate à examiner les éléments avec en display:none;
608
		ignore: [],// Forcer Jquery Validate à examiner les éléments avec en display:none;
584
		highlight: function(element) {
609
		highlight: function(element) {
585
			$(element).closest('.control-group').removeClass('success').addClass('error');
610
			$(element).closest('.control-group').removeClass('success').addClass('error');
586
		},
611
		},
587
		success: function(element) {
612
		success: function(element) {
588
			element.text('OK!').addClass('valid');
613
			element.text('OK!').addClass('valid');
589
			element.closest('.control-group').removeClass('error').addClass('success');
614
			element.closest('.control-group').removeClass('error').addClass('success');
590
 
615
 
591
			if (element.attr('id') == 'taxon' && $('#taxon').val() != '') {
616
			if (element.attr('id') == 'taxon' && $('#taxon').val() != '') {
592
				// Si le taxon n'est pas lié au référentiel, on vide le data associé
617
				// Si le taxon n'est pas lié au référentiel, on vide le data associé
593
				if ($('#taxon').data('value') != $('#taxon').val()) {
618
				if ($('#taxon').data('value') != $('#taxon').val()) {
594
					$('#taxon').data('numNomSel', '');
619
					$('#taxon').data('numNomSel', '');
595
					$('#taxon').data('nomRet', '');
620
					$('#taxon').data('nomRet', '');
596
					$('#taxon').data('numNomRet', '');
621
					$('#taxon').data('numNomRet', '');
597
					$('#taxon').data('nt', '');
622
					$('#taxon').data('nt', '');
598
					$('#taxon').data('famille', '');
623
					$('#taxon').data('famille', '');
599
				}
624
				}
600
			}
625
			}
601
		}
626
		}
602
	});
627
	});
603
};
628
};
604
 
629
 
605
// surcharge
630
// surcharge
606
WidgetSaisieSauvages.prototype.definirReglesFormValidator = function() {
631
WidgetSaisieSauvages.prototype.definirReglesFormValidator = function() {
607
	$('#form-observateur').validate({
632
	$('#form-observateur').validate({
608
		rules: {
633
		rules: {
609
			courriel: {
634
			courriel: {
610
				required: true,
635
				required: true,
611
				email: true},
636
				email: true},
612
			courriel_confirmation: {
637
			courriel_confirmation: {
613
				required: true,
638
				required: true,
614
				equalTo: '#courriel'},
639
				equalTo: '#courriel'},
615
			prenom: {
640
			prenom: {
616
				required: true},
641
				required: true},
617
			nom: {
642
			nom: {
618
				required: true}
643
				required: true}
619
		}
644
		}
620
	});
645
	});
621
	$('#form-obs').validate({
646
	$('#form-obs').validate({
622
		rules: {
647
		rules: {
623
			station: {
648
			station: {
624
				required: true},
649
				required: true},
625
			latitude : {
650
			latitude : {
626
				required: true,
651
				required: true,
627
				range: [-90, 90]},
652
				range: [-90, 90]},
628
			longitude: {
653
			longitude: {
629
				required: true,
654
				required: true,
630
				range: [-180, 180]},
655
				range: [-180, 180]},
631
			date: {
656
			date: {
632
				required: true,
657
				required: true,
633
				'dateCel' : true},
658
				'dateCel' : true},
634
			coteRue: {
659
			coteRue: {
635
				required: true},
660
				required: true},
636
			'taxon-liste': {
661
			'taxon-liste': {
637
				required: true},
662
				required: true},
638
			'milieux[]': {
663
			'milieux[]': {
639
				required: true,
664
				required: true,
640
				minlength: 1}
665
				minlength: 1}
641
		},
666
		},
642
		errorPlacement: function(error, element) {
667
		errorPlacement: function(error, element) {
643
			if (element.attr('name') == 'date') {
668
			if (element.attr('name') == 'date') {
644
				element.parent('.input-prepend').after(error);
669
				element.parent('.input-prepend').after(error);
645
			} else if (element.attr('name') == 'milieux[]') {
670
			} else if (element.attr('name') == 'milieux[]') {
646
				error.insertAfter('#milieux-controls');
671
				error.insertAfter('#milieux-controls');
647
			} else {
672
			} else {
648
				error.insertAfter(element);
673
				error.insertAfter(element);
649
			}
674
			}
650
		},
675
		},
651
		messages: {
676
		messages: {
652
			'milieu[]': 'Vous devez sélectionner au moins un milieu'
677
			'milieu[]': 'Vous devez sélectionner au moins un milieu'
653
		}
678
		}
654
	});
679
	});
655
};
680
};
656
 
681
 
657
WidgetSaisieSauvages.prototype.validerFormulaire = function() {
682
WidgetSaisieSauvages.prototype.validerFormulaire = function() {
658
	var observateur = $('#form-observateur').valid(),
683
	var observateur = $('#form-observateur').valid(),
659
		obs = $('#form-obs').valid(),
684
		obs = $('#form-obs').valid(),
660
		debRue = (this.latLngDeb == undefined || this.latLngDeb == this.latLngFin) ? false : true,
685
		debRue = (this.latLngDeb == undefined || this.latLngDeb == this.latLngFin) ? false : true,
661
		finRue = (this.latLngFin == undefined || this.latLngDeb == this.latLngFin) ? false : true;
686
		finRue = (this.latLngFin == undefined || this.latLngDeb == this.latLngFin) ? false : true;
662
	var ok = (observateur && obs && debRue && finRue) ? true : false;
687
	var ok = (observateur && obs && debRue && finRue) ? true : false;
663
	//console.log('observateur:'+observateur+'-obs:'+obs+'-debRue:'+debRue+'('+latLngDeb+')-finRue:'+finRue+'('+latLngDeb+')');
688
	//console.log('observateur:'+observateur+'-obs:'+obs+'-debRue:'+debRue+'('+latLngDeb+')-finRue:'+finRue+'('+latLngDeb+')');
664
	return ok;
689
	return ok;
665
};
690
};
666
 
691
 
667
WidgetSaisieSauvages.prototype.surChangementTaxonListe = function() {
692
WidgetSaisieSauvages.prototype.surChangementTaxonListe = function() {
668
	if ($('#taxon-liste').val() === '?') {
693
	if ($('#taxon-liste').val() === '?') {
669
		$('#taxon-input-groupe').removeClass('hidden');
694
		$('#taxon-input-groupe').removeClass('hidden');
670
	} else {
695
	} else {
671
		$('#taxon-input-groupe').addClass('hidden');
696
		$('#taxon-input-groupe').addClass('hidden');
672
	}
697
	}
673
};
698
};
674
 
699
 
675
WidgetSaisieSauvages.prototype.surChangementValeurTaxon = function() {
700
WidgetSaisieSauvages.prototype.surChangementValeurTaxon = function() {
676
	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
701
	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
677
	var nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special');
702
	var nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special');
678
	var numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val();
703
	var numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val();
679
	
704
	
680
	// Un nom non valide entraine automatiquement une certitude "à déterminer"
705
	// Un nom non valide entraine automatiquement une certitude "à déterminer"
681
	if(nomSpecial || !numNomSel) {
706
	if(nomSpecial || !numNomSel) {
682
		$('#certitude-adeterminer').attr('checked', 'checked');
707
		$('#certitude-adeterminer').attr('checked', 'checked');
683
	} else {
708
	} else {
684
		$('#certitude-adeterminer').removeAttr('checked');
709
		$('#certitude-adeterminer').removeAttr('checked');
685
	}
710
	}
686
};
711
};
687
 
712
 
688
// surcharge
713
// surcharge
689
WidgetSaisieSauvages.prototype.ajouterObs = function() {
714
WidgetSaisieSauvages.prototype.ajouterObs = function() {
690
	if (this.validerFormulaire() == true) {
715
	if (this.validerFormulaire() == true) {
691
		this.obsNbre = this.obsNbre + 1;
716
		this.obsNbre = this.obsNbre + 1;
692
		$('.obs-nbre').text(this.obsNbre);
717
		$('.obs-nbre').text(this.obsNbre);
693
		$('.obs-nbre').triggerHandler('changement');
718
		$('.obs-nbre').triggerHandler('changement');
694
		this.afficherObs();
719
		this.afficherObs();
695
		this.stockerObsData();
720
		this.stockerObsData();
696
		this.supprimerMiniatures();
721
		this.supprimerMiniatures();
697
	} else {
722
	} else {
698
		// Affichage de tous les panneau cachés avec champ obligatoire
723
		// Affichage de tous les panneau cachés avec champ obligatoire
699
		var debRue = (this.latLngDeb == undefined || this.latLngDeb == this.latLngFin) ? false : true,
724
		var debRue = (this.latLngDeb == undefined || this.latLngDeb == this.latLngFin) ? false : true,
700
			finRue = (this.latLngFin == undefined || this.latLngDeb == this.latLngFin) ? false : true;
725
			finRue = (this.latLngFin == undefined || this.latLngDeb == this.latLngFin) ? false : true;
701
		if (debRue == false || finRue == false) {
726
		if (debRue == false || finRue == false) {
702
			this.afficherPanneau('#dialogue-form-invalide-rue');
727
			this.afficherPanneau('#dialogue-form-invalide-rue');
703
		} else {
728
		} else {
704
			this.afficherPanneau('#dialogue-form-invalide');
729
			this.afficherPanneau('#dialogue-form-invalide');
705
		}
730
		}
706
		this.montrerFormIdentite();
731
		this.montrerFormIdentite();
707
	}
732
	}
708
};
733
};
709
 
734
 
710
// surcharge
735
// surcharge
711
WidgetSaisieSauvages.prototype.afficherObs = function() {
736
WidgetSaisieSauvages.prototype.afficherObs = function() {
712
	var numNomSel = ($('#taxon-liste').val() == '?') ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
737
	var numNomSel = ($('#taxon-liste').val() == '?') ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
713
		nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
738
		nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
714
		taxon = ($('#taxon-liste').val() == '?') ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
739
		taxon = ($('#taxon-liste').val() == '?') ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
715
		referentiel = (numNomSel == undefined) ? '' : '['+ this.nomSciReferentiel +']',
740
		referentiel = (numNomSel == undefined) ? '' : '['+ this.nomSciReferentiel +']',
716
		commune = $('#commune-nom').text(),
741
		commune = $('#commune-nom').text(),
717
		codeInsee = $('#commune-code-insee').text(),
742
		codeInsee = $('#commune-code-insee').text(),
718
		station = this.getValeurStation(),
743
		station = this.getValeurStation(),
719
		lat = $('input[name="latitude"]').val(),
744
		lat = $('input[name="latitude"]').val(),
720
		lng = $('input[name="longitude"]').val(),
745
		lng = $('input[name="longitude"]').val(),
721
		date = $('#date').val(),
746
		date = $('#date').val(),
722
		milieux = this.getMilieux(),
747
		milieux = this.getMilieux(),
723
		notes = (nomSpecial ? this.taxons[numNomSel]['nom_fr'] + ".<br />" : '') + $('#notes').val();
748
		notes = (nomSpecial ? this.taxons[numNomSel]['nom_fr'] + ".<br />" : '') + $('#notes').val();
724
 
749
 
725
	$('#liste-obs').prepend(
750
	$('#liste-obs').prepend(
726
		'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">' +
751
		'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">' +
727
			'<div class="span12">' +
752
			'<div class="span12">' +
728
				'<div class="well">' +
753
				'<div class="well">' +
729
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" ' +
754
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" ' +
730
						'title="Supprimer cette observation de la liste à transmettre">' +
755
						'title="Supprimer cette observation de la liste à transmettre">' +
731
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">' +
756
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">' +
732
							'<i class="icon-trash icon-white"></i>' +
757
							'<i class="icon-trash icon-white"></i>' +
733
						'</button>' +
758
						'</button>' +
734
					'</div> ' +
759
					'</div> ' +
735
					'<div class="row-fluid">' +
760
					'<div class="row-fluid">' +
736
						'<div class="span2 obs-miniatures">' +
761
						'<div class="span2 obs-miniatures">' +
737
						this.ajouterImgMiniatureAuTransfert() +
762
						this.ajouterImgMiniatureAuTransfert() +
738
						'</div>'+
763
						'</div>'+
739
						'<div class="span7">' +
764
						'<div class="span7">' +
740
							'<ul class="unstyled">' +
765
							'<ul class="unstyled">' +
741
								'<li>'+
766
								'<li>'+
742
									'<span class="nom-sci">' + taxon + '</span> ' +
767
									'<span class="nom-sci">' + taxon + '</span> ' +
743
									this.formaterNumNomSel(numNomSel) +
768
									this.formaterNumNomSel(numNomSel) +
744
									' observé à <br />' +
769
									' observé à <br />' +
745
									'<span class="commune">' + commune + '</span> ' +
770
									'<span class="commune">' + commune + '</span> ' +
746
									'(' + codeInsee + '), ' +
771
									'(' + codeInsee + '), ' +
747
									'<span class="station">' + station + '</span><br /> ' +
772
									'<span class="station">' + station + '</span><br /> ' +
748
									' le ' +
773
									' le ' +
749
									'<span class="date">' + date + '</span>' +
774
									'<span class="date">' + date + '</span>' +
750
								'</li>' +
775
								'</li>' +
751
								'<li>' +
776
								'<li>' +
752
									'Milieux : ' + milieux + ' ' + ' ; ' +
777
									'Milieux : ' + milieux + ' ' + ' ; ' +
753
								'</li>' +
778
								'</li>' +
754
								'<li>' +
779
								'<li>' +
755
									'Notes : ' + notes +
780
									'Notes : ' + notes +
756
								'</li>' +
781
								'</li>' +
757
							'</ul>' +
782
							'</ul>' +
758
						'</div>' +
783
						'</div>' +
759
					'</div>' +
784
					'</div>' +
760
				'</div>' +
785
				'</div>' +
761
			'</div>'+
786
			'</div>'+
762
		'</div>');
787
		'</div>');
763
	$('#zone-liste-obs').removeClass("hidden");
788
	$('#zone-liste-obs').removeClass("hidden");
764
};
789
};
765
 
790
 
766
WidgetSaisieSauvages.prototype.getValeurStation = function() { 
791
WidgetSaisieSauvages.prototype.getValeurStation = function() { 
767
	var station = "";
792
	var station = "";
768
	var valeurSelectionnee = $("#indication-nom-rue-nom").text().trim();
793
	var valeurSelectionnee = $("#indication-nom-rue-nom").text().trim();
769
	if(valeurSelectionnee == this.aucuneRueSelectionnee || valeurSelectionnee == this.nomDeRueInconnue) {
794
	if(valeurSelectionnee == this.aucuneRueSelectionnee || valeurSelectionnee == this.nomDeRueInconnue) {
770
		station = $('input[name="adresse"]').val().trim()
795
		station = $('input[name="adresse"]').val().trim()
771
	} else {
796
	} else {
772
		station = $("#indication-nom-rue-nom").text().trim();
797
		station = $("#indication-nom-rue-nom").text().trim();
773
	}
798
	}
774
	
799
	
775
	return station;
800
	return station;
776
}
801
}
777
 
802
 
778
WidgetSaisieSauvages.prototype.getMilieux = function() {
803
WidgetSaisieSauvages.prototype.getMilieux = function() {
779
	var milieuxStr = '',
804
	var milieuxStr = '',
780
		milieux = [];
805
		milieux = [];
781
	$('.cb-milieux:checked').each(function() {
806
	$('.cb-milieux:checked').each(function() {
782
		milieux.push($(this).val());
807
		milieux.push($(this).val());
783
	});
808
	});
784
 
809
 
785
	milieuxStr = Array.prototype.slice.call(milieux).join(', ');
810
	milieuxStr = Array.prototype.slice.call(milieux).join(', ');
786
	return milieuxStr;
811
	return milieuxStr;
787
};
812
};
788
 
813
 
789
WidgetSaisieSauvages.prototype.ajouterImgMiniatureAuTransfert = function() {
814
WidgetSaisieSauvages.prototype.ajouterImgMiniatureAuTransfert = function() {
790
	var html = '',
815
	var html = '',
791
		miniatures = '',
816
		miniatures = '',
792
		indicateurs = '',
817
		indicateurs = '',
793
		premiere = true,
818
		premiere = true,
794
		numero = 1;
819
		numero = 1;
795
	if ($('#miniatures img').length == 0) {
820
	if ($('#miniatures img').length == 0) {
796
		html = '<img class="miniature" alt="Aucune photo"src="'+ this.pasDePhotoIconeUrl +'" />';
821
		html = '<img class="miniature" alt="Aucune photo"src="'+ this.pasDePhotoIconeUrl +'" />';
797
	} else if ($('#miniatures img').length >= 1) {
822
	} else if ($('#miniatures img').length >= 1) {
798
		$('#miniatures img').each(function() {
823
		$('#miniatures img').each(function() {
799
			var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee',
824
			var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee',
800
				css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
825
				css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
801
				src = $(this).attr('src'),
826
				src = $(this).attr('src'),
802
				alt = $(this).attr('alt');
827
				alt = $(this).attr('alt');
803
 
828
 
804
			var miniature = '<img class="'+css+' '+visible+'"  alt="'+alt+'"src="'+src+'" />';
829
			var miniature = '<img class="'+css+' '+visible+'"  alt="'+alt+'"src="'+src+'" />';
805
			miniatures += miniature;
830
			miniatures += miniature;
806
 
831
 
807
			var indicateurActif = premiere ? 'active' : '';
832
			var indicateurActif = premiere ? 'active' : '';
808
			var indicateur = '<li class="' + indicateurActif + '" data-numero="' + numero++ + '"></li>';
833
			var indicateur = '<li class="' + indicateurActif + '" data-numero="' + numero++ + '"></li>';
809
			indicateurs += indicateur;
834
			indicateurs += indicateur;
810
 
835
 
811
			premiere = false;
836
			premiere = false;
812
		});
837
		});
813
 
838
 
814
		if ($('#miniatures img').length == 1) {
839
		if ($('#miniatures img').length == 1) {
815
			html = miniatures;
840
			html = miniatures;
816
		} else {
841
		} else {
817
			html =
842
			html =
818
				'<div class="defilement">' +
843
				'<div class="defilement">' +
819
					miniatures +
844
					miniatures +
820
					'<a class="defilement-control-zone gauche">' +
845
					'<a class="defilement-control-zone gauche">' +
821
					'	<span class="defilement-control gauche hidden">&#60;</span>' +
846
					'	<span class="defilement-control gauche hidden">&#60;</span>' +
822
					'</a>' +
847
					'</a>' +
823
					'<a class="defilement-control-zone droite">' +
848
					'<a class="defilement-control-zone droite">' +
824
					'	<span class="defilement-control droite hidden">&#62;</span>' +
849
					'	<span class="defilement-control droite hidden">&#62;</span>' +
825
					'</a>' +
850
					'</a>' +
826
					'<ol class="defilement-indicateurs">' + indicateurs + '</ol>' +
851
					'<ol class="defilement-indicateurs">' + indicateurs + '</ol>' +
827
				'</div>';
852
				'</div>';
828
		}
853
		}
829
	}
854
	}
830
	return html;
855
	return html;
831
};
856
};
832
 
857
 
833
WidgetSaisieSauvages.prototype.defilerMiniatures = function(element) {
858
WidgetSaisieSauvages.prototype.defilerMiniatures = function(element) {
834
	var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
859
	var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
835
	miniatureSelectionne.removeClass('miniature-selectionnee').addClass('miniature-cachee');
860
	miniatureSelectionne.removeClass('miniature-selectionnee').addClass('miniature-cachee');
836
	var miniatureAffichee = miniatureSelectionne;
861
	var miniatureAffichee = miniatureSelectionne;
837
 
862
 
838
	var indicateurActif = element.parent().find('.defilement-indicateurs .active');
863
	var indicateurActif = element.parent().find('.defilement-indicateurs .active');
839
	indicateurActif.removeClass('active');
864
	indicateurActif.removeClass('active');
840
 
865
 
841
	if (element.hasClass('defilement-control-zone') && element.hasClass('gauche')) {
866
	if (element.hasClass('defilement-control-zone') && element.hasClass('gauche')) {
842
		if (miniatureSelectionne.prev('.miniature').length != 0) {
867
		if (miniatureSelectionne.prev('.miniature').length != 0) {
843
			miniatureAffichee = miniatureSelectionne.prev('.miniature');
868
			miniatureAffichee = miniatureSelectionne.prev('.miniature');
844
			indicateurActif.prev().addClass('active');
869
			indicateurActif.prev().addClass('active');
845
		} else {
870
		} else {
846
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
871
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
847
			indicateurActif.siblings().last().addClass('active');
872
			indicateurActif.siblings().last().addClass('active');
848
		}
873
		}
849
	} else {
874
	} else {
850
		if (miniatureSelectionne.next('.miniature').length != 0) {
875
		if (miniatureSelectionne.next('.miniature').length != 0) {
851
			miniatureAffichee = miniatureSelectionne.next('.miniature');
876
			miniatureAffichee = miniatureSelectionne.next('.miniature');
852
			indicateurActif.next().addClass('active');
877
			indicateurActif.next().addClass('active');
853
		} else {
878
		} else {
854
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
879
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
855
			indicateurActif.siblings().first().addClass('active');
880
			indicateurActif.siblings().first().addClass('active');
856
		}
881
		}
857
	}
882
	}
858
	miniatureAffichee.addClass('miniature-selectionnee').removeClass('miniature-cachee');
883
	miniatureAffichee.addClass('miniature-selectionnee').removeClass('miniature-cachee');
859
};
884
};
860
 
885
 
861
WidgetSaisieSauvages.prototype.formaterNumNomSel = function(numNomSel) {
886
WidgetSaisieSauvages.prototype.formaterNumNomSel = function(numNomSel) {
862
	var nn = '';
887
	var nn = '';
863
	if (numNomSel == undefined) {
888
	if (numNomSel == undefined) {
864
		nn = '<span class="alert-error">[non lié au référentiel]</span>';
889
		nn = '<span class="alert-error">[non lié au référentiel]</span>';
865
	} else {
890
	} else {
866
		nn = '<span class="nn">[nn'+numNomSel+']</span>';
891
		nn = '<span class="nn">[nn'+numNomSel+']</span>';
867
	}
892
	}
868
	return nn;
893
	return nn;
869
};
894
};
870
 
895
 
871
// surcharge
896
// surcharge
872
WidgetSaisieSauvages.prototype.surChangementReferentiel = function() {
897
WidgetSaisieSauvages.prototype.surChangementReferentiel = function() {
873
	this.nomSciReferentiel = $('#referentiel').val();
898
	this.nomSciReferentiel = $('#referentiel').val();
874
	$('#taxon').val('');
899
	$('#taxon').val('');
875
};
900
};
876
 
901
 
877
// surcharge
902
// surcharge
878
WidgetSaisieSauvages.prototype.stockerObsData = function() {
903
WidgetSaisieSauvages.prototype.stockerObsData = function() {
879
	var lthis = this;
904
	var lthis = this;
880
	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
905
	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
881
		nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
906
		nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
882
		numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val();
907
		numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val();
883
	var nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
908
	var nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
884
		nomRet = nomHorsListe ? $('#taxon').data('nomRet') : this.taxons[numNomSel]['nom_ret'],
909
		nomRet = nomHorsListe ? $('#taxon').data('nomRet') : this.taxons[numNomSel]['nom_ret'],
885
		numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : this.taxons[numNomSel]['num_nom_ret'],
910
		numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : this.taxons[numNomSel]['num_nom_ret'],
886
		numTaxon = nomHorsListe ? $('#taxon').data('nt') : this.taxons[numNomSel]['num_taxon'],
911
		numTaxon = nomHorsListe ? $('#taxon').data('nt') : this.taxons[numNomSel]['num_taxon'],
887
		famille = nomHorsListe ? $('#taxon').data('famille') : this.taxons[numNomSel]['famille'],
912
		famille = nomHorsListe ? $('#taxon').data('famille') : this.taxons[numNomSel]['famille'],
888
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel,
913
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel,
889
		notes = (nomSpecial ? this.taxons[numNomSel]['nom_fr'] + '. ' : '') + $('#notes').val();
914
		notes = (nomSpecial ? this.taxons[numNomSel]['nom_fr'] + '. ' : '') + $('#notes').val();
890
		
915
		
891
		certitude = $('input[name=certitude]:checked').val();
916
		certitude = $('input[name=certitude]:checked').val();
892
		certitude = (certitude == undefined) ? '' : certitude;
917
		certitude = (certitude == undefined) ? '' : certitude;
893
 
918
 
894
	$('#liste-obs').data('obsId'+this.obsNbre, {
919
	$('#liste-obs').data('obsId'+this.obsNbre, {
895
		'date': $('#date').val(),
920
		'date': $('#date').val(),
896
		'notes': notes,
921
		'notes': notes,
897
 
922
 
898
		'station': this.getValeurStation(),
923
		'station': this.getValeurStation(),
899
		'latitude': $('#latitude').val(),
924
		'latitude': $('#latitude').val(),
900
		'longitude': $('#longitude').val(),
925
		'longitude': $('#longitude').val(),
901
		'commune_nom': $('#commune-nom').text(),
926
		'commune_nom': $('#commune-nom').text(),
902
		'commune_code_insee': $('#commune-code-insee').text(),
927
		'commune_code_insee': $('#commune-code-insee').text(),
903
 
928
 
904
		'nom_sel': nomSel,
929
		'nom_sel': nomSel,
905
		'num_nom_sel': numNomSel,
930
		'num_nom_sel': numNomSel,
906
		'nom_ret': nomRet,
931
		'nom_ret': nomRet,
907
		'num_nom_ret': numNomRet,
932
		'num_nom_ret': numNomRet,
908
		'num_taxon': numTaxon,
933
		'num_taxon': numTaxon,
909
		'famille': famille,
934
		'famille': famille,
910
		'referentiel': referentiel,
935
		'referentiel': referentiel,
911
		'certitude': certitude,
936
		'certitude': certitude,
912
		'milieu': lthis.getMilieux(),
937
		'milieu': lthis.getMilieux(),
913
 
938
 
914
		// Ajout des champs images
939
		// Ajout des champs images
915
		'image_nom': lthis.getNomsImgsOriginales(),
940
		'image_nom': lthis.getNomsImgsOriginales(),
916
 
941
 
917
		// Ajout des champs étendus de l'obs
942
		// Ajout des champs étendus de l'obs
918
		'obs_etendue': lthis.getObsChpEtendus()
943
		'obs_etendue': lthis.getObsChpEtendus()
919
	});
944
	});
920
	if (this.debug) {
945
	if (this.debug) {
921
		console.log($('#liste-obs').data('obsId'+this.obsNbre));
946
		console.log($('#liste-obs').data('obsId'+this.obsNbre));
922
	}
947
	}
923
};
948
};
924
 
949
 
925
WidgetSaisieSauvages.prototype.getObsChpEtendus = function() {
950
WidgetSaisieSauvages.prototype.getObsChpEtendus = function() {
926
	var champs = [];
951
	var champs = [];
927
	if (this.latLngDeb != undefined) {
952
	if (this.latLngDeb != undefined) {
928
		var latitudeDebutRue = {cle: 'latitudeDebutRue', label: 'Latitude du début de la rue', valeur: this.latLngDeb.lat().toFixed(5)};
953
		var latitudeDebutRue = {cle: 'latitudeDebutRue', label: 'Latitude du début de la rue', valeur: this.latLngDeb.lat().toFixed(5)};
929
		champs.push(latitudeDebutRue);
954
		champs.push(latitudeDebutRue);
930
		var longitudeDebutRue = {cle: 'longitudeDebutRue', label: 'Longitude du début de la rue', valeur: this.latLngDeb.lng().toFixed(5)};
955
		var longitudeDebutRue = {cle: 'longitudeDebutRue', label: 'Longitude du début de la rue', valeur: this.latLngDeb.lng().toFixed(5)};
931
		champs.push(longitudeDebutRue);
956
		champs.push(longitudeDebutRue);
932
	}
957
	}
933
	if (this.latLngFin != undefined) {
958
	if (this.latLngFin != undefined) {
934
		var latitudeFinRue = {cle: 'latitudeFinRue', label: 'Latitude de fin de la rue', valeur: this.latLngFin.lat().toFixed(5)};
959
		var latitudeFinRue = {cle: 'latitudeFinRue', label: 'Latitude de fin de la rue', valeur: this.latLngFin.lat().toFixed(5)};
935
		champs.push(latitudeFinRue);
960
		champs.push(latitudeFinRue);
936
		var longitudeFinRue = {cle: 'longitudeFinRue', label: 'Longitude de fin de la rue', valeur: this.latLngFin.lng().toFixed(5)};
961
		var longitudeFinRue = {cle: 'longitudeFinRue', label: 'Longitude de fin de la rue', valeur: this.latLngFin.lng().toFixed(5)};
937
		champs.push(longitudeFinRue);
962
		champs.push(longitudeFinRue);
938
	}
963
	}
939
 
964
 
940
	$('.obs-chp-etendu').each(function() {
965
	$('.obs-chp-etendu').each(function() {
941
		var valeur = $(this).val(),
966
		var valeur = $(this).val(),
942
			cle = $(this).attr('name'),
967
			cle = $(this).attr('name'),
943
			label = $(this).data('label');
968
			label = $(this).data('label');
944
		if (valeur != '') {
969
		if (valeur != '') {
945
			var chpEtendu = {cle: cle, label: label, valeur: valeur};
970
			var chpEtendu = {cle: cle, label: label, valeur: valeur};
946
			champs.push(chpEtendu);
971
			champs.push(chpEtendu);
947
		}
972
		}
948
	});
973
	});
949
	return champs;
974
	return champs;
950
};
975
};