Subversion Repositories eFlore/Applications.cel

Rev

Rev 2440 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2440 Rev 2710
Line 1... Line -...
1
//+---------------------------------------------------------------------------------------------------------+
-
 
2
// GÉNÉRAL
1
// Héritage
3
$(document).ready(function() {
-
 
4
	if (DEBUG == false) {
-
 
5
		$(window).on('beforeunload', function(event) {
-
 
6
			return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.';
-
 
7
		});
-
 
8
	}
-
 
9
});
-
 
10
//+----------------------------------------------------------------------------------------------------------+
-
 
11
// FONCTIONS GÉNÉRIQUES
-
 
12
/**
-
 
13
 * Stope l'évènement courrant quand on clique sur un lien.
-
 
14
 * Utile pour Chrome, Safari...
-
 
15
 * @param evenement
-
 
16
 * @return
-
 
17
 */
-
 
18
function arreter(evenement) {
-
 
19
	if (evenement.stopPropagation) {
-
 
20
		evenement.stopPropagation();
-
 
21
	}
-
 
22
	if (evenement.preventDefault) {
-
 
23
		evenement.preventDefault();
-
 
24
	}
-
 
25
	return false;
-
 
26
}
-
 
27
 
-
 
28
function extraireEnteteDebug(jqXHR) {
-
 
29
	var msgDebug = '';
-
 
30
	if (jqXHR.getResponseHeader('X-DebugJrest-Data') != '') {
-
 
31
		var debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader('X-DebugJrest-Data'));
-
 
32
		if (debugInfos != null) {
-
 
33
			$.each(debugInfos, function (cle, valeur) {
-
 
34
				msgDebug += valeur + "\n";
-
 
35
			});
-
 
36
		}
-
 
37
	}
-
 
38
	return msgDebug;
-
 
39
}
-
 
40
 
-
 
41
function afficherPanneau(selecteur) {
2
function WidgetSaisieMissionsFlore() {
42
	$(selecteur).fadeIn('slow').delay(DUREE_MESSAGE).fadeOut('slow');
-
 
43
}
-
 
44
 
-
 
45
 
-
 
46
//+---------------------------------------------------------------------------------------------------------+
-
 
47
//FORMULAIRE
-
 
48
$(document).ready(function() {
-
 
49
	if (OBS_ID != '') {
-
 
50
		chargerInfoObs();
-
 
51
	}
-
 
52
});
-
 
53
 
-
 
54
function chargerInfoObs() {
-
 
55
	var urlObs = SERVICE_OBS_URL + '/' + OBS_ID;
-
 
56
	$.ajax({
-
 
57
		url: urlObs,
-
 
58
		type: 'GET',
-
 
59
		success: function(data, textStatus, jqXHR) {
-
 
60
			if (data != undefined && data != '') {
-
 
61
				prechargerForm(data);
-
 
62
			}
-
 
63
			// TODO: voir s'il est pertinent d'indiquer quelque chose en cas d'erreur ou d'obs
-
 
64
			// inexistante
-
 
65
		},
-
 
66
		error: function(jqXHR, textStatus, errorThrown) {
-
 
67
			// TODO: cf TODO ci-dessus
-
 
68
		}
-
 
69
	});
-
 
70
}
-
 
71
 
-
 
72
function prechargerForm(data) {
-
 
73
	$('#milieu').val(data.milieu);
-
 
74
 
-
 
75
	$('#carte-recherche').val(data.zoneGeo);
-
 
76
	$('#commune-nom').text(data.zoneGeo);
-
 
77
 
-
 
78
	if (data.hasOwnProperty('codeZoneGeo')) {
-
 
79
		// TODO: trouver un moyen qui fonctionne lorsqu'on aura d'autres référentiels que INSEE
-
 
80
		$('#commune-code-insee').text(data.codeZoneGeo.replace('INSEE-C:', ''));
-
 
81
	}
-
 
82
 
-
 
83
	if (data.hasOwnProperty('latitude') && data.hasOwnProperty('longitude')) {
-
 
84
		var latLng = new google.maps.LatLng(data.latitude, data.longitude);
-
 
85
		mettreAJourMarkerPosition(latLng);
-
 
86
		marker.setPosition(latLng);
3
	this.serviceAltitudeUrl = null;
87
		 map.setCenter(latLng);
-
 
88
	    map.setZoom(16);
-
 
89
	}
-
 
90
}
-
 
91
 
-
 
92
 
-
 
93
//+----------------------------------------------------------------------------------------------------------+
-
 
94
//FORM IDENTITE : gestion de l'observateur
-
 
95
 
-
 
96
$(document).ready(function() {
-
 
97
	requeterIdentite();// Sur rechargement de la page
-
 
98
 
-
 
99
	// Interaction sur le formulaire observateur
-
 
100
	$('#prenom').on('change', formaterPrenom);
-
 
101
	$('#nom').on('change', formaterNom);
-
 
102
	$('#courriel').on('blur', requeterIdentite);
-
 
103
	$('#courriel').on('keyup', testerLancementRequeteIdentite);
-
 
104
	$('#courriel_confirmation').on('paste', bloquerCopierCollerCourriel);
-
 
105
});
-
 
106
 
-
 
107
function testerLancementRequeteIdentite(event) {
-
 
108
	if (event.which == 13) {
-
 
109
		requeterIdentite();
-
 
110
		event.preventDefault();
-
 
111
		event.stopPropagation();
-
 
112
	}
-
 
113
}
-
 
114
 
-
 
115
function requeterIdentite() {
-
 
116
	var courriel = $('#courriel').val();
-
 
117
	if (courriel) {
-
 
118
		var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL + courriel;
-
 
119
		$.ajax({
-
 
120
			url: urlAnnuaire,
-
 
121
			type: 'GET',
-
 
122
			success: function(data, textStatus, jqXHR) {
-
 
123
				if (data != undefined && data[courriel] != undefined) {
-
 
124
					var infos = data[courriel];
-
 
125
					surSuccesCompletionCourriel(infos, courriel);
-
 
126
				} else {
-
 
127
					surErreurCompletionCourriel();
-
 
128
				}
-
 
129
			},
-
 
130
			error: function(jqXHR, textStatus, errorThrown) {
-
 
131
				surErreurCompletionCourriel();
-
 
132
			},
-
 
133
			complete: function(jqXHR, textStatus) {
-
 
134
				$('#zone-courriel-confirmation, #zone-prenom-nom').removeClass('hidden');
-
 
135
				$('#form-observateur').valid();
-
 
136
			}
-
 
137
		});
-
 
138
	}
-
 
139
}
-
 
140
 
-
 
141
function surErreurCompletionCourriel() {
-
 
142
	$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
-
 
143
	afficherPanneau('#dialogue-courriel-introuvable');
-
 
144
}
-
 
145
 
-
 
146
function surSuccesCompletionCourriel(infos, courriel) {
-
 
147
	$('#id_utilisateur').val(infos.id);
-
 
148
	$('#prenom').val(infos.prenom);
-
 
149
	$('#nom').val(infos.nom);
-
 
150
	$('#courriel_confirmation').val(courriel);
-
 
151
	$('#prenom, #nom, #courriel_confirmation').attr('disabled', 'disabled');
-
 
152
 
-
 
153
	$('#dialogue-courriel-introuvable').hide();
-
 
154
}
-
 
155
 
-
 
156
function formaterNom() {
-
 
157
	$(this).val($(this).val().toUpperCase());
-
 
158
}
-
 
159
 
-
 
160
function formaterPrenom() {
-
 
161
	var prenom = new Array(),
-
 
162
		mots = $(this).val().split(' ');
-
 
163
	for (var i = 0; i < mots.length; i++) {
-
 
164
		var mot = mots[i];
-
 
165
		if (mot.indexOf('-') >= 0) {
-
 
166
			var prenomCompose = new Array(),
-
 
167
				motsComposes = mot.split('-');
-
 
168
			for (var j = 0; j < motsComposes.length; j++) {
-
 
169
				var motSimple = motsComposes[j],
-
 
170
					motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
-
 
171
				prenomCompose.push(motMajuscule);
-
 
172
			}
-
 
173
			prenom.push(prenomCompose.join('-'));
-
 
174
		} else {
-
 
175
			var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
-
 
176
			prenom.push(motMajuscule);
-
 
177
		}
-
 
178
	}
-
 
179
	$(this).val(prenom.join(' '));
-
 
180
}
-
 
181
 
-
 
182
function bloquerCopierCollerCourriel() {
-
 
183
	afficherPanneau('#dialogue-bloquer-copier-coller');
-
 
184
	return false;
-
 
185
}
-
 
186
 
-
 
187
 
-
 
188
//+----------------------------------------------------------------------------------------------------------+
-
 
189
// GOOGLE MAP
-
 
190
var map,
-
 
191
	marker,
-
 
192
	latLng,
-
 
193
	geocoder;
-
 
194
 
-
 
195
$(document).ready(function() {
-
 
196
	initialiserGoogleMap();
-
 
197
	initialiserAutocompleteCommune();
-
 
198
});
-
 
199
 
-
 
200
function afficherErreurGoogleMap(status) {
-
 
201
	if (DEBUG) {
-
 
202
		$('#dialogue-google-map .contenu').empty().append(
-
 
203
			'<pre class="msg-erreur">'+
-
 
204
			"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
-
 
205
			'</pre>');
-
 
206
		afficherPanneau('#dialogue-google-map');
-
 
207
	}
-
 
208
}
4
}
-
 
