Subversion Repositories eFlore/Applications.cel

Rev

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

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