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() {
|
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,
|
1577 |
jpm |
220 |
geocoder,
|
|
|
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);
|
1537 |
jpm |
231 |
|
|
|
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 |
});
|
|
|
239 |
|
1540 |
jpm |
240 |
$('#carte-recherche').keypress(function(e) {
|
1537 |
jpm |
241 |
if (e.which == 13) {
|
|
|
242 |
e.preventDefault();
|
|
|
243 |
}
|
|
|
244 |
});
|
|
|
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) {
|
|
|
249 |
|
|
|
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 |
});
|
|
|
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: {
|
|
|
286 |
mapTypeIds: ['OSM',
|
|
|
287 |
google.maps.MapTypeId.ROADMAP,
|
|
|
288 |
google.maps.MapTypeId.HYBRID,
|
|
|
289 |
google.maps.MapTypeId.SATELLITE,
|
|
|
290 |
google.maps.MapTypeId.TERRAIN]}
|
|
|
291 |
};
|
1562 |
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 |
});
|
|
|
304 |
|
|
|
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);
|
|
|
308 |
|
1587 |
jpm |
309 |
// Ajout de l'évènment sur click dans Carte
|
|
|
310 |
google.maps.event.addListener(map, 'click', surClickDansCarte);
|
1537 |
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 |
});
|
|
|
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 |
}
|
1587 |
jpm |
344 |
|
|
|
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 |
}
|
|
|
409 |
|
|
|
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();
|
|
|
423 |
latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLngDeb.lat())/2, (latLngFin.lng() + latLngDeb.lng())/2);
|
|
|
424 |
mettreAJourStationPosition(latLngCentre);
|
1577 |
jpm |
425 |
}
|
|
|
426 |
|
1587 |
jpm |
427 |
function mettreAJourStationPosition(latLng) {
|
1540 |
jpm |
428 |
var lat = latLng.lat().toFixed(5),
|
|
|
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() {
|
|
|
453 |
$('.commune-info').empty();
|
|
|
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) {
|
1537 |
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 |
}
|
|
|
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 |
}
|
|
|
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({
|
|
|
559 |
source: function(requete, add){
|
|
|
560 |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
|
|
|
561 |
|
|
|
562 |
var url = getUrlAutocompletionNomsSci();
|
|
|
563 |
$.getJSON(url, function(data) {
|
|
|
564 |
var suggestions = traiterRetourNomsSci(data);
|
|
|
565 |
add(suggestions);
|
|
|
566 |
});
|
|
|
567 |
},
|
|
|
568 |
html: true
|
|
|
569 |
});
|
|
|
570 |
|
|
|
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(),
|
|
|
583 |
url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_PROJET);
|
|
|
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;
|
|
|
612 |
|
|
|
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
|
|
|
627 |
*
|
|
|
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;
|
|
|
633 |
|
|
|
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 |
}
|
|
|
640 |
|
|
|
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 |
}
|
|
|
655 |
|
|
|
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 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
665 |
//UPLOAD PHOTO : Traitement de l'image
|
|
|
666 |
$(document).ready(function() {
|
1577 |
jpm |
667 |
$('#fichier').on('click change', function(event) {
|
|
|
668 |
if ($(this).val().length > 0) {
|
|
|
669 |
arreter(event);
|
|
|
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
|
|
|
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 |
});
|
|
|
687 |
|
|
|
688 |
$('#photo-placeholder').click(function(event) {
|
|
|
689 |
$('#fichier').click();
|
|
|
690 |
});
|
|
|
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 |
|
1562 |
jpm |
705 |
function afficherMiniature(reponse) {
|
|
|
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(),
|
|
|
722 |
html =
|
|
|
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 |
|
1946 |
jpm |
743 |
$(document).ready(function() {
|
|
|
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 |
});
|
|
|
751 |
|
|
|
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);
|
|
|
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');
|
1540 |
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);
|
1540 |
jpm |
771 |
|
1946 |
jpm |
772 |
// Validation du formulaire
|
1537 |
jpm |
773 |
configurerFormValidator();
|
|
|
774 |
definirReglesFormValidator();
|
1562 |
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 |
}
|
1946 |
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 |
});
|
|
|
806 |
|
1537 |
jpm |
807 |
});
|
|
|
808 |
|
|
|
809 |
function transformerEnSlider(selector) {
|
|
|
810 |
$(selector).each(function(index, el) {
|
|
|
811 |
// hide the element
|
|
|
812 |
$(el).addClass('slider-on');
|
|
|
813 |
|
|
|
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);
|
1562 |
jpm |
824 |
|
|
|
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 |
});
|
|
|
833 |
|
|
|
834 |
slider.find('a').text(el.options[el.selectedIndex].text);
|
|
|
835 |
|
|
|
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));
|
|
|
845 |
|
|
|
846 |
// Add the legend. Half the width of the first and last options for display consistency.
|
|
|
847 |
slider.after('<div class="slider-legend"><p style="width:' + (width / 2) + 'px;text-align:left;">' +
|
|
|
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');
|
|
|
851 |
|
|
|
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(
|
|
|
895 |
'dateCel',
|
|
|
896 |
function (value, element) {
|
|
|
897 |
return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
|
|
|
898 |
},
|
|
|
899 |
'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
|
|
|
900 |
|
|
|
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');
|
|
|
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 {
|
|
|
1058 |
afficherPanneau('#dialogue-form-invalide');
|
|
|
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'),
|
1540 |
jpm |
1067 |
referentiel = (numNomSel == undefined) ? '' : '['+NOM_SCI_PROJET+']',
|
|
|
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();
|
1540 |
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>'+
|
|
|
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>' +
|
1614 |
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 |
});
|
|
|
1130 |
|
|
|
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');
|
1562 |
jpm |
1149 |
|
|
|
1150 |
var miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
|
|
|
1151 |
miniatures += miniature;
|
|
|
1152 |
|
|
|
1153 |
var indicateurActif = premiere ? 'active' : '';
|
|
|
1154 |
var indicateur = '<li class="' + indicateurActif + '" data-numero="' + numero++ + '"></li>';
|
|
|
1155 |
indicateurs += indicateur;
|
|
|
1156 |
|
1540 |
jpm |
1157 |
premiere = false;
|
|
|
1158 |
});
|
1562 |
jpm |
1159 |
|
|
|
1160 |
if ($('#miniatures img').length == 1) {
|
|
|
1161 |
html = miniatures;
|
|
|
1162 |
} else {
|
|
|
1163 |
html =
|
|
|
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;
|
|
|
1183 |
|
|
|
1184 |
var indicateurActif = element.parent().find('.defilement-indicateurs .active');
|
|
|
1185 |
indicateurActif.removeClass('active');
|
|
|
1186 |
|
|
|
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() {
|
|
|
1218 |
NOM_SCI_PROJET = $('#referentiel').val();
|
|
|
1219 |
NOM_SCI_REFERENTIEL = NOM_SCI_PROJET+':'+PROJETS_VERSIONS[NOM_SCI_PROJET];
|
|
|
1220 |
$('#taxon').val('');
|
|
|
1221 |
}
|
|
|
1222 |
|
|
|
1223 |
function surChangementNbreObs() {
|
|
|
1224 |
if (obsNbre == 0) {
|
|
|
1225 |
$('#transmettre-obs').attr('disabled', 'disabled');
|
|
|
1226 |
$('#ajouter-obs').removeAttr('disabled');
|
1564 |
jpm |
1227 |
$('#zone-liste-obs').addClass('hidden');
|
|
|
1228 |
} else {
|
|
|
1229 |
$('#zone-liste-obs').removeClass('hidden');
|
|
|
1230 |
|
|
|
1231 |
if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
|
|
|
1232 |
$('#transmettre-obs').removeAttr('disabled');
|
|
|
1233 |
$('#ajouter-obs').removeAttr('disabled');
|
|
|
1234 |
} else if (obsNbre >= OBS_MAX_NBRE) {
|
|
|
1235 |
$('#ajouter-obs').attr('disabled', 'disabled');
|
|
|
1236 |
afficherPanneau('#dialogue-bloquer-creer-obs');
|
|
|
1237 |
}
|
1537 |
jpm |
1238 |
}
|
|
|
1239 |
}
|
|
|
1240 |
|
1562 |
jpm |
1241 |
function supprimerObs() {
|
|
|
1242 |
var obsId = $(this).val();
|
|
|
1243 |
// Problème avec IE 6 et 7
|
2118 |
aurelien |
1244 |
if (obsId == "Supprimer") {
|
|
|
1245 |
obsId = $(this).attr("title");
|
1562 |
jpm |
1246 |
}
|
2118 |
aurelien |
1247 |
supprimerObsParId(obsId);
|
|
|
1248 |
}
|
|
|
1249 |
|
|
|
1250 |
function supprimerObsParId(obsId) {
|
1562 |
jpm |
1251 |
obsNbre = obsNbre - 1;
|
2118 |
aurelien |
1252 |
$(".obs-nbre").text(obsNbre);
|
|
|
1253 |
$(".obs-nbre").triggerHandler('changement');
|
1562 |
jpm |
1254 |
$('.obs'+obsId).remove();
|
2118 |
aurelien |
1255 |
$("#liste-obs").removeData('obsId'+obsId);
|
1562 |
jpm |
1256 |
}
|
|
|
1257 |
|
2118 |
aurelien |
1258 |
function initialiserBarreProgression() {
|
|
|
1259 |
$('#barre-progression-upload').attr('aria-valuenow', 0);
|
|
|
1260 |
$('#barre-progression-upload').attr('style', "width: 0%");
|
|
|
1261 |
$('#barre-progression-upload .sr-only').text("0/0 observations transmises");
|
|
|
1262 |
$('.progress').addClass('active');
|
|
|
1263 |
$('.progress').addClass('progress-striped');
|
|
|
1264 |
}
|
|
|
1265 |
|
1562 |
jpm |
1266 |
function initialiserObs() {
|
|
|
1267 |
obsNbre = 0;
|
2118 |
aurelien |
1268 |
nbObsTransmises = 0;
|
|
|
1269 |
nbObsEnCours = 0;
|
|
|
1270 |
totalObsATransmettre = 0;
|
|
|
1271 |
initialiserBarreProgression();
|
|
|
1272 |
$(".obs-nbre").text(obsNbre);
|
|
|
1273 |
$(".obs-nbre").triggerHandler('changement');
|
|
|
1274 |
$("#liste-obs").removeData();
|
1562 |
jpm |
1275 |
$('.obs').remove();
|
2118 |
aurelien |
1276 |
$("#dialogue-bloquer-creer-obs").hide();
|
1562 |
jpm |
1277 |
}
|
|
|
1278 |
|
|
|
1279 |
function getNomsImgsOriginales() {
|
|
|
1280 |
var noms = new Array();
|
|
|
1281 |
$('.miniature-img').each(function() {
|
|
|
1282 |
noms.push($(this).attr('alt'));
|
|
|
1283 |
});
|
|
|
1284 |
return noms;
|
|
|
1285 |
}
|
|
|
1286 |
|
1567 |
jpm |
1287 |
function stockerObsData() {
|
|
|
1288 |
var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
|
1614 |
jpm |
1289 |
nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
|
1567 |
jpm |
1290 |
numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
|
1613 |
jpm |
1291 |
nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
|
1567 |
jpm |
1292 |
nomRet = nomHorsListe ? $('#taxon').data('nomRet') : taxons[numNomSel]['nom_ret'],
|
|
|
1293 |
numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : taxons[numNomSel]['num_nom_ret'],
|
|
|
1294 |
numTaxon = nomHorsListe ? $('#taxon').data('nt') : taxons[numNomSel]['num_taxon'],
|
|
|
1295 |
famille = nomHorsListe ? $('#taxon').data('famille') : taxons[numNomSel]['famille'],
|
1614 |
jpm |
1296 |
referentiel = (numNomSel == undefined) ? '' : NOM_SCI_REFERENTIEL,
|
|
|
1297 |
notes = (nomSpecial ? taxons[numNomSel]['nom_fr'] + '. ' : '') + $('#notes').val();
|
1567 |
jpm |
1298 |
|
|
|
1299 |
$('#liste-obs').data('obsId'+obsNbre, {
|
|
|
1300 |
'date': $('#date').val(),
|
1614 |
jpm |
1301 |
'notes': notes,
|
1567 |
jpm |
1302 |
|
|
|
1303 |
'station': $('#station').val(),
|
|
|
1304 |
'latitude': $('#latitude').val(),
|
|
|
1305 |
'longitude': $('#longitude').val(),
|
|
|
1306 |
'commune_nom': $('#commune-nom').text(),
|
|
|
1307 |
'commune_code_insee': $('#commune-code-insee').text(),
|
|
|
1308 |
|
|
|
1309 |
'nom_sel': nomSel,
|
|
|
1310 |
'num_nom_sel': numNomSel,
|
|
|
1311 |
'nom_ret': nomRet,
|
|
|
1312 |
'num_nom_ret': numNomRet,
|
|
|
1313 |
'num_taxon': numTaxon,
|
|
|
1314 |
'famille': famille,
|
|
|
1315 |
'referentiel': referentiel,
|
|
|
1316 |
|
|
|
1317 |
'milieu': getMilieux(),
|
|
|
1318 |
|
|
|
1319 |
// Ajout des champs images
|
|
|
1320 |
'image_nom': getNomsImgsOriginales(),
|
|
|
1321 |
|
|
|
1322 |
// Ajout des champs étendus de l'obs
|
|
|
1323 |
'obs_etendue': getObsChpEtendus()
|
|
|
1324 |
});
|
1577 |
jpm |
1325 |
//console.log($('#liste-obs').data('obsId'+obsNbre));
|
1567 |
jpm |
1326 |
}
|
|
|
1327 |
|
|
|
1328 |
function getObsChpEtendus() {
|
|
|
1329 |
var champs = [],
|
|
|
1330 |
perceptionTechnicien = getPerceptionTechnicien();
|
|
|
1331 |
if (perceptionTechnicien != undefined) {
|
|
|
1332 |
champs.push(perceptionTechnicien);
|
|
|
1333 |
}
|
1577 |
jpm |
1334 |
if (latLngDeb != undefined) {
|
|
|
1335 |
var latitudeDebutRue = {cle: 'latitudeDebutRue', label: 'Latitude du début de la rue', valeur: latLngDeb.lat().toFixed(5)};
|
|
|
1336 |
champs.push(latitudeDebutRue);
|
|
|
1337 |
var longitudeDebutRue = {cle: 'longitudeDebutRue', label: 'Longitude du début de la rue', valeur: latLngDeb.lng().toFixed(5)};
|
|
|
1338 |
champs.push(longitudeDebutRue);
|
|
|
1339 |
}
|
|
|
1340 |
if (latLngFin != undefined) {
|
|
|
1341 |
var latitudeFinRue = {cle: 'latitudeFinRue', label: 'Latitude de fin de la rue', valeur: latLngFin.lat().toFixed(5)};
|
|
|
1342 |
champs.push(latitudeFinRue);
|
|
|
1343 |
var longitudeFinRue = {cle: 'longitudeFinRue', label: 'Longitude de fin de la rue', valeur: latLngFin.lng().toFixed(5)};
|
|
|
1344 |
champs.push(longitudeFinRue);
|
|
|
1345 |
}
|
|
|
1346 |
|
1567 |
jpm |
1347 |
$('.obs-chp-etendu').each(function() {
|
|
|
1348 |
var valeur = $(this).val(),
|
|
|
1349 |
cle = $(this).attr('name'),
|
|
|
1350 |
label = $(this).data('label');
|
|
|
1351 |
if (valeur != '') {
|
|
|
1352 |
var chpEtendu = {cle: cle, label: label, valeur: valeur};
|
|
|
1353 |
champs.push(chpEtendu);
|
1562 |
jpm |
1354 |
}
|
|
|
1355 |
});
|
1567 |
jpm |
1356 |
return champs;
|
1562 |
jpm |
1357 |
}
|
|
|
1358 |
|
1567 |
jpm |
1359 |
function getPerceptionTechnicien() {
|
|
|
1360 |
var perceptionTechnicien = undefined,
|
|
|
1361 |
perceptions = [];
|
|
|
1362 |
$('.cb-perception-technicien:checked').each(function() {
|
|
|
1363 |
perceptions.push($(this).val());
|
|
|
1364 |
});
|
|
|
1365 |
if (perceptions.length > 0) {
|
|
|
1366 |
var valeur = Array.prototype.slice.call(perceptions).join(', ');
|
|
|
1367 |
perceptionTechnicien = {cle: 'perceptionTechnicien', label: "Perceptions par l'équipe", valeur: valeur};
|
|
|
1368 |
}
|
|
|
1369 |
return perceptionTechnicien;
|
|
|
1370 |
}
|
|
|
1371 |
|
1562 |
jpm |
1372 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
1373 |
// TRANSFERER OBS : envoie des obs au CEL
|
2118 |
aurelien |
1374 |
var nbObsEnCours = 1;
|
|
|
1375 |
var totalObsATransmettre = 0;
|
1537 |
jpm |
1376 |
function transmettreObs() {
|
2118 |
aurelien |
1377 |
var observations = $("#liste-obs").data();
|
1537 |
jpm |
1378 |
if (observations == undefined || jQuery.isEmptyObject(observations)) {
|
2118 |
aurelien |
1379 |
afficherPanneau("#dialogue-zero-obs");
|
1537 |
jpm |
1380 |
} else {
|
2118 |
aurelien |
1381 |
nbObsEnCours = 1;
|
|
|
1382 |
nbObsTransmises = 0;
|
|
|
1383 |
totalObsATransmettre = $.map(observations, function(n, i) { return i; }).length;
|
|
|
1384 |
depilerObsPourEnvoi();
|
|
|
1385 |
}
|
|
|
1386 |
return false;
|
|
|
1387 |
}
|
|
|
1388 |
|
|
|
1389 |
function depilerObsPourEnvoi() {
|
|
|
1390 |
var observations = $("#liste-obs").data();
|
|
|
1391 |
// la boucle est factice car on utilise un tableau
|
|
|
1392 |
// dont on a besoin de n'extraire que le premier élément
|
|
|
1393 |
// or javascript n'a pas de méthode cross browsers pour extraire les clés
|
|
|
1394 |
// TODO: utiliser var.keys quand ça sera plus répandu
|
|
|
1395 |
// ou bien utiliser un vrai tableau et pas un objet
|
|
|
1396 |
for (var obsNum in observations) {
|
|
|
1397 |
obsATransmettre = new Object();
|
|
|
1398 |
|
|
|
1399 |
obsATransmettre['projet'] = TAG_PROJET;
|
|
|
1400 |
obsATransmettre['tag-obs'] = TAG_OBS;
|
|
|
1401 |
obsATransmettre['tag-img'] = TAG_IMG;
|
1537 |
jpm |
1402 |
|
|
|
1403 |
var utilisateur = new Object();
|
2118 |
aurelien |
1404 |
utilisateur.id_utilisateur = $("#id_utilisateur").val();
|
|
|
1405 |
utilisateur.prenom = $("#prenom").val();
|
|
|
1406 |
utilisateur.nom = $("#nom").val();
|
|
|
1407 |
utilisateur.courriel = $("#courriel").val();
|
|
|
1408 |
obsATransmettre['utilisateur'] = utilisateur;
|
|
|
1409 |
obsATransmettre[obsNum] = observations[obsNum];
|
|
|
1410 |
var idObsNumerique = obsNum.replace('obsId', '');
|
|
|
1411 |
if(idObsNumerique != "") {
|
|
|
1412 |
envoyerObsAuCel(idObsNumerique, obsATransmettre);
|
|
|
1413 |
}
|
|
|
1414 |
|
|
|
1415 |
break;
|
1537 |
jpm |
1416 |
}
|
|
|
1417 |
}
|
|
|
1418 |
|
2118 |
aurelien |
1419 |
var nbObsTransmises = 0;
|
|
|
1420 |
function mettreAJourProgression() {
|
|
|
1421 |
nbObsTransmises++;
|
|
|
1422 |
var pct = (nbObsTransmises/totalObsATransmettre)*100;
|
|
|
1423 |
$('#barre-progression-upload').attr('aria-valuenow', nbObsTransmises);
|
|
|
1424 |
$('#barre-progression-upload').attr('style', "width: "+pct+"%");
|
|
|
1425 |
$('#barre-progression-upload .sr-only').text(nbObsTransmises+"/"+totalObsATransmettre+" observations transmises");
|
|
|
1426 |
|
|
|
1427 |
if(obsNbre == 0) {
|
|
|
1428 |
$('.progress').removeClass('active');
|
|
|
1429 |
$('.progress').removeClass('progress-striped');
|
|
|
1430 |
}
|
|
|
1431 |
}
|
|
|
1432 |
|
|
|
1433 |
function envoyerObsAuCel(idObs, observation) {
|
1911 |
raphael |
1434 |
var erreurMsg = '',
|
|
|
1435 |
debugNonJson = '';
|
1537 |
jpm |
1436 |
$.ajax({
|
1540 |
jpm |
1437 |
url: SERVICE_SAISIE_URL,
|
|
|
1438 |
type: 'POST',
|
2118 |
aurelien |
1439 |
data: observation,
|
1540 |
jpm |
1440 |
dataType: 'json',
|
|
|
1441 |
beforeSend: function() {
|
1537 |
jpm |
1442 |
$('#dialogue-obs-transaction-ko').hide();
|
|
|
1443 |
$('#dialogue-obs-transaction-ok').hide();
|
1961 |
jpm |
1444 |
$('.alert-txt').empty();
|
1537 |
jpm |
1445 |
$('#chargement').show();
|
|
|
1446 |
},
|
1540 |
jpm |
1447 |
success: function(data, textStatus, jqXHR) {
|
2118 |
aurelien |
1448 |
// mise à jour du nombre d'obs à transmettre
|
|
|
1449 |
// et suppression de l'obs
|
|
|
1450 |
supprimerObsParId(idObs);
|
|
|
1451 |
nbObsEnCours++;
|
|
|
1452 |
// mise à jour du statut
|
|
|
1453 |
mettreAJourProgression();
|
|
|
1454 |
if(obsNbre > 0) {
|
|
|
1455 |
// dépilement de la suivante
|
|
|
1456 |
depilerObsPourEnvoi();
|
|
|
1457 |
}
|
1537 |
jpm |
1458 |
supprimerMiniatures();
|
|
|
1459 |
},
|
1540 |
jpm |
1460 |
statusCode: {
|
|
|
1461 |
500: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
1462 |
erreurMsg += "Erreur 500 :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
1540 |
jpm |
1463 |
}
|
1537 |
jpm |
1464 |
},
|
1540 |
jpm |
1465 |
error: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
1466 |
erreurMsg += "Erreur Ajax :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
|
|
1467 |
try {
|
|
|
1468 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
1469 |
if (reponse != null) {
|
|
|
1470 |
$.each(reponse, function (cle, valeur) {
|
|
|
1471 |
erreurMsg += valeur + "\n";
|
|
|
1472 |
});
|
|
|
1473 |
}
|
|
|
1474 |
} catch(e) {
|
1911 |
raphael |
1475 |
erreurMsg += "L'erreur n'est pas en JSON.";
|
|
|
1476 |
debugNonJson = jqXHR.responseText;
|
1537 |
jpm |
1477 |
}
|
|
|
1478 |
},
|
1540 |
jpm |
1479 |
complete: function(jqXHR, textStatus) {
|
1537 |
jpm |
1480 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
1481 |
|
|
|
1482 |
if (erreurMsg != '') {
|
|
|
1483 |
if (DEBUG) {
|
|
|
1484 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-erreur">' + erreurMsg + '</pre>');
|
1911 |
raphael |
1485 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugNonJson + debugMsg + '</pre>');
|
1537 |
jpm |
1486 |
}
|
1922 |
jpm |
1487 |
var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?' +
|
1540 |
jpm |
1488 |
'subject=Disfonctionnement du widget de saisie ' + TAG_PROJET +
|
1911 |
raphael |
1489 |
'&body=' + erreurMsg + "\nDébogage :\n" + debugMsg + debugNonJson;
|
1537 |
jpm |
1490 |
|
2118 |
aurelien |
1491 |
// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
|
|
|
1492 |
$('#obs'+idObs+' div div').addClass('obs-erreur');
|
|
|
1493 |
window.location.hash = "obs"+idObs;
|
|
|
1494 |
|
1537 |
jpm |
1495 |
$('#dialogue-obs-transaction-ko .alert-txt').append($('#tpl-transmission-ko').clone()
|
|
|
1496 |
.find('.courriel-erreur')
|
|
|
1497 |
.attr('href', hrefCourriel)
|
|
|
1498 |
.end()
|
|
|
1499 |
.html());
|
|
|
1500 |
$('#dialogue-obs-transaction-ko').show();
|
2118 |
aurelien |
1501 |
$("#chargement").hide();
|
|
|
1502 |
initialiserBarreProgression();
|
1537 |
jpm |
1503 |
} else {
|
|
|
1504 |
if (DEBUG) {
|
1911 |
raphael |
1505 |
$('#dialogue-obs-transaction-ok .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugMsg + debugNonJson + '</pre>');
|
1537 |
jpm |
1506 |
}
|
2118 |
aurelien |
1507 |
if(obsNbre == 0) {
|
|
|
1508 |
setTimeout(function() {
|
|
|
1509 |
$("#chargement").hide();
|
|
|
1510 |
$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
|
|
|
1511 |
$("#dialogue-obs-transaction-ok").show();
|
|
|
1512 |
window.location.hash = "dialogue-obs-transaction-ok";
|
|
|
1513 |
initialiserObs();
|
|
|
1514 |
}, 1500);
|
|
|
1515 |
|
|
|
1516 |
}
|
1537 |
jpm |
1517 |
}
|
|
|
1518 |
}
|
|
|
1519 |
});
|
1562 |
jpm |
1520 |
}
|