5
WidgetSaisieMissionsFlore.prototype = new WidgetSaisie();
Line 209... Line -...
209
 
-
 
210
function surDeplacementMarker() {
-
 
211
	mettreAJourMarkerPosition(marker.getPosition());
-
 
Line 212... Line 6...
212
}
6
 
-
 
7
 
213
 
8
WidgetSaisieMissionsFlore.prototype.initForm = function() {
214
function surClickDansCarte(event) {
-
 
Line 215... Line -...
215
	deplacerMarker(event.latLng);
-
 
216
}
-
 
217
 
9
	// super()
218
function geolocaliser() {
10
	WidgetSaisie.prototype.initForm.call(this);
219
	var latitude = $('#latitude').val(),
-
 
220
		longitude = $('#longitude').val();
11
 
Line 221... Line 12...
221
	latLng = new google.maps.LatLng(latitude, longitude);
12
	this.surChangementAbondance();// Vérif lors du chargement de la page
222
	deplacerMarker(latLng);
13
	$('#abondance').on('change', this.surChangementAbondance.bind(this));
223
}
-
 
224
 
-
 
225
function initialiserGoogleMap(){
-
 
226
	// Carte
-
 
227
	var latLng = new google.maps.LatLng(46.30871, 2.54395);// Centre de la France
-
 
228
	var zoomDefaut = 5;
-
 
229
 
-
 
230
	var options = {
-
 
231
		zoom: zoomDefaut,
-
 
232
		center: latLng,
-
 
233
		mapTypeId: google.maps.MapTypeId.HYBRID,
-
 
234
		mapTypeControlOptions: {
-
 
235
			mapTypeIds: ['OSM', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]}
-
 
236
	};
-
 
237
 
14
};
238
	// Ajout de la couche OSM à la carte
-
 
239
	osmMapType = new google.maps.ImageMapType({
-
 
240
		getTileUrl: function(coord, zoom) {
-
 
241
			return 'http://tile.openstreetmap.org/' +
-
 
242
			zoom + '/' + coord.x + '/' + coord.y + '.png';
-
 
243
		},
-
 
244
		tileSize: new google.maps.Size(256, 256),
-
 
245
		isPng: true,
-
 
Line 246... Line -...
246
		alt: 'OpenStreetMap',
-
 
247
		name: 'OSM',
-
 
248
		maxZoom: 19
-
 
249
	});
-
 
250
 
15
 
251
	// Création de la carte Google
16
WidgetSaisieMissionsFlore.prototype.initEvts = function() {
252
	map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
-
 
253
	map.mapTypes.set('OSM', osmMapType);
17
	// super()
254
 
18
	WidgetSaisie.prototype.initEvts.call(this);
255
	// Création du Geocoder
-
 
256
	geocoder = new google.maps.Geocoder();
-
 
257
 
-
 
258
	// Marqueur google draggable
-
 
259
	marker = new google.maps.Marker({
-
 
260
		map: map,
19
 
-
 
20
	var lthis = this;
Line 261... Line -...
261
		draggable: true,
-
 
262
		title: 'Ma station',
-
 
263
		icon: GOOGLE_MAP_MARQUEUR_URL,
-
 
264
		position: latLng
-
 
265
	});
-
 
266
 
-
 
267
	initialiserMarker(latLng);
-
 
268
 
-
 
269
	// Tentative de geocalisation
-
 
270
	if (navigator.geolocation) {
-
 
271
		navigator.geolocation.getCurrentPosition(function(position) {
-
 
272
			var latitude = position.coords.latitude;
-
 
273
			var longitude = position.coords.longitude;
-
 
274
			latLng = new google.maps.LatLng(latitude, longitude);
-
 
275
			deplacerMarker(latLng);
-
 
276
		});
-
 
277
	}
-
 
278
 
-
 
279
	// intéraction carte
-
 
280
	$('#geolocaliser').on('click', geolocaliser);
-
 
281
	google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
-
 
282
	google.maps.event.addListener(map, 'click', surClickDansCarte);
-
 
283
}
-
 
284
 
-
 
285
function initialiserMarker(latLng) {
-
 
286
	if (marker != undefined) {
-
 
287
		marker.setPosition(latLng);
-
 
288
		map.setCenter(latLng);
-
 
289
		mettreAJourMarkerPosition(latLng);
-
 
290
	}
21
	$('body').on('click', '.fermer', function(event) {
291
}
-
 
292
 
-
 
293
function deplacerMarker(latLng) {
22
			event.preventDefault();
Line 294... Line 23...
294
	if (marker != undefined) {
23
			lthis.basculerOuvertureFermetureCadre($(this).find('.icone'));
295
		marker.setPosition(latLng);
24
	});
296
		map.setCenter(latLng);
25
	$('.btn-coord ').on('click', this.basculerAffichageCoord);
Line 297... Line 26...
297
		mettreAJourMarkerPosition(latLng);
26
 
298
	}
27
	this.surChangementNbreObs();
299
}
28
};
300
 
29
 
301
function mettreAJourMarkerPosition(latLng) {
30
WidgetSaisieMissionsFlore.prototype.mettreAJourMarkerPosition = function(latLng) {
302
	trouverCommune(latLng);
-
 
303
	trouverAltitude(latLng);
-
 
304
 
-
 
305
	var lat = latLng.lat().toFixed(5),
-
 
306
		lng = latLng.lng().toFixed(5);
-
 
307
	remplirChampLatitude(lat);
-
 
308
	remplirChampLongitude(lng);
-
 
309
	remplirChampsLambert93(lat, lng);
-
 
310
}
-
 
311
 
-
 
312
function remplirChampLatitude(latDecimale) {
31
	this.trouverCommune(latLng);
Line 313... Line 32...
313
	var lat = Math.round(latDecimale * 100000) / 100000;
32
	this.trouverAltitude(latLng);
314
	$('#latitude').val(lat);
33
 
315
}
34
	var lat = latLng.lat().toFixed(5),
316
 
35
		lng = latLng.lng().toFixed(5);
317
function remplirChampLongitude(lngDecimale) {
36
	this.remplirChampLatitude(lat);
318
	var lng = Math.round(lngDecimale * 100000) / 100000;
37
	this.remplirChampLongitude(lng);
319
	$('#longitude').val(lng);
38
	this.remplirChampsLambert93(lat, lng);
320
}
39
};
321
 
40
 
