Subversion Repositories eFlore/Applications.cel

Rev

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

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