Subversion Repositories eFlore/Applications.cel

Rev

Rev 2907 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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