322
proj4.defs([
41
proj4.defs([
323
	['EPSG:4326', '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'],
42
	['EPSG:4326', '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'],
324
	['EPSG:2154', '+title=RGF93 / Lambert-93 +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs']
-
 
325
]);
-
 
326
function remplirChampsLambert93(lat, lng) {
-
 
327
	// Prendre en compte l'initialisation des projections
-
 
328
	var coordinate = {x: lng,y: lat};
-
 
329
	proj4(proj4.defs('EPSG:4326'), proj4.defs('EPSG:2154')).forward(coordinate);
-
 
330
	$('#l93-x').val(coordinate.x.toFixed(0));
-
 
331
	$('#l93-y').val(coordinate.y.toFixed(0));
-
 
332
}
-
 
333
 
-
 
334
function trouverAltitude(pos) {
-
 
335
	$(function() {
-
 
336
		var url_service = SERVICE_ALTITUDE_URL,
-
 
337
			urlAltFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
-
 
338
		$.ajax({
-
 
339
			url: urlAltFormatee,
-
 
340
			type: 'GET',
-
 
341
			dataType: 'jsonp',
-
 
342
			beforeSend : function() {
-
 
343
				$('#altitude').empty();
-
 
344
				$('#dialogue-erreur .alert-txt').empty();
-
 
345
			},
-
 
346
			success : function(data, textStatus, jqXHR) {
-
 
347
				$('#altitude').empty().append(data.altitude);
-
 
348
				$('#marqueur-altitude').data('altitude', data.altitude);
-
 
349
			},
-
 
350
			statusCode : {
-
 
351
			    500 : function(jqXHR, textStatus, errorThrown) {
-
 
Line -... Line 43...
-
 
43
	['EPSG:2154', '+title=RGF93 / Lambert-93 +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs']
-
 
44
]);
-
 
45
WidgetSaisieMissionsFlore.prototype.remplirChampsLambert93 = function(lat, lng) {
352
					if (DEBUG) {
46
	// Prendre en compte l'initialisation des projections
353
						$('#dialogue-erreur .alert-txt').append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissant l\'altitude.</p>');
47
	var coordinate = {x: lng,y: lat};
-
 
48
	proj4(proj4.defs('EPSG:4326'), proj4.defs('EPSG:2154')).forward(coordinate);
-
 
49
	$('#l93-x').val(coordinate.x.toFixed(0));
-
 
50
	$('#l93-y').val(coordinate.y.toFixed(0));
-
 
51
};
-
 
52
 
-
 
53
WidgetSaisieMissionsFlore.prototype.trouverAltitude = function(pos) {
354
						reponse = jQuery.parseJSON(jqXHR.responseText);
54
	var lthis = this;
-
 
55
	var url_service = this.serviceAltitudeUrl,
-
 
56
		urlAltFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
-
 
57
	$.ajax({
355
						var erreurMsg = '';
58
		url: urlAltFormatee,
-
 
59
		type: 'GET',
356
						if (reponse != null) {
60
		dataType: 'jsonp',
357
							$.each(reponse, function (cle, valeur) {
61
		beforeSend : function() {
358
								erreurMsg += valeur + '<br />';
62
			$('#altitude').empty();
359
							});
63
			$('#dialogue-erreur .alert-txt').empty();
360
						}
64
		},
361
 
65
		success : function(data, textStatus, jqXHR) {
362
						$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
66
			$('#altitude').empty().append(data.altitude);
363
					}
67
			$('#marqueur-altitude').data('altitude', data.altitude);
364
			    }
68
		},
365
			},
69
		statusCode : {
Line 366... Line 70...
366
			error : function(jqXHR, textStatus, errorThrown) {
70
		    500 : function(jqXHR, textStatus, errorThrown) {
367
				if (DEBUG) {
-
 
368
					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de l\'appel au service fournissant l\'altitude.</p>');
-
 
369
					reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
370
					var erreurMsg = '';
-
 
371
					if (reponse != null) {
-
 
372
						$.each(reponse, function (cle, valeur) {
-
 
373
							erreurMsg += valeur + '<br />';
-
 
374
						});
-
 
375
					}
71
				if (lthis.debug) {
-
 
72
					$('#dialogue-erreur .alert-txt').append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissant l\'altitude.</p>');
-
 
73
					reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
74
					var erreurMsg = '';
-
 
75
					if (reponse != null) {
-
 
76
						$.each(reponse, function (cle, valeur) {
-
 
77
							erreurMsg += valeur + '<br />';
-
 
78
						});
-
 
79
					}
376
 
80
 
377
					$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
81
					$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
-
 
82
				}
378
				}
83
		    }
379
			},
-
 
380
			complete : function(jqXHR, textStatus) {
-
 
381
				var debugMsg = extraireEnteteDebug(jqXHR);
-
 
382
				if (debugMsg != '') {
-
 
383
					if (DEBUG) {
-
 
384
						$('#dialogue-erreur .alert-txt').append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
-
 
385
					}
-
 
386
				}
-
 
387
				if ($('#dialogue-erreur .msg').length > 0) {
-
 
388
					$('#dialogue-erreur').show();
-
 
389
				}
-
 
390
			}
-
 
391
		});
-
 
392
	});
-
 
393
}
-
 
394
 
-
 
395
function trouverCommune(pos) {
-
 
396
	$(function() {
-
 
397
		var url_service = SERVICE_NOM_COMMUNE_URL,
-
 
398
			urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
-
 
399
		$.ajax({
-
 
400
			url: urlNomCommuneFormatee,
-
 
401
			type: 'GET',
-
 
402
			dataType: 'jsonp',
-
 
403
			beforeSend : function() {
-
 
404
				$('.commune-info').empty();
-
 
405
				$('#dialogue-erreur .alert-txt').empty();
-
 
406
			},
-
 
407
			success : function(data, textStatus, jqXHR) {
-
 
408
				$('.commune-info').empty();
-
 
409
				$('#commune-nom').append(data.nom);
-
 
410
				$('#commune-code-insee').append(data.codeINSEE);
-
 
411
				$('#marqueur-commune').data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
-
 
412
			},
-
 
413
			statusCode : {
-
 
414
			    500 : function(jqXHR, textStatus, errorThrown) {
-
 
415
					if (DEBUG) {
-
 
416
						$('#dialogue-erreur .alert-txt').append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissante le nom des communes.</p>');
-
 
417
						reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
418
						var erreurMsg = '';
-
 
419
						if (reponse != null) {
-
 
420
							$.each(reponse, function (cle, valeur) {
-
 
421
								erreurMsg += valeur + '<br />';
-
 
422
							});
-
 
423
						}
-
 
424
 
-
 
425
						$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
-
 
426
					}
-
 
427
			    }
-
 
Line 428... Line 84...
428
			},
84
		},
429
			error : function(jqXHR, textStatus, errorThrown) {
-
 
430
				if (DEBUG) {
-
 
431
					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
-
 
432
					reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
433
					var erreurMsg = '';
-
 
434
					if (reponse != null) {
-
 
435
						$.each(reponse, function (cle, valeur) {
-
 
436
							erreurMsg += valeur + '<br />';
-
 
437
						});
-
 
438
					}
-
 
439
 
-
 
440
					$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
-
 
441
				}
85
		error : function(jqXHR, textStatus, errorThrown) {
442
			},
-
 
443
			complete : function(jqXHR, textStatus) {
-
 
444
				var debugMsg = extraireEnteteDebug(jqXHR);
-
 
445
				if (debugMsg != '') {
-
 
446
					if (DEBUG) {
-
 
447
						$('#dialogue-erreur .alert-txt').append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
-
 
448
					}
-
 
449
				}
-
 
450
				if ($('#dialogue-erreur .msg').length > 0) {
-
 
451
					$('#dialogue-erreur').show();
-
 
452
				}
-
 
453
			}
-
 
454
		});
-
 
455
	});
-
 
456
}
-
 
457
 
-
 
458
 
-
 
459
//+---------------------------------------------------------------------------------------------------------+
-
 
460
//AUTO-COMPLÉTION Noms Scientifiques
86
			if (lthis.debug) {
461
 
-
 
462
function ajouterAutocompletionNoms() {
-
 
463
	$('#taxon').autocomplete({
-
 
464
		source: function(requete, add){
87
				$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de l\'appel au service fournissant l\'altitude.</p>');
465
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
-
 
466
 
-
 
467
			var url = getUrlAutocompletionNomsSci();
-
 
468
			$.getJSON(url, function(data) {
-
 
469
				var suggestions = traiterRetourNomsSci(data);
88
				reponse = jQuery.parseJSON(jqXHR.responseText);
470
				add(suggestions);
-
 
471
			});
-
 
472
		},
-
 
473
		html: true
-
 
474
	});
-
 
475
 
-
 
476
	$('#taxon').on('autocompleteselect', function(event, ui) {
-
 
477
		$('#taxon').data(ui.item);
-
 
478
		if (ui.item.retenu == true) {
-
 
479
			$('#taxon').addClass('ns-retenu');
-
 
480
		} else {
-
 
481
			$('#taxon').removeClass('ns-retenu');
-
 
482
		}
-
 
483
	});
89
				var erreurMsg = '';
484
}
-
 
485
 
-
 
486
function getUrlAutocompletionNomsSci() {
-
 
487
	var mots = $('#taxon').val(),
-
 
488
		url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_REFERENTIEL);
-
 
489
	url = url.replace('{masque}', mots);
-
 
490
	return url;
-
 
491
}
-
 
