1537 |
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 = '';
|
|
|
30 |
if (jqXHR.getResponseHeader('X-DebugJrest-Data') != '') {
|
|
|
31 |
var debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader('X-DebugJrest-Data'));
|
|
|
32 |
if (debugInfos != null) {
|
|
|
33 |
$.each(debugInfos, function (cle, valeur) {
|
|
|
34 |
msgDebug += valeur + "\n";
|
|
|
35 |
});
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
return msgDebug;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
function afficherPanneau(selecteur) {
|
|
|
42 |
$(selecteur).fadeIn('slow').delay(DUREE_MESSAGE).fadeOut('slow');
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
//+----------------------------------------------------------------------------------------------------------+
|
1580 |
jpm |
46 |
// PRÉCHARGEMENT DU FORMULAIRE
|
1587 |
jpm |
47 |
var latLngDebPre = {lat: null, lng: null},
|
|
|
48 |
latLngFinPre = {lat: null, lng: null},
|
|
|
49 |
okPourChargementCarte = 2;
|
|
|
50 |
|
1580 |
jpm |
51 |
$(document).ready(function() {
|
|
|
52 |
if (OBS_ID != '') {
|
|
|
53 |
chargerInfoObs();
|
|
|
54 |
}
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
function chargerInfoObs() {
|
|
|
58 |
var urlObs = SERVICE_OBS_URL + '/' + OBS_ID;
|
|
|
59 |
$.ajax({
|
|
|
60 |
url: urlObs,
|
|
|
61 |
type: 'GET',
|
|
|
62 |
success: function(data, textStatus, jqXHR) {
|
|
|
63 |
if (data != undefined) {
|
|
|
64 |
prechargerForm(data);
|
|
|
65 |
} else {
|
|
|
66 |
surErreurChargementInfosObs();
|
|
|
67 |
}
|
|
|
68 |
},
|
|
|
69 |
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
70 |
surErreurChargementInfosObs();
|
|
|
71 |
}
|
|
|
72 |
});
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
function prechargerForm(infos) {
|
|
|
76 |
$('input[name="station"]').val(infos.station);
|
|
|
77 |
|
1587 |
jpm |
78 |
//console.log(infos.extension);
|
|
|
79 |
if (infos.extension) {
|
|
|
80 |
var ext = infos.extension;
|
|
|
81 |
if (ext.latitudeDebutRue && ext.longitudeDebutRue && ext.latitudeFinRue && ext.longitudeFinRue) {
|
|
|
82 |
okPourChargementCarte--;
|
|
|
83 |
latLngDebPre.lat = parseFloat(ext.latitudeDebutRue.valeur);
|
|
|
84 |
latLngDebPre.lng = parseFloat(ext.longitudeDebutRue.valeur);
|
|
|
85 |
latLngFinPre.lat = parseFloat(ext.latitudeFinRue.valeur);
|
|
|
86 |
latLngFinPre.lng = parseFloat(ext.longitudeFinRue.valeur);
|
|
|
87 |
prechargerRue();
|
1580 |
jpm |
88 |
}
|
1587 |
jpm |
89 |
|
|
|
90 |
var chpsARemplir = ['adresse', 'typoUrbaine', 'revetementSol', 'presenceZoneVegetalise', 'hauteurBatimentAvoisinant',
|
|
|
91 |
'intensiteGestion', 'periodiciteTraitementPhyto', 'dateArretTraitementPhyto', 'itineraireGestion'];
|
|
|
92 |
$.each(infos.extension, function(nomDuChp, value) {
|
|
|
93 |
if (chpsARemplir.indexOf(nomDuChp) >= 0) {
|
|
|
94 |
if ($('[name="' + nomDuChp + '"]').hasClass('slider')) {
|
|
|
95 |
$('select[name="' + nomDuChp + '"] option[value="' + value.valeur + '"]')
|
|
|
96 |
.attr('selected', 'selected');
|
|
|
97 |
var selectedIndexOptions = $('select[name="' + nomDuChp + '"]').prop('selectedIndex') + 1;
|
|
|
98 |
$('[name="' + nomDuChp + '"]').parent().find('.horizontal-slider').slider('value', selectedIndexOptions);
|
|
|
99 |
|
|
|
100 |
if (nomDuChp == 'periodiciteTraitementPhyto') {
|
|
|
101 |
$('[name="periodiciteTraitementPhyto"]').trigger('change');
|
|
|
102 |
}
|
|
|
103 |
} else {
|
|
|
104 |
$('[name="' + nomDuChp + '"]').val(value.valeur);
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
});
|
|
|
108 |
}
|
1580 |
jpm |
109 |
}
|
|
|
110 |
|
1587 |
jpm |
111 |
function prechargerRue() {
|
|
|
112 |
//console.log('okPourChargementCarte : '+okPourChargementCarte);
|
|
|
113 |
if (okPourChargementCarte == 0) {
|
|
|
114 |
latLngDeb = new google.maps.LatLng(latLngDebPre.lat, latLngDebPre.lng);
|
|
|
115 |
markerDeb = undefined;
|
|
|
116 |
initialiserMarkerDeb();
|
|
|
117 |
deplacerMarkerDeb(latLngDeb);
|
|
|
118 |
premierDeplacement = false;
|
|
|
119 |
markerFin = undefined;
|
|
|
120 |
latLngFin = new google.maps.LatLng(latLngFinPre.lat, latLngFinPre.lng);
|
|
|
121 |
initialiserMarkerFin();
|
|
|
122 |
deplacerMakerFin(latLngFin)
|
|
|
123 |
surDeplacementMarkerFin();
|
|
|
124 |
map.setZoom(16);
|
|
|
125 |
}
|
|
|
126 |
}
|
1580 |
jpm |
127 |
|
|
|
128 |
//+----------------------------------------------------------------------------------------------------------+
|
1562 |
jpm |
129 |
//FORM IDENTITE : gestion de l'observateur
|
|
|
130 |
|
1537 |
jpm |
131 |
$(document).ready(function() {
|
1562 |
jpm |
132 |
$('#courriel').on('blur', requeterIdentite);
|
|
|
133 |
$('#courriel').on('keypress', testerLancementRequeteIdentite);
|
1537 |
jpm |
134 |
});
|
|
|
135 |
|
1562 |
jpm |
136 |
function testerLancementRequeteIdentite(event) {
|
|
|
137 |
if (event.which == 13) {
|
|
|
138 |
requeterIdentite();
|
|
|
139 |
event.preventDefault();
|
|
|
140 |
event.stopPropagation();
|
|
|
141 |
}
|
1537 |
jpm |
142 |
}
|
|
|
143 |
|
1562 |
jpm |
144 |
function requeterIdentite() {
|
|
|
145 |
var courriel = $('#courriel').val();
|
|
|
146 |
//TODO: mettre ceci en paramètre de config
|
|
|
147 |
var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL + courriel;
|
|
|
148 |
$.ajax({
|
|
|
149 |
url: urlAnnuaire,
|
|
|
150 |
type: 'GET',
|
|
|
151 |
success: function(data, textStatus, jqXHR) {
|
|
|
152 |
if (data != undefined && data[courriel] != undefined) {
|
|
|
153 |
var infos = data[courriel];
|
|
|
154 |
$('#id_utilisateur').val(infos.id);
|
|
|
155 |
$('#prenom').val(infos.prenom);
|
|
|
156 |
$('#nom').val(infos.nom);
|
|
|
157 |
$('#courriel_confirmation').val(courriel);
|
|
|
158 |
$('#prenom, #nom, #courriel_confirmation').attr('disabled', 'disabled');
|
1580 |
jpm |
159 |
$('#structure').focus();
|
1562 |
jpm |
160 |
} else {
|
|
|
161 |
surErreurCompletionCourriel();
|
|
|
162 |
}
|
|
|
163 |
},
|
|
|
164 |
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
165 |
surErreurCompletionCourriel();
|
|
|
166 |
},
|
|
|
167 |
complete: function(jqXHR, textStatus) {
|
|
|
168 |
$('#zone-prenom-nom').removeClass('hidden');
|
|
|
169 |
$('#zone-courriel-confirmation').removeClass('hidden');
|
|
|
170 |
}
|
|
|
171 |
});
|
1537 |
jpm |
172 |
}
|
|
|
173 |
|
1562 |
jpm |
174 |
function surErreurCompletionCourriel() {
|
|
|
175 |
$('#prenom, #nom, #courriel_confirmation').val('');
|
|
|
176 |
$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
|
|
|
177 |
afficherPanneau('#dialogue-courriel-introuvable');
|
1537 |
jpm |
178 |
}
|
|
|
179 |
|
1562 |
jpm |
180 |
function formaterNom() {
|
|
|
181 |
$(this).val($(this).val().toUpperCase());
|
1537 |
jpm |
182 |
}
|
|
|
183 |
|
1562 |
jpm |
184 |
function formaterPrenom() {
|
|
|
185 |
var prenom = new Array(),
|
|
|
186 |
mots = $(this).val().split(' ');
|
|
|
187 |
for (var i = 0; i < mots.length; i++) {
|
|
|
188 |
var mot = mots[i];
|
|
|
189 |
if (mot.indexOf('-') >= 0) {
|
|
|
190 |
var prenomCompose = new Array(),
|
|
|
191 |
motsComposes = mot.split('-');
|
|
|
192 |
for (var j = 0; j < motsComposes.length; j++) {
|
|
|
193 |
var motSimple = motsComposes[j],
|
|
|
194 |
motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
|
|
|
195 |
prenomCompose.push(motMajuscule);
|
|
|
196 |
}
|
|
|
197 |
prenom.push(prenomCompose.join('-'));
|
|
|
198 |
} else {
|
|
|
199 |
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
|
|
|
200 |
prenom.push(motMajuscule);
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
$(this).val(prenom.join(' '));
|
|
|
204 |
}
|
|
|
205 |
|
1537 |
jpm |
206 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
207 |
// GOOGLE MAP
|
1562 |
jpm |
208 |
|
1540 |
jpm |
209 |
var map,
|
1577 |
jpm |
210 |
geocoder,
|
|
|
211 |
markerDeb,
|
|
|
212 |
latLngDeb,
|
|
|
213 |
markerFin,
|
|
|
214 |
latLngFin,
|
|
|
215 |
ligneRue,
|
|
|
216 |
premierDeplacement = true;
|
1537 |
jpm |
217 |
|
|
|
218 |
$(document).ready(function() {
|
|
|
219 |
initialiserGoogleMap();
|
1577 |
jpm |
220 |
afficherEtapeGeolocalisation(1);
|
1537 |
jpm |
221 |
|
|
|
222 |
// Autocompletion du champ adresse
|
1540 |
jpm |
223 |
$('#carte-recherche').on('focus', function() {
|
1537 |
jpm |
224 |
$(this).select();
|
|
|
225 |
});
|
1540 |
jpm |
226 |
$('#carte-recherche').on('mouseup', function(event) {// Pour Safari...
|
1537 |
jpm |
227 |
event.preventDefault();
|
|
|
228 |
});
|
|
|
229 |
|
1540 |
jpm |
230 |
$('#carte-recherche').keypress(function(e) {
|
1537 |
jpm |
231 |
if (e.which == 13) {
|
|
|
232 |
e.preventDefault();
|
|
|
233 |
}
|
|
|
234 |
});
|
|
|
235 |
|
1540 |
jpm |
236 |
$('#carte-recherche').autocomplete({
|
1537 |
jpm |
237 |
//Cette partie utilise geocoder pour extraire des valeurs d'adresse
|
|
|
238 |
source: function(request, response) {
|
|
|
239 |
|
|
|
240 |
geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
|
|
|
241 |
if (status == google.maps.GeocoderStatus.OK) {
|
|
|
242 |
response($.map(results, function(item) {
|
|
|
243 |
var retour = {
|
|
|
244 |
label: item.formatted_address,
|
|
|
245 |
value: item.formatted_address,
|
|
|
246 |
latitude: item.geometry.location.lat(),
|
|
|
247 |
longitude: item.geometry.location.lng()
|
|
|
248 |
};
|
|
|
249 |
return retour;
|
|
|
250 |
}));
|
|
|
251 |
} else {
|
|
|
252 |
afficherErreurGoogleMap(status);
|
|
|
253 |
}
|
|
|
254 |
});
|
|
|
255 |
},
|
|
|
256 |
// Cette partie est executee a la selection d'une adresse
|
|
|
257 |
select: function(event, ui) {
|
1587 |
jpm |
258 |
var nouvellePosition = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
|
|
|
259 |
initialiserMarkerDeb();
|
|
|
260 |
deplacerMarkerDeb(nouvellePosition);
|
1577 |
jpm |
261 |
map.setZoom(16);
|
1587 |
jpm |
262 |
afficherEtapeGeolocalisation(2);
|
1537 |
jpm |
263 |
}
|
|
|
264 |
});
|
|
|
265 |
|
1540 |
jpm |
266 |
$('#geolocaliser').on('click', geolocaliser);
|
1537 |
jpm |
267 |
});
|
|
|
268 |
|
|
|
269 |
function initialiserGoogleMap(){
|
1577 |
jpm |
270 |
latLngDeb = new google.maps.LatLng(46.30871, 2.54395);// Centre de la France
|
|
|
271 |
var options = {
|
|
|
272 |
zoom: 5,
|
|
|
273 |
center: latLngDeb,
|
1540 |
jpm |
274 |
mapTypeId: google.maps.MapTypeId.HYBRID,
|
|
|
275 |
mapTypeControlOptions: {
|
|
|
276 |
mapTypeIds: ['OSM',
|
|
|
277 |
google.maps.MapTypeId.ROADMAP,
|
|
|
278 |
google.maps.MapTypeId.HYBRID,
|
|
|
279 |
google.maps.MapTypeId.SATELLITE,
|
|
|
280 |
google.maps.MapTypeId.TERRAIN]}
|
|
|
281 |
};
|
1562 |
jpm |
282 |
|
1537 |
jpm |
283 |
// Ajout de la couche OSM à la carte
|
|
|
284 |
osmMapType = new google.maps.ImageMapType({
|
|
|
285 |
getTileUrl: function(coord, zoom) {
|
1540 |
jpm |
286 |
return 'http://tile.openstreetmap.org/' + zoom + '/' + coord.x + '/' + coord.y + '.png';
|
1537 |
jpm |
287 |
},
|
|
|
288 |
tileSize: new google.maps.Size(256, 256),
|
|
|
289 |
isPng: true,
|
|
|
290 |
alt: 'OpenStreetMap',
|
|
|
291 |
name: 'OSM',
|
|
|
292 |
maxZoom: 19
|
|
|
293 |
});
|
|
|
294 |
|
|
|
295 |
// Création de la carte Google
|
|
|
296 |
map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
|
|
|
297 |
map.mapTypes.set('OSM', osmMapType);
|
|
|
298 |
|
1587 |
jpm |
299 |
// Ajout de l'évènment sur click dans Carte
|
|
|
300 |
google.maps.event.addListener(map, 'click', surClickDansCarte);
|
1537 |
jpm |
301 |
|
1587 |
jpm |
302 |
// Lorsque la carte est chargée, on vérifie si on peut précharger des données
|
|
|
303 |
google.maps.event.addListenerOnce(map, 'idle', function(){
|
|
|
304 |
if (OBS_ID == '') {
|
|
|
305 |
// Initialisation du marker de début de rue
|
|
|
306 |
initialiserMarkerDeb();
|
|
|
307 |
// Tentative de geocalisation si aucune obs à précharger
|
|
|
308 |
if (OBS_ID == '') {
|
|
|
309 |
tenterGeolocalisation();
|
|
|
310 |
}
|
|
|
311 |
} else {
|
|
|
312 |
okPourChargementCarte--;
|
|
|
313 |
prechargerRue();
|
|
|
314 |
}
|
1537 |
jpm |
315 |
});
|
|
|
316 |
|
1587 |
jpm |
317 |
// Création du Geocoder
|
|
|
318 |
geocoder = new google.maps.Geocoder();
|
1537 |
jpm |
319 |
}
|
|
|
320 |
|
1587 |
jpm |
321 |
function initialiserMarkerDeb() {
|
|
|
322 |
premierDeplacement = true;
|
|
|
323 |
if (markerDeb == undefined) {
|
|
|
324 |
// Marqueur de début de Rue
|
|
|
325 |
markerDeb = new google.maps.Marker({
|
|
|
326 |
map: map,
|
|
|
327 |
draggable: true,
|
|
|
328 |
title: 'Début de la portion de rue étudiée',
|
|
|
329 |
icon: GOOGLE_MAP_MARQUEUR_DEBUT_URL,
|
|
|
330 |
position: latLngDeb
|
|
|
331 |
});
|
|
|
332 |
google.maps.event.addListener(markerDeb, 'dragend', surDeplacementMarkerDeb);
|
1577 |
jpm |
333 |
}
|
1587 |
jpm |
334 |
|
|
|
335 |
latLngFin = latLngDeb;
|
|
|
336 |
if (markerFin != undefined) {
|
|
|
337 |
markerFin.setMap(null);
|
|
|
338 |
}
|
|
|
339 |
latLngCentre = latLngDeb;
|
|
|
340 |
if (ligneRue != undefined) {
|
|
|
341 |
ligneRue.setMap(null);
|
|
|
342 |
}
|
1537 |
jpm |
343 |
}
|
|
|
344 |
|
1577 |
jpm |
345 |
function surDeplacementMarkerDeb() {
|
1587 |
jpm |
346 |
deplacerMarkerDeb(markerDeb.getPosition());
|
1577 |
jpm |
347 |
}
|
|
|
348 |
|
1587 |
jpm |
349 |
function deplacerMarkerDeb(nouvellePosition) {
|
|
|
350 |
latLngDeb = nouvellePosition;
|
|
|
351 |
markerDeb.setPosition(latLngDeb);
|
|
|
352 |
map.setCenter(latLngDeb);
|
|
|
353 |
mettreAJourStationPosition(latLngDeb);
|
|
|
354 |
trouverCommune(latLngDeb);
|
1577 |
jpm |
355 |
|
1587 |
jpm |
356 |
if (premierDeplacement) {
|
|
|
357 |
initialiserMarkerDeb();
|
|
|
358 |
premierDeplacement = false;
|
|
|
359 |
} else {
|
|
|
360 |
var nouvellePositionFin = new google.maps.LatLng(latLngDeb.lat(), latLngDeb.lng() + 0.0010);
|
|
|
361 |
initialiserMarkerFin();
|
|
|
362 |
deplacerMakerFin(nouvellePositionFin)
|
|
|
363 |
afficherEtapeGeolocalisation(3);
|
1537 |
jpm |
364 |
}
|
|
|
365 |
}
|
|
|
366 |
|
1587 |
jpm |
367 |
function initialiserMarkerFin() {
|
|
|
368 |
if (markerFin == undefined) {
|
|
|
369 |
markerFin = new google.maps.Marker({
|
|
|
370 |
map: map,
|
|
|
371 |
draggable: true,
|
|
|
372 |
title: 'Fin de la portion de rue étudiée',
|
|
|
373 |
icon: GOOGLE_MAP_MARQUEUR_FIN_URL,
|
|
|
374 |
position: latLngFin
|
1577 |
jpm |
375 |
});
|
1587 |
jpm |
376 |
google.maps.event.addListener(markerFin, 'dragend', surDeplacementMarkerFin);
|
|
|
377 |
} else {
|
|
|
378 |
markerFin.setMap(null);
|
1577 |
jpm |
379 |
}
|
|
|
380 |
}
|
|
|
381 |
|
1587 |
jpm |
382 |
function deplacerMakerFin(nouvellePosition) {
|
|
|
383 |
latLngFin = nouvellePosition;
|
|
|
384 |
markerFin.setMap(map);
|
|
|
385 |
markerFin.setPosition(latLngFin);
|
|
|
386 |
dessinerLigneRue(latLngDeb, latLngFin);
|
1537 |
jpm |
387 |
}
|
|
|
388 |
|
1587 |
jpm |
389 |
function surDeplacementMarkerFin() {
|
|
|
390 |
dessinerLigneRue(markerDeb.getPosition(), markerFin.getPosition());
|
|
|
391 |
afficherCentreRue();
|
|
|
392 |
afficherEtapeGeolocalisation(4);
|
|
|
393 |
}
|
|
|
394 |
|
1577 |
jpm |
395 |
function dessinerLigneRue(pointDebut, pointFin) {
|
|
|
396 |
if (ligneRue != undefined) {
|
|
|
397 |
ligneRue.setMap(null);
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
ligneRue = new google.maps.Polyline({
|
|
|
401 |
path: [pointDebut, pointFin],
|
|
|
402 |
strokeColor: "#FF0000",
|
|
|
403 |
strokeOpacity: 1.0,
|
|
|
404 |
strokeWeight: 2
|
|
|
405 |
});
|
|
|
406 |
|
|
|
407 |
ligneRue.setMap(map);
|
|
|
408 |
}
|
|
|
409 |
|
1587 |
jpm |
410 |
function afficherCentreRue() {
|
|
|
411 |
latLngDeb = markerDeb.getPosition();
|
|
|
412 |
latLngFin = markerFin.getPosition();
|
|
|
413 |
latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLngDeb.lat())/2, (latLngFin.lng() + latLngDeb.lng())/2);
|
|
|
414 |
mettreAJourStationPosition(latLngCentre);
|
1577 |
jpm |
415 |
}
|
|
|
416 |
|
1587 |
jpm |
417 |
function mettreAJourStationPosition(latLng) {
|
1540 |
jpm |
418 |
var lat = latLng.lat().toFixed(5),
|
|
|
419 |
lng = latLng.lng().toFixed(5);
|
1537 |
jpm |
420 |
remplirChampLatitude(lat);
|
|
|
421 |
remplirChampLongitude(lng);
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
function remplirChampLatitude(latDecimale) {
|
|
|
425 |
var lat = Math.round(latDecimale * 100000) / 100000;
|
|
|
426 |
$('#latitude').val(lat);
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
function remplirChampLongitude(lngDecimale) {
|
|
|
430 |
var lng = Math.round(lngDecimale * 100000) / 100000;
|
|
|
431 |
$('#longitude').val(lng);
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
function trouverCommune(pos) {
|
|
|
435 |
$(function() {
|
1540 |
jpm |
436 |
var url_service = SERVICE_NOM_COMMUNE_URL,
|
|
|
437 |
urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
|
1537 |
jpm |
438 |
$.ajax({
|
1540 |
jpm |
439 |
url: urlNomCommuneFormatee,
|
|
|
440 |
type: 'GET',
|
|
|
441 |
dataType: 'jsonp',
|
|
|
442 |
beforeSend: function() {
|
|
|
443 |
$('.commune-info').empty();
|
|
|
444 |
$('#dialogue-erreur .alert-txt').empty();
|
1537 |
jpm |
445 |
},
|
1540 |
jpm |
446 |
success: function(data, textStatus, jqXHR) {
|
|
|
447 |
$('.commune-info').empty();
|
|
|
448 |
$('#commune-nom').append(data.nom);
|
|
|
449 |
$('#commune-code-insee').append(data.codeINSEE);
|
|
|
450 |
$('#marqueur-commune').data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
|
1537 |
jpm |
451 |
},
|
1540 |
jpm |
452 |
statusCode: {
|
|
|
453 |
500: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
454 |
if (DEBUG) {
|
1540 |
jpm |
455 |
$('#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>');
|
1537 |
jpm |
456 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
457 |
var erreurMsg = "";
|
|
|
458 |
if (reponse != null) {
|
|
|
459 |
$.each(reponse, function (cle, valeur) {
|
1540 |
jpm |
460 |
erreurMsg += valeur + '<br />';
|
1537 |
jpm |
461 |
});
|
|
|
462 |
}
|
|
|
463 |
|
1540 |
jpm |
464 |
$('#dialogue-erreur .alert-txt').append(
|
|
|
465 |
'<p class="msg-erreur">Erreur 500 : '+errorThrown+'<br />'+erreurMsg+'</p>');
|
1537 |
jpm |
466 |
}
|
1540 |
jpm |
467 |
}
|
1537 |
jpm |
468 |
},
|
1540 |
jpm |
469 |
error: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
470 |
if (DEBUG) {
|
1540 |
jpm |
471 |
$('#dialogue-erreur .alert-txt').append(
|
|
|
472 |
'<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
|
1537 |
jpm |
473 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
1540 |
jpm |
474 |
var erreurMsg = '';
|
1537 |
jpm |
475 |
if (reponse != null) {
|
|
|
476 |
$.each(reponse, function (cle, valeur) {
|
1540 |
jpm |
477 |
erreurMsg += valeur + '<br />';
|
1537 |
jpm |
478 |
});
|
|
|
479 |
}
|
|
|
480 |
|
1540 |
jpm |
481 |
$('#dialogue-erreur .alert-txt').append(
|
|
|
482 |
'<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
|
1537 |
jpm |
483 |
}
|
|
|
484 |
},
|
1540 |
jpm |
485 |
complete: function(jqXHR, textStatus) {
|
1537 |
jpm |
486 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
487 |
if (debugMsg != '') {
|
|
|
488 |
if (DEBUG) {
|
|
|
489 |
$("#dialogue-erreur .alert-txt").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
|
|
|
490 |
}
|
|
|
491 |
}
|
|
|
492 |
if ($("#dialogue-erreur .msg").length > 0) {
|
|
|
493 |
$("#dialogue-erreur").show();
|
|
|
494 |
}
|
|
|
495 |
}
|
|
|
496 |
});
|
|
|
497 |
});
|
|
|
498 |
}
|
1562 |
jpm |
499 |
|
1587 |
jpm |
500 |
function afficherEtapeGeolocalisation(numEtape) {
|
|
|
501 |
$('.liste_indication_geolocalisation').children().hide();
|
|
|
502 |
$('.liste_indication_geolocalisation :nth-child('+numEtape+')').show();
|
|
|
503 |
}
|
1562 |
jpm |
504 |
|
1587 |
jpm |
505 |
function afficherErreurGoogleMap(status) {
|
|
|
506 |
if (DEBUG) {
|
|
|
507 |
$('#dialogue-google-map .contenu').empty().append(
|
|
|
508 |
'<pre class="msg-erreur">'+
|
|
|
509 |
"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
|
|
|
510 |
'</pre>');
|
|
|
511 |
afficherPanneau('#dialogue-google-map');
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
function geolocaliser(event) {
|
|
|
516 |
var latitude = $('#latitude').val(),
|
|
|
517 |
longitude = $('#longitude').val(),
|
|
|
518 |
nouvellePosition = new google.maps.LatLng(latitude, longitude);
|
|
|
519 |
initialiserMarkerDeb();
|
|
|
520 |
deplacerMarkerDeb(nouvellePosition);
|
|
|
521 |
afficherEtapeGeolocalisation(2);
|
|
|
522 |
map.setZoom(16);
|
|
|
523 |
arreter(event);
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
function tenterGeolocalisation() {
|
|
|
527 |
if (navigator.geolocation) {
|
|
|
528 |
navigator.geolocation.getCurrentPosition(function(position) {
|
|
|
529 |
var latitude = position.coords.latitude,
|
|
|
530 |
longitude = position.coords.longitude,
|
|
|
531 |
nouvellePosition = new google.maps.LatLng(latitude, longitude);
|
|
|
532 |
initialiserMarkerDeb();
|
|
|
533 |
deplacerMarkerDeb(nouvellePosition);
|
|
|
534 |
map.setZoom(16);
|
|
|
535 |
});
|
|
|
536 |
}
|
|
|
537 |
}
|
|
|
538 |
|
|
|
539 |
function surClickDansCarte(event) {
|
|
|
540 |
deplacerMarkerDeb(event.latLng);
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
|
1537 |
jpm |
544 |
//+---------------------------------------------------------------------------------------------------------+
|
1562 |
jpm |
545 |
//AUTO-COMPLÉTION Noms Scientifiques
|
1537 |
jpm |
546 |
|
1562 |
jpm |
547 |
function ajouterAutocompletionNoms() {
|
|
|
548 |
$('#taxon').autocomplete({
|
|
|
549 |
source: function(requete, add){
|
|
|
550 |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
|
|
|
551 |
|
|
|
552 |
var url = getUrlAutocompletionNomsSci();
|
|
|
553 |
$.getJSON(url, function(data) {
|
|
|
554 |
var suggestions = traiterRetourNomsSci(data);
|
|
|
555 |
add(suggestions);
|
|
|
556 |
});
|
|
|
557 |
},
|
|
|
558 |
html: true
|
|
|
559 |
});
|
|
|
560 |
|
|
|
561 |
$('#taxon').bind('autocompleteselect', function(event, ui) {
|
|
|
562 |
$('#taxon').data(ui.item);
|
|
|
563 |
if (ui.item.retenu == true) {
|
|
|
564 |
$('#taxon').addClass('ns-retenu');
|
|
|
565 |
} else {
|
|
|
566 |
$('#taxon').removeClass('ns-retenu');
|
|
|
567 |
}
|
|
|
568 |
});
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
function getUrlAutocompletionNomsSci() {
|
|
|
572 |
var mots = $('#taxon').val(),
|
|
|
573 |
url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_PROJET);
|
|
|
574 |
url = url.replace('{masque}', mots);
|
|
|
575 |
return url;
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
function traiterRetourNomsSci(data) {
|
|
|
579 |
var suggestions = [];
|
|
|
580 |
if (data.resultat != undefined) {
|
|
|
581 |
$.each(data.resultat, function(i, val) {
|
|
|
582 |
val.nn = i;
|
|
|
583 |
var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
|
|
|
584 |
nomRet: '', numNomRet: '', famille: '', retenu: false
|
|
|
585 |
};
|
|
|
586 |
if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
|
|
|
587 |
nom.label = '...';
|
|
|
588 |
nom.value = $('#taxon').val();
|
|
|
589 |
suggestions.push(nom);
|
|
|
590 |
return false;
|
|
|
591 |
} else {
|
|
|
592 |
nom.label = val.nom_sci_complet;
|
|
|
593 |
nom.value = val.nom_sci_complet;
|
|
|
594 |
nom.nt = val.num_taxonomique;
|
|
|
595 |
nom.nomSel = val.nom_sci;
|
|
|
596 |
nom.nomSelComplet = val.nom_sci_complet;
|
|
|
597 |
nom.numNomSel = val.nn;
|
|
|
598 |
nom.nomRet = val.nom_retenu_complet;
|
|
|
599 |
nom.numNomRet = val['nom_retenu.id'];
|
|
|
600 |
nom.famille = val.famille;
|
|
|
601 |
nom.retenu = (val.retenu == 'false') ? false : true;
|
|
|
602 |
|
|
|
603 |
suggestions.push(nom);
|
|
|
604 |
}
|
|
|
605 |
});
|
1537 |
jpm |
606 |
}
|
1562 |
jpm |
607 |
return suggestions;
|
1537 |
jpm |
608 |
}
|
|
|
609 |
|
1562 |
jpm |
610 |
/*
|
|
|
611 |
* jQuery UI Autocomplete HTML Extension
|
|
|
612 |
*
|
|
|
613 |
* Copyright 2010, Scott González (http://scottgonzalez.com)
|
|
|
614 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
615 |
*
|
|
|
616 |
* http://github.com/scottgonzalez/jquery-ui-extensions
|
|
|
617 |
*
|
|
|
618 |
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
|
|
|
619 |
*/
|
|
|
620 |
(function($) {
|
|
|
621 |
var proto = $.ui.autocomplete.prototype,
|
|
|
622 |
initSource = proto._initSource;
|
|
|
623 |
|
|
|
624 |
function filter(array, term) {
|
|
|
625 |
var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
|
|
|
626 |
return $.grep(array, function(value) {
|
|
|
627 |
return matcher.test($('<div>').html(value.label || value.value || value).text());
|
|
|
628 |
});
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
$.extend(proto, {
|
|
|
632 |
_initSource: function() {
|
|
|
633 |
if (this.options.html && $.isArray(this.options.source)) {
|
|
|
634 |
this.source = function( request, response ) {
|
|
|
635 |
response(filter(this.options.source, request.term));
|
|
|
636 |
};
|
1537 |
jpm |
637 |
} else {
|
1562 |
jpm |
638 |
initSource.call(this);
|
1537 |
jpm |
639 |
}
|
|
|
640 |
},
|
1562 |
jpm |
641 |
_renderItem: function(ul, item) {
|
|
|
642 |
if (item.retenu == true) {
|
|
|
643 |
item.label = '<strong>'+item.label+'</strong>';
|
|
|
644 |
}
|
|
|
645 |
|
|
|
646 |
return $('<li></li>')
|
|
|
647 |
.data('item.autocomplete', item)
|
|
|
648 |
.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
|
|
|
649 |
.appendTo(ul);
|
1537 |
jpm |
650 |
}
|
|
|
651 |
});
|
1562 |
jpm |
652 |
})(jQuery);
|
|
|
653 |
|
|
|
654 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
655 |
//UPLOAD PHOTO : Traitement de l'image
|
|
|
656 |
$(document).ready(function() {
|
1577 |
jpm |
657 |
$('#fichier').on('click change', function(event) {
|
|
|
658 |
if ($(this).val().length > 0) {
|
|
|
659 |
arreter(event);
|
|
|
660 |
var options = {
|
|
|
661 |
success: afficherMiniature, // post-submit callback
|
|
|
662 |
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
|
|
|
663 |
resetForm: true // reset the form after successful submit
|
|
|
664 |
};
|
|
|
665 |
$('#miniature').append(
|
|
|
666 |
'<img id="miniature-chargement" class="miniature" alt="chargement" src="'+CHARGEMENT_IMAGE_URL+'"/>');
|
|
|
667 |
$('#ajouter-obs').attr('disabled', 'disabled');
|
|
|
668 |
if (verifierFormat($(this).val())) {
|
|
|
669 |
$('#form-upload').ajaxSubmit(options);
|
|
|
670 |
} else {
|
|
|
671 |
window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+ $('#fichier').attr('accept'));
|
|
|
672 |
}
|
|
|
673 |
return false;
|
|
|
674 |
}
|
1562 |
jpm |
675 |
});
|
|
|
676 |
|
|
|
677 |
$('#photo-placeholder').click(function(event) {
|
|
|
678 |
$('#fichier').click();
|
|
|
679 |
});
|
|
|
680 |
|
1577 |
jpm |
681 |
$('body').on('click', '.effacer-miniature', function(event) {
|
|
|
682 |
supprimerMiniature($(this));
|
1562 |
jpm |
683 |
});
|
|
|
684 |
});
|
|
|
685 |
|
1577 |
jpm |
686 |
|
|
|
687 |
|
1562 |
jpm |
688 |
function verifierFormat(nom) {
|
|
|
689 |
var parts = nom.split('.');
|
|
|
690 |
extension = parts[parts.length - 1];
|
|
|
691 |
return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
|
1537 |
jpm |
692 |
}
|
|
|
693 |
|
1562 |
jpm |
694 |
function afficherMiniature(reponse) {
|
|
|
695 |
if (DEBUG) {
|
|
|
696 |
var debogage = $('debogage', reponse).text();
|
1577 |
jpm |
697 |
//console.log('Débogage upload : ' + debogage);
|
1562 |
jpm |
698 |
}
|
|
|
699 |
var message = $('message', reponse).text();
|
|
|
700 |
if (message != '') {
|
|
|
701 |
$('#miniature-msg').append(message);
|
|
|
702 |
} else {
|
|
|
703 |
$('#miniatures').append(creerWidgetMiniature(reponse));
|
|
|
704 |
}
|
1577 |
jpm |
705 |
$('#ajouter-obs').removeAttr('disabled');
|
1537 |
jpm |
706 |
}
|
1562 |
jpm |
707 |
|
|
|
708 |
function creerWidgetMiniature(reponse) {
|
|
|
709 |
var miniatureUrl = $('miniature-url', reponse).text(),
|
|
|
710 |
imgNom = $('image-nom', reponse).text(),
|
|
|
711 |
html =
|
|
|
712 |
'<div class="miniature">'+
|
|
|
713 |
'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
|
|
|
714 |
'<button class="btn effacer-miniature" type="button">Effacer</button>'+
|
|
|
715 |
'</div>'
|
|
|
716 |
return html;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
function supprimerMiniature(miniature) {
|
|
|
720 |
miniature.parents('.miniature').remove();
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
function supprimerMiniatures() {
|
|
|
724 |
$('#miniatures').empty();
|
|
|
725 |
$('#miniature-msg').empty();
|
|
|
726 |
}
|
|
|
727 |
|
|
|
728 |
|
1537 |
jpm |
729 |
//+---------------------------------------------------------------------------------------------------------+
|
1562 |
jpm |
730 |
// FORMULAIRE : traitements génériques
|
1537 |
jpm |
731 |
|
|
|
732 |
$(document).ready(function() {
|
|
|
733 |
// Sliders
|
|
|
734 |
transformerEnSlider('#presence-zone-vegetalise');
|
|
|
735 |
transformerEnSlider('#hauteur-batiment-avoisinant');
|
|
|
736 |
transformerEnSlider('#periodicite-traitement-phyto');
|
|
|
737 |
transformerEnSlider('#resistance-traitement-phyto');
|
|
|
738 |
transformerEnSlider('#vitesse-croissance');
|
|
|
739 |
|
1540 |
jpm |
740 |
// Afficher/Cacher champs cachés par défaut
|
1587 |
jpm |
741 |
$('#periodicite-traitement-phyto').on('change', surChangementPeriodiciteTraitementPhyto);
|
|
|
742 |
$('#taxon-liste').on('change', surChangementTaxonListe);
|
1537 |
jpm |
743 |
|
|
|
744 |
$('.alert .close').on('click', fermerPanneauAlert);
|
|
|
745 |
|
1608 |
jpm |
746 |
$('.has-tooltip').tooltip('enable');
|
1537 |
jpm |
747 |
$('#btn-aide').on('click', basculerAffichageAide);
|
|
|
748 |
|
|
|
749 |
$('#prenom').on('change', formaterPrenom);
|
|
|
750 |
$('#nom').on('change', formaterNom);
|
|
|
751 |
|
|
|
752 |
configurerDatePicker('#date');
|
|
|
753 |
configurerDatePicker('#date-arret-traitement-phyto');
|
1540 |
jpm |
754 |
|
1537 |
jpm |
755 |
ajouterAutocompletionNoms();
|
1540 |
jpm |
756 |
|
1537 |
jpm |
757 |
configurerFormValidator();
|
|
|
758 |
definirReglesFormValidator();
|
1562 |
jpm |
759 |
|
|
|
760 |
$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
|
|
|
761 |
event.stopPropagation();
|
|
|
762 |
});
|
|
|
763 |
$('.cb-milieux').on('click', function(event) {
|
|
|
764 |
$(this).valid();
|
|
|
765 |
event.stopPropagation();
|
|
|
766 |
});
|
|
|
767 |
|
|
|
768 |
$('input#hauteur-plante').on('blur', function() {
|
|
|
769 |
// if there's a bad value
|
|
|
770 |
var valeur = $(this).val();
|
|
|
771 |
if (! valeur.match(/^[0-9]+$/)) {
|
|
|
772 |
// replace it with nothing
|
|
|
773 |
var nouvelleValeur = valeur.replace(/[^0-9]/g, '');
|
|
|
774 |
$(this).val(nouvelleValeur);
|
|
|
775 |
}
|
|
|
776 |
});
|
|
|
777 |
|
1537 |
jpm |
778 |
$('#courriel_confirmation').on('paste', bloquerCopierCollerCourriel);
|
|
|
779 |
|
|
|
780 |
$('a.afficher-coord').on('click', basculerAffichageCoord);
|
|
|
781 |
|
|
|
782 |
$('#ajouter-obs').on('click', ajouterObs);
|
|
|
783 |
|
|
|
784 |
$('.obs-nbre').on('changement', surChangementNbreObs);
|
|
|
785 |
|
|
|
786 |
$('body').on('click', '.supprimer-obs', supprimerObs);
|
|
|
787 |
|
|
|
788 |
$('#transmettre-obs').on('click', transmettreObs);
|
|
|
789 |
|
1562 |
jpm |
790 |
$('body').on('click', '.defilement-control-zone', function(event) {
|
1537 |
jpm |
791 |
defilerMiniatures($(this));
|
|
|
792 |
});
|
1562 |
jpm |
793 |
$('body').on('mouseover', '.defilement-control-zone', function(event) {
|
|
|
794 |
$('.defilement-control', this).removeClass('hidden');
|
1537 |
jpm |
795 |
});
|
1562 |
jpm |
796 |
$('body').on('mouseout', '.defilement-control-zone', function(event) {
|
|
|
797 |
$('.defilement-control', this).addClass('hidden');
|
1540 |
jpm |
798 |
});
|
|
|
799 |
|
1537 |
jpm |
800 |
});
|
|
|
801 |
|
|
|
802 |
function transformerEnSlider(selector) {
|
|
|
803 |
$(selector).each(function(index, el) {
|
|
|
804 |
// hide the element
|
|
|
805 |
$(el).addClass('slider-on');
|
|
|
806 |
|
|
|
807 |
// add the slider to each element
|
|
|
808 |
var slider = $( '<div class="slider-holder"><div class="horizontal-slider"></div></div>' ).
|
1560 |
jpm |
809 |
insertBefore( el ).find('.horizontal-slider').slider({
|
1537 |
jpm |
810 |
min: 1,
|
|
|
811 |
max: el.options.length,
|
|
|
812 |
range: 'min',
|
|
|
813 |
value: el.selectedIndex + 1,
|
1562 |
jpm |
814 |
slide: function(event, ui) {
|
1537 |
jpm |
815 |
el.selectedIndex = ui.value - 1;
|
|
|
816 |
slider.find('a').text(el.options[el.selectedIndex].text);
|
1562 |
jpm |
817 |
|
|
|
818 |
$(selector + ' option[selected="selected"]').removeAttr('selected');
|
|
|
819 |
$(selector + ' :nth-child('+ui.value+')').attr('selected', 'selected')
|
|
|
820 |
$(selector).valid();
|
1537 |
jpm |
821 |
},
|
|
|
822 |
stop: function() {
|
|
|
823 |
$(el).change();
|
|
|
824 |
}
|
|
|
825 |
});
|
|
|
826 |
|
|
|
827 |
slider.find('a').text(el.options[el.selectedIndex].text);
|
|
|
828 |
|
|
|
829 |
// Create a legend under the slider so we can see the options
|
|
|
830 |
var options = [];
|
|
|
831 |
for (var option in $(el).children()) {
|
|
|
832 |
if (!isNaN(parseInt(option))) {
|
|
|
833 |
options.push(el.options[option].text);
|
|
|
834 |
}
|
|
|
835 |
}
|
|
|
836 |
// the width of each legend/option
|
|
|
837 |
var width = (slider.width() / (options.length - 1));
|
|
|
838 |
|
|
|
839 |
// Add the legend. Half the width of the first and last options for display consistency.
|
|
|
840 |
slider.after('<div class="slider-legend"><p style="width:' + (width / 2) + 'px;text-align:left;">' +
|
|
|
841 |
options.join('</p><p style="width:' + width + 'px;">') +'</p></div>')
|
|
|
842 |
.parent().find('.slider-legend p:last-child').css('width', width / 2)
|
|
|
843 |
.css('text-align', 'right');
|
|
|
844 |
|
|
|
845 |
// if there are too many options so that the text is wider than the width, then hide the text
|
|
|
846 |
var lastChild = slider.parent().find('.slider-legend p:last-child');
|
|
|
847 |
if (lastChild[0].clientWidth < lastChild[0].scrollWidth) {
|
1560 |
jpm |
848 |
slider.parent().find('.slider-legend p');//.css('text-indent', '200%');
|
1537 |
jpm |
849 |
}
|
|
|
850 |
});
|
|
|
851 |
}
|
|
|
852 |
|
1587 |
jpm |
853 |
function surChangementPeriodiciteTraitementPhyto() {
|
|
|
854 |
if ($('#periodicite-traitement-phyto').val() === 'jamais') {
|
|
|
855 |
$('#datp-zone').removeClass('hidden');
|
|
|
856 |
} else {
|
|
|
857 |
$('#datp-zone').addClass('hidden');
|
|
|
858 |
}
|
|
|
859 |
}
|
|
|
860 |
|
|
|
861 |
function surChangementTaxonListe() {
|
|
|
862 |
if ($('#taxon-liste').val() === '?') {
|
|
|
863 |
$('#taxon-input-groupe').removeClass('hidden');
|
|
|
864 |
} else {
|
|
|
865 |
$('#taxon-input-groupe').addClass('hidden');
|
|
|
866 |
}
|
|
|
867 |
}
|
|
|
868 |
|
1562 |
jpm |
869 |
function configurerDatePicker(selector) {
|
|
|
870 |
$.datepicker.setDefaults($.datepicker.regional['fr']);
|
|
|
871 |
$(selector).datepicker({
|
|
|
872 |
dateFormat: 'dd/mm/yy',
|
|
|
873 |
showOn: 'button',
|
|
|
874 |
buttonImageOnly: true,
|
|
|
875 |
buttonImage: CALENDRIER_ICONE_URL,
|
|
|
876 |
buttonText: 'Afficher le calendrier pour saisir la date.',
|
|
|
877 |
showButtonPanel: true,
|
|
|
878 |
onSelect: function(date) {
|
|
|
879 |
$(this).valid();
|
1577 |
jpm |
880 |
}
|
1562 |
jpm |
881 |
});
|
|
|
882 |
$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
|
|
|
883 |
}
|
|
|
884 |
|
1537 |
jpm |
885 |
function configurerFormValidator() {
|
|
|
886 |
$.validator.addMethod(
|
|
|
887 |
'dateCel',
|
|
|
888 |
function (value, element) {
|
|
|
889 |
return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
|
|
|
890 |
},
|
|
|
891 |
'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
|
|
|
892 |
|
|
|
893 |
$.extend($.validator.defaults, {
|
1562 |
jpm |
894 |
ignore: [],// Forcer Jquery Validate à examiner les éléments avec en display:none;
|
1540 |
jpm |
895 |
highlight: function(element) {
|
|
|
896 |
$(element).closest('.control-group').removeClass('success').addClass('error');
|
1537 |
jpm |
897 |
},
|
1540 |
jpm |
898 |
success: function(element) {
|
1560 |
jpm |
899 |
element.text('OK!').addClass('valid');
|
|
|
900 |
element.closest('.control-group').removeClass('error').addClass('success');
|
|
|
901 |
|
1540 |
jpm |
902 |
if (element.attr('id') == 'taxon' && $('#taxon').val() != '') {
|
|
|
903 |
// Si le taxon n'est pas lié au référentiel, on vide le data associé
|
|
|
904 |
if ($('#taxon').data('value') != $('#taxon').val()) {
|
|
|
905 |
$('#taxon').data('numNomSel', '');
|
|
|
906 |
$('#taxon').data('nomRet', '');
|
|
|
907 |
$('#taxon').data('numNomRet', '');
|
|
|
908 |
$('#taxon').data('nt', '');
|
|
|
909 |
$('#taxon').data('famille', '');
|
1537 |
jpm |
910 |
}
|
|
|
911 |
}
|
|
|
912 |
}
|
|
|
913 |
});
|
|
|
914 |
}
|
|
|
915 |
|
|
|
916 |
function definirReglesFormValidator() {
|
|
|
917 |
$('#form-observateur').validate({
|
|
|
918 |
rules: {
|
|
|
919 |
courriel: {
|
|
|
920 |
required: true,
|
|
|
921 |
email: true},
|
|
|
922 |
courriel_confirmation: {
|
|
|
923 |
required: true,
|
1560 |
jpm |
924 |
equalTo: '#courriel'},
|
|
|
925 |
prenom: {
|
|
|
926 |
required: true},
|
|
|
927 |
nom: {
|
|
|
928 |
required: true},
|
|
|
929 |
personneStructure: {
|
|
|
930 |
required: true},
|
|
|
931 |
personneService: {
|
|
|
932 |
required: true}
|
1537 |
jpm |
933 |
}
|
|
|
934 |
});
|
1560 |
jpm |
935 |
$('#form-site').validate({
|
1537 |
jpm |
936 |
rules: {
|
1560 |
jpm |
937 |
station: {
|
|
|
938 |
required: true},
|
1537 |
jpm |
939 |
latitude : {
|
1560 |
jpm |
940 |
required: true,
|
1537 |
jpm |
941 |
range: [-90, 90]},
|
1540 |
jpm |
942 |
longitude: {
|
1560 |
jpm |
943 |
required: true,
|
|
|
944 |
range: [-180, 180]},
|
|
|
945 |
typoUrbaine: {
|
|
|
946 |
required: true},
|
|
|
947 |
revetementSol: {
|
|
|
948 |
required: true},
|
|
|
949 |
intensiteGestion: {
|
|
|
950 |
required: true},
|
|
|
951 |
periodiciteTraitementPhyto: {
|
|
|
952 |
required: true},
|
|
|
953 |
itineraireGestion: {
|
|
|
954 |
required: true}
|
1537 |
jpm |
955 |
}
|
|
|
956 |
});
|
1560 |
jpm |
957 |
$('#form-date').validate({
|
|
|
958 |
rules: {
|
|
|
959 |
date: {
|
|
|
960 |
required: true,
|
|
|
961 |
'dateCel' : true},
|
|
|
962 |
dateDerniereIntervention: {
|
|
|
963 |
required: true}
|
1562 |
jpm |
964 |
},
|
|
|
965 |
errorPlacement: function(error, element) {
|
1577 |
jpm |
966 |
if (element.attr('name') == 'date') {
|
|
|
967 |
element.parent('.input-prepend').after(error);
|
|
|
968 |
} else {
|
|
|
969 |
error.insertAfter(element);
|
|
|
970 |
}
|
|
|
971 |
}
|
1560 |
jpm |
972 |
});
|
1537 |
jpm |
973 |
$('#form-obs').validate({
|
|
|
974 |
rules: {
|
1560 |
jpm |
975 |
'taxon-liste': {
|
|
|
976 |
required: true},
|
1562 |
jpm |
977 |
'milieux[]': {
|
|
|
978 |
required: true,
|
|
|
979 |
minlength: 1},
|
1560 |
jpm |
980 |
hauteurPlante: {
|
|
|
981 |
required: true,
|
|
|
982 |
digits: true},
|
|
|
983 |
resistanceTraitementPhyto: {
|
|
|
984 |
required: true}
|
1562 |
jpm |
985 |
},
|
|
|
986 |
errorPlacement: function(error, element) {
|
1577 |
jpm |
987 |
if (element.attr('name') == 'milieux[]') {
|
|
|
988 |
error.insertAfter('#milieux-controls');
|
|
|
989 |
} else {
|
|
|
990 |
error.insertAfter(element);
|
|
|
991 |
}
|
|
|
992 |
}
|
1537 |
jpm |
993 |
});
|
|
|
994 |
}
|
|
|
995 |
|
1562 |
jpm |
996 |
function validerFormulaire() {
|
|
|
997 |
var observateur = $('#form-observateur').valid(),
|
|
|
998 |
station = $('#form-site').valid(),
|
|
|
999 |
date = $('#form-date').valid(),
|
1577 |
jpm |
1000 |
obs = $('#form-obs').valid(),
|
|
|
1001 |
debRue = (latLngDeb == undefined) ? false : true,
|
|
|
1002 |
finRue = (latLngFin == undefined) ? false : true;
|
|
|
1003 |
var ok = (observateur && station && obs && date && debRue && finRue) ? true : false;
|
|
|
1004 |
//console.log(observateur+'-'+station+'-'+obs+'-'+date+'-'+debRue+'-'+finRue);
|
|
|
1005 |
return ok;
|
1537 |
jpm |
1006 |
}
|
|
|
1007 |
|
1562 |
jpm |
1008 |
|
1537 |
jpm |
1009 |
function fermerPanneauAlert() {
|
|
|
1010 |
$(this).parentsUntil('.zone-alerte', '.alert').hide();
|
|
|
1011 |
}
|
|
|
1012 |
|
1560 |
jpm |
1013 |
function basculerAffichageAide() {
|
1537 |
jpm |
1014 |
if ($(this).hasClass('btn-warning')) {
|
1608 |
jpm |
1015 |
$('.has-tooltip').tooltip('enable');
|
1537 |
jpm |
1016 |
$(this).removeClass('btn-warning').addClass('btn-success');
|
1540 |
jpm |
1017 |
$('#btn-aide-txt', this).text("Désactiver l'aide");
|
1537 |
jpm |
1018 |
} else {
|
1608 |
jpm |
1019 |
$('.has-tooltip').tooltip('disable');
|
1537 |
jpm |
1020 |
$(this).removeClass('btn-success').addClass('btn-warning');
|
|
|
1021 |
$('#btn-aide-txt', this).text("Activer l'aide");
|
|
|
1022 |
}
|
|
|
1023 |
}
|
|
|
1024 |
|
|
|
1025 |
function bloquerCopierCollerCourriel() {
|
|
|
1026 |
afficherPanneau('#dialogue-bloquer-copier-coller');
|
|
|
1027 |
return false;
|
|
|
1028 |
}
|
|
|
1029 |
|
|
|
1030 |
function basculerAffichageCoord() {
|
1540 |
jpm |
1031 |
$('.afficher-coord-action').toggle();
|
1537 |
jpm |
1032 |
$('#coordonnees-geo').toggle('slow');
|
|
|
1033 |
//valeur false pour que le lien ne soit pas suivi
|
|
|
1034 |
return false;
|
|
|
1035 |
}
|
|
|
1036 |
|
1562 |
jpm |
1037 |
|
|
|
1038 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
1039 |
// CRÉER OBS : Gestion des obs
|
|
|
1040 |
|
|
|
1041 |
var obsNbre = 0;
|
|
|
1042 |
|
1537 |
jpm |
1043 |
function ajouterObs() {
|
|
|
1044 |
if (validerFormulaire() == true) {
|
|
|
1045 |
obsNbre = obsNbre + 1;
|
|
|
1046 |
$('.obs-nbre').text(obsNbre);
|
|
|
1047 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
1048 |
afficherObs();
|
|
|
1049 |
stockerObsData();
|
|
|
1050 |
supprimerMiniatures();
|
|
|
1051 |
} else {
|
1577 |
jpm |
1052 |
var debRue = (latLngDeb == undefined) ? false : true,
|
|
|
1053 |
finRue = (latLngFin == undefined) ? false : true;
|
|
|
1054 |
if (debRue == false || finRue == false) {
|
|
|
1055 |
afficherPanneau('#dialogue-form-invalide-rue');
|
|
|
1056 |
} else {
|
|
|
1057 |
afficherPanneau('#dialogue-form-invalide');
|
|
|
1058 |
}
|
1537 |
jpm |
1059 |
}
|
|
|
1060 |
}
|
|
|
1061 |
|
|
|
1062 |
function afficherObs() {
|
1540 |
jpm |
1063 |
var numNomSel = ($('#taxon-liste').val() == '?') ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
|
|
|
1064 |
taxon = ($('#taxon-liste').val() == '?') ? $('#taxon').val() : taxons[numNomSel]['nom_sel'],
|
|
|
1065 |
referentiel = (numNomSel == undefined) ? '' : '['+NOM_SCI_PROJET+']',
|
|
|
1066 |
commune = $('#commune-nom').text(),
|
|
|
1067 |
codeInsee = $('#commune-code-insee').text(),
|
|
|
1068 |
lat = $('input[name="latitude"]').val(),
|
|
|
1069 |
lng = $('input[name="longitude"]').val(),
|
|
|
1070 |
date = $('#date').val(),
|
|
|
1071 |
site = $('#station').val(),
|
1608 |
jpm |
1072 |
revetement = $('#revetement-sol').val(),
|
|
|
1073 |
intensiteGestion = $('#intensite-gestion').val(),
|
|
|
1074 |
resistance = $('#resistance-traitement-phyto').val(),
|
1540 |
jpm |
1075 |
milieux = getMilieux(),
|
|
|
1076 |
notes = $('#notes').val();
|
|
|
1077 |
|
1537 |
jpm |
1078 |
$('#liste-obs').prepend(
|
|
|
1079 |
'<div id="obs'+obsNbre+'" class="row-fluid obs obs'+obsNbre+'">'+
|
|
|
1080 |
'<div class="span12">'+
|
|
|
1081 |
'<div class="well">'+
|
1608 |
jpm |
1082 |
'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
|
1537 |
jpm |
1083 |
'title="Supprimer cette observation de la liste à transmettre">'+
|
|
|
1084 |
'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
|
|
|
1085 |
'<i class="icon-trash icon-white"></i>'+
|
|
|
1086 |
'</button>'+
|
|
|
1087 |
'</div> '+
|
|
|
1088 |
'<div class="row-fluid">'+
|
1562 |
jpm |
1089 |
'<div class="span2 obs-miniatures">'+
|
1537 |
jpm |
1090 |
ajouterImgMiniatureAuTransfert()+
|
|
|
1091 |
'</div>'+
|
1562 |
jpm |
1092 |
'<div class="span8">'+
|
1537 |
jpm |
1093 |
'<ul class="unstyled">'+
|
|
|
1094 |
'<li>'+
|
1540 |
jpm |
1095 |
'<span class="nom-sci">' + taxon + '</span> ' +
|
|
|
1096 |
formaterNumNomSel(numNomSel)+
|
|
|
1097 |
'<span class="referentiel-obs">' + referentiel + '</span>' +
|
|
|
1098 |
' observé à ' +
|
|
|
1099 |
'<span class="commune">' + commune + '</span> ' +
|
|
|
1100 |
'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
|
|
|
1101 |
' le ' +
|
|
|
1102 |
'<span class="date">' + date + '</span>' +
|
|
|
1103 |
'</li>' +
|
|
|
1104 |
'<li>' +
|
1608 |
jpm |
1105 |
'<span>Site :</span> ' + site + ' ' + ' ; ' +
|
|
|
1106 |
'<span>Revêtement au sol :</span> ' + revetement + ' ' + ' ; ' +
|
|
|
1107 |
'<span>Intensité de gestion :</span> ' + intensiteGestion + ' ' + ' ; ' +
|
|
|
1108 |
'<span>Milieu :</span> ' + milieux + ' ' + ' ; ' +
|
|
|
1109 |
'<span>Résistance/Résilience :</span> ' + resistance + ' ' +
|
1540 |
jpm |
1110 |
'</li>' +
|
|
|
1111 |
'<li>' +
|
|
|
1112 |
'Commentaires : <span class="discretion">' + notes + '</span>'+
|
1537 |
jpm |
1113 |
'</li>'+
|
|
|
1114 |
'</ul>'+
|
|
|
1115 |
'</div>'+
|
|
|
1116 |
'</div>'+
|
|
|
1117 |
'</div>'+
|
|
|
1118 |
'</div>'+
|
|
|
1119 |
'</div>');
|
|
|
1120 |
}
|
|
|
1121 |
|
1540 |
jpm |
1122 |
function getMilieux() {
|
|
|
1123 |
var milieuxStr = '',
|
|
|
1124 |
milieux = [];
|
1567 |
jpm |
1125 |
$('.cb-milieux:checked').each(function() {
|
1540 |
jpm |
1126 |
milieux.push($(this).val());
|
|
|
1127 |
});
|
|
|
1128 |
|
|
|
1129 |
milieuxStr = Array.prototype.slice.call(milieux).join(', ');
|
|
|
1130 |
return milieuxStr;
|
|
|
1131 |
}
|
|
|
1132 |
|
|
|
1133 |
function ajouterImgMiniatureAuTransfert() {
|
|
|
1134 |
var html = '',
|
|
|
1135 |
miniatures = '',
|
1562 |
jpm |
1136 |
indicateurs = '',
|
|
|
1137 |
premiere = true,
|
|
|
1138 |
numero = 1;
|
|
|
1139 |
if ($('#miniatures img').length == 0) {
|
|
|
1140 |
html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
|
|
|
1141 |
} else if ($('#miniatures img').length >= 1) {
|
1540 |
jpm |
1142 |
$('#miniatures img').each(function() {
|
|
|
1143 |
var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee',
|
|
|
1144 |
css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
|
|
|
1145 |
src = $(this).attr('src'),
|
|
|
1146 |
alt = $(this).attr('alt');
|
1562 |
jpm |
1147 |
|
|
|
1148 |
var miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
|
|
|
1149 |
miniatures += miniature;
|
|
|
1150 |
|
|
|
1151 |
var indicateurActif = premiere ? 'active' : '';
|
|
|
1152 |
var indicateur = '<li class="' + indicateurActif + '" data-numero="' + numero++ + '"></li>';
|
|
|
1153 |
indicateurs += indicateur;
|
|
|
1154 |
|
1540 |
jpm |
1155 |
premiere = false;
|
|
|
1156 |
});
|
1562 |
jpm |
1157 |
|
|
|
1158 |
if ($('#miniatures img').length == 1) {
|
|
|
1159 |
html = miniatures;
|
|
|
1160 |
} else {
|
|
|
1161 |
html =
|
|
|
1162 |
'<div class="defilement">' +
|
|
|
1163 |
miniatures +
|
|
|
1164 |
'<a class="defilement-control-zone gauche">' +
|
|
|
1165 |
' <span class="defilement-control gauche hidden"><</span>' +
|
|
|
1166 |
'</a>' +
|
|
|
1167 |
'<a class="defilement-control-zone droite">' +
|
|
|
1168 |
' <span class="defilement-control droite hidden">></span>' +
|
|
|
1169 |
'</a>' +
|
|
|
1170 |
'<ol class="defilement-indicateurs">' + indicateurs + '</ol>' +
|
|
|
1171 |
'</div>';
|
|
|
1172 |
}
|
1540 |
jpm |
1173 |
}
|
|
|
1174 |
return html;
|
|
|
1175 |
}
|
|
|
1176 |
|
1562 |
jpm |
1177 |
function defilerMiniatures(element) {
|
|
|
1178 |
var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
|
|
|
1179 |
miniatureSelectionne.removeClass('miniature-selectionnee').addClass('miniature-cachee');
|
|
|
1180 |
var miniatureAffichee = miniatureSelectionne;
|
|
|
1181 |
|
|
|
1182 |
var indicateurActif = element.parent().find('.defilement-indicateurs .active');
|
|
|
1183 |
indicateurActif.removeClass('active');
|
|
|
1184 |
|
|
|
1185 |
if (element.hasClass('defilement-control-zone') && element.hasClass('gauche')) {
|
|
|
1186 |
if (miniatureSelectionne.prev('.miniature').length != 0) {
|
|
|
1187 |
miniatureAffichee = miniatureSelectionne.prev('.miniature');
|
|
|
1188 |
indicateurActif.prev().addClass('active');
|
|
|
1189 |
} else {
|
|
|
1190 |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
|
|
|
1191 |
indicateurActif.siblings().last().addClass('active');
|
|
|
1192 |
}
|
|
|
1193 |
} else {
|
|
|
1194 |
if (miniatureSelectionne.next('.miniature').length != 0) {
|
|
|
1195 |
miniatureAffichee = miniatureSelectionne.next('.miniature');
|
|
|
1196 |
indicateurActif.next().addClass('active');
|
|
|
1197 |
} else {
|
|
|
1198 |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
|
|
|
1199 |
indicateurActif.siblings().first().addClass('active');
|
|
|
1200 |
}
|
|
|
1201 |
}
|
|
|
1202 |
miniatureAffichee.addClass('miniature-selectionnee').removeClass('miniature-cachee');
|
|
|
1203 |
}
|
|
|
1204 |
|
1540 |
jpm |
1205 |
function formaterNumNomSel(numNomSel) {
|
|
|
1206 |
var nn = '';
|
|
|
1207 |
if (numNomSel == undefined) {
|
|
|
1208 |
nn = '<span class="alert-error">[non lié au référentiel]</span>';
|
|
|
1209 |
} else {
|
|
|
1210 |
nn = '<span class="nn">[nn'+numNomSel+']</span>';
|
|
|
1211 |
}
|
|
|
1212 |
return nn;
|
|
|
1213 |
}
|
|
|
1214 |
|
1537 |
jpm |
1215 |
function surChangementReferentiel() {
|
|
|
1216 |
NOM_SCI_PROJET = $('#referentiel').val();
|
|
|
1217 |
NOM_SCI_REFERENTIEL = NOM_SCI_PROJET+':'+PROJETS_VERSIONS[NOM_SCI_PROJET];
|
|
|
1218 |
$('#taxon').val('');
|
|
|
1219 |
}
|
|
|
1220 |
|
|
|
1221 |
function surChangementNbreObs() {
|
|
|
1222 |
if (obsNbre == 0) {
|
|
|
1223 |
$('#transmettre-obs').attr('disabled', 'disabled');
|
|
|
1224 |
$('#ajouter-obs').removeAttr('disabled');
|
1564 |
jpm |
1225 |
$('#zone-liste-obs').addClass('hidden');
|
|
|
1226 |
} else {
|
|
|
1227 |
$('#zone-liste-obs').removeClass('hidden');
|
|
|
1228 |
|
|
|
1229 |
if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
|
|
|
1230 |
$('#transmettre-obs').removeAttr('disabled');
|
|
|
1231 |
$('#ajouter-obs').removeAttr('disabled');
|
|
|
1232 |
} else if (obsNbre >= OBS_MAX_NBRE) {
|
|
|
1233 |
$('#ajouter-obs').attr('disabled', 'disabled');
|
|
|
1234 |
afficherPanneau('#dialogue-bloquer-creer-obs');
|
|
|
1235 |
}
|
1537 |
jpm |
1236 |
}
|
|
|
1237 |
}
|
|
|
1238 |
|
1562 |
jpm |
1239 |
function supprimerObs() {
|
|
|
1240 |
var obsId = $(this).val();
|
|
|
1241 |
// Problème avec IE 6 et 7
|
|
|
1242 |
if (obsId == 'Supprimer') {
|
|
|
1243 |
obsId = $(this).attr('title');
|
|
|
1244 |
}
|
|
|
1245 |
obsNbre = obsNbre - 1;
|
|
|
1246 |
$('.obs-nbre').text(obsNbre);
|
|
|
1247 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
1248 |
|
|
|
1249 |
$('.obs'+obsId).remove();
|
|
|
1250 |
$('#liste-obs').removeData('obsId' + obsId);
|
|
|
1251 |
}
|
|
|
1252 |
|
|
|
1253 |
function initialiserObs() {
|
|
|
1254 |
obsNbre = 0;
|
|
|
1255 |
$('.obs-nbre').text(obsNbre);
|
|
|
1256 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
1257 |
$('#liste-obs').removeData();
|
|
|
1258 |
$('.obs').remove();
|
|
|
1259 |
$('#dialogue-bloquer-creer-obs').hide();
|
|
|
1260 |
}
|
|
|
1261 |
|
|
|
1262 |
function getNomsImgsOriginales() {
|
|
|
1263 |
var noms = new Array();
|
|
|
1264 |
$('.miniature-img').each(function() {
|
|
|
1265 |
noms.push($(this).attr('alt'));
|
|
|
1266 |
});
|
|
|
1267 |
return noms;
|
|
|
1268 |
}
|
|
|
1269 |
|
1567 |
jpm |
1270 |
function stockerObsData() {
|
|
|
1271 |
var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
|
|
|
1272 |
numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
|
|
|
1273 |
nomSel = nomHorsListe ? $('#taxon').val() : taxons[numNomSel]['nom_sel'],
|
|
|
1274 |
nomRet = nomHorsListe ? $('#taxon').data('nomRet') : taxons[numNomSel]['nom_ret'],
|
|
|
1275 |
numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : taxons[numNomSel]['num_nom_ret'],
|
|
|
1276 |
numTaxon = nomHorsListe ? $('#taxon').data('nt') : taxons[numNomSel]['num_taxon'],
|
|
|
1277 |
famille = nomHorsListe ? $('#taxon').data('famille') : taxons[numNomSel]['famille'],
|
|
|
1278 |
referentiel = (numNomSel == undefined) ? '' : NOM_SCI_REFERENTIEL;
|
|
|
1279 |
|
|
|
1280 |
$('#liste-obs').data('obsId'+obsNbre, {
|
|
|
1281 |
'date': $('#date').val(),
|
|
|
1282 |
'notes': $('#notes').val(),
|
|
|
1283 |
|
|
|
1284 |
'station': $('#station').val(),
|
|
|
1285 |
'latitude': $('#latitude').val(),
|
|
|
1286 |
'longitude': $('#longitude').val(),
|
|
|
1287 |
'commune_nom': $('#commune-nom').text(),
|
|
|
1288 |
'commune_code_insee': $('#commune-code-insee').text(),
|
|
|
1289 |
|
|
|
1290 |
'nom_sel': nomSel,
|
|
|
1291 |
'num_nom_sel': numNomSel,
|
|
|
1292 |
'nom_ret': nomRet,
|
|
|
1293 |
'num_nom_ret': numNomRet,
|
|
|
1294 |
'num_taxon': numTaxon,
|
|
|
1295 |
'famille': famille,
|
|
|
1296 |
'referentiel': referentiel,
|
|
|
1297 |
|
|
|
1298 |
'milieu': getMilieux(),
|
|
|
1299 |
|
|
|
1300 |
// Ajout des champs images
|
|
|
1301 |
'image_nom': getNomsImgsOriginales(),
|
|
|
1302 |
|
|
|
1303 |
// Ajout des champs étendus de l'obs
|
|
|
1304 |
'obs_etendue': getObsChpEtendus()
|
|
|
1305 |
});
|
1577 |
jpm |
1306 |
//console.log($('#liste-obs').data('obsId'+obsNbre));
|
1567 |
jpm |
1307 |
}
|
|
|
1308 |
|
|
|
1309 |
function getObsChpEtendus() {
|
|
|
1310 |
var champs = [],
|
|
|
1311 |
perceptionTechnicien = getPerceptionTechnicien();
|
|
|
1312 |
if (perceptionTechnicien != undefined) {
|
|
|
1313 |
champs.push(perceptionTechnicien);
|
|
|
1314 |
}
|
1577 |
jpm |
1315 |
if (latLngDeb != undefined) {
|
|
|
1316 |
var latitudeDebutRue = {cle: 'latitudeDebutRue', label: 'Latitude du début de la rue', valeur: latLngDeb.lat().toFixed(5)};
|
|
|
1317 |
champs.push(latitudeDebutRue);
|
|
|
1318 |
var longitudeDebutRue = {cle: 'longitudeDebutRue', label: 'Longitude du début de la rue', valeur: latLngDeb.lng().toFixed(5)};
|
|
|
1319 |
champs.push(longitudeDebutRue);
|
|
|
1320 |
}
|
|
|
1321 |
if (latLngFin != undefined) {
|
|
|
1322 |
var latitudeFinRue = {cle: 'latitudeFinRue', label: 'Latitude de fin de la rue', valeur: latLngFin.lat().toFixed(5)};
|
|
|
1323 |
champs.push(latitudeFinRue);
|
|
|
1324 |
var longitudeFinRue = {cle: 'longitudeFinRue', label: 'Longitude de fin de la rue', valeur: latLngFin.lng().toFixed(5)};
|
|
|
1325 |
champs.push(longitudeFinRue);
|
|
|
1326 |
}
|
|
|
1327 |
|
1567 |
jpm |
1328 |
$('.obs-chp-etendu').each(function() {
|
|
|
1329 |
var valeur = $(this).val(),
|
|
|
1330 |
cle = $(this).attr('name'),
|
|
|
1331 |
label = $(this).data('label');
|
|
|
1332 |
if (valeur != '') {
|
|
|
1333 |
var chpEtendu = {cle: cle, label: label, valeur: valeur};
|
|
|
1334 |
champs.push(chpEtendu);
|
1562 |
jpm |
1335 |
}
|
|
|
1336 |
});
|
1567 |
jpm |
1337 |
return champs;
|
1562 |
jpm |
1338 |
}
|
|
|
1339 |
|
1567 |
jpm |
1340 |
function getPerceptionTechnicien() {
|
|
|
1341 |
var perceptionTechnicien = undefined,
|
|
|
1342 |
perceptions = [];
|
|
|
1343 |
$('.cb-perception-technicien:checked').each(function() {
|
|
|
1344 |
perceptions.push($(this).val());
|
|
|
1345 |
});
|
|
|
1346 |
if (perceptions.length > 0) {
|
|
|
1347 |
var valeur = Array.prototype.slice.call(perceptions).join(', ');
|
|
|
1348 |
perceptionTechnicien = {cle: 'perceptionTechnicien', label: "Perceptions par l'équipe", valeur: valeur};
|
|
|
1349 |
}
|
|
|
1350 |
return perceptionTechnicien;
|
|
|
1351 |
}
|
|
|
1352 |
|
1562 |
jpm |
1353 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
1354 |
// TRANSFERER OBS : envoie des obs au CEL
|
|
|
1355 |
|
1537 |
jpm |
1356 |
function transmettreObs() {
|
|
|
1357 |
var observations = $('#liste-obs').data();
|
|
|
1358 |
|
|
|
1359 |
if (observations == undefined || jQuery.isEmptyObject(observations)) {
|
|
|
1360 |
afficherPanneau('#dialogue-zero-obs');
|
|
|
1361 |
} else {
|
|
|
1362 |
observations['projet'] = TAG_PROJET;
|
|
|
1363 |
observations['tag-obs'] = TAG_OBS;
|
|
|
1364 |
observations['tag-img'] = TAG_IMG;
|
|
|
1365 |
|
|
|
1366 |
var utilisateur = new Object();
|
|
|
1367 |
utilisateur.id_utilisateur = $('#id_utilisateur').val();
|
|
|
1368 |
utilisateur.prenom = $('#prenom').val();
|
|
|
1369 |
utilisateur.nom = $('#nom').val();
|
|
|
1370 |
utilisateur.courriel = $('#courriel').val();
|
|
|
1371 |
observations['utilisateur'] = utilisateur;
|
|
|
1372 |
envoyerObsAuCel(observations);
|
|
|
1373 |
}
|
|
|
1374 |
return false;
|
|
|
1375 |
}
|
|
|
1376 |
|
|
|
1377 |
function envoyerObsAuCel(observations) {
|
|
|
1378 |
var erreurMsg = '';
|
|
|
1379 |
$.ajax({
|
1540 |
jpm |
1380 |
url: SERVICE_SAISIE_URL,
|
|
|
1381 |
type: 'POST',
|
|
|
1382 |
data: observations,
|
|
|
1383 |
dataType: 'json',
|
|
|
1384 |
beforeSend: function() {
|
1537 |
jpm |
1385 |
$('#dialogue-obs-transaction-ko').hide();
|
|
|
1386 |
$('#dialogue-obs-transaction-ok').hide();
|
|
|
1387 |
$('.alert-txt .msg').remove();
|
|
|
1388 |
$('.alert-txt .msg-erreur').remove();
|
|
|
1389 |
$('.alert-txt .msg-debug').remove();
|
|
|
1390 |
$('#chargement').show();
|
|
|
1391 |
},
|
1540 |
jpm |
1392 |
success: function(data, textStatus, jqXHR) {
|
1537 |
jpm |
1393 |
$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
|
|
|
1394 |
supprimerMiniatures();
|
|
|
1395 |
},
|
1540 |
jpm |
1396 |
statusCode: {
|
|
|
1397 |
500: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
1398 |
erreurMsg += "Erreur 500 :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
1540 |
jpm |
1399 |
}
|
1537 |
jpm |
1400 |
},
|
1540 |
jpm |
1401 |
error: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
1402 |
erreurMsg += "Erreur Ajax :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
|
|
1403 |
try {
|
|
|
1404 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
1405 |
if (reponse != null) {
|
|
|
1406 |
$.each(reponse, function (cle, valeur) {
|
|
|
1407 |
erreurMsg += valeur + "\n";
|
|
|
1408 |
});
|
|
|
1409 |
}
|
|
|
1410 |
} catch(e) {
|
|
|
1411 |
erreurMsg += "L'erreur n'était pas en JSON.";
|
|
|
1412 |
}
|
|
|
1413 |
},
|
1540 |
jpm |
1414 |
complete: function(jqXHR, textStatus) {
|
1537 |
jpm |
1415 |
$('#chargement').hide();
|
|
|
1416 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
1417 |
|
|
|
1418 |
if (erreurMsg != '') {
|
|
|
1419 |
if (DEBUG) {
|
|
|
1420 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-erreur">' + erreurMsg + '</pre>');
|
|
|
1421 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>');
|
|
|
1422 |
}
|
1540 |
jpm |
1423 |
var hrefCourriel = 'mailto:cel@tela-botanica.org?' +
|
|
|
1424 |
'subject=Disfonctionnement du widget de saisie ' + TAG_PROJET +
|
|
|
1425 |
'&body=' + erreurMsg + "\nDébogage :\n" + debugMsg;
|
1537 |
jpm |
1426 |
|
|
|
1427 |
$('#dialogue-obs-transaction-ko .alert-txt').append($('#tpl-transmission-ko').clone()
|
|
|
1428 |
.find('.courriel-erreur')
|
|
|
1429 |
.attr('href', hrefCourriel)
|
|
|
1430 |
.end()
|
|
|
1431 |
.html());
|
|
|
1432 |
$('#dialogue-obs-transaction-ko').show();
|
|
|
1433 |
} else {
|
|
|
1434 |
if (DEBUG) {
|
|
|
1435 |
$('#dialogue-obs-transaction-ok .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>');
|
|
|
1436 |
}
|
|
|
1437 |
$('#dialogue-obs-transaction-ok').show();
|
|
|
1438 |
}
|
|
|
1439 |
initialiserObs();
|
|
|
1440 |
}
|
|
|
1441 |
});
|
1562 |
jpm |
1442 |
}
|