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