492
 
-
 
493
function traiterRetourNomsSci(data) {
-
 
494
	var suggestions = [];
90
				if (reponse != null) {
495
	if (data.resultat != undefined) {
-
 
496
		$.each(data.resultat, function(i, val) {
-
 
497
			val.nn = i;
-
 
498
			var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
-
 
499
				nomRet: '', numNomRet: '', famille: '', retenu: false
-
 
500
			};
-
 
501
			if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
-
 
502
				nom.label = '...';
-
 
503
				nom.value = $('#taxon').val();
-
 
504
				suggestions.push(nom);
-
 
505
				return false;
-
 
506
			} else {
-
 
507
				nom.label = val.nom_sci_complet;
-
 
508
				nom.value = val.nom_sci_complet;
-
 
509
				nom.nt = val.num_taxonomique;
-
 
510
				nom.nomSel = val.nom_sci;
-
 
511
				nom.nomSelComplet = val.nom_sci_complet;
-
 
512
				nom.numNomSel = val.nn;
-
 
513
				nom.nomRet = val.nom_retenu_complet;
-
 
514
				nom.numNomRet = val['nom_retenu.id'];
-
 
515
				nom.famille = val.famille;
-
 
516
				nom.retenu = (val.retenu == 'false') ? false : true;
-
 
517
 
-
 
518
				suggestions.push(nom);
-
 
519
			}
-
 
520
		});
-
 
521
	}
-
 
522
	return suggestions;
-
 
523
}
-
 
524
 
-
 
525
/*
-
 
526
* jQuery UI Autocomplete HTML Extension
-
 
527
*
-
 
528
* Copyright 2010, Scott González (http://scottgonzalez.com)
-
 
529
* Dual licensed under the MIT or GPL Version 2 licenses.
-
 
530
*
91
					$.each(reponse, function (cle, valeur) {
531
* http://github.com/scottgonzalez/jquery-ui-extensions
-
 
532
*
-
 
533
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
-
 
534
*/
-
 
535
(function($) {
-
 
536
	var proto = $.ui.autocomplete.prototype,
-
 
537
		initSource = proto._initSource;
-
 
538
 
-
 
539
	function filter(array, term) {
92
						erreurMsg += valeur + '<br />';
540
		var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
-
 
541
		return $.grep(array, function(value) {
-
 
542
			return matcher.test($('<div>').html(value.label || value.value || value).text());
93
					});
543
		});
-
 
544
	}
-
 
545
 
94
				}
546
	$.extend(proto, {
95
 
547
		_initSource: function() {
96
				$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
548
			if (this.options.html && $.isArray(this.options.source)) {
-
 
549
				this.source = function( request, response ) {
-
 
550
					response(filter(this.options.source, request.term));
-
 
551
				};
-
 
552
			} else {
-
 
553
				initSource.call(this);
-
 
554
			}
-
 
555
		},
-
 
556
		_renderItem: function(ul, item) {
-
 
557
			if (item.retenu == true) {
-
 
558
				item.label = '<strong>'+item.label+'</strong>';
-
 
559
			}
-
 
560
 
-
 
561
			return $('<li></li>')
-
 
562
				.data('item.autocomplete', item)
-
 
563
				.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
-
 
564
				.appendTo(ul);
-
 
565
		}
-
 
566
	});
-
 
567
})(jQuery);
-
 
568
 
-
 
569
//+----------------------------------------------------------------------------------------------------------+
-
 
570
//UPLOAD PHOTO : Traitement de l'image
-
 
571
$(document).ready(function() {
-
 
572
	$('.effacer-miniature').click(function () {
-
 
573
		supprimerMiniatures($(this));
-
 
574
	});
-
 
575
 
-
 
576
	$('#fichier').on('change', function (e) {
-
 
577
		arreter(e);
-
 
578
		var options = {
-
 
579
			success: afficherMiniature, // post-submit callback
-
 
580
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
-
 
581
			resetForm: true // reset the form after successful submit
-
 
582
		};
-
 
583
		$('#ajouter-obs').attr('disabled', 'disabled');
-
 
584
		if (verifierFormat($('#fichier').val())) {
-
 
585
			$('#form-upload').ajaxSubmit(options);
-
 
586
		} else {
-
 
587
			$('#form-upload')[0].reset();
-
 
588
			window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+$('#fichier').attr('accept'));
-
 
589
		}
-
 
590
		return false;
-
 
591
	});
-
 
592
 
-
 
593
	if (ESPECE_IMPOSEE) {
-
 
594
		$('#taxon').attr('disabled', 'disabled');
-
 
595
		$('#taxon-input-groupe').attr('title', '');
-
 
596
		var infosAssociee = new Object();
-
 
597
		infosAssociee.label = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
-
 
598
		infosAssociee.value = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
-
 
599
		infosAssociee.nt = INFOS_ESPECE_IMPOSEE.num_taxonomique;
-
 
600
		infosAssociee.nomSel = INFOS_ESPECE_IMPOSEE.nom_sci;
-
 
601
		infosAssociee.nomSelComplet = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
-
 
602
		infosAssociee.numNomSel = INFOS_ESPECE_IMPOSEE.id;
-
 
603
		infosAssociee.nomRet = INFOS_ESPECE_IMPOSEE['nom_retenu.libelle'];
-
 
604
		infosAssociee.numNomRet = INFOS_ESPECE_IMPOSEE['nom_retenu.id'];
-
 
605
		infosAssociee.famille = INFOS_ESPECE_IMPOSEE.famille;
-
 
606
		infosAssociee.retenu = (INFOS_ESPECE_IMPOSEE.retenu == 'false') ? false : true;
-
 
607
		$('#taxon').data(infosAssociee);
-
 
608
	}
-
 
609
 
-
 
610
	$('body').on('click', '.effacer-miniature', function() {
-
 
611
		$(this).parent().remove();
-
 
612
	});
-
 
613
});
-
 
614
 
-
 
615
function verifierFormat(nom) {
-
 
616
	var parts = nom.split('.');
-
 
617
	extension = parts[parts.length - 1];
-
 
618
	return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
-
 
619
}
-
 
620
 
-
 
621
function afficherMiniature(reponse) {
-
 
622
	if (DEBUG) {
-
 
623
		var debogage = $('debogage', reponse).text();
-
 
624
		console.log("Débogage upload : "+debogage);
-
 
625
	}
-
 
626
	var message = $('message', reponse).text();
-
 
627
	if (message != '') {
-
 
628
		$('#miniature-msg').append(message);
-
 
629
	} else {
-
 
630
		$('#miniatures').append(creerWidgetMiniature(reponse));
-
 
631
	}
-
 
632
	$('#ajouter-obs').removeAttr('disabled');
-
 
633
}
-
 
634
 
-
 
635
function creerWidgetMiniature(reponse) {
-
 
636
	var miniatureUrl = $('miniature-url', reponse).text();
-
 
637
	var imgNom = $('image-nom', reponse).text();
-
 
638
	var html =
-
 
639
		'<div class="miniature">'+
-
 
640
			'<img class="miniature-img thumbnail" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
-
 
641
			'<button class="effacer-miniature" type="button">Effacer</button>'+
-
 
642
		'</div>'
-
 
643
	return html;
-
 
644
}
-
 
645
 
-
 
646
function supprimerMiniatures() {
-
 
647
	$('#miniatures').empty();
-
 
648
	$('#miniature-msg').empty();
-
 
649
}
-
 
650
 
-
 
651
//Initialise l'autocomplétion de la commune, en fonction du référentiel
-
 
