| 2360 | jpm | 1 | //+---------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 2 | // GÉNÉRAL
 | 
        
           |  |  | 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 = '';
 | 
        
           | 2372 | jpm | 30 | 	if (jqXHR.getResponseHeader('X-DebugJrest-Data') != '') {
 | 
        
           |  |  | 31 | 		var debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader('X-DebugJrest-Data'));
 | 
        
           | 2360 | jpm | 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) {
 | 
        
           | 2372 | jpm | 42 | 	$(selecteur).fadeIn('slow').delay(DUREE_MESSAGE).fadeOut('slow');
 | 
        
           | 2360 | jpm | 43 | }
 | 
        
           |  |  | 44 |   | 
        
           | 2372 | jpm | 45 |   | 
        
           |  |  | 46 | //+---------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 47 | //FORMULAIRE
 | 
        
           | 2360 | jpm | 48 | $(document).ready(function() {
 | 
        
           | 2372 | jpm | 49 | 	if (OBS_ID != '') {
 | 
        
           |  |  | 50 | 		chargerInfoObs();
 | 
        
           |  |  | 51 | 	}
 | 
        
           |  |  | 52 | });
 | 
        
           | 2360 | jpm | 53 |   | 
        
           | 2372 | jpm | 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
 | 
        
           | 2360 | jpm | 68 | 		}
 | 
        
           |  |  | 69 | 	});
 | 
        
           | 2372 | jpm | 70 | }
 | 
        
           | 2360 | jpm | 71 |   | 
        
           | 2372 | jpm | 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:', ''));
 | 
        
           | 2360 | jpm | 81 | 	}
 | 
        
           |  |  | 82 |   | 
        
           | 2372 | jpm | 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);
 | 
        
           |  |  | 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);
 | 
        
           | 2360 | jpm | 105 | });
 | 
        
           |  |  | 106 |   | 
        
           | 2372 | jpm | 107 | function testerLancementRequeteIdentite(event) {
 | 
        
           |  |  | 108 | 	if (event.which == 13) {
 | 
        
           |  |  | 109 | 		requeterIdentite();
 | 
        
           |  |  | 110 | 		event.preventDefault();
 | 
        
           |  |  | 111 | 		event.stopPropagation();
 | 
        
           |  |  | 112 | 	}
 | 
        
           | 2360 | jpm | 113 | }
 | 
        
           |  |  | 114 |   | 
        
           | 2372 | jpm | 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];
 | 
        
           | 2374 | jpm | 125 | 					surSuccesCompletionCourriel(infos, courriel);
 | 
        
           | 2372 | jpm | 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 | 		});
 | 
        
           | 2360 | jpm | 138 | 	}
 | 
        
           |  |  | 139 | }
 | 
        
           |  |  | 140 |   | 
        
           | 2372 | jpm | 141 | function surErreurCompletionCourriel() {
 | 
        
           |  |  | 142 | 	$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
 | 
        
           |  |  | 143 | 	afficherPanneau('#dialogue-courriel-introuvable');
 | 
        
           | 2360 | jpm | 144 | }
 | 
        
           |  |  | 145 |   | 
        
           | 2374 | jpm | 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 | 	$('#structure').focus();
 | 
        
           |  |  | 153 |   | 
        
           |  |  | 154 | 	$('#dialogue-courriel-introuvable').hide();
 | 
        
           |  |  | 155 | }
 | 
        
           |  |  | 156 |   | 
        
           | 2372 | jpm | 157 | function formaterNom() {
 | 
        
           |  |  | 158 | 	$(this).val($(this).val().toUpperCase());
 | 
        
           | 2360 | jpm | 159 | }
 | 
        
           |  |  | 160 |   | 
        
           | 2372 | jpm | 161 | function formaterPrenom() {
 | 
        
           |  |  | 162 | 	var prenom = new Array(),
 | 
        
           |  |  | 163 | 		mots = $(this).val().split(' ');
 | 
        
           |  |  | 164 | 	for (var i = 0; i < mots.length; i++) {
 | 
        
           |  |  | 165 | 		var mot = mots[i];
 | 
        
           |  |  | 166 | 		if (mot.indexOf('-') >= 0) {
 | 
        
           |  |  | 167 | 			var prenomCompose = new Array(),
 | 
        
           |  |  | 168 | 				motsComposes = mot.split('-');
 | 
        
           |  |  | 169 | 			for (var j = 0; j < motsComposes.length; j++) {
 | 
        
           |  |  | 170 | 				var motSimple = motsComposes[j],
 | 
        
           |  |  | 171 | 					motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
 | 
        
           |  |  | 172 | 				prenomCompose.push(motMajuscule);
 | 
        
           |  |  | 173 | 			}
 | 
        
           |  |  | 174 | 			prenom.push(prenomCompose.join('-'));
 | 
        
           |  |  | 175 | 		} else {
 | 
        
           |  |  | 176 | 			var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
 | 
        
           |  |  | 177 | 			prenom.push(motMajuscule);
 | 
        
           |  |  | 178 | 		}
 | 
        
           | 2360 | jpm | 179 | 	}
 | 
        
           | 2372 | jpm | 180 | 	$(this).val(prenom.join(' '));
 | 
        
           |  |  | 181 | }
 | 
        
           | 2360 | jpm | 182 |   | 
        
           | 2372 | jpm | 183 | function bloquerCopierCollerCourriel() {
 | 
        
           |  |  | 184 | 	afficherPanneau('#dialogue-bloquer-copier-coller');
 | 
        
           |  |  | 185 | 	return false;
 | 
        
           |  |  | 186 | }
 | 
        
           | 2360 | jpm | 187 |   | 
        
           |  |  | 188 |   | 
        
           |  |  | 189 | //+----------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 190 | // GOOGLE MAP
 | 
        
           | 2372 | jpm | 191 | var map,
 | 
        
           |  |  | 192 | 	marker,
 | 
        
           |  |  | 193 | 	latLng,
 | 
        
           |  |  | 194 | 	geocoder;
 | 
        
           | 2360 | jpm | 195 |   | 
        
           |  |  | 196 | $(document).ready(function() {
 | 
        
           |  |  | 197 | 	initialiserGoogleMap();
 | 
        
           |  |  | 198 | 	initialiserAutocompleteCommune();
 | 
        
           |  |  | 199 | });
 | 
        
           |  |  | 200 |   | 
        
           |  |  | 201 | function afficherErreurGoogleMap(status) {
 | 
        
           |  |  | 202 | 	if (DEBUG) {
 | 
        
           |  |  | 203 | 		$('#dialogue-google-map .contenu').empty().append(
 | 
        
           |  |  | 204 | 			'<pre class="msg-erreur">'+
 | 
        
           |  |  | 205 | 			"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
 | 
        
           |  |  | 206 | 			'</pre>');
 | 
        
           |  |  | 207 | 		afficherPanneau('#dialogue-google-map');
 | 
        
           |  |  | 208 | 	}
 | 
        
           |  |  | 209 | }
 | 
        
           |  |  | 210 |   | 
        
           |  |  | 211 | function surDeplacementMarker() {
 | 
        
           |  |  | 212 | 	mettreAJourMarkerPosition(marker.getPosition());
 | 
        
           |  |  | 213 | }
 | 
        
           |  |  | 214 |   | 
        
           |  |  | 215 | function surClickDansCarte(event) {
 | 
        
           |  |  | 216 | 	deplacerMarker(event.latLng);
 | 
        
           |  |  | 217 | }
 | 
        
           |  |  | 218 |   | 
        
           |  |  | 219 | function geolocaliser() {
 | 
        
           | 2372 | jpm | 220 | 	var latitude = $('#latitude').val(),
 | 
        
           |  |  | 221 | 		longitude = $('#longitude').val();
 | 
        
           | 2360 | jpm | 222 | 	latLng = new google.maps.LatLng(latitude, longitude);
 | 
        
           |  |  | 223 | 	deplacerMarker(latLng);
 | 
        
           |  |  | 224 | }
 | 
        
           |  |  | 225 |   | 
        
           |  |  | 226 | function initialiserGoogleMap(){
 | 
        
           |  |  | 227 | 	// Carte
 | 
        
           | 2408 | jpm | 228 | 	var latLng = new google.maps.LatLng(45.1667, 5.7905);// Centre de l'Isère
 | 
        
           |  |  | 229 | 	var zoomDefaut = 8;
 | 
        
           | 2360 | jpm | 230 |   | 
        
           |  |  | 231 | 	var options = {
 | 
        
           |  |  | 232 | 		zoom: zoomDefaut,
 | 
        
           |  |  | 233 | 		center: latLng,
 | 
        
           |  |  | 234 | 		mapTypeId: google.maps.MapTypeId.HYBRID,
 | 
        
           |  |  | 235 | 		mapTypeControlOptions: {
 | 
        
           |  |  | 236 | 			mapTypeIds: ['OSM', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]}
 | 
        
           |  |  | 237 | 	};
 | 
        
           |  |  | 238 |   | 
        
           |  |  | 239 | 	// Ajout de la couche OSM à la carte
 | 
        
           |  |  | 240 | 	osmMapType = new google.maps.ImageMapType({
 | 
        
           |  |  | 241 | 		getTileUrl: function(coord, zoom) {
 | 
        
           | 2372 | jpm | 242 | 			return 'http://tile.openstreetmap.org/' +
 | 
        
           |  |  | 243 | 			zoom + '/' + coord.x + '/' + coord.y + '.png';
 | 
        
           | 2360 | jpm | 244 | 		},
 | 
        
           |  |  | 245 | 		tileSize: new google.maps.Size(256, 256),
 | 
        
           |  |  | 246 | 		isPng: true,
 | 
        
           |  |  | 247 | 		alt: 'OpenStreetMap',
 | 
        
           |  |  | 248 | 		name: 'OSM',
 | 
        
           |  |  | 249 | 		maxZoom: 19
 | 
        
           |  |  | 250 | 	});
 | 
        
           |  |  | 251 |   | 
        
           |  |  | 252 | 	// Création de la carte Google
 | 
        
           |  |  | 253 | 	map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
 | 
        
           |  |  | 254 | 	map.mapTypes.set('OSM', osmMapType);
 | 
        
           |  |  | 255 |   | 
        
           |  |  | 256 | 	// Création du Geocoder
 | 
        
           |  |  | 257 | 	geocoder = new google.maps.Geocoder();
 | 
        
           |  |  | 258 |   | 
        
           |  |  | 259 | 	// Marqueur google draggable
 | 
        
           |  |  | 260 | 	marker = new google.maps.Marker({
 | 
        
           |  |  | 261 | 		map: map,
 | 
        
           |  |  | 262 | 		draggable: true,
 | 
        
           |  |  | 263 | 		title: 'Ma station',
 | 
        
           |  |  | 264 | 		icon: GOOGLE_MAP_MARQUEUR_URL,
 | 
        
           |  |  | 265 | 		position: latLng
 | 
        
           |  |  | 266 | 	});
 | 
        
           |  |  | 267 |   | 
        
           |  |  | 268 | 	initialiserMarker(latLng);
 | 
        
           |  |  | 269 |   | 
        
           |  |  | 270 | 	// Tentative de geocalisation
 | 
        
           |  |  | 271 | 	if (navigator.geolocation) {
 | 
        
           |  |  | 272 | 		navigator.geolocation.getCurrentPosition(function(position) {
 | 
        
           |  |  | 273 | 			var latitude = position.coords.latitude;
 | 
        
           |  |  | 274 | 			var longitude = position.coords.longitude;
 | 
        
           |  |  | 275 | 			latLng = new google.maps.LatLng(latitude, longitude);
 | 
        
           |  |  | 276 | 			deplacerMarker(latLng);
 | 
        
           |  |  | 277 | 		});
 | 
        
           |  |  | 278 | 	}
 | 
        
           |  |  | 279 |   | 
        
           |  |  | 280 | 	// intéraction carte
 | 
        
           | 2372 | jpm | 281 | 	$('#geolocaliser').on('click', geolocaliser);
 | 
        
           | 2360 | jpm | 282 | 	google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
 | 
        
           |  |  | 283 | 	google.maps.event.addListener(map, 'click', surClickDansCarte);
 | 
        
           |  |  | 284 | }
 | 
        
           |  |  | 285 |   | 
        
           |  |  | 286 | function initialiserMarker(latLng) {
 | 
        
           |  |  | 287 | 	if (marker != undefined) {
 | 
        
           |  |  | 288 | 		marker.setPosition(latLng);
 | 
        
           |  |  | 289 | 		map.setCenter(latLng);
 | 
        
           | 2372 | jpm | 290 | 		mettreAJourMarkerPosition(latLng);
 | 
        
           | 2360 | jpm | 291 | 	}
 | 
        
           |  |  | 292 | }
 | 
        
           |  |  | 293 |   | 
        
           |  |  | 294 | function deplacerMarker(latLng) {
 | 
        
           |  |  | 295 | 	if (marker != undefined) {
 | 
        
           |  |  | 296 | 		marker.setPosition(latLng);
 | 
        
           |  |  | 297 | 		map.setCenter(latLng);
 | 
        
           |  |  | 298 | 		mettreAJourMarkerPosition(latLng);
 | 
        
           |  |  | 299 | 	}
 | 
        
           |  |  | 300 | }
 | 
        
           |  |  | 301 |   | 
        
           |  |  | 302 | function mettreAJourMarkerPosition(latLng) {
 | 
        
           | 2372 | jpm | 303 | 	trouverCommune(latLng);
 | 
        
           |  |  | 304 | 	trouverAltitude(latLng);
 | 
        
           |  |  | 305 |   | 
        
           |  |  | 306 | 	var lat = latLng.lat().toFixed(5),
 | 
        
           |  |  | 307 | 		lng = latLng.lng().toFixed(5);
 | 
        
           | 2360 | jpm | 308 | 	remplirChampLatitude(lat);
 | 
        
           |  |  | 309 | 	remplirChampLongitude(lng);
 | 
        
           | 2372 | jpm | 310 | 	remplirChampsLambert93(lat, lng);
 | 
        
           | 2360 | jpm | 311 | }
 | 
        
           |  |  | 312 |   | 
        
           |  |  | 313 | function remplirChampLatitude(latDecimale) {
 | 
        
           |  |  | 314 | 	var lat = Math.round(latDecimale * 100000) / 100000;
 | 
        
           |  |  | 315 | 	$('#latitude').val(lat);
 | 
        
           |  |  | 316 | }
 | 
        
           |  |  | 317 |   | 
        
           |  |  | 318 | function remplirChampLongitude(lngDecimale) {
 | 
        
           |  |  | 319 | 	var lng = Math.round(lngDecimale * 100000) / 100000;
 | 
        
           |  |  | 320 | 	$('#longitude').val(lng);
 | 
        
           |  |  | 321 | }
 | 
        
           |  |  | 322 |   | 
        
           | 2372 | jpm | 323 | proj4.defs([
 | 
        
           |  |  | 324 | 	['EPSG:4326', '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'],
 | 
        
           |  |  | 325 | 	['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']
 | 
        
           |  |  | 326 | ]);
 | 
        
           |  |  | 327 | function remplirChampsLambert93(lat, lng) {
 | 
        
           |  |  | 328 | 	// Prendre en compte l'initialisation des projections
 | 
        
           |  |  | 329 | 	var coordinate = {x: lng,y: lat};
 | 
        
           |  |  | 330 | 	proj4(proj4.defs('EPSG:4326'), proj4.defs('EPSG:2154')).forward(coordinate);
 | 
        
           |  |  | 331 | 	$('#l93-x').val(coordinate.x.toFixed(0));
 | 
        
           |  |  | 332 | 	$('#l93-y').val(coordinate.y.toFixed(0));
 | 
        
           |  |  | 333 | }
 | 
        
           |  |  | 334 |   | 
        
           |  |  | 335 | function trouverAltitude(pos) {
 | 
        
           | 2360 | jpm | 336 | 	$(function() {
 | 
        
           | 2372 | jpm | 337 | 		var url_service = SERVICE_ALTITUDE_URL,
 | 
        
           |  |  | 338 | 			urlAltFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
 | 
        
           |  |  | 339 | 		$.ajax({
 | 
        
           |  |  | 340 | 			url: urlAltFormatee,
 | 
        
           |  |  | 341 | 			type: 'GET',
 | 
        
           |  |  | 342 | 			dataType: 'jsonp',
 | 
        
           |  |  | 343 | 			beforeSend : function() {
 | 
        
           |  |  | 344 | 				$('#altitude').empty();
 | 
        
           |  |  | 345 | 				$('#dialogue-erreur .alert-txt').empty();
 | 
        
           |  |  | 346 | 			},
 | 
        
           |  |  | 347 | 			success : function(data, textStatus, jqXHR) {
 | 
        
           |  |  | 348 | 				$('#altitude').empty().append(data.altitude);
 | 
        
           |  |  | 349 | 				$('#marqueur-altitude').data('altitude', data.altitude);
 | 
        
           |  |  | 350 | 			},
 | 
        
           |  |  | 351 | 			statusCode : {
 | 
        
           |  |  | 352 | 			    500 : function(jqXHR, textStatus, errorThrown) {
 | 
        
           |  |  | 353 | 					if (DEBUG) {
 | 
        
           |  |  | 354 | 						$('#dialogue-erreur .alert-txt').append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissant l\'altitude.</p>');
 | 
        
           |  |  | 355 | 						reponse = jQuery.parseJSON(jqXHR.responseText);
 | 
        
           |  |  | 356 | 						var erreurMsg = '';
 | 
        
           |  |  | 357 | 						if (reponse != null) {
 | 
        
           |  |  | 358 | 							$.each(reponse, function (cle, valeur) {
 | 
        
           |  |  | 359 | 								erreurMsg += valeur + '<br />';
 | 
        
           |  |  | 360 | 							});
 | 
        
           |  |  | 361 | 						}
 | 
        
           | 2360 | jpm | 362 |   | 
        
           | 2372 | jpm | 363 | 						$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
 | 
        
           |  |  | 364 | 					}
 | 
        
           |  |  | 365 | 			    }
 | 
        
           |  |  | 366 | 			},
 | 
        
           |  |  | 367 | 			error : function(jqXHR, textStatus, errorThrown) {
 | 
        
           |  |  | 368 | 				if (DEBUG) {
 | 
        
           |  |  | 369 | 					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de l\'appel au service fournissant l\'altitude.</p>');
 | 
        
           |  |  | 370 | 					reponse = jQuery.parseJSON(jqXHR.responseText);
 | 
        
           |  |  | 371 | 					var erreurMsg = '';
 | 
        
           |  |  | 372 | 					if (reponse != null) {
 | 
        
           |  |  | 373 | 						$.each(reponse, function (cle, valeur) {
 | 
        
           |  |  | 374 | 							erreurMsg += valeur + '<br />';
 | 
        
           |  |  | 375 | 						});
 | 
        
           |  |  | 376 | 					}
 | 
        
           | 2360 | jpm | 377 |   | 
        
           | 2372 | jpm | 378 | 					$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
 | 
        
           |  |  | 379 | 				}
 | 
        
           |  |  | 380 | 			},
 | 
        
           |  |  | 381 | 			complete : function(jqXHR, textStatus) {
 | 
        
           |  |  | 382 | 				var debugMsg = extraireEnteteDebug(jqXHR);
 | 
        
           |  |  | 383 | 				if (debugMsg != '') {
 | 
        
           |  |  | 384 | 					if (DEBUG) {
 | 
        
           |  |  | 385 | 						$('#dialogue-erreur .alert-txt').append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
 | 
        
           |  |  | 386 | 					}
 | 
        
           |  |  | 387 | 				}
 | 
        
           |  |  | 388 | 				if ($('#dialogue-erreur .msg').length > 0) {
 | 
        
           |  |  | 389 | 					$('#dialogue-erreur').show();
 | 
        
           |  |  | 390 | 				}
 | 
        
           |  |  | 391 | 			}
 | 
        
           |  |  | 392 | 		});
 | 
        
           |  |  | 393 | 	});
 | 
        
           |  |  | 394 | }
 | 
        
           |  |  | 395 |   | 
        
           |  |  | 396 | function trouverCommune(pos) {
 | 
        
           |  |  | 397 | 	$(function() {
 | 
        
           |  |  | 398 | 		var url_service = SERVICE_NOM_COMMUNE_URL,
 | 
        
           |  |  | 399 | 			urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
 | 
        
           | 2360 | jpm | 400 | 		$.ajax({
 | 
        
           | 2372 | jpm | 401 | 			url: urlNomCommuneFormatee,
 | 
        
           |  |  | 402 | 			type: 'GET',
 | 
        
           |  |  | 403 | 			dataType: 'jsonp',
 | 
        
           | 2360 | jpm | 404 | 			beforeSend : function() {
 | 
        
           | 2372 | jpm | 405 | 				$('.commune-info').empty();
 | 
        
           |  |  | 406 | 				$('#dialogue-erreur .alert-txt').empty();
 | 
        
           | 2360 | jpm | 407 | 			},
 | 
        
           |  |  | 408 | 			success : function(data, textStatus, jqXHR) {
 | 
        
           | 2372 | jpm | 409 | 				$('.commune-info').empty();
 | 
        
           |  |  | 410 | 				$('#commune-nom').append(data.nom);
 | 
        
           |  |  | 411 | 				$('#commune-code-insee').append(data.codeINSEE);
 | 
        
           |  |  | 412 | 				$('#marqueur-commune').data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
 | 
        
           | 2360 | jpm | 413 | 			},
 | 
        
           |  |  | 414 | 			statusCode : {
 | 
        
           |  |  | 415 | 			    500 : function(jqXHR, textStatus, errorThrown) {
 | 
        
           |  |  | 416 | 					if (DEBUG) {
 | 
        
           | 2372 | jpm | 417 | 						$('#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>');
 | 
        
           | 2360 | jpm | 418 | 						reponse = jQuery.parseJSON(jqXHR.responseText);
 | 
        
           | 2372 | jpm | 419 | 						var erreurMsg = '';
 | 
        
           | 2360 | jpm | 420 | 						if (reponse != null) {
 | 
        
           |  |  | 421 | 							$.each(reponse, function (cle, valeur) {
 | 
        
           | 2372 | jpm | 422 | 								erreurMsg += valeur + '<br />';
 | 
        
           | 2360 | jpm | 423 | 							});
 | 
        
           |  |  | 424 | 						}
 | 
        
           |  |  | 425 |   | 
        
           | 2372 | jpm | 426 | 						$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
 | 
        
           | 2360 | jpm | 427 | 					}
 | 
        
           |  |  | 428 | 			    }
 | 
        
           |  |  | 429 | 			},
 | 
        
           |  |  | 430 | 			error : function(jqXHR, textStatus, errorThrown) {
 | 
        
           |  |  | 431 | 				if (DEBUG) {
 | 
        
           |  |  | 432 | 					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
 | 
        
           |  |  | 433 | 					reponse = jQuery.parseJSON(jqXHR.responseText);
 | 
        
           | 2372 | jpm | 434 | 					var erreurMsg = '';
 | 
        
           | 2360 | jpm | 435 | 					if (reponse != null) {
 | 
        
           |  |  | 436 | 						$.each(reponse, function (cle, valeur) {
 | 
        
           | 2372 | jpm | 437 | 							erreurMsg += valeur + '<br />';
 | 
        
           | 2360 | jpm | 438 | 						});
 | 
        
           |  |  | 439 | 					}
 | 
        
           |  |  | 440 |   | 
        
           | 2372 | jpm | 441 | 					$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
 | 
        
           | 2360 | jpm | 442 | 				}
 | 
        
           |  |  | 443 | 			},
 | 
        
           |  |  | 444 | 			complete : function(jqXHR, textStatus) {
 | 
        
           |  |  | 445 | 				var debugMsg = extraireEnteteDebug(jqXHR);
 | 
        
           |  |  | 446 | 				if (debugMsg != '') {
 | 
        
           |  |  | 447 | 					if (DEBUG) {
 | 
        
           | 2372 | jpm | 448 | 						$('#dialogue-erreur .alert-txt').append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
 | 
        
           | 2360 | jpm | 449 | 					}
 | 
        
           |  |  | 450 | 				}
 | 
        
           | 2372 | jpm | 451 | 				if ($('#dialogue-erreur .msg').length > 0) {
 | 
        
           |  |  | 452 | 					$('#dialogue-erreur').show();
 | 
        
           | 2360 | jpm | 453 | 				}
 | 
        
           |  |  | 454 | 			}
 | 
        
           |  |  | 455 | 		});
 | 
        
           |  |  | 456 | 	});
 | 
        
           |  |  | 457 | }
 | 
        
           | 2372 | jpm | 458 |   | 
        
           |  |  | 459 |   | 
        
           | 2360 | jpm | 460 | //+---------------------------------------------------------------------------------------------------------+
 | 
        
           | 2372 | jpm | 461 | //AUTO-COMPLÉTION Noms Scientifiques
 | 
        
           | 2360 | jpm | 462 |   | 
        
           | 2372 | jpm | 463 | function ajouterAutocompletionNoms() {
 | 
        
           |  |  | 464 | 	$('#taxon').autocomplete({
 | 
        
           |  |  | 465 | 		source: function(requete, add){
 | 
        
           |  |  | 466 | 			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
 | 
        
           | 2360 | jpm | 467 |   | 
        
           | 2372 | jpm | 468 | 			var url = getUrlAutocompletionNomsSci();
 | 
        
           |  |  | 469 | 			$.getJSON(url, function(data) {
 | 
        
           |  |  | 470 | 				var suggestions = traiterRetourNomsSci(data);
 | 
        
           |  |  | 471 | 				add(suggestions);
 | 
        
           |  |  | 472 | 			});
 | 
        
           | 2360 | jpm | 473 | 		},
 | 
        
           | 2372 | jpm | 474 | 		html: true
 | 
        
           |  |  | 475 | 	});
 | 
        
           |  |  | 476 |   | 
        
           |  |  | 477 | 	$('#taxon').on('autocompleteselect', function(event, ui) {
 | 
        
           |  |  | 478 | 		$('#taxon').data(ui.item);
 | 
        
           |  |  | 479 | 		if (ui.item.retenu == true) {
 | 
        
           |  |  | 480 | 			$('#taxon').addClass('ns-retenu');
 | 
        
           |  |  | 481 | 		} else {
 | 
        
           |  |  | 482 | 			$('#taxon').removeClass('ns-retenu');
 | 
        
           | 2360 | jpm | 483 | 		}
 | 
        
           |  |  | 484 | 	});
 | 
        
           |  |  | 485 | }
 | 
        
           |  |  | 486 |   | 
        
           | 2372 | jpm | 487 | function getUrlAutocompletionNomsSci() {
 | 
        
           |  |  | 488 | 	var mots = $('#taxon').val(),
 | 
        
           | 2408 | jpm | 489 | 		url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_REFERENTIEL);
 | 
        
           | 2372 | jpm | 490 | 	url = url.replace('{masque}', mots);
 | 
        
           |  |  | 491 | 	return url;
 | 
        
           | 2360 | jpm | 492 | }
 | 
        
           | 2372 | jpm | 493 |   | 
        
           |  |  | 494 | function traiterRetourNomsSci(data) {
 | 
        
           |  |  | 495 | 	var suggestions = [];
 | 
        
           |  |  | 496 | 	if (data.resultat != undefined) {
 | 
        
           |  |  | 497 | 		$.each(data.resultat, function(i, val) {
 | 
        
           |  |  | 498 | 			val.nn = i;
 | 
        
           |  |  | 499 | 			var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
 | 
        
           |  |  | 500 | 				nomRet: '', numNomRet: '', famille: '', retenu: false
 | 
        
           |  |  | 501 | 			};
 | 
        
           |  |  | 502 | 			if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
 | 
        
           |  |  | 503 | 				nom.label = '...';
 | 
        
           |  |  | 504 | 				nom.value = $('#taxon').val();
 | 
        
           |  |  | 505 | 				suggestions.push(nom);
 | 
        
           |  |  | 506 | 				return false;
 | 
        
           |  |  | 507 | 			} else {
 | 
        
           |  |  | 508 | 				nom.label = val.nom_sci_complet;
 | 
        
           |  |  | 509 | 				nom.value = val.nom_sci_complet;
 | 
        
           |  |  | 510 | 				nom.nt = val.num_taxonomique;
 | 
        
           |  |  | 511 | 				nom.nomSel = val.nom_sci;
 | 
        
           |  |  | 512 | 				nom.nomSelComplet = val.nom_sci_complet;
 | 
        
           |  |  | 513 | 				nom.numNomSel = val.nn;
 | 
        
           |  |  | 514 | 				nom.nomRet = val.nom_retenu_complet;
 | 
        
           |  |  | 515 | 				nom.numNomRet = val['nom_retenu.id'];
 | 
        
           |  |  | 516 | 				nom.famille = val.famille;
 | 
        
           |  |  | 517 | 				nom.retenu = (val.retenu == 'false') ? false : true;
 | 
        
           |  |  | 518 |   | 
        
           |  |  | 519 | 				suggestions.push(nom);
 | 
        
           |  |  | 520 | 			}
 | 
        
           |  |  | 521 | 		});
 | 
        
           | 2360 | jpm | 522 | 	}
 | 
        
           | 2372 | jpm | 523 | 	return suggestions;
 | 
        
           |  |  | 524 | }
 | 
        
           | 2360 | jpm | 525 |   | 
        
           | 2372 | jpm | 526 | /*
 | 
        
           |  |  | 527 | * jQuery UI Autocomplete HTML Extension
 | 
        
           |  |  | 528 | *
 | 
        
           |  |  | 529 | * Copyright 2010, Scott González (http://scottgonzalez.com)
 | 
        
           |  |  | 530 | * Dual licensed under the MIT or GPL Version 2 licenses.
 | 
        
           |  |  | 531 | *
 | 
        
           |  |  | 532 | * http://github.com/scottgonzalez/jquery-ui-extensions
 | 
        
           |  |  | 533 | *
 | 
        
           |  |  | 534 | * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
 | 
        
           |  |  | 535 | */
 | 
        
           |  |  | 536 | (function($) {
 | 
        
           |  |  | 537 | 	var proto = $.ui.autocomplete.prototype,
 | 
        
           |  |  | 538 | 		initSource = proto._initSource;
 | 
        
           |  |  | 539 |   | 
        
           |  |  | 540 | 	function filter(array, term) {
 | 
        
           |  |  | 541 | 		var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
 | 
        
           |  |  | 542 | 		return $.grep(array, function(value) {
 | 
        
           |  |  | 543 | 			return matcher.test($('<div>').html(value.label || value.value || value).text());
 | 
        
           |  |  | 544 | 		});
 | 
        
           |  |  | 545 | 	}
 | 
        
           |  |  | 546 |   | 
        
           |  |  | 547 | 	$.extend(proto, {
 | 
        
           |  |  | 548 | 		_initSource: function() {
 | 
        
           |  |  | 549 | 			if (this.options.html && $.isArray(this.options.source)) {
 | 
        
           |  |  | 550 | 				this.source = function( request, response ) {
 | 
        
           |  |  | 551 | 					response(filter(this.options.source, request.term));
 | 
        
           |  |  | 552 | 				};
 | 
        
           |  |  | 553 | 			} else {
 | 
        
           |  |  | 554 | 				initSource.call(this);
 | 
        
           | 2360 | jpm | 555 | 			}
 | 
        
           |  |  | 556 | 		},
 | 
        
           | 2372 | jpm | 557 | 		_renderItem: function(ul, item) {
 | 
        
           |  |  | 558 | 			if (item.retenu == true) {
 | 
        
           |  |  | 559 | 				item.label = '<strong>'+item.label+'</strong>';
 | 
        
           |  |  | 560 | 			}
 | 
        
           |  |  | 561 |   | 
        
           |  |  | 562 | 			return $('<li></li>')
 | 
        
           |  |  | 563 | 				.data('item.autocomplete', item)
 | 
        
           |  |  | 564 | 				.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
 | 
        
           |  |  | 565 | 				.appendTo(ul);
 | 
        
           | 2360 | jpm | 566 | 		}
 | 
        
           |  |  | 567 | 	});
 | 
        
           | 2372 | jpm | 568 | })(jQuery);
 | 
        
           | 2360 | jpm | 569 |   | 
        
           | 2372 | jpm | 570 | //+----------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 571 | //UPLOAD PHOTO : Traitement de l'image
 | 
        
           |  |  | 572 | $(document).ready(function() {
 | 
        
           |  |  | 573 | 	$('.effacer-miniature').click(function () {
 | 
        
           |  |  | 574 | 		supprimerMiniatures($(this));
 | 
        
           |  |  | 575 | 	});
 | 
        
           | 2360 | jpm | 576 |   | 
        
           | 2372 | jpm | 577 | 	$('#fichier').on('change', function (e) {
 | 
        
           |  |  | 578 | 		arreter(e);
 | 
        
           |  |  | 579 | 		var options = {
 | 
        
           |  |  | 580 | 			success: afficherMiniature, // post-submit callback
 | 
        
           |  |  | 581 | 			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
 | 
        
           |  |  | 582 | 			resetForm: true // reset the form after successful submit
 | 
        
           |  |  | 583 | 		};
 | 
        
           |  |  | 584 | 		$('#ajouter-obs').attr('disabled', 'disabled');
 | 
        
           |  |  | 585 | 		if (verifierFormat($('#fichier').val())) {
 | 
        
           |  |  | 586 | 			$('#form-upload').ajaxSubmit(options);
 | 
        
           |  |  | 587 | 		} else {
 | 
        
           |  |  | 588 | 			$('#form-upload')[0].reset();
 | 
        
           |  |  | 589 | 			window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+$('#fichier').attr('accept'));
 | 
        
           |  |  | 590 | 		}
 | 
        
           |  |  | 591 | 		return false;
 | 
        
           |  |  | 592 | 	});
 | 
        
           | 2360 | jpm | 593 |   | 
        
           | 2372 | jpm | 594 | 	if (ESPECE_IMPOSEE) {
 | 
        
           |  |  | 595 | 		$('#taxon').attr('disabled', 'disabled');
 | 
        
           |  |  | 596 | 		$('#taxon-input-groupe').attr('title', '');
 | 
        
           |  |  | 597 | 		var infosAssociee = new Object();
 | 
        
           |  |  | 598 | 		infosAssociee.label = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
 | 
        
           |  |  | 599 | 		infosAssociee.value = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
 | 
        
           |  |  | 600 | 		infosAssociee.nt = INFOS_ESPECE_IMPOSEE.num_taxonomique;
 | 
        
           |  |  | 601 | 		infosAssociee.nomSel = INFOS_ESPECE_IMPOSEE.nom_sci;
 | 
        
           |  |  | 602 | 		infosAssociee.nomSelComplet = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
 | 
        
           |  |  | 603 | 		infosAssociee.numNomSel = INFOS_ESPECE_IMPOSEE.id;
 | 
        
           |  |  | 604 | 		infosAssociee.nomRet = INFOS_ESPECE_IMPOSEE['nom_retenu.libelle'];
 | 
        
           |  |  | 605 | 		infosAssociee.numNomRet = INFOS_ESPECE_IMPOSEE['nom_retenu.id'];
 | 
        
           |  |  | 606 | 		infosAssociee.famille = INFOS_ESPECE_IMPOSEE.famille;
 | 
        
           |  |  | 607 | 		infosAssociee.retenu = (INFOS_ESPECE_IMPOSEE.retenu == 'false') ? false : true;
 | 
        
           |  |  | 608 | 		$('#taxon').data(infosAssociee);
 | 
        
           | 2360 | jpm | 609 | 	}
 | 
        
           |  |  | 610 |   | 
        
           | 2372 | jpm | 611 | 	$('body').on('click', '.effacer-miniature', function() {
 | 
        
           |  |  | 612 | 		$(this).parent().remove();
 | 
        
           |  |  | 613 | 	});
 | 
        
           |  |  | 614 | });
 | 
        
           |  |  | 615 |   | 
        
           |  |  | 616 | function verifierFormat(nom) {
 | 
        
           |  |  | 617 | 	var parts = nom.split('.');
 | 
        
           |  |  | 618 | 	extension = parts[parts.length - 1];
 | 
        
           |  |  | 619 | 	return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
 | 
        
           |  |  | 620 | }
 | 
        
           |  |  | 621 |   | 
        
           |  |  | 622 | function afficherMiniature(reponse) {
 | 
        
           |  |  | 623 | 	if (DEBUG) {
 | 
        
           |  |  | 624 | 		var debogage = $('debogage', reponse).text();
 | 
        
           |  |  | 625 | 		console.log("Débogage upload : "+debogage);
 | 
        
           | 2360 | jpm | 626 | 	}
 | 
        
           | 2372 | jpm | 627 | 	var message = $('message', reponse).text();
 | 
        
           |  |  | 628 | 	if (message != '') {
 | 
        
           |  |  | 629 | 		$('#miniature-msg').append(message);
 | 
        
           |  |  | 630 | 	} else {
 | 
        
           |  |  | 631 | 		$('#miniatures').append(creerWidgetMiniature(reponse));
 | 
        
           |  |  | 632 | 	}
 | 
        
           |  |  | 633 | 	$('#ajouter-obs').removeAttr('disabled');
 | 
        
           | 2360 | jpm | 634 | }
 | 
        
           |  |  | 635 |   | 
        
           | 2372 | jpm | 636 | function creerWidgetMiniature(reponse) {
 | 
        
           |  |  | 637 | 	var miniatureUrl = $('miniature-url', reponse).text();
 | 
        
           |  |  | 638 | 	var imgNom = $('image-nom', reponse).text();
 | 
        
           |  |  | 639 | 	var html =
 | 
        
           |  |  | 640 | 		'<div class="miniature">'+
 | 
        
           |  |  | 641 | 			'<img class="miniature-img thumbnail" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
 | 
        
           |  |  | 642 | 			'<button class="effacer-miniature" type="button">Effacer</button>'+
 | 
        
           |  |  | 643 | 		'</div>'
 | 
        
           |  |  | 644 | 	return html;
 | 
        
           |  |  | 645 | }
 | 
        
           |  |  | 646 |   | 
        
           |  |  | 647 | function supprimerMiniatures() {
 | 
        
           |  |  | 648 | 	$('#miniatures').empty();
 | 
        
           |  |  | 649 | 	$('#miniature-msg').empty();
 | 
        
           |  |  | 650 | }
 | 
        
           |  |  | 651 |   | 
        
           |  |  | 652 | //Initialise l'autocomplétion de la commune, en fonction du référentiel
 | 
        
           |  |  | 653 | function initialiserAutocompleteCommune() {
 | 
        
           |  |  | 654 | 	var geocoderOptions = {},
 | 
        
           |  |  | 655 | 		addressSuffix = '';
 | 
        
           |  |  | 656 |   | 
        
           | 2408 | jpm | 657 | 	geocoderOptions.region = 'fr';
 | 
        
           |  |  | 658 | 	addressSuffix = ', France';
 | 
        
           | 2372 | jpm | 659 |   | 
        
           |  |  | 660 | 	$('#carte-recherche').autocomplete({
 | 
        
           |  |  | 661 | 		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
 | 
        
           |  |  | 662 | 		source: function(request, response) {
 | 
        
           |  |  | 663 | 			geocoderOptions.address = request.term + addressSuffix;
 | 
        
           |  |  | 664 | 			geocoder.geocode( geocoderOptions, function(results, status) {
 | 
        
           |  |  | 665 | 				if (status == google.maps.GeocoderStatus.OK) {
 | 
        
           |  |  | 666 | 					response($.map(results, function(item) {
 | 
        
           |  |  | 667 | 						var retour = {
 | 
        
           |  |  | 668 | 							label: item.formatted_address,
 | 
        
           |  |  | 669 | 							value: item.formatted_address,
 | 
        
           |  |  | 670 | 							latitude: item.geometry.location.lat(),
 | 
        
           |  |  | 671 | 							longitude: item.geometry.location.lng()
 | 
        
           |  |  | 672 | 						};
 | 
        
           |  |  | 673 | 						return retour;
 | 
        
           |  |  | 674 | 					}));
 | 
        
           |  |  | 675 | 				} else {
 | 
        
           |  |  | 676 | 					afficherErreurGoogleMap(status);
 | 
        
           |  |  | 677 | 				}
 | 
        
           |  |  | 678 | 			});
 | 
        
           |  |  | 679 | 		},
 | 
        
           |  |  | 680 | 		// Cette partie est executee a la selection d'une adresse
 | 
        
           |  |  | 681 | 		select: function(event, ui) {
 | 
        
           |  |  | 682 | 			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
 | 
        
           |  |  | 683 | 			deplacerMarker(latLng);
 | 
        
           |  |  | 684 | 		}
 | 
        
           |  |  | 685 | 	});
 | 
        
           |  |  | 686 |   | 
        
           |  |  | 687 | 	// Autocompletion du champ adresse
 | 
        
           |  |  | 688 | 	$('#carte-recherche').on('focus', function() {
 | 
        
           |  |  | 689 | 		$(this).select();
 | 
        
           |  |  | 690 | 	});
 | 
        
           |  |  | 691 | 	$('#carte-recherche').on('mouseup', function(event) {// Pour Safari...
 | 
        
           |  |  | 692 | 		event.preventDefault();
 | 
        
           |  |  | 693 | 	});
 | 
        
           |  |  | 694 |   | 
        
           |  |  | 695 | 	$('#carte-recherche').keypress(function(e) {
 | 
        
           |  |  | 696 | 		if (e.which == 13) {
 | 
        
           |  |  | 697 | 			e.preventDefault();
 | 
        
           |  |  | 698 | 		}
 | 
        
           |  |  | 699 | 	});
 | 
        
           |  |  | 700 | };
 | 
        
           |  |  | 701 |   | 
        
           |  |  | 702 |   | 
        
           |  |  | 703 | //+---------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 704 | // FORMULAIRE : traitements génériques
 | 
        
           | 2360 | jpm | 705 | var obsNbre = 0;
 | 
        
           |  |  | 706 |   | 
        
           |  |  | 707 | $(document).ready(function() {
 | 
        
           | 2372 | jpm | 708 | 	$('.alert .close').on('click', fermerPanneauAlert);
 | 
        
           |  |  | 709 | 	$('body').on('click', '.fermer', function(event) {
 | 
        
           | 2360 | jpm | 710 | 			event.preventDefault();
 | 
        
           |  |  | 711 | 			basculerOuvertureFermetureCadre($(this).find('.icone'));
 | 
        
           |  |  | 712 | 	});
 | 
        
           |  |  | 713 | 	$('.has-tooltip').tooltip('enable');
 | 
        
           | 2372 | jpm | 714 | 	$('#btn-aide').on('click', basculerAffichageAide);
 | 
        
           | 2360 | jpm | 715 |   | 
        
           | 2372 | jpm | 716 | 	// Date picker
 | 
        
           | 2360 | jpm | 717 | 	configurerDatePicker();
 | 
        
           |  |  | 718 |   | 
        
           | 2372 | jpm | 719 | 	// Gestion de la liste des taxons
 | 
        
           | 2360 | jpm | 720 | 	ajouterAutocompletionNoms();
 | 
        
           | 2372 | jpm | 721 | 	surChangementTaxonListe();// Vérif lors du chargement de la page
 | 
        
           |  |  | 722 | 	$('#taxon-liste').on('change', surChangementTaxonListe);
 | 
        
           |  |  | 723 | 	surChangementFormation();// Vérif lors du chargement de la page
 | 
        
           |  |  | 724 | 	$('#formation').on('change', surChangementFormation);
 | 
        
           | 2360 | jpm | 725 |   | 
        
           | 2372 | jpm | 726 | 	// Validation du formulaire
 | 
        
           | 2360 | jpm | 727 | 	configurerFormValidator();
 | 
        
           |  |  | 728 | 	definirReglesFormValidator();
 | 
        
           |  |  | 729 |   | 
        
           | 2372 | jpm | 730 | 	// Gestion des obs
 | 
        
           |  |  | 731 | 	configurerMilieux();
 | 
        
           |  |  | 732 | 	$('.btn-coord ').on('click', basculerAffichageCoord);
 | 
        
           |  |  | 733 | 	$('#ajouter-obs').on('click', ajouterObs);
 | 
        
           |  |  | 734 | 	surChangementNbreObs();
 | 
        
           |  |  | 735 | 	$('.obs-nbre').on('changement', surChangementNbreObs);
 | 
        
           |  |  | 736 | 	$('body').on('click', '.supprimer-obs', supprimerObs);
 | 
        
           |  |  | 737 | 	$('#transmettre-obs').on('click', transmettreObs);
 | 
        
           | 2360 | jpm | 738 |   | 
        
           |  |  | 739 |   | 
        
           | 2372 | jpm | 740 | 	// Défilement des photos
 | 
        
           |  |  | 741 | 	$('body').on('click', '.defilement-miniatures-gauche', function(event) {
 | 
        
           | 2360 | jpm | 742 | 			event.preventDefault();
 | 
        
           |  |  | 743 | 			defilerMiniatures($(this));
 | 
        
           |  |  | 744 | 	});
 | 
        
           | 2372 | jpm | 745 | 	$('body').on('click', '.defilement-miniatures-droite', function(event) {
 | 
        
           | 2360 | jpm | 746 | 		event.preventDefault();
 | 
        
           |  |  | 747 | 		defilerMiniatures($(this));
 | 
        
           |  |  | 748 | 	});
 | 
        
           |  |  | 749 | });
 | 
        
           |  |  | 750 |   | 
        
           | 2372 | jpm | 751 | function surChangementTaxonListe() {
 | 
        
           |  |  | 752 | 	if ($('#taxon-liste').val() === '?') {
 | 
        
           |  |  | 753 | 		$('#taxon-input-groupe').removeClass('hidden');
 | 
        
           |  |  | 754 | 		$('#taxon').valid();
 | 
        
           |  |  | 755 | 	} else {
 | 
        
           |  |  | 756 | 		$('#taxon-input-groupe').addClass('hidden');
 | 
        
           |  |  | 757 | 	}
 | 
        
           |  |  | 758 | }
 | 
        
           |  |  | 759 |   | 
        
           |  |  | 760 | function surChangementFormation() {
 | 
        
           |  |  | 761 | 	if ($('#formation').val() === 'alignement') {
 | 
        
           |  |  | 762 | 		$('#aligne-nbre-groupe').removeClass('hidden');
 | 
        
           |  |  | 763 | 		$('#aligne-nbre').valid();
 | 
        
           |  |  | 764 | 	} else {
 | 
        
           |  |  | 765 | 		$('#aligne-nbre-groupe').addClass('hidden');
 | 
        
           |  |  | 766 | 	}
 | 
        
           |  |  | 767 | }
 | 
        
           |  |  | 768 |   | 
        
           | 2360 | jpm | 769 | function configurerFormValidator() {
 | 
        
           |  |  | 770 | 	$.validator.addMethod(
 | 
        
           | 2372 | jpm | 771 | 		'dateCel',
 | 
        
           | 2360 | jpm | 772 | 		function (value, element) {
 | 
        
           | 2372 | jpm | 773 | 			return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
 | 
        
           | 2360 | jpm | 774 | 		},
 | 
        
           | 2372 | jpm | 775 | 		'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
 | 
        
           | 2360 | jpm | 776 |   | 
        
           | 2372 | jpm | 777 | 	$.validator.addMethod(
 | 
        
           |  |  | 778 | 		'aligneNbre',
 | 
        
           |  |  | 779 | 		function (value, element) {
 | 
        
           |  |  | 780 | 			var ok = true;
 | 
        
           |  |  | 781 | 			if ($('#formation').val() === 'alignement') {
 | 
        
           |  |  | 782 | 				ok = (value != '' && /^[0-9]+$/.test(value) && value > 1);
 | 
        
           |  |  | 783 | 			}
 | 
        
           |  |  | 784 | 			console.log(ok);
 | 
        
           |  |  | 785 | 			return ok;
 | 
        
           |  |  | 786 | 		},
 | 
        
           |  |  | 787 | 		"Veuillez indiquer le nombre d'arbres d'alignement.");
 | 
        
           |  |  | 788 |   | 
        
           |  |  | 789 | 	$.validator.addMethod(
 | 
        
           |  |  | 790 | 		'autreSp',
 | 
        
           |  |  | 791 | 		function (value, element) {
 | 
        
           |  |  | 792 | 			var taxonListe = $('#taxon-liste').val();
 | 
        
           |  |  | 793 | 			return taxonListe !== '?' || (taxonListe === '?' && value != '');
 | 
        
           |  |  | 794 | 		},
 | 
        
           |  |  | 795 | 		"Veuillez sélectionner une espèce ou une indication sur la plante.");
 | 
        
           |  |  | 796 |   | 
        
           |  |  | 797 | 	// Modification des méthodes par défaut de Jquery Validation pour Boostrap 3
 | 
        
           |  |  | 798 | 	$.validator.setDefaults({
 | 
        
           |  |  | 799 | 		ignore: [],// Forcer Jquery Validate à examiner les éléments en "display:none;"
 | 
        
           | 2360 | jpm | 800 | 		highlight: function(element) {
 | 
        
           | 2372 | jpm | 801 | 			$(element).closest('.form-group').addClass('has-error');
 | 
        
           | 2360 | jpm | 802 | 		},
 | 
        
           | 2372 | jpm | 803 | 		unhighlight: function(element) {
 | 
        
           |  |  | 804 | 			$(element).closest('.form-group').removeClass('has-error');
 | 
        
           |  |  | 805 | 		},
 | 
        
           | 2360 | jpm | 806 | 		success: function(element) {
 | 
        
           | 2372 | jpm | 807 | 			$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
 | 
        
           | 2360 | jpm | 808 |   | 
        
           | 2372 | jpm | 809 | 			if ($(element).attr('id') == 'taxon' && $('#taxon').val() != '') {
 | 
        
           | 2360 | jpm | 810 | 				// Si le taxon n'est pas lié au référentiel, on vide le data associé
 | 
        
           |  |  | 811 | 				if ($('#taxon').data('value') != $('#taxon').val()) {
 | 
        
           |  |  | 812 | 					$('#taxon').data('numNomSel', '');
 | 
        
           |  |  | 813 | 					$('#taxon').data('nomRet', '');
 | 
        
           |  |  | 814 | 					$('#taxon').data('numNomRet', '');
 | 
        
           |  |  | 815 | 					$('#taxon').data('nt', '');
 | 
        
           |  |  | 816 | 					$('#taxon').data('famille', '');
 | 
        
           |  |  | 817 | 				}
 | 
        
           |  |  | 818 | 			}
 | 
        
           | 2372 | jpm | 819 | 		},
 | 
        
           |  |  | 820 | 		errorElement: 'span',
 | 
        
           |  |  | 821 | 		errorClass: 'help-block',
 | 
        
           |  |  | 822 | 		errorPlacement: function(error, element) {
 | 
        
           |  |  | 823 | 			//console.log(element.attr('name') +'-'+ element.parent('.input-group').length);
 | 
        
           |  |  | 824 | 			if (element.parent('.input-group').length) {
 | 
        
           |  |  | 825 | 				error.insertAfter(element.parent());
 | 
        
           |  |  | 826 | 			} else {
 | 
        
           |  |  | 827 | 				error.insertAfter(element);
 | 
        
           |  |  | 828 | 			}
 | 
        
           | 2360 | jpm | 829 | 		}
 | 
        
           |  |  | 830 | 	});
 | 
        
           |  |  | 831 | }
 | 
        
           |  |  | 832 |   | 
        
           |  |  | 833 | function definirReglesFormValidator() {
 | 
        
           |  |  | 834 | 	$('#form-observateur').validate({
 | 
        
           |  |  | 835 | 		rules: {
 | 
        
           |  |  | 836 | 			courriel : {
 | 
        
           |  |  | 837 | 				required : true,
 | 
        
           |  |  | 838 | 				email : true},
 | 
        
           |  |  | 839 | 			courriel_confirmation : {
 | 
        
           |  |  | 840 | 				required : true,
 | 
        
           |  |  | 841 | 				equalTo: '#courriel'}
 | 
        
           |  |  | 842 | 		}
 | 
        
           |  |  | 843 | 	});
 | 
        
           |  |  | 844 | 	$('#form-station').validate({
 | 
        
           |  |  | 845 | 		rules: {
 | 
        
           |  |  | 846 | 			latitude : {
 | 
        
           |  |  | 847 | 				range: [-90, 90],
 | 
        
           |  |  | 848 | 				required: true},
 | 
        
           |  |  | 849 | 			longitude : {
 | 
        
           |  |  | 850 | 				range: [-180, 180],
 | 
        
           |  |  | 851 | 				required: true},
 | 
        
           | 2372 | jpm | 852 | 			'l93-x': 'required',
 | 
        
           | 2380 | jpm | 853 | 			'l93-y': 'required'
 | 
        
           | 2360 | jpm | 854 | 		}
 | 
        
           |  |  | 855 | 	});
 | 
        
           |  |  | 856 | 	$('#form-obs').validate({
 | 
        
           |  |  | 857 | 		rules: {
 | 
        
           |  |  | 858 | 			date: {
 | 
        
           |  |  | 859 | 				required: true,
 | 
        
           |  |  | 860 | 				'dateCel' : true},
 | 
        
           | 2372 | jpm | 861 | 			'taxon-liste': {required: true},
 | 
        
           |  |  | 862 | 			taxon: {autreSp: true},
 | 
        
           |  |  | 863 | 			certitude: 'required',
 | 
        
           |  |  | 864 | 			arbreTetardFormation: 'required',
 | 
        
           |  |  | 865 | 			arbreTetardAligneNbre: {aligneNbre: true}
 | 
        
           | 2360 | jpm | 866 | 		}
 | 
        
           |  |  | 867 | 	});
 | 
        
           |  |  | 868 | }
 | 
        
           |  |  | 869 |   | 
        
           |  |  | 870 | function configurerDatePicker() {
 | 
        
           | 2372 | jpm | 871 | 	$.datepicker.setDefaults($.datepicker.regional['fr']);
 | 
        
           |  |  | 872 | 	$('#date').datepicker({
 | 
        
           |  |  | 873 | 		dateFormat: 'dd/mm/yy',
 | 
        
           | 2360 | jpm | 874 | 		maxDate: new Date,
 | 
        
           | 2372 | jpm | 875 | 		showOn: 'button',
 | 
        
           | 2360 | jpm | 876 | 		buttonImageOnly: true,
 | 
        
           |  |  | 877 | 		buttonImage: CALENDRIER_ICONE_URL,
 | 
        
           | 2372 | jpm | 878 | 		buttonText: 'Afficher le calendrier pour saisir la date.',
 | 
        
           | 2360 | jpm | 879 | 		showButtonPanel: true,
 | 
        
           |  |  | 880 | 		onSelect: function(date) {
 | 
        
           |  |  | 881 | 			$(this).valid();
 | 
        
           |  |  | 882 | 		}
 | 
        
           |  |  | 883 | 	});
 | 
        
           | 2372 | jpm | 884 | 	$('img.ui-datepicker-trigger').appendTo('#date-icone');
 | 
        
           | 2360 | jpm | 885 | }
 | 
        
           |  |  | 886 |   | 
        
           | 2372 | jpm | 887 | function configurerMilieux() {
 | 
        
           |  |  | 888 | 	$('.cb-milieux').on('click', function(event) {
 | 
        
           |  |  | 889 | 		$(this).valid();
 | 
        
           |  |  | 890 | 		event.stopPropagation();
 | 
        
           |  |  | 891 | 	});
 | 
        
           | 2360 | jpm | 892 | }
 | 
        
           |  |  | 893 |   | 
        
           | 2372 | jpm | 894 | function fermerPanneauAlert() {
 | 
        
           |  |  | 895 | 	$(this).parentsUntil('.zone-alerte', '.alert').hide();
 | 
        
           | 2360 | jpm | 896 | }
 | 
        
           |  |  | 897 |   | 
        
           |  |  | 898 | function basculerOuvertureFermetureCadre(element) {
 | 
        
           | 2372 | jpm | 899 | 	if (element.hasClass('glyphicon-plus-sign')) {
 | 
        
           |  |  | 900 | 		element.removeClass('glyphicon-plus-sign').addClass('glyphicon-minus-sign');
 | 
        
           | 2360 | jpm | 901 | 	} else {
 | 
        
           | 2372 | jpm | 902 | 		element.removeClass('glyphicon-minus-sign').addClass('glyphicon-plus-sign');
 | 
        
           | 2360 | jpm | 903 | 	}
 | 
        
           |  |  | 904 | }
 | 
        
           |  |  | 905 |   | 
        
           |  |  | 906 | function basculerAffichageAide()  {
 | 
        
           |  |  | 907 | 	if ($(this).hasClass('btn-warning')) {
 | 
        
           |  |  | 908 | 		$('.has-tooltip').tooltip('enable');
 | 
        
           |  |  | 909 | 		$(this).removeClass('btn-warning').addClass('btn-success');
 | 
        
           |  |  | 910 | 		$('#btn-aide-txt', this).text("Désactiver l'aide");
 | 
        
           |  |  | 911 | 	} else {
 | 
        
           |  |  | 912 | 		$('.has-tooltip').tooltip('disable');
 | 
        
           |  |  | 913 | 		$(this).removeClass('btn-success').addClass('btn-warning');
 | 
        
           |  |  | 914 | 		$('#btn-aide-txt', this).text("Activer l'aide");
 | 
        
           |  |  | 915 | 	}
 | 
        
           |  |  | 916 | }
 | 
        
           |  |  | 917 |   | 
        
           |  |  | 918 | function bloquerCopierCollerCourriel() {
 | 
        
           | 2372 | jpm | 919 | 	afficherPanneau('#dialogue-bloquer-copier-coller');
 | 
        
           | 2360 | jpm | 920 | 	return false;
 | 
        
           |  |  | 921 | }
 | 
        
           |  |  | 922 |   | 
        
           |  |  | 923 | function basculerAffichageCoord() {
 | 
        
           | 2372 | jpm | 924 | 	var textActuel = $(this).text(),
 | 
        
           |  |  | 925 | 			textARemplacer = $(this).data('toggle-text');
 | 
        
           |  |  | 926 | 	$(this).text(textARemplacer).data('toggle-text', textActuel);
 | 
        
           |  |  | 927 |   | 
        
           |  |  | 928 | 	if ($(this).hasClass('cacher-coord')) {
 | 
        
           |  |  | 929 | 		$(this).removeClass('cacher-coord').addClass('afficher-coord');
 | 
        
           |  |  | 930 | 		$('#coordonnees-geo').addClass('hidden');
 | 
        
           |  |  | 931 | 	} else {
 | 
        
           |  |  | 932 | 		$(this).removeClass('afficher-coord').addClass('cacher-coord');
 | 
        
           |  |  | 933 | 		$('#coordonnees-geo').removeClass('hidden');
 | 
        
           |  |  | 934 | 	}
 | 
        
           |  |  | 935 |   | 
        
           | 2360 | jpm | 936 | 	return false;
 | 
        
           |  |  | 937 | }
 | 
        
           |  |  | 938 |   | 
        
           |  |  | 939 | function ajouterObs() {
 | 
        
           | 2374 | jpm | 940 | 	// Fermeture automatique des dialogue de transmission de données
 | 
        
           |  |  | 941 | 	$('#dialogue-obs-transaction-ko').hide();
 | 
        
           |  |  | 942 | 	$('#dialogue-obs-transaction-ok').hide();
 | 
        
           |  |  | 943 |   | 
        
           | 2360 | jpm | 944 | 	if (validerFormulaire() == true) {
 | 
        
           |  |  | 945 | 		obsNbre = obsNbre + 1;
 | 
        
           | 2372 | jpm | 946 | 		$('.obs-nbre').text(obsNbre);
 | 
        
           |  |  | 947 | 		$('.obs-nbre').triggerHandler('changement');
 | 
        
           | 2360 | jpm | 948 | 		afficherObs();
 | 
        
           |  |  | 949 | 		stockerObsData();
 | 
        
           |  |  | 950 | 		supprimerMiniatures();
 | 
        
           |  |  | 951 | 		if(!ESPECE_IMPOSEE) {
 | 
        
           | 2372 | jpm | 952 | 			$('#taxon').val('');
 | 
        
           |  |  | 953 | 			$('#taxon').data('numNomSel',undefined);
 | 
        
           | 2360 | jpm | 954 | 		}
 | 
        
           |  |  | 955 | 		$('#barre-progression-upload').attr('aria-valuemax', obsNbre);
 | 
        
           | 2372 | jpm | 956 | 		$('#barre-progression-upload .sr-only').text('0/'+obsNbre+' observations transmises');
 | 
        
           | 2360 | jpm | 957 | 	} else {
 | 
        
           |  |  | 958 | 		afficherPanneau('#dialogue-form-invalide');
 | 
        
           |  |  | 959 | 	}
 | 
        
           |  |  | 960 | }
 | 
        
           |  |  | 961 |   | 
        
           |  |  | 962 | function afficherObs() {
 | 
        
           | 2372 | jpm | 963 | 	var numNomSel = ($('#taxon-liste').val() == '?') ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
 | 
        
           |  |  | 964 | 		nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
 | 
        
           |  |  | 965 | 		taxon = ($('#taxon-liste').val() == '?') ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
 | 
        
           | 2408 | jpm | 966 | 		referentiel = (numNomSel == undefined) ? '' : '['+NOM_SCI_REFERENTIEL+']',
 | 
        
           | 2372 | jpm | 967 | 		commune = $('#commune-nom').text(),
 | 
        
           |  |  | 968 | 		codeInsee = $('#commune-code-insee').text(),
 | 
        
           |  |  | 969 | 		lat = $('input[name="latitude"]').val(),
 | 
        
           |  |  | 970 | 		lng = $('input[name="longitude"]').val(),
 | 
        
           |  |  | 971 | 		date = $('#date').val(),
 | 
        
           |  |  | 972 | 		formation = getTextOptionSelectionne('formation'),
 | 
        
           |  |  | 973 | 		nbreAligne = ($('#aligne-nbre').val() != undefined ? ' (' + $('#aligne-nbre').val() + ')' : ''),
 | 
        
           |  |  | 974 | 		cavites = getTextOptionSelectionne('cavites'),
 | 
        
           |  |  | 975 | 		circonference = getTextOptionSelectionne('circonference'),
 | 
        
           |  |  | 976 | 		hauteurTete = getTextOptionSelectionne('hauteur-tete'),
 | 
        
           |  |  | 977 | 		presenceSp = $('#presence-sp').val(),
 | 
        
           |  |  | 978 | 		taille = getTextOptionSelectionne('taille-type'),
 | 
        
           | 2391 | jpm | 979 | 		entretien = getTextOptionSelectionne('entretien'),
 | 
        
           | 2372 | jpm | 980 | 		etatSanitaire = getTextOptionSelectionne('etat-sanitaire'),
 | 
        
           |  |  | 981 | 		milieux = getMilieux(),
 | 
        
           |  |  | 982 | 		notes = (nomSpecial ? taxons[numNomSel]['nom_fr'] + ".<br />" : '') + $('#notes').val();
 | 
        
           |  |  | 983 |   | 
        
           |  |  | 984 | 	$('#liste-obs').prepend(
 | 
        
           |  |  | 985 | 		'<div id="obs'+obsNbre+'" class="obs obs'+obsNbre+'">'+
 | 
        
           | 2360 | jpm | 986 | 				'<div class="well">'+
 | 
        
           |  |  | 987 | 					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
 | 
        
           |  |  | 988 | 						'title="Supprimer cette observation de la liste à transmettre">'+
 | 
        
           |  |  | 989 | 						'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
 | 
        
           | 2372 | jpm | 990 | 							'<span class="glyphicon glyphicon-trash icon-white"></i>'+
 | 
        
           | 2360 | jpm | 991 | 						'</button>'+
 | 
        
           |  |  | 992 | 					'</div> '+
 | 
        
           | 2372 | jpm | 993 | 					'<div class="row">'+
 | 
        
           |  |  | 994 | 						'<div class="col-md-2 obs-miniatures">'+
 | 
        
           | 2360 | jpm | 995 | 							ajouterImgMiniatureAuTransfert()+
 | 
        
           |  |  | 996 | 						'</div>'+
 | 
        
           | 2372 | jpm | 997 | 						'<div class="col-md-8">'+
 | 
        
           |  |  | 998 | 							'<ul class="list-unstyled obs-entete">'+
 | 
        
           | 2360 | jpm | 999 | 								'<li>'+
 | 
        
           | 2372 | jpm | 1000 | 									'<span class="nom-sci">' + taxon + '</span> ' +
 | 
        
           |  |  | 1001 | 									formaterNumNomSel(numNomSel)+
 | 
        
           |  |  | 1002 | 									'<span class="referentiel-obs">' + referentiel + '</span>' +
 | 
        
           |  |  | 1003 | 									' observé à ' +
 | 
        
           |  |  | 1004 | 									'<span class="commune">' + commune + '</span> ' +
 | 
        
           |  |  | 1005 | 									'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
 | 
        
           |  |  | 1006 | 									' le ' +
 | 
        
           |  |  | 1007 | 									'<span class="date">' + date + '</span>' +
 | 
        
           |  |  | 1008 | 								'</li>' +
 | 
        
           |  |  | 1009 | 							'</ul>'+
 | 
        
           |  |  | 1010 | 							'<ul class="list-unstyled obs-details">'+
 | 
        
           |  |  | 1011 | 								'<li>' +
 | 
        
           |  |  | 1012 | 									'<span>Situation(s) :</span> ' + milieux + ' ; ' +
 | 
        
           |  |  | 1013 | 									'<span>Formation :</span> ' + formation + nbreAligne + ' ; ' +
 | 
        
           |  |  | 1014 | 									'<span>Cavités :</span> ' + cavites + ' ; ' +
 | 
        
           |  |  | 1015 | 									'<span>Circonférence :</span> ' + circonference + ' ; ' +
 | 
        
           |  |  | 1016 | 									'<span>Hauteur de la tête :</span> ' + hauteurTete + ' ; ' +
 | 
        
           |  |  | 1017 | 								'</li>' +
 | 
        
           |  |  | 1018 | 								'<li>' +
 | 
        
           |  |  | 1019 | 									'<span>Présences sur l\'arbre :</span> ' + presenceSp + ' ' +
 | 
        
           |  |  | 1020 | 								'</li>' +
 | 
        
           |  |  | 1021 | 								'<li>' +
 | 
        
           |  |  | 1022 | 									'<span>Type taille :</span> ' + taille + ' ; ' +
 | 
        
           | 2391 | jpm | 1023 | 									'<span>Entretien :</span> ' + entretien + ' ; ' +
 | 
        
           | 2372 | jpm | 1024 | 									'<span>État sanitaire :</span> ' + etatSanitaire + ' ; ' +
 | 
        
           |  |  | 1025 | 								'</li>' +
 | 
        
           |  |  | 1026 | 								'<li>' +
 | 
        
           |  |  | 1027 | 									'<span>Commentaires :</span> ' + notes +
 | 
        
           | 2360 | jpm | 1028 | 								'</li>'+
 | 
        
           |  |  | 1029 | 							'</ul>'+
 | 
        
           |  |  | 1030 | 						'</div>'+
 | 
        
           |  |  | 1031 | 					'</div>'+
 | 
        
           |  |  | 1032 | 				'</div>'+
 | 
        
           |  |  | 1033 | 		'</div>');
 | 
        
           |  |  | 1034 | }
 | 
        
           |  |  | 1035 |   | 
        
           | 2372 | jpm | 1036 | function getMilieux() {
 | 
        
           |  |  | 1037 | 	var milieuxStr = '',
 | 
        
           |  |  | 1038 | 		milieux = [];
 | 
        
           |  |  | 1039 | 	$('.cb-milieux:checked').each(function() {
 | 
        
           |  |  | 1040 | 		milieux.push($(this).val());
 | 
        
           |  |  | 1041 | 	});
 | 
        
           |  |  | 1042 |   | 
        
           |  |  | 1043 | 	milieuxStr = Array.prototype.slice.call(milieux).join(', ');
 | 
        
           |  |  | 1044 | 	return milieuxStr;
 | 
        
           |  |  | 1045 | }
 | 
        
           |  |  | 1046 |   | 
        
           |  |  | 1047 | function getTextOptionSelectionne(id) {
 | 
        
           |  |  | 1048 | 	return ($('#' + id).val() != undefined ? $('#' + id + ' option:selected').text()  : '');
 | 
        
           |  |  | 1049 | }
 | 
        
           |  |  | 1050 |   | 
        
           | 2360 | jpm | 1051 | function stockerObsData() {
 | 
        
           | 2372 | jpm | 1052 | 	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
 | 
        
           |  |  | 1053 | 		nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
 | 
        
           |  |  | 1054 | 		numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
 | 
        
           |  |  | 1055 | 		nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
 | 
        
           |  |  | 1056 | 		nomRet = nomHorsListe ? $('#taxon').data('nomRet') : taxons[numNomSel]['nom_ret'],
 | 
        
           |  |  | 1057 | 		numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : taxons[numNomSel]['num_nom_ret'],
 | 
        
           |  |  | 1058 | 		numTaxon = nomHorsListe ? $('#taxon').data('nt') : taxons[numNomSel]['num_taxon'],
 | 
        
           |  |  | 1059 | 		famille = nomHorsListe ? $('#taxon').data('famille') : taxons[numNomSel]['famille'],
 | 
        
           |  |  | 1060 | 		referentiel = (numNomSel == undefined) ? '' : NOM_SCI_REFERENTIEL;
 | 
        
           | 2360 | jpm | 1061 |   | 
        
           | 2372 | jpm | 1062 | 	$('#liste-obs').data('obsId'+obsNbre, {
 | 
        
           |  |  | 1063 | 		'date' : $('#date').val(),
 | 
        
           |  |  | 1064 | 		'notes' : $('#notes').val(),
 | 
        
           | 2360 | jpm | 1065 |   | 
        
           | 2372 | jpm | 1066 | 		'nom_sel': nomSel,
 | 
        
           |  |  | 1067 | 		'num_nom_sel': numNomSel,
 | 
        
           |  |  | 1068 | 		'nom_ret': nomRet,
 | 
        
           |  |  | 1069 | 		'num_nom_ret': numNomRet,
 | 
        
           |  |  | 1070 | 		'num_taxon': numTaxon,
 | 
        
           |  |  | 1071 | 		'famille': famille,
 | 
        
           |  |  | 1072 | 		'referentiel': referentiel,
 | 
        
           | 2360 | jpm | 1073 |   | 
        
           | 2372 | jpm | 1074 | 		'latitude' : $('#latitude').val(),
 | 
        
           |  |  | 1075 | 		'longitude' : $('#longitude').val(),
 | 
        
           |  |  | 1076 | 		'commune_nom' : $('#commune-nom').text(),
 | 
        
           |  |  | 1077 | 		'commune_code_insee' : $('#commune-code-insee').text(),
 | 
        
           |  |  | 1078 | 		'altitude': $('#altitude').text(),
 | 
        
           |  |  | 1079 | 		'lieudit': $('#lieudit').val(),
 | 
        
           |  |  | 1080 | 		'milieu': getMilieux(),
 | 
        
           |  |  | 1081 | 		'certitude': $('#certitude').val(),
 | 
        
           |  |  | 1082 |   | 
        
           | 2360 | jpm | 1083 | 		//Ajout des champs images
 | 
        
           |  |  | 1084 | 		'image_nom' : getNomsImgsOriginales(),
 | 
        
           |  |  | 1085 |   | 
        
           |  |  | 1086 | 		// Ajout des champs étendus de l'obs
 | 
        
           |  |  | 1087 | 		'obs_etendue': getObsChpEtendus()
 | 
        
           |  |  | 1088 | 	});
 | 
        
           |  |  | 1089 | }
 | 
        
           |  |  | 1090 |   | 
        
           |  |  | 1091 | function getObsChpEtendus() {
 | 
        
           |  |  | 1092 | 	var champs = [];
 | 
        
           |  |  | 1093 |   | 
        
           |  |  | 1094 | 	$('.obs-chp-etendu').each(function() {
 | 
        
           |  |  | 1095 | 		var valeur = $(this).val(),
 | 
        
           |  |  | 1096 | 			cle = $(this).attr('name'),
 | 
        
           |  |  | 1097 | 			label = $(this).data('label');
 | 
        
           |  |  | 1098 | 		if (valeur != '') {
 | 
        
           |  |  | 1099 | 			var chpEtendu = {cle: cle, label: label, valeur: valeur};
 | 
        
           |  |  | 1100 | 			champs.push(chpEtendu);
 | 
        
           |  |  | 1101 | 		}
 | 
        
           |  |  | 1102 | 	});
 | 
        
           |  |  | 1103 | 	return champs;
 | 
        
           |  |  | 1104 | }
 | 
        
           |  |  | 1105 |   | 
        
           |  |  | 1106 | function surChangementNbreObs() {
 | 
        
           |  |  | 1107 | 	if (obsNbre == 0) {
 | 
        
           | 2372 | jpm | 1108 | 		$('#transmettre-obs').attr('disabled', 'disabled');
 | 
        
           |  |  | 1109 | 		$('#ajouter-obs').removeAttr('disabled');
 | 
        
           | 2360 | jpm | 1110 | 	} else if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
 | 
        
           | 2372 | jpm | 1111 | 		$('#transmettre-obs').removeAttr('disabled');
 | 
        
           |  |  | 1112 | 		$('#ajouter-obs').removeAttr('disabled');
 | 
        
           | 2360 | jpm | 1113 | 	} else if (obsNbre >= OBS_MAX_NBRE) {
 | 
        
           | 2372 | jpm | 1114 | 		$('#ajouter-obs').attr('disabled', 'disabled');
 | 
        
           |  |  | 1115 | 		afficherPanneau('#dialogue-bloquer-creer-obs');
 | 
        
           | 2360 | jpm | 1116 | 	}
 | 
        
           |  |  | 1117 | }
 | 
        
           |  |  | 1118 |   | 
        
           |  |  | 1119 | var nbObsEnCours = 1;
 | 
        
           |  |  | 1120 | var totalObsATransmettre = 0;
 | 
        
           |  |  | 1121 | function transmettreObs() {
 | 
        
           | 2372 | jpm | 1122 | 	var observations = $('#liste-obs').data();
 | 
        
           |  |  | 1123 | 	console.log(observations);
 | 
        
           | 2360 | jpm | 1124 | 	if (observations == undefined || jQuery.isEmptyObject(observations)) {
 | 
        
           | 2372 | jpm | 1125 | 		afficherPanneau('#dialogue-zero-obs');
 | 
        
           | 2360 | jpm | 1126 | 	} else {
 | 
        
           |  |  | 1127 | 		nbObsEnCours = 1;
 | 
        
           |  |  | 1128 | 		nbObsTransmises = 0;
 | 
        
           |  |  | 1129 | 		totalObsATransmettre = $.map(observations, function(n, i) { return i; }).length;
 | 
        
           |  |  | 1130 | 		depilerObsPourEnvoi();
 | 
        
           |  |  | 1131 | 	}
 | 
        
           |  |  | 1132 | 	return false;
 | 
        
           |  |  | 1133 | }
 | 
        
           |  |  | 1134 |   | 
        
           |  |  | 1135 | function depilerObsPourEnvoi() {
 | 
        
           | 2372 | jpm | 1136 | 	var observations = $('#liste-obs').data();
 | 
        
           | 2360 | jpm | 1137 | 	// la boucle est factice car on utilise un tableau
 | 
        
           |  |  | 1138 | 	// dont on a besoin de n'extraire que le premier élément
 | 
        
           |  |  | 1139 | 	// or javascript n'a pas de méthode cross browsers pour extraire les clés
 | 
        
           |  |  | 1140 | 	// TODO: utiliser var.keys quand ça sera plus répandu
 | 
        
           |  |  | 1141 | 	// ou bien utiliser un vrai tableau et pas un objet
 | 
        
           |  |  | 1142 | 	for (var obsNum in observations) {
 | 
        
           |  |  | 1143 | 		obsATransmettre = new Object();
 | 
        
           |  |  | 1144 |   | 
        
           |  |  | 1145 | 	    obsATransmettre['projet'] = TAG_PROJET;
 | 
        
           |  |  | 1146 | 	    obsATransmettre['tag-obs'] = TAG_OBS;
 | 
        
           |  |  | 1147 | 	    obsATransmettre['tag-img'] = TAG_IMG;
 | 
        
           |  |  | 1148 |   | 
        
           |  |  | 1149 | 		var utilisateur = new Object();
 | 
        
           | 2372 | jpm | 1150 | 		utilisateur.id_utilisateur = $('#id_utilisateur').val();
 | 
        
           |  |  | 1151 | 		utilisateur.prenom = $('#prenom').val();
 | 
        
           |  |  | 1152 | 		utilisateur.nom = $('#nom').val();
 | 
        
           |  |  | 1153 | 		utilisateur.courriel = $('#courriel').val();
 | 
        
           | 2360 | jpm | 1154 | 		obsATransmettre['utilisateur'] = utilisateur;
 | 
        
           |  |  | 1155 | 		obsATransmettre[obsNum] = observations[obsNum];
 | 
        
           |  |  | 1156 | 		var idObsNumerique = obsNum.replace('obsId', '');
 | 
        
           | 2372 | jpm | 1157 | 		if (idObsNumerique != '') {
 | 
        
           | 2360 | jpm | 1158 | 			envoyerObsAuCel(idObsNumerique, obsATransmettre);
 | 
        
           |  |  | 1159 | 		}
 | 
        
           |  |  | 1160 |   | 
        
           |  |  | 1161 | 		break;
 | 
        
           |  |  | 1162 | 	}
 | 
        
           |  |  | 1163 | }
 | 
        
           |  |  | 1164 |   | 
        
           |  |  | 1165 | var nbObsTransmises = 0;
 | 
        
           |  |  | 1166 | function mettreAJourProgression() {
 | 
        
           |  |  | 1167 | 	nbObsTransmises++;
 | 
        
           |  |  | 1168 | 	var pct = (nbObsTransmises/totalObsATransmettre)*100;
 | 
        
           |  |  | 1169 | 	$('#barre-progression-upload').attr('aria-valuenow', nbObsTransmises);
 | 
        
           | 2372 | jpm | 1170 | 	$('#barre-progression-upload').attr('style', 'width: '+pct+'%');
 | 
        
           |  |  | 1171 | 	$('#barre-progression-upload .sr-only').text(nbObsTransmises+'/'+totalObsATransmettre+' observations transmises');
 | 
        
           | 2360 | jpm | 1172 |   | 
        
           | 2372 | jpm | 1173 | 	if (obsNbre == 0) {
 | 
        
           | 2360 | jpm | 1174 | 		$('.progress').removeClass('active');
 | 
        
           |  |  | 1175 | 		$('.progress').removeClass('progress-striped');
 | 
        
           |  |  | 1176 | 	}
 | 
        
           |  |  | 1177 | }
 | 
        
           |  |  | 1178 |   | 
        
           |  |  | 1179 | function envoyerObsAuCel(idObs, observation) {
 | 
        
           | 2372 | jpm | 1180 | 	var erreurMsg = '';
 | 
        
           | 2360 | jpm | 1181 | 	$.ajax({
 | 
        
           |  |  | 1182 | 		url : SERVICE_SAISIE_URL,
 | 
        
           | 2372 | jpm | 1183 | 		type : 'POST',
 | 
        
           | 2360 | jpm | 1184 | 		data : observation,
 | 
        
           | 2372 | jpm | 1185 | 		dataType : 'json',
 | 
        
           | 2360 | jpm | 1186 | 		beforeSend : function() {
 | 
        
           | 2372 | jpm | 1187 | 			$('#dialogue-obs-transaction-ko').hide();
 | 
        
           |  |  | 1188 | 			$('#dialogue-obs-transaction-ok').hide();
 | 
        
           |  |  | 1189 | 			$('.alert-txt .msg').remove();
 | 
        
           |  |  | 1190 | 			$('.alert-txt .msg-erreur').remove();
 | 
        
           |  |  | 1191 | 			$('.alert-txt .msg-debug').remove();
 | 
        
           |  |  | 1192 | 			$('#chargement').show();
 | 
        
           | 2360 | jpm | 1193 | 		},
 | 
        
           |  |  | 1194 | 		success : function(data, textStatus, jqXHR) {
 | 
        
           |  |  | 1195 | 			// mise à jour du nombre d'obs à transmettre
 | 
        
           |  |  | 1196 | 			// et suppression de l'obs
 | 
        
           |  |  | 1197 | 			supprimerObsParId(idObs);
 | 
        
           |  |  | 1198 | 			nbObsEnCours++;
 | 
        
           |  |  | 1199 | 			// mise à jour du statut
 | 
        
           |  |  | 1200 | 			mettreAJourProgression();
 | 
        
           |  |  | 1201 | 			if(obsNbre > 0) {
 | 
        
           |  |  | 1202 | 				// dépilement de la suivante
 | 
        
           |  |  | 1203 | 				depilerObsPourEnvoi();
 | 
        
           |  |  | 1204 | 			}
 | 
        
           |  |  | 1205 | 		},
 | 
        
           |  |  | 1206 | 		statusCode : {
 | 
        
           |  |  | 1207 | 			500 : function(jqXHR, textStatus, errorThrown) {
 | 
        
           |  |  | 1208 | 				erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
 | 
        
           |  |  | 1209 | 		    }
 | 
        
           |  |  | 1210 | 		},
 | 
        
           |  |  | 1211 | 		error : function(jqXHR, textStatus, errorThrown) {
 | 
        
           |  |  | 1212 | 			erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
 | 
        
           |  |  | 1213 | 			try {
 | 
        
           |  |  | 1214 | 				reponse = jQuery.parseJSON(jqXHR.responseText);
 | 
        
           |  |  | 1215 | 				if (reponse != null) {
 | 
        
           |  |  | 1216 | 					$.each(reponse, function (cle, valeur) {
 | 
        
           |  |  | 1217 | 						erreurMsg += valeur + "\n";
 | 
        
           |  |  | 1218 | 					});
 | 
        
           |  |  | 1219 | 				}
 | 
        
           |  |  | 1220 | 			} catch(e) {
 | 
        
           |  |  | 1221 | 				erreurMsg += "L'erreur n'était pas en JSON.";
 | 
        
           |  |  | 1222 | 			}
 | 
        
           |  |  | 1223 | 		},
 | 
        
           |  |  | 1224 | 		complete : function(jqXHR, textStatus) {
 | 
        
           |  |  | 1225 | 			var debugMsg = extraireEnteteDebug(jqXHR);
 | 
        
           |  |  | 1226 |   | 
        
           |  |  | 1227 | 			if (erreurMsg != '') {
 | 
        
           |  |  | 1228 | 				if (DEBUG) {
 | 
        
           | 2372 | jpm | 1229 | 					$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
 | 
        
           |  |  | 1230 | 					$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
 | 
        
           | 2360 | jpm | 1231 | 				}
 | 
        
           | 2372 | jpm | 1232 | 				var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
 | 
        
           |  |  | 1233 | 					'subject=Dysfonctionnement du widget de saisie '+TAG_PROJET+
 | 
        
           |  |  | 1234 | 					'&body='+erreurMsg+'%0D%0ADébogage :%0D%0A'+debugMsg;
 | 
        
           | 2360 | jpm | 1235 |   | 
        
           |  |  | 1236 | 				// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
 | 
        
           |  |  | 1237 | 				$('#obs'+idObs+' div div').addClass('obs-erreur');
 | 
        
           | 2372 | jpm | 1238 | 				window.location.hash = 'obs'+idObs;
 | 
        
           | 2360 | jpm | 1239 |   | 
        
           | 2372 | jpm | 1240 | 				$('#dialogue-obs-transaction-ko .alert-txt').append($('#tpl-transmission-ko').clone()
 | 
        
           | 2360 | jpm | 1241 | 					.find('.courriel-erreur')
 | 
        
           |  |  | 1242 | 					.attr('href', hrefCourriel)
 | 
        
           |  |  | 1243 | 					.end()
 | 
        
           |  |  | 1244 | 					.html());
 | 
        
           | 2372 | jpm | 1245 | 				$('#dialogue-obs-transaction-ko').show();
 | 
        
           |  |  | 1246 | 				$('#chargement').hide();
 | 
        
           | 2360 | jpm | 1247 | 				initialiserBarreProgression();
 | 
        
           |  |  | 1248 | 			} else {
 | 
        
           |  |  | 1249 | 				if (DEBUG) {
 | 
        
           | 2372 | jpm | 1250 | 					$('#dialogue-obs-transaction-ok .alert-txt').append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
 | 
        
           | 2360 | jpm | 1251 | 				}
 | 
        
           |  |  | 1252 | 				if(obsNbre == 0) {
 | 
        
           |  |  | 1253 | 					setTimeout(function() {
 | 
        
           | 2372 | jpm | 1254 | 						$('#chargement').hide();
 | 
        
           | 2360 | jpm | 1255 | 						$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
 | 
        
           | 2372 | jpm | 1256 | 						$('#dialogue-obs-transaction-ok').show();
 | 
        
           |  |  | 1257 | 						window.location.hash = 'dialogue-obs-transaction-ok';
 | 
        
           | 2360 | jpm | 1258 | 						initialiserObs();
 | 
        
           |  |  | 1259 | 					}, 1500);
 | 
        
           |  |  | 1260 |   | 
        
           |  |  | 1261 | 				}
 | 
        
           |  |  | 1262 | 			}
 | 
        
           |  |  | 1263 | 		}
 | 
        
           |  |  | 1264 | 	});
 | 
        
           |  |  | 1265 | }
 | 
        
           |  |  | 1266 |   | 
        
           |  |  | 1267 | function validerFormulaire() {
 | 
        
           | 2372 | jpm | 1268 | 	$observateur = $('#form-observateur').valid();
 | 
        
           |  |  | 1269 | 	$station = $('#form-station').valid();
 | 
        
           |  |  | 1270 | 	$obs = $('#form-obs').valid();
 | 
        
           | 2360 | jpm | 1271 | 	return ($observateur == true && $station == true && $obs == true) ? true : false;
 | 
        
           |  |  | 1272 | }
 | 
        
           |  |  | 1273 |   | 
        
           |  |  | 1274 | function getNomsImgsOriginales() {
 | 
        
           |  |  | 1275 | 	var noms = new Array();
 | 
        
           | 2372 | jpm | 1276 | 	$('.miniature-img').each(function() {
 | 
        
           | 2360 | jpm | 1277 | 		noms.push($(this).attr('alt'));
 | 
        
           |  |  | 1278 | 	});
 | 
        
           |  |  | 1279 | 	return noms;
 | 
        
           |  |  | 1280 | }
 | 
        
           |  |  | 1281 |   | 
        
           |  |  | 1282 | function supprimerObs() {
 | 
        
           |  |  | 1283 | 	var obsId = $(this).val();
 | 
        
           |  |  | 1284 | 	// Problème avec IE 6 et 7
 | 
        
           | 2372 | jpm | 1285 | 	if (obsId == 'Supprimer') {
 | 
        
           |  |  | 1286 | 		obsId = $(this).attr('title');
 | 
        
           | 2360 | jpm | 1287 | 	}
 | 
        
           |  |  | 1288 | 	supprimerObsParId(obsId);
 | 
        
           |  |  | 1289 | }
 | 
        
           |  |  | 1290 |   | 
        
           |  |  | 1291 | function supprimerObsParId(obsId) {
 | 
        
           |  |  | 1292 | 	obsNbre = obsNbre - 1;
 | 
        
           | 2372 | jpm | 1293 | 	$('.obs-nbre').text(obsNbre);
 | 
        
           |  |  | 1294 | 	$('.obs-nbre').triggerHandler('changement');
 | 
        
           | 2360 | jpm | 1295 | 	$('.obs'+obsId).remove();
 | 
        
           | 2372 | jpm | 1296 | 	$('#liste-obs').removeData('obsId'+obsId);
 | 
        
           | 2360 | jpm | 1297 | }
 | 
        
           |  |  | 1298 |   | 
        
           |  |  | 1299 | function initialiserBarreProgression() {
 | 
        
           |  |  | 1300 | 	$('#barre-progression-upload').attr('aria-valuenow', 0);
 | 
        
           | 2372 | jpm | 1301 | 	$('#barre-progression-upload').attr('style', 'width: 0%');
 | 
        
           |  |  | 1302 | 	$('#barre-progression-upload .sr-only').text('0/0 observations transmises');
 | 
        
           | 2360 | jpm | 1303 | 	$('.progress').addClass('active');
 | 
        
           |  |  | 1304 | 	$('.progress').addClass('progress-striped');
 | 
        
           |  |  | 1305 | }
 | 
        
           |  |  | 1306 |   | 
        
           |  |  | 1307 | function initialiserObs() {
 | 
        
           |  |  | 1308 | 	obsNbre = 0;
 | 
        
           |  |  | 1309 | 	nbObsTransmises = 0;
 | 
        
           |  |  | 1310 | 	nbObsEnCours = 0;
 | 
        
           |  |  | 1311 | 	totalObsATransmettre = 0;
 | 
        
           |  |  | 1312 | 	initialiserBarreProgression();
 | 
        
           | 2372 | jpm | 1313 | 	$('.obs-nbre').text(obsNbre);
 | 
        
           |  |  | 1314 | 	$('.obs-nbre').triggerHandler('changement');
 | 
        
           |  |  | 1315 | 	$('#liste-obs').removeData();
 | 
        
           | 2360 | jpm | 1316 | 	$('.obs').remove();
 | 
        
           | 2372 | jpm | 1317 | 	$('#dialogue-bloquer-creer-obs').hide();
 | 
        
           | 2360 | jpm | 1318 | }
 | 
        
           |  |  | 1319 |   | 
        
           |  |  | 1320 | function ajouterImgMiniatureAuTransfert() {
 | 
        
           |  |  | 1321 | 	var html = '';
 | 
        
           |  |  | 1322 | 	var miniatures = '';
 | 
        
           |  |  | 1323 | 	var premiere = true;
 | 
        
           | 2372 | jpm | 1324 | 	if ($('#miniatures img').length >= 1) {
 | 
        
           |  |  | 1325 | 		$('#miniatures img').each(function() {
 | 
        
           | 2360 | jpm | 1326 | 			var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee';
 | 
        
           |  |  | 1327 | 			premiere = false;
 | 
        
           | 2372 | jpm | 1328 | 			var css = $(this).hasClass('b64') ? 'thumbnail b64' : 'thumbnail';
 | 
        
           |  |  | 1329 | 			var src = $(this).attr('src');
 | 
        
           |  |  | 1330 | 			var alt = $(this).attr('alt');
 | 
        
           |  |  | 1331 | 			miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
 | 
        
           | 2360 | jpm | 1332 | 			miniatures += miniature;
 | 
        
           |  |  | 1333 | 		});
 | 
        
           | 2372 | jpm | 1334 | 		visible = ($('#miniatures img').length > 1) ? '' : 'defilement-miniatures-cache';
 | 
        
           | 2360 | jpm | 1335 | 		var html =
 | 
        
           |  |  | 1336 | 			'<div class="defilement-miniatures">'+
 | 
        
           | 2372 | jpm | 1337 | 				'<a class="defilement-miniatures-gauche '+visible+'"><</a>'+
 | 
        
           | 2360 | jpm | 1338 | 				miniatures+
 | 
        
           | 2372 | jpm | 1339 | 				'<a class="defilement-miniatures-droite '+visible+'">></a>'+
 | 
        
           | 2360 | jpm | 1340 | 			'</div>';
 | 
        
           |  |  | 1341 | 	} else {
 | 
        
           | 2372 | jpm | 1342 | 		html = '<img class="thumbnail" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
 | 
        
           | 2360 | jpm | 1343 | 	}
 | 
        
           |  |  | 1344 | 	return html;
 | 
        
           |  |  | 1345 | }
 | 
        
           |  |  | 1346 |   | 
        
           |  |  | 1347 | function defilerMiniatures(element) {
 | 
        
           | 2372 | jpm | 1348 | 	var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
 | 
        
           | 2360 | jpm | 1349 | 	miniatureSelectionne.removeClass('miniature-selectionnee');
 | 
        
           |  |  | 1350 | 	miniatureSelectionne.addClass('miniature-cachee');
 | 
        
           |  |  | 1351 | 	var miniatureAffichee = miniatureSelectionne;
 | 
        
           |  |  | 1352 |   | 
        
           |  |  | 1353 | 	if(element.hasClass('defilement-miniatures-gauche')) {
 | 
        
           |  |  | 1354 | 		if(miniatureSelectionne.prev('.miniature').length != 0) {
 | 
        
           | 2372 | jpm | 1355 | 			miniatureAffichee = miniatureSelectionne.prev('.thumbnail');
 | 
        
           | 2360 | jpm | 1356 | 		} else {
 | 
        
           | 2372 | jpm | 1357 | 			miniatureAffichee = miniatureSelectionne.siblings('.thumbnail').last();
 | 
        
           | 2360 | jpm | 1358 | 		}
 | 
        
           |  |  | 1359 | 	} else {
 | 
        
           |  |  | 1360 | 		if(miniatureSelectionne.next('.miniature').length != 0) {
 | 
        
           | 2372 | jpm | 1361 | 			miniatureAffichee = miniatureSelectionne.next('.thumbnail');
 | 
        
           | 2360 | jpm | 1362 | 		} else {
 | 
        
           | 2372 | jpm | 1363 | 			miniatureAffichee = miniatureSelectionne.siblings('.thumbnail').first();
 | 
        
           | 2360 | jpm | 1364 | 		}
 | 
        
           |  |  | 1365 | 	}
 | 
        
           |  |  | 1366 | 	//console.log(miniatureAffichee);
 | 
        
           |  |  | 1367 | 	miniatureAffichee.addClass('miniature-selectionnee');
 | 
        
           |  |  | 1368 | 	miniatureAffichee.removeClass('miniature-cachee');
 | 
        
           |  |  | 1369 | }
 | 
        
           |  |  | 1370 |   | 
        
           | 2372 | jpm | 1371 |   | 
        
           |  |  | 1372 | function formaterNumNomSel(numNomSel) {
 | 
        
           | 2360 | jpm | 1373 | 	var nn = '';
 | 
        
           | 2372 | jpm | 1374 | 	if (numNomSel == undefined) {
 | 
        
           | 2360 | jpm | 1375 | 		nn = '<span class="alert-error">[non lié au référentiel]</span>';
 | 
        
           |  |  | 1376 | 	} else {
 | 
        
           | 2372 | jpm | 1377 | 		nn = '<span class="nn">[nn'+numNomSel+']</span>';
 | 
        
           | 2360 | jpm | 1378 | 	}
 | 
        
           |  |  | 1379 | 	return nn;
 | 
        
           | 2372 | jpm | 1380 | }
 |