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;
|
|
|
1044 |
|
1537 |
jpm |
1045 |
function ajouterObs() {
|
|
|
1046 |
if (validerFormulaire() == true) {
|
|
|
1047 |
obsNbre = obsNbre + 1;
|
|
|
1048 |
$('.obs-nbre').text(obsNbre);
|
|
|
1049 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
1050 |
afficherObs();
|
|
|
1051 |
stockerObsData();
|
|
|
1052 |
supprimerMiniatures();
|
|
|
1053 |
} else {
|
1577 |
jpm |
1054 |
var debRue = (latLngDeb == undefined) ? false : true,
|
|
|
1055 |
finRue = (latLngFin == undefined) ? false : true;
|
|
|
1056 |
if (debRue == false || finRue == false) {
|
|
|
1057 |
afficherPanneau('#dialogue-form-invalide-rue');
|
|
|
1058 |
} else {
|
|
|
1059 |
afficherPanneau('#dialogue-form-invalide');
|
|
|
1060 |
}
|
1537 |
jpm |
1061 |
}
|
|
|
1062 |
}
|
|
|
1063 |
|
|
|
1064 |
function afficherObs() {
|
1540 |
jpm |
1065 |
var numNomSel = ($('#taxon-liste').val() == '?') ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
|
1614 |
jpm |
1066 |
nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
|
1613 |
jpm |
1067 |
taxon = ($('#taxon-liste').val() == '?') ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
|
1540 |
jpm |
1068 |
referentiel = (numNomSel == undefined) ? '' : '['+NOM_SCI_PROJET+']',
|
|
|
1069 |
commune = $('#commune-nom').text(),
|
|
|
1070 |
codeInsee = $('#commune-code-insee').text(),
|
|
|
1071 |
lat = $('input[name="latitude"]').val(),
|
|
|
1072 |
lng = $('input[name="longitude"]').val(),
|
|
|
1073 |
date = $('#date').val(),
|
|
|
1074 |
site = $('#station').val(),
|
1608 |
jpm |
1075 |
revetement = $('#revetement-sol').val(),
|
|
|
1076 |
intensiteGestion = $('#intensite-gestion').val(),
|
|
|
1077 |
resistance = $('#resistance-traitement-phyto').val(),
|
1540 |
jpm |
1078 |
milieux = getMilieux(),
|
1614 |
jpm |
1079 |
notes = (nomSpecial ? taxons[numNomSel]['nom_fr'] + ".<br />" : '') + $('#notes').val();
|
1540 |
jpm |
1080 |
|
1537 |
jpm |
1081 |
$('#liste-obs').prepend(
|
|
|
1082 |
'<div id="obs'+obsNbre+'" class="row-fluid obs obs'+obsNbre+'">'+
|
|
|
1083 |
'<div class="span12">'+
|
|
|
1084 |
'<div class="well">'+
|
1608 |
jpm |
1085 |
'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
|
1537 |
jpm |
1086 |
'title="Supprimer cette observation de la liste à transmettre">'+
|
|
|
1087 |
'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
|
|
|
1088 |
'<i class="icon-trash icon-white"></i>'+
|
|
|
1089 |
'</button>'+
|
|
|
1090 |
'</div> '+
|
|
|
1091 |
'<div class="row-fluid">'+
|
1562 |
jpm |
1092 |
'<div class="span2 obs-miniatures">'+
|
1537 |
jpm |
1093 |
ajouterImgMiniatureAuTransfert()+
|
|
|
1094 |
'</div>'+
|
1562 |
jpm |
1095 |
'<div class="span8">'+
|
1537 |
jpm |
1096 |
'<ul class="unstyled">'+
|
|
|
1097 |
'<li>'+
|
1540 |
jpm |
1098 |
'<span class="nom-sci">' + taxon + '</span> ' +
|
|
|
1099 |
formaterNumNomSel(numNomSel)+
|
|
|
1100 |
'<span class="referentiel-obs">' + referentiel + '</span>' +
|
|
|
1101 |
' observé à ' +
|
|
|
1102 |
'<span class="commune">' + commune + '</span> ' +
|
|
|
1103 |
'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
|
|
|
1104 |
' le ' +
|
|
|
1105 |
'<span class="date">' + date + '</span>' +
|
|
|
1106 |
'</li>' +
|
|
|
1107 |
'<li>' +
|
1608 |
jpm |
1108 |
'<span>Site :</span> ' + site + ' ' + ' ; ' +
|
|
|
1109 |
'<span>Revêtement au sol :</span> ' + revetement + ' ' + ' ; ' +
|
|
|
1110 |
'<span>Intensité de gestion :</span> ' + intensiteGestion + ' ' + ' ; ' +
|
|
|
1111 |
'<span>Milieu :</span> ' + milieux + ' ' + ' ; ' +
|
|
|
1112 |
'<span>Résistance/Résilience :</span> ' + resistance + ' ' +
|
1540 |
jpm |
1113 |
'</li>' +
|
|
|
1114 |
'<li>' +
|
1614 |
jpm |
1115 |
'Commentaires : ' + notes +
|
1537 |
jpm |
1116 |
'</li>'+
|
|
|
1117 |
'</ul>'+
|
|
|
1118 |
'</div>'+
|
|
|
1119 |
'</div>'+
|
|
|
1120 |
'</div>'+
|
|
|
1121 |
'</div>'+
|
|
|
1122 |
'</div>');
|
|
|
1123 |
}
|
|
|
1124 |
|
1540 |
jpm |
1125 |
function getMilieux() {
|
|
|
1126 |
var milieuxStr = '',
|
|
|
1127 |
milieux = [];
|
1567 |
jpm |
1128 |
$('.cb-milieux:checked').each(function() {
|
1540 |
jpm |
1129 |
milieux.push($(this).val());
|
|
|
1130 |
});
|
|
|
1131 |
|
|
|
1132 |
milieuxStr = Array.prototype.slice.call(milieux).join(', ');
|
|
|
1133 |
return milieuxStr;
|
|
|
1134 |
}
|
|
|
1135 |
|
|
|
1136 |
function ajouterImgMiniatureAuTransfert() {
|
|
|
1137 |
var html = '',
|
|
|
1138 |
miniatures = '',
|
1562 |
jpm |
1139 |
indicateurs = '',
|
|
|
1140 |
premiere = true,
|
|
|
1141 |
numero = 1;
|
|
|
1142 |
if ($('#miniatures img').length == 0) {
|
|
|
1143 |
html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
|
|
|
1144 |
} else if ($('#miniatures img').length >= 1) {
|
1540 |
jpm |
1145 |
$('#miniatures img').each(function() {
|
|
|
1146 |
var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee',
|
|
|
1147 |
css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
|
|
|
1148 |
src = $(this).attr('src'),
|
|
|
1149 |
alt = $(this).attr('alt');
|
1562 |
jpm |
1150 |
|
|
|
1151 |
var miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
|
|
|
1152 |
miniatures += miniature;
|
|
|
1153 |
|
|
|
1154 |
var indicateurActif = premiere ? 'active' : '';
|
|
|
1155 |
var indicateur = '<li class="' + indicateurActif + '" data-numero="' + numero++ + '"></li>';
|
|
|
1156 |
indicateurs += indicateur;
|
|
|
1157 |
|
1540 |
jpm |
1158 |
premiere = false;
|
|
|
1159 |
});
|
1562 |
jpm |
1160 |
|
|
|
1161 |
if ($('#miniatures img').length == 1) {
|
|
|
1162 |
html = miniatures;
|
|
|
1163 |
} else {
|
|
|
1164 |
html =
|
|
|
1165 |
'<div class="defilement">' +
|
|
|
1166 |
miniatures +
|
|
|
1167 |
'<a class="defilement-control-zone gauche">' +
|
|
|
1168 |
' <span class="defilement-control gauche hidden"><</span>' +
|
|
|
1169 |
'</a>' +
|
|
|
1170 |
'<a class="defilement-control-zone droite">' +
|
|
|
1171 |
' <span class="defilement-control droite hidden">></span>' +
|
|
|
1172 |
'</a>' +
|
|
|
1173 |
'<ol class="defilement-indicateurs">' + indicateurs + '</ol>' +
|
|
|
1174 |
'</div>';
|
|
|
1175 |
}
|
1540 |
jpm |
1176 |
}
|
|
|
1177 |
return html;
|
|
|
1178 |
}
|
|
|
1179 |
|
1562 |
jpm |
1180 |
function defilerMiniatures(element) {
|
|
|
1181 |
var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
|
|
|
1182 |
miniatureSelectionne.removeClass('miniature-selectionnee').addClass('miniature-cachee');
|
|
|
1183 |
var miniatureAffichee = miniatureSelectionne;
|
|
|
1184 |
|
|
|
1185 |
var indicateurActif = element.parent().find('.defilement-indicateurs .active');
|
|
|
1186 |
indicateurActif.removeClass('active');
|
|
|
1187 |
|
|
|
1188 |
if (element.hasClass('defilement-control-zone') && element.hasClass('gauche')) {
|
|
|
1189 |
if (miniatureSelectionne.prev('.miniature').length != 0) {
|
|
|
1190 |
miniatureAffichee = miniatureSelectionne.prev('.miniature');
|
|
|
1191 |
indicateurActif.prev().addClass('active');
|
|
|
1192 |
} else {
|
|
|
1193 |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
|
|
|
1194 |
indicateurActif.siblings().last().addClass('active');
|
|
|
1195 |
}
|
|
|
1196 |
} else {
|
|
|
1197 |
if (miniatureSelectionne.next('.miniature').length != 0) {
|
|
|
1198 |
miniatureAffichee = miniatureSelectionne.next('.miniature');
|
|
|
1199 |
indicateurActif.next().addClass('active');
|
|
|
1200 |
} else {
|
|
|
1201 |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
|
|
|
1202 |
indicateurActif.siblings().first().addClass('active');
|
|
|
1203 |
}
|
|
|
1204 |
}
|
|
|
1205 |
miniatureAffichee.addClass('miniature-selectionnee').removeClass('miniature-cachee');
|
|
|
1206 |
}
|
|
|
1207 |
|
1540 |
jpm |
1208 |
function formaterNumNomSel(numNomSel) {
|
|
|
1209 |
var nn = '';
|
|
|
1210 |
if (numNomSel == undefined) {
|
|
|
1211 |
nn = '<span class="alert-error">[non lié au référentiel]</span>';
|
|
|
1212 |
} else {
|
|
|
1213 |
nn = '<span class="nn">[nn'+numNomSel+']</span>';
|
|
|
1214 |
}
|
|
|
1215 |
return nn;
|
|
|
1216 |
}
|
|
|
1217 |
|
1537 |
jpm |
1218 |
function surChangementReferentiel() {
|
|
|
1219 |
NOM_SCI_PROJET = $('#referentiel').val();
|
|
|
1220 |
NOM_SCI_REFERENTIEL = NOM_SCI_PROJET+':'+PROJETS_VERSIONS[NOM_SCI_PROJET];
|
|
|
1221 |
$('#taxon').val('');
|
|
|
1222 |
}
|
|
|
1223 |
|
|
|
1224 |
function surChangementNbreObs() {
|
|
|
1225 |
if (obsNbre == 0) {
|
|
|
1226 |
$('#transmettre-obs').attr('disabled', 'disabled');
|
|
|
1227 |
$('#ajouter-obs').removeAttr('disabled');
|
1564 |
jpm |
1228 |
$('#zone-liste-obs').addClass('hidden');
|
|
|
1229 |
} else {
|
|
|
1230 |
$('#zone-liste-obs').removeClass('hidden');
|
|
|
1231 |
|
|
|
1232 |
if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
|
|
|
1233 |
$('#transmettre-obs').removeAttr('disabled');
|
|
|
1234 |
$('#ajouter-obs').removeAttr('disabled');
|
|
|
1235 |
} else if (obsNbre >= OBS_MAX_NBRE) {
|
|
|
1236 |
$('#ajouter-obs').attr('disabled', 'disabled');
|
|
|
1237 |
afficherPanneau('#dialogue-bloquer-creer-obs');
|
|
|
1238 |
}
|
1537 |
jpm |
1239 |
}
|
|
|
1240 |
}
|
|
|
1241 |
|
1562 |
jpm |
1242 |
function supprimerObs() {
|
|
|
1243 |
var obsId = $(this).val();
|
|
|
1244 |
// Problème avec IE 6 et 7
|
|
|
1245 |
if (obsId == 'Supprimer') {
|
|
|
1246 |
obsId = $(this).attr('title');
|
|
|
1247 |
}
|
|
|
1248 |
obsNbre = obsNbre - 1;
|
|
|
1249 |
$('.obs-nbre').text(obsNbre);
|
|
|
1250 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
1251 |
|
|
|
1252 |
$('.obs'+obsId).remove();
|
|
|
1253 |
$('#liste-obs').removeData('obsId' + obsId);
|
|
|
1254 |
}
|
|
|
1255 |
|
|
|
1256 |
function initialiserObs() {
|
|
|
1257 |
obsNbre = 0;
|
|
|
1258 |
$('.obs-nbre').text(obsNbre);
|
|
|
1259 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
1260 |
$('#liste-obs').removeData();
|
|
|
1261 |
$('.obs').remove();
|
|
|
1262 |
$('#dialogue-bloquer-creer-obs').hide();
|
|
|
1263 |
}
|
|
|
1264 |
|
|
|
1265 |
function getNomsImgsOriginales() {
|
|
|
1266 |
var noms = new Array();
|
|
|
1267 |
$('.miniature-img').each(function() {
|
|
|
1268 |
noms.push($(this).attr('alt'));
|
|
|
1269 |
});
|
|
|
1270 |
return noms;
|
|
|
1271 |
}
|
|
|
1272 |
|
1567 |
jpm |
1273 |
function stockerObsData() {
|
|
|
1274 |
var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
|
1614 |
jpm |
1275 |
nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
|
1567 |
jpm |
1276 |
numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
|
1613 |
jpm |
1277 |
nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
|
1567 |
jpm |
1278 |
nomRet = nomHorsListe ? $('#taxon').data('nomRet') : taxons[numNomSel]['nom_ret'],
|
|
|
1279 |
numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : taxons[numNomSel]['num_nom_ret'],
|
|
|
1280 |
numTaxon = nomHorsListe ? $('#taxon').data('nt') : taxons[numNomSel]['num_taxon'],
|
|
|
1281 |
famille = nomHorsListe ? $('#taxon').data('famille') : taxons[numNomSel]['famille'],
|
1614 |
jpm |
1282 |
referentiel = (numNomSel == undefined) ? '' : NOM_SCI_REFERENTIEL,
|
|
|
1283 |
notes = (nomSpecial ? taxons[numNomSel]['nom_fr'] + '. ' : '') + $('#notes').val();
|
1567 |
jpm |
1284 |
|
|
|
1285 |
$('#liste-obs').data('obsId'+obsNbre, {
|
|
|
1286 |
'date': $('#date').val(),
|
1614 |
jpm |
1287 |
'notes': notes,
|
1567 |
jpm |
1288 |
|
|
|
1289 |
'station': $('#station').val(),
|
|
|
1290 |
'latitude': $('#latitude').val(),
|
|
|
1291 |
'longitude': $('#longitude').val(),
|
|
|
1292 |
'commune_nom': $('#commune-nom').text(),
|
|
|
1293 |
'commune_code_insee': $('#commune-code-insee').text(),
|
|
|
1294 |
|
|
|
1295 |
'nom_sel': nomSel,
|
|
|
1296 |
'num_nom_sel': numNomSel,
|
|
|
1297 |
'nom_ret': nomRet,
|
|
|
1298 |
'num_nom_ret': numNomRet,
|
|
|
1299 |
'num_taxon': numTaxon,
|
|
|
1300 |
'famille': famille,
|
|
|
1301 |
'referentiel': referentiel,
|
|
|
1302 |
|
|
|
1303 |
'milieu': getMilieux(),
|
|
|
1304 |
|
|
|
1305 |
// Ajout des champs images
|
|
|
1306 |
'image_nom': getNomsImgsOriginales(),
|
|
|
1307 |
|
|
|
1308 |
// Ajout des champs étendus de l'obs
|
|
|
1309 |
'obs_etendue': getObsChpEtendus()
|
|
|
1310 |
});
|
1577 |
jpm |
1311 |
//console.log($('#liste-obs').data('obsId'+obsNbre));
|
1567 |
jpm |
1312 |
}
|
|
|
1313 |
|
|
|
1314 |
function getObsChpEtendus() {
|
|
|
1315 |
var champs = [],
|
|
|
1316 |
perceptionTechnicien = getPerceptionTechnicien();
|
|
|
1317 |
if (perceptionTechnicien != undefined) {
|
|
|
1318 |
champs.push(perceptionTechnicien);
|
|
|
1319 |
}
|
1577 |
jpm |
1320 |
if (latLngDeb != undefined) {
|
|
|
1321 |
var latitudeDebutRue = {cle: 'latitudeDebutRue', label: 'Latitude du début de la rue', valeur: latLngDeb.lat().toFixed(5)};
|
|
|
1322 |
champs.push(latitudeDebutRue);
|
|
|
1323 |
var longitudeDebutRue = {cle: 'longitudeDebutRue', label: 'Longitude du début de la rue', valeur: latLngDeb.lng().toFixed(5)};
|
|
|
1324 |
champs.push(longitudeDebutRue);
|
|
|
1325 |
}
|
|
|
1326 |
if (latLngFin != undefined) {
|
|
|
1327 |
var latitudeFinRue = {cle: 'latitudeFinRue', label: 'Latitude de fin de la rue', valeur: latLngFin.lat().toFixed(5)};
|
|
|
1328 |
champs.push(latitudeFinRue);
|
|
|
1329 |
var longitudeFinRue = {cle: 'longitudeFinRue', label: 'Longitude de fin de la rue', valeur: latLngFin.lng().toFixed(5)};
|
|
|
1330 |
champs.push(longitudeFinRue);
|
|
|
1331 |
}
|
|
|
1332 |
|
1567 |
jpm |
1333 |
$('.obs-chp-etendu').each(function() {
|
|
|
1334 |
var valeur = $(this).val(),
|
|
|
1335 |
cle = $(this).attr('name'),
|
|
|
1336 |
label = $(this).data('label');
|
|
|
1337 |
if (valeur != '') {
|
|
|
1338 |
var chpEtendu = {cle: cle, label: label, valeur: valeur};
|
|
|
1339 |
champs.push(chpEtendu);
|
1562 |
jpm |
1340 |
}
|
|
|
1341 |
});
|
1567 |
jpm |
1342 |
return champs;
|
1562 |
jpm |
1343 |
}
|
|
|
1344 |
|
1567 |
jpm |
1345 |
function getPerceptionTechnicien() {
|
|
|
1346 |
var perceptionTechnicien = undefined,
|
|
|
1347 |
perceptions = [];
|
|
|
1348 |
$('.cb-perception-technicien:checked').each(function() {
|
|
|
1349 |
perceptions.push($(this).val());
|
|
|
1350 |
});
|
|
|
1351 |
if (perceptions.length > 0) {
|
|
|
1352 |
var valeur = Array.prototype.slice.call(perceptions).join(', ');
|
|
|
1353 |
perceptionTechnicien = {cle: 'perceptionTechnicien', label: "Perceptions par l'équipe", valeur: valeur};
|
|
|
1354 |
}
|
|
|
1355 |
return perceptionTechnicien;
|
|
|
1356 |
}
|
|
|
1357 |
|
1562 |
jpm |
1358 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
1359 |
// TRANSFERER OBS : envoie des obs au CEL
|
|
|
1360 |
|
1537 |
jpm |
1361 |
function transmettreObs() {
|
|
|
1362 |
var observations = $('#liste-obs').data();
|
|
|
1363 |
|
|
|
1364 |
if (observations == undefined || jQuery.isEmptyObject(observations)) {
|
|
|
1365 |
afficherPanneau('#dialogue-zero-obs');
|
|
|
1366 |
} else {
|
|
|
1367 |
observations['projet'] = TAG_PROJET;
|
|
|
1368 |
observations['tag-obs'] = TAG_OBS;
|
|
|
1369 |
observations['tag-img'] = TAG_IMG;
|
|
|
1370 |
|
|
|
1371 |
var utilisateur = new Object();
|
|
|
1372 |
utilisateur.id_utilisateur = $('#id_utilisateur').val();
|
|
|
1373 |
utilisateur.prenom = $('#prenom').val();
|
|
|
1374 |
utilisateur.nom = $('#nom').val();
|
|
|
1375 |
utilisateur.courriel = $('#courriel').val();
|
|
|
1376 |
observations['utilisateur'] = utilisateur;
|
|
|
1377 |
envoyerObsAuCel(observations);
|
|
|
1378 |
}
|
|
|
1379 |
return false;
|
|
|
1380 |
}
|
|
|
1381 |
|
|
|
1382 |
function envoyerObsAuCel(observations) {
|
1911 |
raphael |
1383 |
var erreurMsg = '',
|
|
|
1384 |
debugNonJson = '';
|
1537 |
jpm |
1385 |
$.ajax({
|
1540 |
jpm |
1386 |
url: SERVICE_SAISIE_URL,
|
|
|
1387 |
type: 'POST',
|
|
|
1388 |
data: observations,
|
|
|
1389 |
dataType: 'json',
|
|
|
1390 |
beforeSend: function() {
|
1537 |
jpm |
1391 |
$('#dialogue-obs-transaction-ko').hide();
|
|
|
1392 |
$('#dialogue-obs-transaction-ok').hide();
|
1961 |
jpm |
1393 |
$('.alert-txt').empty();
|
1537 |
jpm |
1394 |
$('#chargement').show();
|
|
|
1395 |
},
|
1540 |
jpm |
1396 |
success: function(data, textStatus, jqXHR) {
|
1537 |
jpm |
1397 |
$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
|
|
|
1398 |
supprimerMiniatures();
|
|
|
1399 |
},
|
1540 |
jpm |
1400 |
statusCode: {
|
|
|
1401 |
500: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
1402 |
erreurMsg += "Erreur 500 :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
1540 |
jpm |
1403 |
}
|
1537 |
jpm |
1404 |
},
|
1540 |
jpm |
1405 |
error: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
1406 |
erreurMsg += "Erreur Ajax :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
|
|
1407 |
try {
|
|
|
1408 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
1409 |
if (reponse != null) {
|
|
|
1410 |
$.each(reponse, function (cle, valeur) {
|
|
|
1411 |
erreurMsg += valeur + "\n";
|
|
|
1412 |
});
|
|
|
1413 |
}
|
|
|
1414 |
} catch(e) {
|
1911 |
raphael |
1415 |
erreurMsg += "L'erreur n'est pas en JSON.";
|
|
|
1416 |
debugNonJson = jqXHR.responseText;
|
1537 |
jpm |
1417 |
}
|
|
|
1418 |
},
|
1540 |
jpm |
1419 |
complete: function(jqXHR, textStatus) {
|
1537 |
jpm |
1420 |
$('#chargement').hide();
|
|
|
1421 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
1422 |
|
|
|
1423 |
if (erreurMsg != '') {
|
|
|
1424 |
if (DEBUG) {
|
|
|
1425 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-erreur">' + erreurMsg + '</pre>');
|
1911 |
raphael |
1426 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugNonJson + debugMsg + '</pre>');
|
1537 |
jpm |
1427 |
}
|
1922 |
jpm |
1428 |
var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?' +
|
1540 |
jpm |
1429 |
'subject=Disfonctionnement du widget de saisie ' + TAG_PROJET +
|
1911 |
raphael |
1430 |
'&body=' + erreurMsg + "\nDébogage :\n" + debugMsg + debugNonJson;
|
1537 |
jpm |
1431 |
|
|
|
1432 |
$('#dialogue-obs-transaction-ko .alert-txt').append($('#tpl-transmission-ko').clone()
|
|
|
1433 |
.find('.courriel-erreur')
|
|
|
1434 |
.attr('href', hrefCourriel)
|
|
|
1435 |
.end()
|
|
|
1436 |
.html());
|
|
|
1437 |
$('#dialogue-obs-transaction-ko').show();
|
|
|
1438 |
} else {
|
|
|
1439 |
if (DEBUG) {
|
1911 |
raphael |
1440 |
$('#dialogue-obs-transaction-ok .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugMsg + debugNonJson + '</pre>');
|
1537 |
jpm |
1441 |
}
|
|
|
1442 |
$('#dialogue-obs-transaction-ok').show();
|
|
|
1443 |
}
|
|
|
1444 |
initialiserObs();
|
|
|
1445 |
}
|
|
|
1446 |
});
|
1562 |
jpm |
1447 |
}
|