652
function initialiserAutocompleteCommune() {
-
 
653
	var geocoderOptions = {},
-
 
654
		addressSuffix = '';
-
 
655
 
-
 
656
	geocoderOptions.region = 'fr';
-
 
657
	addressSuffix = ', France';
-
 
658
 
-
 
659
	$('#carte-recherche').autocomplete({
-
 
660
		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
-
 
661
		source: function(request, response) {
-
 
662
			geocoderOptions.address = request.term + addressSuffix;
-
 
663
			geocoder.geocode( geocoderOptions, function(results, status) {
-
 
664
				if (status == google.maps.GeocoderStatus.OK) {
-
 
665
					response($.map(results, function(item) {
-
 
666
						var retour = {
-
 
667
							label: item.formatted_address,
-
 
668
							value: item.formatted_address,
-
 
669
							latitude: item.geometry.location.lat(),
-
 
670
							longitude: item.geometry.location.lng()
-
 
671
						};
-
 
672
						return retour;
-
 
673
					}));
-
 
674
				} else {
-
 
675
					afficherErreurGoogleMap(status);
-
 
676
				}
-
 
677
			});
-
 
678
		},
-
 
679
		// Cette partie est executee a la selection d'une adresse
-
 
680
		select: function(event, ui) {
-
 
681
			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
-
 
682
			deplacerMarker(latLng);
-
 
683
		}
-
 
684
	});
-
 
685
 
97
			}
686
	// Autocompletion du champ adresse
98
		},
687
	$('#carte-recherche').on('focus', function() {
99
		complete : function(jqXHR, textStatus) {
Line 688... Line -...
688
		$(this).select();
-
 
689
	});
-
 
690
	$('#carte-recherche').on('mouseup', function(event) {// Pour Safari...
-
 
691
		event.preventDefault();
-
 
692
	});
-
 
693
 
-
 
694
	$('#carte-recherche').keypress(function(e) {
-
 
695
		if (e.which == 13) {
-
 
696
			e.preventDefault();
-
 
697
		}
-
 
698
	});
-
 
699
};
-
 
700
 
-
 
701
 
-
 
702
//+---------------------------------------------------------------------------------------------------------+
-
 
703
// FORMULAIRE : traitements génériques
-
 
704
var obsNbre = 0;
-
 
705
 
-
 
706
$(document).ready(function() {
-
 
707
	$('.alert .close').on('click', fermerPanneauAlert);
-
 
708
	$('body').on('click', '.fermer', function(event) {
-
 
709
			event.preventDefault();
-
 
710
			basculerOuvertureFermetureCadre($(this).find('.icone'));
-
 
711
	});
-
 
712
	$('.has-tooltip').tooltip('enable');
100
			var debugMsg = extraireEnteteDebug(jqXHR);
713
	$('#btn-aide').on('click', basculerAffichageAide);
-
 
714
 
-
 
715
	// Validation du formulaire
-
 
716
	configurerFormValidator();
-
 
717
	definirReglesFormValidator();
-
 
718
 
-
 
719
	// Date picker
-
 
720
	configurerDatePicker();
-
 
721
 
-
 
722
	// Gestion de la liste des taxons
-
 
723
	ajouterAutocompletionNoms();
-
 
724
	surChangementAbondance();// Vérif lors du chargement de la page
-
 
725
	$('#abondance').on('change', surChangementAbondance);
-
 
726
 
-
 
727
	// Gestion des obs
-
 
728
	$('.btn-coord ').on('click', basculerAffichageCoord);
-
 
729
	$('#ajouter-obs').on('click', ajouterObs);
-
 
730
	surChangementNbreObs();
-
 
731
	$('.obs-nbre').on('changement', surChangementNbreObs);
-
 
732
	$('body').on('click', '.supprimer-obs', supprimerObs);
-
 
733
	$('#transmettre-obs').on('click', transmettreObs);
-
 
734
 
-
 
735
 
101
			if (debugMsg != '') {
736
	// Défilement des photos
102
				if (lthis.debug) {
737
	$('body').on('click', '.defilement-miniatures-gauche', function(event) {
103
					$('#dialogue-erreur .alert-txt').append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
738
			event.preventDefault();
104
				}
739
			defilerMiniatures($(this));
105
			}
740
	});
106
			if ($('#dialogue-erreur .msg').length > 0) {
741
	$('body').on('click', '.defilement-miniatures-droite', function(event) {
107
				$('#dialogue-erreur').show();
Line 742... Line 108...
742
		event.preventDefault();
108
			}
743
		defilerMiniatures($(this));
109
		}
744
	});
110
	});
745
});
111
};
746
 
112
 
747
function surChangementAbondance() {
113
WidgetSaisieMissionsFlore.prototype.surChangementAbondance = function() {
748
	if (afficherIndividusNbreGroupe()) {
114
	if (this.afficherIndividusNbreGroupe()) {
749
		$('#individus-nbre-groupe').removeClass('hidden');
115
		$('#individus-nbre-groupe').removeClass('hidden');
Line 750... Line 116...
750
		$('#individus-nbre').valid();
116
		$('#individus-nbre').valid();
-
 
117
	} else {
751
	} else {
118
		$('#individus-nbre-groupe').addClass('hidden');
752
		$('#individus-nbre-groupe').addClass('hidden');
119
	}
753
	}
120
};
754
}
121
 
755
 
122
WidgetSaisieMissionsFlore.prototype.afficherIndividusNbreGroupe = function() {
Line 772... Line 139...
772
 
139
 
773
	$.validator.addMethod(
140
	$.validator.addMethod(
774
		'individusNbre',
141
		'individusNbre',
775
		function (value, element) {
142
		function (value, element) {
776
			var ok = true;
143
			var ok = true;
777
			if (afficherIndividusNbreGroupe()) {
144
			if (lthis.afficherIndividusNbreGroupe()) {
778
				var abondance = $('#abondance').val();
145
				var abondance = $('#abondance').val();
779
				if (abondance === '1-4 individus') {
146
				if (abondance === '1-4 individus') {
780
					ok = value === '' || (value !== '' && /^[0-9]+$/.test(value) && value >= 1 && value < 5);
147
					ok = value === '' || (value !== '' && /^[0-9]+$/.test(value) && value >= 1 && value < 5);
781
				} else if (abondance == '5-9 individus') {
148
				} else if (abondance == '5-9 individus') {
Line 830... Line 197...
830
			} else {
197
			} else {
831
				error.insertAfter(element);
198
				error.insertAfter(element);
832
			}
199
			}
833
		}
200
		}
834
	});
201
	});
835
}
202
};
Line 836... Line 203...
836
 
203
 
837
function definirReglesFormValidator() {
204
WidgetSaisieMissionsFlore.prototype.definirReglesFormValidator = function() {
838
	$('#form-observateur').validate({
205
	$('#form-observateur').validate({
839
		rules: {
206
		rules: {
840
			courriel : {
207
			courriel : {
841
				required : true,
208
				required : true,
Line 868... Line 235...
868
		rules: {
235
		rules: {
869
			individusNombre: {individusNbre: true},
236
			individusNombre: {individusNbre: true},
870
			determinationSource: {isbn: true}
237
			determinationSource: {isbn: true}
871
		}
238
		}
872
	});
239
	});
873
}
240
};
874
 
-
 
875
function configurerDatePicker() {
-
 
876
	$.datepicker.setDefaults($.datepicker.regional['fr']);
-
 
877
	$('#date').datepicker({
-
 
878
		dateFormat: 'dd/mm/yy',
-
 
879
		maxDate: new Date,
-
 
880
		showOn: 'button',
-
 
881
		buttonImageOnly: true,
-
 
882
		buttonImage: CALENDRIER_ICONE_URL,
-
 
883
		buttonText: 'Afficher le calendrier pour saisir la date.',
-
 
884
		showButtonPanel: true,
-
 
885
		onSelect: function(date) {
-
 
886
			$(this).valid();
-
 
887
		}
-
 
888
	});
-
 
889
	$('img.ui-datepicker-trigger').appendTo('#date-icone');
-
 
890
}
-
 
891
 
-
 
892
function fermerPanneauAlert() {
-
 
893
	$(this).parentsUntil('.zone-alerte', '.alert').hide();
-
 
894
}
-
 
Line 895... Line 241...
895
 
241
 
896
function basculerOuvertureFermetureCadre(element) {
242
WidgetSaisieMissionsFlore.prototype.basculerOuvertureFermetureCadre = function(element) {
897
	if (element.hasClass('glyphicon-plus-sign')) {
243
	if (element.hasClass('glyphicon-plus-sign')) {
898
		element.removeClass('glyphicon-plus-sign').addClass('glyphicon-minus-sign');
244
		element.removeClass('glyphicon-plus-sign').addClass('glyphicon-minus-sign');
899
	} else {
245
	} else {
900
		element.removeClass('glyphicon-minus-sign').addClass('glyphicon-plus-sign');
246
		element.removeClass('glyphicon-minus-sign').addClass('glyphicon-plus-sign');
901
	}
247
	}
902
}
-
 
903
 
-
 
904
function basculerAffichageAide()  {
-
 
905
	if ($(this).hasClass('btn-warning')) {
-
 
906
		$('.has-tooltip').tooltip('enable');
-
 
907
		$(this).removeClass('btn-warning').addClass('btn-success');
-
 
908
		$('#btn-aide-txt', this).text("Désactiver l'aide");
-
 
909
	} else {
-
 
910
		$('.has-tooltip').tooltip('disable');
-
 
911
		$(this).removeClass('btn-success').addClass('btn-warning');
-
 
912
		$('#btn-aide-txt', this).text("Activer l'aide");
-
 
913
	}
-
 
914
}
-
 
915
 
-
 
916
function bloquerCopierCollerCourriel() {
-
 
917
	afficherPanneau('#dialogue-bloquer-copier-coller');
-
 
918
	return false;
-
 
Line 919... Line 248...
919
}
248
};
920
 
249
 
921
function basculerAffichageCoord() {
250
WidgetSaisieMissionsFlore.prototype.basculerAffichageCoord = function() {
922
	var textActuel = $(this).text(),
251
	var textActuel = $(this).text(),
Line 923... Line 252...
923
			textARemplacer = $(this).data('toggle-text');
252
		textARemplacer = $(this).data('toggle-text');
924
	$(this).text(textARemplacer).data('toggle-text', textActuel);
253
	$(this).text(textARemplacer).data('toggle-text', textActuel);
925
 
254
 
Line 930... Line 259...
930
		$(this).removeClass('afficher-coord').addClass('cacher-coord');
259
		$(this).removeClass('afficher-coord').addClass('cacher-coord');
931
		$('#coordonnees-geo').removeClass('hidden');
260
		$('#coordonnees-geo').removeClass('hidden');
932
	}
261
	}
Line 933... Line 262...
933
 
262
 
934
	return false;
263
	return false;
935
}
-
 
936
 
-
 
937
function ajouterObs() {
-
 
938
	// Fermeture automatique des dialogue de transmission de données
-
 
939
	$('#dialogue-obs-transaction-ko').hide();
-
 
940
	$('#dialogue-obs-transaction-ok').hide();
-
 
941
 
-
 
942
	if (validerFormulaire() == true) {
-
 
943
		obsNbre = obsNbre + 1;
-
 
944
		$('.obs-nbre').text(obsNbre);
-
 
945
		$('.obs-nbre').triggerHandler('changement');
-
 
946
		afficherObs();
-
 
947
		stockerObsData();
-
 
948
		supprimerMiniatures();
-
 
949
		if(!ESPECE_IMPOSEE) {
-
 
950
			$('#taxon').val('');
-
 
951
			$('#taxon').data('numNomSel',undefined);
-
 
952
		}
-
 
953
		$('#barre-progression-upload').attr('aria-valuemax', obsNbre);
-
 
954
		$('#barre-progression-upload .sr-only').text('0/'+obsNbre+' observations transmises');
-
 
955
	} else {
-
 
956
		afficherPanneau('#dialogue-form-invalide');
-
 
957
	}
-
 
Line 958... Line 264...
958
}
264
};
959
 
265
 
960
function afficherObs() {
266
WidgetSaisieMissionsFlore.prototype.afficherObs = function() {
961
	var date = $('#date').val(),
267
	var date = $('#date').val(),
962
		commune = $('#commune-nom').text(),
268
		commune = $('#commune-nom').text(),
963
		codeInsee = $('#commune-code-insee').text(),
269
		codeInsee = $('#commune-code-insee').text(),
964
		lat = $('input[name="latitude"]').val(),
270
		lat = $('input[name="latitude"]').val(),
965
		lng = $('input[name="longitude"]').val(),
271
		lng = $('input[name="longitude"]').val(),
Line 966... Line 272...
966
		lieudit = $('#lieudit').val(),
272
		lieudit = $('#lieudit').val(),
967
		station = $('#station').val(),
273
		station = $('#station').val(),
968
 
274
 
Line 969... Line 275...
969
		milieux = $('#milieu').val(),
275
		milieux = $('#milieu').val(),
970
		exposition = getTextOptionSelectionne('station-exposition'),
276
		exposition = this.getTextOptionSelectionne('station-exposition'),
971
		pente = getTextOptionSelectionne('station-pente'),
277
		pente = this.getTextOptionSelectionne('station-pente'),
972
 
278
 
973
		phenologie = getTextOptionSelectionne('phenologie'),
279
		phenologie = this.getTextOptionSelectionne('phenologie'),
Line 974... Line 280...
974
		abondance = getTextOptionSelectionne('abondance'),
280
		abondance = this.getTextOptionSelectionne('abondance'),
Line 975... Line 281...
975
		individus = (($('#individus-nbre').val() === undefined || $('#individus-nbre').val() === '') ? '' : ' (' + $('#individus-nbre').val() + ')'),
281
		individus = (($('#individus-nbre').val() === undefined || $('#individus-nbre').val() === '') ? '' : ' (' + $('#individus-nbre').val() + ')'),
976
		typeReleve = getTextOptionSelectionne('releve-type'),
282
		typeReleve = this.getTextOptionSelectionne('releve-type'),
977
		sourceDet = $('#determination-source').val(),
283
		sourceDet = $('#determination-source').val(),
978
 
284
 
979
		notes = $('#notes').val();
285
		notes = $('#notes').val();
980
 
286
 
981
	$('#liste-obs').prepend(
287
	$('#liste-obs').prepend(
982
		'<div id="obs'+obsNbre+'" class="obs obs'+obsNbre+'">'+
288
		'<div id="obs'+this.obsNbre+'" class="obs obs'+this.obsNbre+'">'+
983
				'<div class="well">'+
289
				'<div class="well">'+
984
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
290
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
985
						'title="Supprimer cette observation de la liste à transmettre">'+
291
						'title="Supprimer cette observation de la liste à transmettre">'+
986
						'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
292
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
987
							'<span class="glyphicon glyphicon-trash icon-white"></i>'+
293
							'<span class="glyphicon glyphicon-trash icon-white"></i>'+
988
						'</button>'+
294
						'</button>'+
989
					'</div> '+
295
					'</div> '+
990
					'<div class="row">'+
296
					'<div class="row">'+
991
						'<div class="col-md-2 obs-miniatures">'+
297
						'<div class="col-md-2 obs-miniatures">'+
Line 1023... Line 329...
1023
							'</ul>'+
329
							'</ul>'+
1024
						'</div>'+
330
						'</div>'+
1025
					'</div>'+
331
					'</div>'+
1026
				'</div>'+
332
				'</div>'+
1027
		'</div>');
333
		'</div>');
-
 
334
	$('#zone-liste-obs').removeClass("hidden").show();
1028
}
335
}
Line 1029... Line 336...
1029
 
336
 
1030
function getTextOptionSelectionne(id) {
337
WidgetSaisieMissionsFlore.prototype.getTextOptionSelectionne = function(id) {
1031
	var optionVal = $('#' + id).val(),
338
	var optionVal = $('#' + id).val(),
1032
		optionText = $('#' + id + ' option:selected').text();
-
 
1033
	//console.log(optionVal+'-'+optionText);
339
		optionText = $('#' + id + ' option:selected').text();
1034
	return ((optionVal === undefined || optionVal === '') ? '' : optionText);
340
	return ((optionVal === undefined || optionVal === '') ? '' : optionText);
Line 1035... Line 341...
1035
}
341
};
1036
 
342
 
1037
function stockerObsData() {
343
WidgetSaisieMissionsFlore.prototype.stockerObsData = function() {
1038
	var numNomSel = $('#taxon').data('numNomSel'),
344
	var numNomSel = $('#taxon').data('numNomSel'),
1039
		nomSel = $('#taxon').val(),
345
		nomSel = $('#taxon').val(),
1040
		nomRet = $('#taxon').data('nomRet'),
346
		nomRet = $('#taxon').data('nomRet'),
1041
		numNomRet = $('#taxon').data('numNomRet'),
347
		numNomRet = $('#taxon').data('numNomRet'),
1042
		numTaxon = $('#taxon').data('nt'),
348
		numTaxon = $('#taxon').data('nt'),
Line 1043... Line 349...
1043
		famille = $('#taxon').data('famille'),
349
		famille = $('#taxon').data('famille'),
1044
		referentiel = (numNomSel == undefined) ? '' : NOM_SCI_REFERENTIEL;
350
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
1045
 
351
 
Line 1046... Line 352...
1046
	$('#liste-obs').data('obsId'+obsNbre, {
352
	$('#liste-obs').data('obsId'+this.obsNbre, {
1047
		'date' : $('#date').val(),
353
		'date' : $('#date').val(),
Line 1065... Line 371...
1065
		'milieu': $('#milieu').val().trim(),
371
		'milieu': $('#milieu').val().trim(),
1066
		'abondance': $('#abondance').val(),
372
		'abondance': $('#abondance').val(),
1067
		'phenologie': $('#phenologie').val(),
373
		'phenologie': $('#phenologie').val(),
Line 1068... Line 374...
1068
 
374
 
1069
		//Ajout des champs images
375
		//Ajout des champs images
Line 1070... Line 376...
1070
		'image_nom' : getNomsImgsOriginales(),
376
		'image_nom' : this.getNomsImgsOriginales(),
1071
 
377
 
1072
		// Ajout des champs étendus de l'obs
-
 
1073
		'obs_etendue': getObsChpEtendus()
-
 
1074
	});
-
 
1075
}
-
 
1076
 
-
 
1077
function getObsChpEtendus() {
-
 
1078
	var champs = [];
-
 
1079
 
-
 
1080
	$('.obs-chp-etendu').each(function() {
-
 
1081
		var valeur = $(this).val(),
-
 
1082
			cle = $(this).attr('name');
-
 
1083
		if (valeur != '') {
-
 
1084
			var chpEtendu = {cle: cle, valeur: valeur.trim()};
-
 
1085
			champs.push(chpEtendu);
378
		// Ajout des champs étendus de l'obs
1086
		}
-
 
1087
	});
-
 
1088
	return champs;
-
 
1089
}
-
 
1090
 
-
 
1091
function surChangementNbreObs() {
-
 
1092
	if (obsNbre == 0) {
-
 
1093
		$('#transmettre-obs').attr('disabled', 'disabled');
-
 
1094
		$('#ajouter-obs').removeAttr('disabled');
-
 
1095
	} else if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
-
 
1096
		$('#transmettre-obs').removeAttr('disabled');
-
 
1097
		$('#ajouter-obs').removeAttr('disabled');
-
 
1098
	} else if (obsNbre >= OBS_MAX_NBRE) {
-
 
1099
		$('#ajouter-obs').attr('disabled', 'disabled');
-
 
1100
		afficherPanneau('#dialogue-bloquer-creer-obs');
-
 
1101
	}
-
 
1102
}
-
 
1103
 
-
 
1104
var nbObsEnCours = 1;
-
 
1105
var totalObsATransmettre = 0;
-
 
1106
function transmettreObs() {
-
 
1107
	var observations = $('#liste-obs').data();
-
 
1108
	if (DEBUG) {
-
 
1109
		console.log(observations);
-
 
1110
	}
-
 
1111
	if (observations == undefined || jQuery.isEmptyObject(observations)) {
-
 
1112
		afficherPanneau('#dialogue-zero-obs');
-
 
1113
	} else {
-
 
1114
		nbObsEnCours = 1;
-
 
1115
		nbObsTransmises = 0;
-
 
1116
		totalObsATransmettre = $.map(observations, function(n, i) { return i; }).length;
-
 
1117
		depilerObsPourEnvoi();
-
 
1118
	}
-
 
1119
	return false;
-
 
1120
}
-
 
1121
 
-
 
1122
function depilerObsPourEnvoi() {
-
 
1123
	var observations = $('#liste-obs').data();
-
 
1124
	// la boucle est factice car on utilise un tableau
-
 
1125
	// dont on a besoin de n'extraire que le premier élément
-
 
1126
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
-
 
1127
	// TODO: utiliser var.keys quand ça sera plus répandu
-
 
1128
	// ou bien utiliser un vrai tableau et pas un objet
-
 
1129
	for (var obsNum in observations) {
-
 
1130
		obsATransmettre = new Object();
-
 
1131
 
-
 
1132
	    obsATransmettre['projet'] = TAG_PROJET;
-
 
1133
	    obsATransmettre['tag-obs'] = TAG_OBS;
-
 
1134
	    obsATransmettre['tag-img'] = TAG_IMG;
-
 
1135
 
-
 
1136
		var utilisateur = new Object();
-
 
1137
		utilisateur.id_utilisateur = $('#id_utilisateur').val();
-
 
1138
		utilisateur.prenom = $('#prenom').val();
-
 
1139
		utilisateur.nom = $('#nom').val();
-
 
1140
		utilisateur.courriel = $('#courriel').val();
-
 
1141
		obsATransmettre['utilisateur'] = utilisateur;
-
 
1142
		obsATransmettre[obsNum] = observations[obsNum];
-
 
1143
		var idObsNumerique = obsNum.replace('obsId', '');
-
 
1144
		if (idObsNumerique != '') {
-
 
1145
			envoyerObsAuCel(idObsNumerique, obsATransmettre);
-
 
1146
		}
-
 
1147
 
-
 
1148
		break;
-
 
1149
	}
-
 
1150
}
-
 
1151
 
-
 
1152
var nbObsTransmises = 0;
-
 
1153
function mettreAJourProgression() {
-
 
1154
	nbObsTransmises++;
-
 
1155
	var pct = (nbObsTransmises/totalObsATransmettre)*100;
-
 
1156
	$('#barre-progression-upload').attr('aria-valuenow', nbObsTransmises);
-
 
1157
	$('#barre-progression-upload').attr('style', 'width: '+pct+'%');
-
 
1158
	$('#barre-progression-upload .sr-only').text(nbObsTransmises+'/'+totalObsATransmettre+' observations transmises');
-
 
1159
 
-
 
1160
	if (obsNbre == 0) {
-
 
1161
		$('.progress').removeClass('active');
-
 
1162
		$('.progress').removeClass('progress-striped');
-
 
1163
	}
-
 
1164
}
-
 
1165
 
-
 
1166
function envoyerObsAuCel(idObs, observation) {
-
 
1167
	var erreurMsg = '';
-
 
1168
	$.ajax({
-
 
1169
		url : SERVICE_SAISIE_URL,
-
 
1170
		type : 'POST',
-
 
1171
		data : observation,
-
 
1172
		dataType : 'json',
-
 
1173
		beforeSend : function() {
-
 
1174
			$('#dialogue-obs-transaction-ko').hide();
-
 
1175
			$('#dialogue-obs-transaction-ok').hide();
-
 
1176
			$('.alert-txt .msg').remove();
-
 
1177
			$('.alert-txt .msg-erreur').remove();
-
 
1178
			$('.alert-txt .msg-debug').remove();
-
 
1179
			$('#chargement').show();
-
 
1180
		},
-
 
1181
		success : function(data, textStatus, jqXHR) {
-
 
1182
			// mise à jour du nombre d'obs à transmettre
-
 
1183
			// et suppression de l'obs
-
 
1184
			supprimerObsParId(idObs);
-
 
1185
			nbObsEnCours++;
-
 
1186
			// mise à jour du statut
-
 
1187
			mettreAJourProgression();
-
 
1188
			if(obsNbre > 0) {
-
 
1189
				// dépilement de la suivante
-
 
1190
				depilerObsPourEnvoi();
-
 
1191
			}
-
 
1192
		},
-
 
1193
		statusCode : {
-
 
1194
			500 : function(jqXHR, textStatus, errorThrown) {
-
 
1195
				erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
1196
		    }
-
 
1197
		},
-
 
1198
		error : function(jqXHR, textStatus, errorThrown) {
-
 
1199
			erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
1200
			try {
-
 
1201
				reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
1202
				if (reponse != null) {
-
 
1203
					$.each(reponse, function (cle, valeur) {
-
 
1204
						erreurMsg += valeur + "\n";
-
 
1205
					});
-
 
1206
				}
-
 
1207
			} catch(e) {
-
 
1208
				erreurMsg += "L'erreur n'était pas en JSON.";
-
 
1209
			}
-
 
1210
		},
-
 
1211
		complete : function(jqXHR, textStatus) {
-
 
1212
			var debugMsg = extraireEnteteDebug(jqXHR);
-
 
1213
 
-
 
1214
			if (erreurMsg != '') {
-
 
1215
				if (DEBUG) {
-
 
1216
					$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
-
 
1217
					$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
-
 
1218
				}
-
 
1219
				var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
-
 
1220
					'subject=Dysfonctionnement du widget de saisie '+TAG_PROJET+
-
 
1221
					'&body='+erreurMsg+'%0D%0ADébogage :%0D%0A'+debugMsg;
-
 
1222
 
-
 
1223
				// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
-
 
1224
				$('#obs'+idObs+' div div').addClass('obs-erreur');
-
 
1225
				window.location.hash = 'obs'+idObs;
-
 
1226
 
-
 
1227
				$('#dialogue-obs-transaction-ko .alert-txt').append($('#tpl-transmission-ko').clone()
-
 
1228
					.find('.courriel-erreur')
-
 
1229
					.attr('href', hrefCourriel)
-
 
1230
					.end()
-
 
1231
					.html());
-
 
1232
				$('#dialogue-obs-transaction-ko').show();
-
 
1233
				$('#chargement').hide();
-
 
1234
				initialiserBarreProgression();
-
 
1235
			} else {
-
 
1236
				if (DEBUG) {
-
 
1237
					$('#dialogue-obs-transaction-ok .alert-txt').append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
-
 
1238
				}
-
 
1239
				if(obsNbre == 0) {
-
 
1240
					setTimeout(function() {
-
 
1241
						$('#chargement').hide();
-
 
1242
						$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
-
 
1243
						$('#dialogue-obs-transaction-ok').show();
-
 
1244
						window.location.hash = 'dialogue-obs-transaction-ok';
-
 
1245
						initialiserObs();
-
 
1246
					}, 1500);
-
 
1247
				}
-
 
1248
			}
-
 
1249
		}
379
		'obs_etendue': this.getObsChpEtendus()
Line 1250... Line 380...
1250
	});
380
	});
1251
}
381
};
1252
 
382
 
1253
function validerFormulaire() {
383
WidgetSaisieMissionsFlore.prototype.validerFormulaire = function() {
1254
	var observateur = $('#form-observateur').valid(),
384
	var observateur = $('#form-observateur').valid(),
1255
		station = $('#form-station').valid(),
385
		station = $('#form-station').valid(),
1256
		obsDate = $('#form-obs-date').valid(),
-
 
1257
		obs = $('#form-obs').valid();
-
 
1258
	return (observateur == true && station == true && obs == true && obsDate == true) ? true : false;
-
 
1259
}
-
 
1260
 
-
 
1261
function getNomsImgsOriginales() {
-
 
1262
	var noms = new Array();
-
 
1263
	$('.miniature-img').each(function() {
-
 
1264
		noms.push($(this).attr('alt'));
-
 
1265
	});
-
 
1266
	return noms;
-
 
1267
}
-
 
1268
 
-
 
1269
function supprimerObs() {
-
 
1270
	var obsId = $(this).val();
-
 
1271
	// Problème avec IE 6 et 7
-
 
1272
	if (obsId == 'Supprimer') {
-
 
1273
		obsId = $(this).attr('title');
-
 
1274
	}
-
 
1275
	supprimerObsParId(obsId);
-
 
1276
}
-
 
1277
 
-
 
1278
function supprimerObsParId(obsId) {
-
 
1279
	obsNbre = obsNbre - 1;
-
 
1280
	$('.obs-nbre').text(obsNbre);
-
 
1281
	$('.obs-nbre').triggerHandler('changement');
-
 
1282
	$('.obs'+obsId).remove();
-
 
1283
	$('#liste-obs').removeData('obsId'+obsId);
-
 
1284
}
-
 
1285
 
-
 
1286
function initialiserBarreProgression() {
-
 
1287
	$('#barre-progression-upload').attr('aria-valuenow', 0);
-
 
1288
	$('#barre-progression-upload').attr('style', 'width: 0%');
-
 
1289
	$('#barre-progression-upload .sr-only').text('0/0 observations transmises');
-
 
1290
	$('.progress').addClass('active');
-
 
1291
	$('.progress').addClass('progress-striped');
-
 
1292
}
-
 
1293
 
-
 
1294
function initialiserObs() {
-
 
1295
	obsNbre = 0;
-
 
1296
	nbObsTransmises = 0;
-
 
1297
	nbObsEnCours = 0;
-
 
1298
	totalObsATransmettre = 0;
-
 
1299
	initialiserBarreProgression();
-
 
1300
	$('.obs-nbre').text(obsNbre);
-
 
1301
	$('.obs-nbre').triggerHandler('changement');
-
 
1302
	$('#liste-obs').removeData();
-
 
1303
	$('.obs').remove();
-
 
1304
	$('#dialogue-bloquer-creer-obs').hide();
-
 
1305
}
-
 
1306
 
-
 
1307
function ajouterImgMiniatureAuTransfert() {
-
 
1308
	var html = '';
-
 
1309
	var miniatures = '';
-
 
1310
	var premiere = true;
-
 
1311
	if ($('#miniatures img').length >= 1) {
-
 
1312
		$('#miniatures img').each(function() {
-
 
1313
			var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee';
-
 
1314
			premiere = false;
-
 
1315
			var css = $(this).hasClass('b64') ? 'thumbnail b64' : 'thumbnail';
-
 
1316
			var src = $(this).attr('src');
-
 
1317
			var alt = $(this).attr('alt');
-
 
1318
			miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
-
 
1319
			miniatures += miniature;
-
 
1320
		});
-
 
1321
		visible = ($('#miniatures img').length > 1) ? '' : 'defilement-miniatures-cache';
-
 
1322
		var html =
-
 
1323
			'<div class="defilement-miniatures">'+
-
 
1324
				'<a class="defilement-miniatures-gauche '+visible+'">&#60;</a>'+
-
 
1325
				miniatures+
-
 
1326
				'<a class="defilement-miniatures-droite '+visible+'">&#62;</a>'+
-
 
1327
			'</div>';
-
 
1328
	} else {
-
 
1329
		html = '<img class="thumbnail" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
-
 
1330
	}
-
 
1331
	return html;
-
 
1332
}
-
 
1333
 
-
 
1334
function defilerMiniatures(element) {
-
 
1335
	var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
-
 
1336
	miniatureSelectionne.removeClass('miniature-selectionnee');
-
 
1337
	miniatureSelectionne.addClass('miniature-cachee');
-
 
1338
	var miniatureAffichee = miniatureSelectionne;
-
 
1339
 
-
 
1340
	if(element.hasClass('defilement-miniatures-gauche')) {
-
 
1341
		if(miniatureSelectionne.prev('.miniature').length != 0) {
-
 
1342
			miniatureAffichee = miniatureSelectionne.prev('.thumbnail');
-
 
1343
		} else {
-
 
1344
			miniatureAffichee = miniatureSelectionne.siblings('.thumbnail').last();
-
 
1345
		}
-
 
1346
	} else {
-
 
1347
		if(miniatureSelectionne.next('.miniature').length != 0) {
-
 
1348
			miniatureAffichee = miniatureSelectionne.next('.thumbnail');
-
 
1349
		} else {
-
 
1350
			miniatureAffichee = miniatureSelectionne.siblings('.thumbnail').first();
-
 
1351
		}
-
 
1352
	}
-
 
1353
	//console.log(miniatureAffichee);
-
 
1354
	miniatureAffichee.addClass('miniature-selectionnee');
-
 
1355
	miniatureAffichee.removeClass('miniature-cachee');
-
 
1356
}
-
 
1357
 
-
 
1358
 
-
 
1359
function formaterNumNomSel(numNomSel) {
-
 
1360
	var nn = '';
-
 
1361
	if (numNomSel == undefined) {
-
 
1362
		nn = '<span class="alert-error">[non lié au référentiel]</span>';
-
 
1363
	} else {
-
 
1364
		nn = '<span class="nn">[nn'+numNomSel+']</span>';
-
 
1365
	}
386
		obsDate = $('#form-obs-date').valid(),
-
 
387
		obs = $('#form-obs').valid();
1366
	return nn;
388
	return (observateur == true && station == true && obs == true && obsDate == true) ? true : false;