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 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
46 |
//UPLOAD PHOTO : Traitement de l'image
|
|
|
47 |
$(document).ready(function() {
|
|
|
48 |
$('.effacer-miniature').click(function () {
|
|
|
49 |
supprimerMiniatures($(this));
|
|
|
50 |
});
|
|
|
51 |
|
|
|
52 |
$('#photo-placeholder').click(function(event) {
|
1540 |
jpm |
53 |
$('#fichier').click();
|
1537 |
jpm |
54 |
});
|
|
|
55 |
|
|
|
56 |
$('#fichier').bind('change', function (e) {
|
|
|
57 |
arreter(e);
|
|
|
58 |
var options = {
|
|
|
59 |
success: afficherMiniature, // post-submit callback
|
|
|
60 |
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
|
|
|
61 |
resetForm: true // reset the form after successful submit
|
|
|
62 |
};
|
1540 |
jpm |
63 |
$('#miniature').append(
|
|
|
64 |
'<img id="miniature-chargement" class="miniature" alt="chargement" src="'+CHARGEMENT_IMAGE_URL+'"/>');
|
1537 |
jpm |
65 |
$('#ajouter-obs').attr('disabled', 'disabled');
|
|
|
66 |
if(verifierFormat($('#fichier').val())) {
|
|
|
67 |
$('#form-upload').ajaxSubmit(options);
|
|
|
68 |
} else {
|
1540 |
jpm |
69 |
window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+ $('#fichier').attr('accept'));
|
1537 |
jpm |
70 |
}
|
|
|
71 |
return false;
|
|
|
72 |
});
|
|
|
73 |
|
|
|
74 |
$('.effacer-miniature').on('click', function() {
|
|
|
75 |
$(this).parent().remove();
|
|
|
76 |
});
|
|
|
77 |
});
|
|
|
78 |
|
|
|
79 |
function verifierFormat(nom) {
|
|
|
80 |
var parts = nom.split('.');
|
|
|
81 |
extension = parts[parts.length - 1];
|
|
|
82 |
return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
function afficherMiniature(reponse) {
|
|
|
86 |
if (DEBUG) {
|
|
|
87 |
var debogage = $('debogage', reponse).text();
|
|
|
88 |
console.log('Débogage upload : ' + debogage);
|
|
|
89 |
}
|
|
|
90 |
var message = $('message', reponse).text();
|
|
|
91 |
if (message != '') {
|
|
|
92 |
$('#miniature-msg').append(message);
|
|
|
93 |
} else {
|
|
|
94 |
$('#miniatures').append(creerWidgetMiniature(reponse));
|
|
|
95 |
}
|
|
|
96 |
$('#ajouter-obs').removeAttr('disabled');
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
function creerWidgetMiniature(reponse) {
|
|
|
100 |
var miniatureUrl = $('miniature-url', reponse).text(),
|
|
|
101 |
imgNom = $('image-nom', reponse).text(),
|
|
|
102 |
html =
|
|
|
103 |
'<div class="miniature">'+
|
|
|
104 |
'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
|
|
|
105 |
'<button class="effacer-miniature" type="button">Effacer</button>'+
|
|
|
106 |
'</div>'
|
|
|
107 |
return html;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
function supprimerMiniatures() {
|
|
|
111 |
$('#miniatures').empty();
|
|
|
112 |
$('#miniature-msg').empty();
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
116 |
// GOOGLE MAP
|
1540 |
jpm |
117 |
var map,
|
|
|
118 |
marker,
|
|
|
119 |
latLng,
|
|
|
120 |
geocoder;
|
1537 |
jpm |
121 |
|
|
|
122 |
$(document).ready(function() {
|
|
|
123 |
initialiserGoogleMap();
|
|
|
124 |
|
|
|
125 |
// Autocompletion du champ adresse
|
1540 |
jpm |
126 |
$('#carte-recherche').on('focus', function() {
|
1537 |
jpm |
127 |
$(this).select();
|
|
|
128 |
});
|
1540 |
jpm |
129 |
$('#carte-recherche').on('mouseup', function(event) {// Pour Safari...
|
1537 |
jpm |
130 |
event.preventDefault();
|
|
|
131 |
});
|
|
|
132 |
|
1540 |
jpm |
133 |
$('#carte-recherche').keypress(function(e) {
|
1537 |
jpm |
134 |
if (e.which == 13) {
|
|
|
135 |
e.preventDefault();
|
|
|
136 |
}
|
|
|
137 |
});
|
|
|
138 |
|
1540 |
jpm |
139 |
$('#carte-recherche').autocomplete({
|
1537 |
jpm |
140 |
//Cette partie utilise geocoder pour extraire des valeurs d'adresse
|
|
|
141 |
source: function(request, response) {
|
|
|
142 |
|
|
|
143 |
geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
|
|
|
144 |
if (status == google.maps.GeocoderStatus.OK) {
|
|
|
145 |
response($.map(results, function(item) {
|
|
|
146 |
var retour = {
|
|
|
147 |
label: item.formatted_address,
|
|
|
148 |
value: item.formatted_address,
|
|
|
149 |
latitude: item.geometry.location.lat(),
|
|
|
150 |
longitude: item.geometry.location.lng()
|
|
|
151 |
};
|
|
|
152 |
return retour;
|
|
|
153 |
}));
|
|
|
154 |
} else {
|
|
|
155 |
afficherErreurGoogleMap(status);
|
|
|
156 |
}
|
|
|
157 |
});
|
|
|
158 |
},
|
|
|
159 |
// Cette partie est executee a la selection d'une adresse
|
|
|
160 |
select: function(event, ui) {
|
|
|
161 |
var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
|
|
|
162 |
deplacerMarker(latLng);
|
|
|
163 |
}
|
|
|
164 |
});
|
|
|
165 |
|
1540 |
jpm |
166 |
$('#geolocaliser').on('click', geolocaliser);
|
1537 |
jpm |
167 |
|
|
|
168 |
google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
|
|
|
169 |
|
|
|
170 |
google.maps.event.addListener(map, 'click', surClickDansCarte);
|
|
|
171 |
});
|
|
|
172 |
|
|
|
173 |
function initialiserGoogleMap(){
|
|
|
174 |
// Carte
|
1540 |
jpm |
175 |
var latLng = new google.maps.LatLng(46.30871, 2.54395),// Centre de la France
|
|
|
176 |
zoomDefaut = 5;
|
|
|
177 |
options = {
|
|
|
178 |
zoom: zoomDefaut,
|
|
|
179 |
center: latLng,
|
|
|
180 |
mapTypeId: google.maps.MapTypeId.HYBRID,
|
|
|
181 |
mapTypeControlOptions: {
|
|
|
182 |
mapTypeIds: ['OSM',
|
|
|
183 |
google.maps.MapTypeId.ROADMAP,
|
|
|
184 |
google.maps.MapTypeId.HYBRID,
|
|
|
185 |
google.maps.MapTypeId.SATELLITE,
|
|
|
186 |
google.maps.MapTypeId.TERRAIN]}
|
|
|
187 |
};
|
1537 |
jpm |
188 |
|
|
|
189 |
// Ajout de la couche OSM à la carte
|
|
|
190 |
osmMapType = new google.maps.ImageMapType({
|
|
|
191 |
getTileUrl: function(coord, zoom) {
|
1540 |
jpm |
192 |
return 'http://tile.openstreetmap.org/' + zoom + '/' + coord.x + '/' + coord.y + '.png';
|
1537 |
jpm |
193 |
},
|
|
|
194 |
tileSize: new google.maps.Size(256, 256),
|
|
|
195 |
isPng: true,
|
|
|
196 |
alt: 'OpenStreetMap',
|
|
|
197 |
name: 'OSM',
|
|
|
198 |
maxZoom: 19
|
|
|
199 |
});
|
|
|
200 |
|
|
|
201 |
// Création de la carte Google
|
|
|
202 |
map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
|
|
|
203 |
map.mapTypes.set('OSM', osmMapType);
|
|
|
204 |
|
|
|
205 |
// Création du Geocoder
|
|
|
206 |
geocoder = new google.maps.Geocoder();
|
|
|
207 |
|
|
|
208 |
// Marqueur google draggable
|
|
|
209 |
marker = new google.maps.Marker({
|
|
|
210 |
map: map,
|
|
|
211 |
draggable: true,
|
|
|
212 |
title: 'Ma station',
|
|
|
213 |
icon: GOOGLE_MAP_MARQUEUR_URL,
|
|
|
214 |
position: latLng
|
|
|
215 |
});
|
|
|
216 |
|
|
|
217 |
initialiserMarker(latLng);
|
|
|
218 |
|
|
|
219 |
// Tentative de geocalisation
|
1540 |
jpm |
220 |
|
1537 |
jpm |
221 |
if (navigator.geolocation) {
|
|
|
222 |
navigator.geolocation.getCurrentPosition(function(position) {
|
1540 |
jpm |
223 |
var latitude = position.coords.latitude,
|
|
|
224 |
longitude = position.coords.longitude;
|
1537 |
jpm |
225 |
latLng = new google.maps.LatLng(latitude, longitude);
|
1540 |
jpm |
226 |
|
1537 |
jpm |
227 |
deplacerMarker(latLng);
|
|
|
228 |
});
|
|
|
229 |
}
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
function surDeplacementMarker() {
|
|
|
233 |
trouverCommune(marker.getPosition());
|
|
|
234 |
mettreAJourMarkerPosition(marker.getPosition());
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
function surClickDansCarte(event) {
|
|
|
238 |
deplacerMarker(event.latLng);
|
|
|
239 |
}
|
|
|
240 |
|
1540 |
jpm |
241 |
function geolocaliser(event) {
|
|
|
242 |
var latitude = $('#latitude').val(),
|
|
|
243 |
longitude = $('#longitude').val();
|
1537 |
jpm |
244 |
latLng = new google.maps.LatLng(latitude, longitude);
|
|
|
245 |
deplacerMarker(latLng);
|
1540 |
jpm |
246 |
arreter(event);
|
1537 |
jpm |
247 |
}
|
|
|
248 |
|
|
|
249 |
function initialiserMarker(latLng) {
|
|
|
250 |
if (marker != undefined) {
|
|
|
251 |
marker.setPosition(latLng);
|
|
|
252 |
map.setCenter(latLng);
|
1540 |
jpm |
253 |
mettreAJourMarkerPosition(latLng);
|
|
|
254 |
trouverCommune(latLng);
|
1537 |
jpm |
255 |
}
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
function deplacerMarker(latLng) {
|
|
|
259 |
if (marker != undefined) {
|
|
|
260 |
marker.setPosition(latLng);
|
|
|
261 |
map.setCenter(latLng);
|
|
|
262 |
mettreAJourMarkerPosition(latLng);
|
|
|
263 |
trouverCommune(latLng);
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
function mettreAJourMarkerPosition(latLng) {
|
1540 |
jpm |
268 |
var lat = latLng.lat().toFixed(5),
|
|
|
269 |
lng = latLng.lng().toFixed(5);
|
1537 |
jpm |
270 |
remplirChampLatitude(lat);
|
|
|
271 |
remplirChampLongitude(lng);
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
function remplirChampLatitude(latDecimale) {
|
|
|
275 |
var lat = Math.round(latDecimale * 100000) / 100000;
|
|
|
276 |
$('#latitude').val(lat);
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
function remplirChampLongitude(lngDecimale) {
|
|
|
280 |
var lng = Math.round(lngDecimale * 100000) / 100000;
|
|
|
281 |
$('#longitude').val(lng);
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
function trouverCommune(pos) {
|
|
|
285 |
$(function() {
|
1540 |
jpm |
286 |
var url_service = SERVICE_NOM_COMMUNE_URL,
|
|
|
287 |
urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
|
1537 |
jpm |
288 |
$.ajax({
|
1540 |
jpm |
289 |
url: urlNomCommuneFormatee,
|
|
|
290 |
type: 'GET',
|
|
|
291 |
dataType: 'jsonp',
|
|
|
292 |
beforeSend: function() {
|
|
|
293 |
$('.commune-info').empty();
|
|
|
294 |
$('#dialogue-erreur .alert-txt').empty();
|
1537 |
jpm |
295 |
},
|
1540 |
jpm |
296 |
success: function(data, textStatus, jqXHR) {
|
|
|
297 |
$('.commune-info').empty();
|
|
|
298 |
$('#commune-nom').append(data.nom);
|
|
|
299 |
$('#commune-code-insee').append(data.codeINSEE);
|
|
|
300 |
$('#marqueur-commune').data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
|
1537 |
jpm |
301 |
},
|
1540 |
jpm |
302 |
statusCode: {
|
|
|
303 |
500: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
304 |
if (DEBUG) {
|
1540 |
jpm |
305 |
$('#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 |
306 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
307 |
var erreurMsg = "";
|
|
|
308 |
if (reponse != null) {
|
|
|
309 |
$.each(reponse, function (cle, valeur) {
|
1540 |
jpm |
310 |
erreurMsg += valeur + '<br />';
|
1537 |
jpm |
311 |
});
|
|
|
312 |
}
|
|
|
313 |
|
1540 |
jpm |
314 |
$('#dialogue-erreur .alert-txt').append(
|
|
|
315 |
'<p class="msg-erreur">Erreur 500 : '+errorThrown+'<br />'+erreurMsg+'</p>');
|
1537 |
jpm |
316 |
}
|
1540 |
jpm |
317 |
}
|
1537 |
jpm |
318 |
},
|
1540 |
jpm |
319 |
error: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
320 |
if (DEBUG) {
|
1540 |
jpm |
321 |
$('#dialogue-erreur .alert-txt').append(
|
|
|
322 |
'<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
|
1537 |
jpm |
323 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
1540 |
jpm |
324 |
var erreurMsg = '';
|
1537 |
jpm |
325 |
if (reponse != null) {
|
|
|
326 |
$.each(reponse, function (cle, valeur) {
|
1540 |
jpm |
327 |
erreurMsg += valeur + '<br />';
|
1537 |
jpm |
328 |
});
|
|
|
329 |
}
|
|
|
330 |
|
1540 |
jpm |
331 |
$('#dialogue-erreur .alert-txt').append(
|
|
|
332 |
'<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
|
1537 |
jpm |
333 |
}
|
|
|
334 |
},
|
1540 |
jpm |
335 |
complete: function(jqXHR, textStatus) {
|
1537 |
jpm |
336 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
337 |
if (debugMsg != '') {
|
|
|
338 |
if (DEBUG) {
|
|
|
339 |
$("#dialogue-erreur .alert-txt").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
if ($("#dialogue-erreur .msg").length > 0) {
|
|
|
343 |
$("#dialogue-erreur").show();
|
|
|
344 |
}
|
|
|
345 |
}
|
|
|
346 |
});
|
|
|
347 |
});
|
|
|
348 |
}
|
|
|
349 |
//+---------------------------------------------------------------------------------------------------------+
|
|
|
350 |
// IDENTITÉ
|
|
|
351 |
$(document).ready(function() {
|
|
|
352 |
$('#courriel').on('blur', requeterIdentite);
|
|
|
353 |
$('#courriel').on('keypress', testerLancementRequeteIdentite);
|
|
|
354 |
});
|
|
|
355 |
|
|
|
356 |
function testerLancementRequeteIdentite(event) {
|
|
|
357 |
if (event.which == 13) {
|
|
|
358 |
requeterIdentite();
|
|
|
359 |
event.preventDefault();
|
|
|
360 |
event.stopPropagation();
|
|
|
361 |
}
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
function requeterIdentite() {
|
|
|
365 |
var courriel = $('#courriel').val();
|
|
|
366 |
//TODO: mettre ceci en paramètre de config
|
|
|
367 |
var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL + courriel;
|
|
|
368 |
$.ajax({
|
1540 |
jpm |
369 |
url: urlAnnuaire,
|
|
|
370 |
type: 'GET',
|
|
|
371 |
success: function(data, textStatus, jqXHR) {
|
1537 |
jpm |
372 |
console.log('SUCCESS:'+textStatus);
|
|
|
373 |
if (data != undefined && data[courriel] != undefined) {
|
|
|
374 |
var infos = data[courriel];
|
|
|
375 |
$('#id_utilisateur').val(infos.id);
|
|
|
376 |
$('#prenom').val(infos.prenom);
|
|
|
377 |
$('#nom').val(infos.nom);
|
|
|
378 |
$('#courriel_confirmation').val(courriel);
|
|
|
379 |
$('#prenom, #nom, #courriel_confirmation').attr('disabled', 'disabled');
|
|
|
380 |
$('#date').focus();
|
|
|
381 |
} else {
|
|
|
382 |
surErreurCompletionCourriel();
|
|
|
383 |
}
|
|
|
384 |
},
|
1540 |
jpm |
385 |
error: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
386 |
console.log('ERREUR :'+textStatus);
|
|
|
387 |
surErreurCompletionCourriel();
|
|
|
388 |
},
|
1540 |
jpm |
389 |
complete: function(jqXHR, textStatus) {
|
1537 |
jpm |
390 |
console.log('COMPLETE :'+textStatus);
|
|
|
391 |
$('#zone-prenom-nom').removeClass('hidden');
|
|
|
392 |
$('#zone-courriel-confirmation').removeClass('hidden');
|
|
|
393 |
}
|
|
|
394 |
});
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
function surErreurCompletionCourriel() {
|
|
|
398 |
$('#prenom, #nom, #courriel_confirmation').val('');
|
|
|
399 |
$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
|
|
|
400 |
afficherPanneau('#dialogue-courriel-introuvable');
|
|
|
401 |
}
|
|
|
402 |
//+---------------------------------------------------------------------------------------------------------+
|
|
|
403 |
// FORMULAIRE
|
|
|
404 |
var obsNbre = 0;
|
|
|
405 |
|
|
|
406 |
$(document).ready(function() {
|
|
|
407 |
// Sliders
|
|
|
408 |
transformerEnSlider('#presence-zone-vegetalise');
|
|
|
409 |
transformerEnSlider('#hauteur-batiment-avoisinant');
|
|
|
410 |
transformerEnSlider('#periodicite-traitement-phyto');
|
|
|
411 |
transformerEnSlider('#resistance-traitement-phyto');
|
|
|
412 |
transformerEnSlider('#vitesse-croissance');
|
|
|
413 |
|
1540 |
jpm |
414 |
// Afficher/Cacher champs cachés par défaut
|
1537 |
jpm |
415 |
$('#periodicite-traitement-phyto').on('change', function() {
|
|
|
416 |
if ($(this).val() === 'jamais') {
|
|
|
417 |
$('#datp-zone').removeClass('hidden');
|
|
|
418 |
} else {
|
1540 |
jpm |
419 |
$('#datp-zone').addClass('hidden');
|
1537 |
jpm |
420 |
}
|
|
|
421 |
});
|
|
|
422 |
$('#taxon-liste').on('change', function() {
|
|
|
423 |
if ($(this).val() === '?') {
|
|
|
424 |
$('#taxon-input-groupe').removeClass('hidden');
|
|
|
425 |
} else {
|
1540 |
jpm |
426 |
$('#taxon-input-groupe').addClass('hidden');
|
1537 |
jpm |
427 |
}
|
|
|
428 |
});
|
|
|
429 |
|
|
|
430 |
$('.alert .close').on('click', fermerPanneauAlert);
|
|
|
431 |
|
|
|
432 |
$('[rel=tooltip]').tooltip('enable');
|
|
|
433 |
$('#btn-aide').on('click', basculerAffichageAide);
|
|
|
434 |
|
|
|
435 |
$('#prenom').on('change', formaterPrenom);
|
|
|
436 |
$('#nom').on('change', formaterNom);
|
|
|
437 |
|
|
|
438 |
configurerDatePicker('#date');
|
|
|
439 |
configurerDatePicker('#date-arret-traitement-phyto');
|
1540 |
jpm |
440 |
|
1537 |
jpm |
441 |
ajouterAutocompletionNoms();
|
1540 |
jpm |
442 |
|
1537 |
jpm |
443 |
configurerFormValidator();
|
|
|
444 |
definirReglesFormValidator();
|
|
|
445 |
|
|
|
446 |
$('#courriel_confirmation').on('paste', bloquerCopierCollerCourriel);
|
|
|
447 |
|
|
|
448 |
$('a.afficher-coord').on('click', basculerAffichageCoord);
|
|
|
449 |
|
|
|
450 |
$('#ajouter-obs').on('click', ajouterObs);
|
|
|
451 |
|
|
|
452 |
$('.obs-nbre').on('changement', surChangementNbreObs);
|
|
|
453 |
|
|
|
454 |
$('body').on('click', '.supprimer-obs', supprimerObs);
|
|
|
455 |
|
|
|
456 |
$('#transmettre-obs').on('click', transmettreObs);
|
|
|
457 |
|
|
|
458 |
$('body').on('click', '.defilement-miniatures-gauche', function(event) {
|
|
|
459 |
event.preventDefault();
|
|
|
460 |
defilerMiniatures($(this));
|
|
|
461 |
});
|
|
|
462 |
|
|
|
463 |
$('body').on('click', '.defilement-miniatures-droite', function(event) {
|
|
|
464 |
event.preventDefault();
|
|
|
465 |
defilerMiniatures($(this));
|
|
|
466 |
});
|
1540 |
jpm |
467 |
|
|
|
468 |
$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
|
|
|
469 |
event.stopPropagation();
|
|
|
470 |
});
|
|
|
471 |
|
|
|
472 |
$('input#hauteur-plante').on('blur', function() {
|
|
|
473 |
// if there's a bad value
|
|
|
474 |
var valeur = $(this).val();
|
|
|
475 |
console.log(valeur);
|
|
|
476 |
if (! valeur.match(/^[0-9]+$/)) {
|
|
|
477 |
// replace it with nothing
|
|
|
478 |
var nouvelleValeur = valeur.replace(/[^0-9]/g, '');
|
|
|
479 |
$(this).val(nouvelleValeur);
|
|
|
480 |
}
|
|
|
481 |
});
|
1537 |
jpm |
482 |
});
|
|
|
483 |
|
|
|
484 |
function transformerEnSlider(selector) {
|
|
|
485 |
$(selector).each(function(index, el) {
|
|
|
486 |
// hide the element
|
|
|
487 |
$(el).addClass('slider-on');
|
|
|
488 |
|
|
|
489 |
// add the slider to each element
|
|
|
490 |
var slider = $( '<div class="slider-holder"><div class="horizontal-slider"></div></div>' ).
|
|
|
491 |
insertAfter( el ).find('.horizontal-slider').slider({
|
|
|
492 |
min: 1,
|
|
|
493 |
max: el.options.length,
|
|
|
494 |
range: 'min',
|
|
|
495 |
value: el.selectedIndex + 1,
|
|
|
496 |
slide: function( event, ui ) {
|
|
|
497 |
el.selectedIndex = ui.value - 1;
|
|
|
498 |
slider.find('a').text(el.options[el.selectedIndex].text);
|
|
|
499 |
},
|
|
|
500 |
stop: function() {
|
|
|
501 |
$(el).change();
|
|
|
502 |
}
|
|
|
503 |
});
|
|
|
504 |
|
|
|
505 |
slider.find('a').text(el.options[el.selectedIndex].text);
|
|
|
506 |
|
|
|
507 |
// Create a legend under the slider so we can see the options
|
|
|
508 |
var options = [];
|
|
|
509 |
for (var option in $(el).children()) {
|
|
|
510 |
if (!isNaN(parseInt(option))) {
|
|
|
511 |
options.push(el.options[option].text);
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
// the width of each legend/option
|
|
|
515 |
var width = (slider.width() / (options.length - 1));
|
|
|
516 |
|
|
|
517 |
// Add the legend. Half the width of the first and last options for display consistency.
|
|
|
518 |
slider.after('<div class="slider-legend"><p style="width:' + (width / 2) + 'px;text-align:left;">' +
|
|
|
519 |
options.join('</p><p style="width:' + width + 'px;">') +'</p></div>')
|
|
|
520 |
.parent().find('.slider-legend p:last-child').css('width', width / 2)
|
|
|
521 |
.css('text-align', 'right');
|
|
|
522 |
|
|
|
523 |
// if there are too many options so that the text is wider than the width, then hide the text
|
|
|
524 |
var lastChild = slider.parent().find('.slider-legend p:last-child');
|
|
|
525 |
if (lastChild[0].clientWidth < lastChild[0].scrollWidth) {
|
|
|
526 |
slider.parent().find('.slider-legend p').css('text-indent', '200%');
|
|
|
527 |
}
|
|
|
528 |
});
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
function configurerFormValidator() {
|
|
|
532 |
$.validator.addMethod(
|
|
|
533 |
'dateCel',
|
|
|
534 |
function (value, element) {
|
|
|
535 |
return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
|
|
|
536 |
},
|
|
|
537 |
'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
|
|
|
538 |
|
|
|
539 |
$.extend($.validator.defaults, {
|
1540 |
jpm |
540 |
highlight: function(element) {
|
|
|
541 |
$(element).closest('.control-group').removeClass('success').addClass('error');
|
1537 |
jpm |
542 |
},
|
1540 |
jpm |
543 |
success: function(element) {
|
|
|
544 |
element.text('OK!').addClass('valid')
|
|
|
545 |
.closest('.control-group').removeClass('error').addClass('success');
|
|
|
546 |
if (element.attr('id') == 'taxon' && $('#taxon').val() != '') {
|
|
|
547 |
// Si le taxon n'est pas lié au référentiel, on vide le data associé
|
|
|
548 |
if ($('#taxon').data('value') != $('#taxon').val()) {
|
|
|
549 |
$('#taxon').data('numNomSel', '');
|
|
|
550 |
$('#taxon').data('nomRet', '');
|
|
|
551 |
$('#taxon').data('numNomRet', '');
|
|
|
552 |
$('#taxon').data('nt', '');
|
|
|
553 |
$('#taxon').data('famille', '');
|
1537 |
jpm |
554 |
}
|
|
|
555 |
}
|
|
|
556 |
}
|
|
|
557 |
});
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
function definirReglesFormValidator() {
|
|
|
561 |
$('#form-observateur').validate({
|
|
|
562 |
rules: {
|
|
|
563 |
courriel: {
|
|
|
564 |
required: true,
|
|
|
565 |
email: true},
|
|
|
566 |
courriel_confirmation: {
|
|
|
567 |
required: true,
|
|
|
568 |
equalTo: '#courriel'}
|
|
|
569 |
}
|
|
|
570 |
});
|
|
|
571 |
$('#form-station').validate({
|
|
|
572 |
rules: {
|
|
|
573 |
latitude : {
|
|
|
574 |
range: [-90, 90]},
|
1540 |
jpm |
575 |
longitude: {
|
1537 |
jpm |
576 |
range: [-180, 180]}
|
|
|
577 |
}
|
|
|
578 |
});
|
|
|
579 |
$('#form-obs').validate({
|
|
|
580 |
rules: {
|
|
|
581 |
date: 'dateCel',
|
1540 |
jpm |
582 |
'taxon-liste': 'required'
|
1537 |
jpm |
583 |
}
|
|
|
584 |
});
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
function configurerDatePicker(selector) {
|
|
|
588 |
$.datepicker.setDefaults($.datepicker.regional['fr']);
|
|
|
589 |
$(selector).datepicker({
|
|
|
590 |
dateFormat: 'dd/mm/yy',
|
|
|
591 |
showOn: 'button',
|
|
|
592 |
buttonImageOnly: true,
|
|
|
593 |
buttonImage: CALENDRIER_ICONE_URL,
|
|
|
594 |
buttonText: 'Afficher le calendrier pour saisir la date.',
|
|
|
595 |
showButtonPanel: true
|
|
|
596 |
});
|
|
|
597 |
$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
|
|
|
598 |
}
|
|
|
599 |
|
|
|
600 |
function fermerPanneauAlert() {
|
|
|
601 |
$(this).parentsUntil('.zone-alerte', '.alert').hide();
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
function formaterNom() {
|
|
|
605 |
$(this).val($(this).val().toUpperCase());
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
function formaterPrenom() {
|
1540 |
jpm |
609 |
var prenom = new Array(),
|
|
|
610 |
mots = $(this).val().split(' ');
|
1537 |
jpm |
611 |
for (var i = 0; i < mots.length; i++) {
|
|
|
612 |
var mot = mots[i];
|
|
|
613 |
if (mot.indexOf('-') >= 0) {
|
1540 |
jpm |
614 |
var prenomCompose = new Array(),
|
|
|
615 |
motsComposes = mot.split('-');
|
1537 |
jpm |
616 |
for (var j = 0; j < motsComposes.length; j++) {
|
1540 |
jpm |
617 |
var motSimple = motsComposes[j],
|
|
|
618 |
motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
|
1537 |
jpm |
619 |
prenomCompose.push(motMajuscule);
|
|
|
620 |
}
|
|
|
621 |
prenom.push(prenomCompose.join('-'));
|
|
|
622 |
} else {
|
|
|
623 |
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
|
|
|
624 |
prenom.push(motMajuscule);
|
|
|
625 |
}
|
|
|
626 |
}
|
|
|
627 |
$(this).val(prenom.join(' '));
|
|
|
628 |
}
|
|
|
629 |
|
|
|
630 |
function basculerAffichageAide() {
|
|
|
631 |
if ($(this).hasClass('btn-warning')) {
|
|
|
632 |
$('[rel=tooltip]').tooltip('enable');
|
|
|
633 |
$(this).removeClass('btn-warning').addClass('btn-success');
|
1540 |
jpm |
634 |
$('#btn-aide-txt', this).text("Désactiver l'aide");
|
1537 |
jpm |
635 |
} else {
|
|
|
636 |
$('[rel=tooltip]').tooltip('disable');
|
|
|
637 |
$(this).removeClass('btn-success').addClass('btn-warning');
|
|
|
638 |
$('#btn-aide-txt', this).text("Activer l'aide");
|
|
|
639 |
}
|
|
|
640 |
}
|
|
|
641 |
|
|
|
642 |
function bloquerCopierCollerCourriel() {
|
|
|
643 |
afficherPanneau('#dialogue-bloquer-copier-coller');
|
|
|
644 |
return false;
|
|
|
645 |
}
|
|
|
646 |
|
|
|
647 |
function basculerAffichageCoord() {
|
1540 |
jpm |
648 |
$('.afficher-coord-action').toggle();
|
1537 |
jpm |
649 |
$('#coordonnees-geo').toggle('slow');
|
|
|
650 |
//valeur false pour que le lien ne soit pas suivi
|
|
|
651 |
return false;
|
|
|
652 |
}
|
|
|
653 |
|
|
|
654 |
function ajouterObs() {
|
|
|
655 |
if (validerFormulaire() == true) {
|
|
|
656 |
obsNbre = obsNbre + 1;
|
|
|
657 |
$('.obs-nbre').text(obsNbre);
|
|
|
658 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
659 |
afficherObs();
|
|
|
660 |
stockerObsData();
|
|
|
661 |
supprimerMiniatures();
|
1540 |
jpm |
662 |
$('#taxon').val('').data('numNomSel', undefined).removeClass('ns-retenu');
|
1537 |
jpm |
663 |
} else {
|
|
|
664 |
afficherPanneau('#dialogue-form-invalide');
|
|
|
665 |
}
|
|
|
666 |
}
|
|
|
667 |
|
|
|
668 |
function afficherObs() {
|
1540 |
jpm |
669 |
var numNomSel = ($('#taxon-liste').val() == '?') ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(),
|
|
|
670 |
taxon = ($('#taxon-liste').val() == '?') ? $('#taxon').val() : taxons[numNomSel]['nom_sel'],
|
|
|
671 |
referentiel = (numNomSel == undefined) ? '' : '['+NOM_SCI_PROJET+']',
|
|
|
672 |
commune = $('#commune-nom').text(),
|
|
|
673 |
codeInsee = $('#commune-code-insee').text(),
|
|
|
674 |
lat = $('input[name="latitude"]').val(),
|
|
|
675 |
lng = $('input[name="longitude"]').val(),
|
|
|
676 |
date = $('#date').val(),
|
|
|
677 |
site = $('#station').val(),
|
|
|
678 |
milieux = getMilieux(),
|
|
|
679 |
notes = $('#notes').val();
|
|
|
680 |
|
1537 |
jpm |
681 |
$('#liste-obs').prepend(
|
|
|
682 |
'<div id="obs'+obsNbre+'" class="row-fluid obs obs'+obsNbre+'">'+
|
|
|
683 |
'<div class="span12">'+
|
|
|
684 |
'<div class="well">'+
|
|
|
685 |
'<div class="obs-action pull-right" rel="tooltip" data-placement="bottom" '+
|
|
|
686 |
'title="Supprimer cette observation de la liste à transmettre">'+
|
|
|
687 |
'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
|
|
|
688 |
'<i class="icon-trash icon-white"></i>'+
|
|
|
689 |
'</button>'+
|
|
|
690 |
'</div> '+
|
|
|
691 |
'<div class="row-fluid">'+
|
|
|
692 |
'<div class="thumbnail span2">'+
|
|
|
693 |
ajouterImgMiniatureAuTransfert()+
|
|
|
694 |
'</div>'+
|
|
|
695 |
'<div class="span9">'+
|
|
|
696 |
'<ul class="unstyled">'+
|
|
|
697 |
'<li>'+
|
1540 |
jpm |
698 |
'<span class="nom-sci">' + taxon + '</span> ' +
|
|
|
699 |
formaterNumNomSel(numNomSel)+
|
|
|
700 |
'<span class="referentiel-obs">' + referentiel + '</span>' +
|
|
|
701 |
' observé à ' +
|
|
|
702 |
'<span class="commune">' + commune + '</span> ' +
|
|
|
703 |
'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
|
|
|
704 |
' le ' +
|
|
|
705 |
'<span class="date">' + date + '</span>' +
|
|
|
706 |
'</li>' +
|
|
|
707 |
'<li>' +
|
|
|
708 |
'<span>Site :</span> ' + site + ' ' +
|
|
|
709 |
'<span>Milieu :</span> ' + milieux + ' ' +
|
|
|
710 |
'</li>' +
|
|
|
711 |
'<li>' +
|
|
|
712 |
'Commentaires : <span class="discretion">' + notes + '</span>'+
|
1537 |
jpm |
713 |
'</li>'+
|
|
|
714 |
'</ul>'+
|
|
|
715 |
'</div>'+
|
|
|
716 |
'</div>'+
|
|
|
717 |
'</div>'+
|
|
|
718 |
'</div>'+
|
|
|
719 |
'</div>');
|
|
|
720 |
}
|
|
|
721 |
|
1540 |
jpm |
722 |
function getMilieux() {
|
|
|
723 |
var milieuxStr = '',
|
|
|
724 |
milieux = [];
|
|
|
725 |
$('input:checkbox[name="milieux"]:checked').each(function() {
|
|
|
726 |
milieux.push($(this).val());
|
|
|
727 |
});
|
|
|
728 |
|
|
|
729 |
milieuxStr = Array.prototype.slice.call(milieux).join(', ');
|
|
|
730 |
return milieuxStr;
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
function ajouterImgMiniatureAuTransfert() {
|
|
|
734 |
var html = '',
|
|
|
735 |
miniatures = '',
|
|
|
736 |
premiere = true;
|
|
|
737 |
if ($('#miniatures img').length >= 1) {
|
|
|
738 |
$('#miniatures img').each(function() {
|
|
|
739 |
var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee',
|
|
|
740 |
css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
|
|
|
741 |
src = $(this).attr('src'),
|
|
|
742 |
alt = $(this).attr('alt');
|
|
|
743 |
premiere = false;
|
|
|
744 |
miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
|
|
|
745 |
miniatures += miniature;
|
|
|
746 |
});
|
|
|
747 |
visible = ($('#miniatures img').length > 1) ? '' : 'defilement-miniatures-cache';
|
|
|
748 |
var html =
|
|
|
749 |
'<div class="defilement-miniatures">'+
|
|
|
750 |
'<a href="#" class="defilement-miniatures-gauche '+visible+'"><</a>'+
|
|
|
751 |
miniatures+
|
|
|
752 |
'<a href="#" class="defilement-miniatures-droite '+visible+'">></a>'+
|
|
|
753 |
'</div>';
|
|
|
754 |
} else {
|
|
|
755 |
html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
|
|
|
756 |
}
|
|
|
757 |
return html;
|
|
|
758 |
}
|
|
|
759 |
|
|
|
760 |
function formaterNumNomSel(numNomSel) {
|
|
|
761 |
var nn = '';
|
|
|
762 |
|
|
|
763 |
if (numNomSel == undefined) {
|
|
|
764 |
nn = '<span class="alert-error">[non lié au référentiel]</span>';
|
|
|
765 |
} else {
|
|
|
766 |
nn = '<span class="nn">[nn'+numNomSel+']</span>';
|
|
|
767 |
}
|
|
|
768 |
return nn;
|
|
|
769 |
}
|
|
|
770 |
|
1537 |
jpm |
771 |
function stockerObsData() {
|
|
|
772 |
$('#liste-obs').data('obsId'+obsNbre, {
|
|
|
773 |
'date' : $('#date').val(),
|
|
|
774 |
'notes' : $('#notes').val(),
|
|
|
775 |
|
|
|
776 |
'nom_sel' : $('#taxon').val(),
|
|
|
777 |
'num_nom_sel' : $('#taxon').data('numNomSel'),
|
|
|
778 |
'nom_ret' : $('#taxon').data('nomRet'),
|
|
|
779 |
'num_nom_ret' : $('#taxon').data('numNomRet'),
|
|
|
780 |
'num_taxon' : $('#taxon').data('nt'),
|
|
|
781 |
'famille' : $('#taxon').data('famille'),
|
|
|
782 |
'referentiel' : ($('#taxon').data('numNomSel') == undefined ? '' : NOM_SCI_REFERENTIEL),
|
|
|
783 |
|
|
|
784 |
'latitude' : $('#latitude').val(),
|
|
|
785 |
'longitude' : $('#longitude').val(),
|
|
|
786 |
'commune_nom' : $('#commune-nom').text(),
|
|
|
787 |
'commune_code_insee' : $('#commune-code-insee').text(),
|
|
|
788 |
'lieudit' : $('#lieudit').val(),
|
|
|
789 |
'station' : $('#station').val(),
|
|
|
790 |
'milieu' : $('#milieu').val(),
|
|
|
791 |
|
|
|
792 |
//Ajout des champs images
|
|
|
793 |
'image_nom' : getNomsImgsOriginales(),
|
|
|
794 |
'image_b64' : getB64ImgsOriginales()
|
|
|
795 |
});
|
|
|
796 |
}
|
|
|
797 |
|
|
|
798 |
function surChangementReferentiel() {
|
|
|
799 |
NOM_SCI_PROJET = $('#referentiel').val();
|
|
|
800 |
NOM_SCI_REFERENTIEL = NOM_SCI_PROJET+':'+PROJETS_VERSIONS[NOM_SCI_PROJET];
|
|
|
801 |
$('#taxon').val('');
|
|
|
802 |
}
|
|
|
803 |
|
|
|
804 |
function surChangementNbreObs() {
|
|
|
805 |
if (obsNbre == 0) {
|
|
|
806 |
$('#transmettre-obs').attr('disabled', 'disabled');
|
|
|
807 |
$('#ajouter-obs').removeAttr('disabled');
|
|
|
808 |
} else if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
|
|
|
809 |
$('#transmettre-obs').removeAttr('disabled');
|
|
|
810 |
$('#ajouter-obs').removeAttr('disabled');
|
|
|
811 |
} else if (obsNbre >= OBS_MAX_NBRE) {
|
|
|
812 |
$('#ajouter-obs').attr('disabled', 'disabled');
|
|
|
813 |
afficherPanneau('#dialogue-bloquer-creer-obs');
|
|
|
814 |
}
|
|
|
815 |
}
|
|
|
816 |
|
|
|
817 |
function transmettreObs() {
|
|
|
818 |
var observations = $('#liste-obs').data();
|
|
|
819 |
console.log(observations);
|
|
|
820 |
|
|
|
821 |
if (observations == undefined || jQuery.isEmptyObject(observations)) {
|
|
|
822 |
afficherPanneau('#dialogue-zero-obs');
|
|
|
823 |
} else {
|
|
|
824 |
observations['projet'] = TAG_PROJET;
|
|
|
825 |
observations['tag-obs'] = TAG_OBS;
|
|
|
826 |
observations['tag-img'] = TAG_IMG;
|
|
|
827 |
|
|
|
828 |
var utilisateur = new Object();
|
|
|
829 |
utilisateur.id_utilisateur = $('#id_utilisateur').val();
|
|
|
830 |
utilisateur.prenom = $('#prenom').val();
|
|
|
831 |
utilisateur.nom = $('#nom').val();
|
|
|
832 |
utilisateur.courriel = $('#courriel').val();
|
|
|
833 |
observations['utilisateur'] = utilisateur;
|
|
|
834 |
envoyerObsAuCel(observations);
|
|
|
835 |
}
|
|
|
836 |
return false;
|
|
|
837 |
}
|
|
|
838 |
|
|
|
839 |
function envoyerObsAuCel(observations) {
|
|
|
840 |
var erreurMsg = '';
|
|
|
841 |
$.ajax({
|
1540 |
jpm |
842 |
url: SERVICE_SAISIE_URL,
|
|
|
843 |
type: 'POST',
|
|
|
844 |
data: observations,
|
|
|
845 |
dataType: 'json',
|
|
|
846 |
beforeSend: function() {
|
1537 |
jpm |
847 |
$('#dialogue-obs-transaction-ko').hide();
|
|
|
848 |
$('#dialogue-obs-transaction-ok').hide();
|
|
|
849 |
$('.alert-txt .msg').remove();
|
|
|
850 |
$('.alert-txt .msg-erreur').remove();
|
|
|
851 |
$('.alert-txt .msg-debug').remove();
|
|
|
852 |
$('#chargement').show();
|
|
|
853 |
},
|
1540 |
jpm |
854 |
success: function(data, textStatus, jqXHR) {
|
1537 |
jpm |
855 |
$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
|
|
|
856 |
supprimerMiniatures();
|
|
|
857 |
},
|
1540 |
jpm |
858 |
statusCode: {
|
|
|
859 |
500: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
860 |
erreurMsg += "Erreur 500 :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
1540 |
jpm |
861 |
}
|
1537 |
jpm |
862 |
},
|
1540 |
jpm |
863 |
error: function(jqXHR, textStatus, errorThrown) {
|
1537 |
jpm |
864 |
erreurMsg += "Erreur Ajax :\ntype : " + textStatus + ' ' + errorThrown + "\n";
|
|
|
865 |
try {
|
|
|
866 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
867 |
if (reponse != null) {
|
|
|
868 |
$.each(reponse, function (cle, valeur) {
|
|
|
869 |
erreurMsg += valeur + "\n";
|
|
|
870 |
});
|
|
|
871 |
}
|
|
|
872 |
} catch(e) {
|
|
|
873 |
erreurMsg += "L'erreur n'était pas en JSON.";
|
|
|
874 |
}
|
|
|
875 |
},
|
1540 |
jpm |
876 |
complete: function(jqXHR, textStatus) {
|
1537 |
jpm |
877 |
$('#chargement').hide();
|
|
|
878 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
879 |
|
|
|
880 |
if (erreurMsg != '') {
|
|
|
881 |
if (DEBUG) {
|
|
|
882 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-erreur">' + erreurMsg + '</pre>');
|
|
|
883 |
$('#dialogue-obs-transaction-ko .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>');
|
|
|
884 |
}
|
1540 |
jpm |
885 |
var hrefCourriel = 'mailto:cel@tela-botanica.org?' +
|
|
|
886 |
'subject=Disfonctionnement du widget de saisie ' + TAG_PROJET +
|
|
|
887 |
'&body=' + erreurMsg + "\nDébogage :\n" + debugMsg;
|
1537 |
jpm |
888 |
|
|
|
889 |
$('#dialogue-obs-transaction-ko .alert-txt').append($('#tpl-transmission-ko').clone()
|
|
|
890 |
.find('.courriel-erreur')
|
|
|
891 |
.attr('href', hrefCourriel)
|
|
|
892 |
.end()
|
|
|
893 |
.html());
|
|
|
894 |
$('#dialogue-obs-transaction-ko').show();
|
|
|
895 |
} else {
|
|
|
896 |
if (DEBUG) {
|
|
|
897 |
$('#dialogue-obs-transaction-ok .alert-txt').append('<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>');
|
|
|
898 |
}
|
|
|
899 |
$('#dialogue-obs-transaction-ok').show();
|
|
|
900 |
}
|
|
|
901 |
initialiserObs();
|
|
|
902 |
}
|
|
|
903 |
});
|
|
|
904 |
}
|
|
|
905 |
|
|
|
906 |
function validerFormulaire() {
|
|
|
907 |
$observateur = $('#form-observateur').valid();
|
|
|
908 |
$station = $('#form-station').valid();
|
|
|
909 |
$obs = $('#form-obs').valid();
|
|
|
910 |
return ($observateur == true && $station == true && $obs == true) ? true : false;
|
|
|
911 |
}
|
|
|
912 |
|
|
|
913 |
function getNomsImgsOriginales() {
|
|
|
914 |
var noms = new Array();
|
|
|
915 |
$('.miniature-img').each(function() {
|
|
|
916 |
noms.push($(this).attr('alt'));
|
|
|
917 |
});
|
|
|
918 |
return noms;
|
|
|
919 |
}
|
|
|
920 |
|
|
|
921 |
function getB64ImgsOriginales() {
|
|
|
922 |
var b64 = new Array();
|
|
|
923 |
$('.miniature-img').each(function() {
|
|
|
924 |
if ($(this).hasClass('b64')) {
|
|
|
925 |
b64.push($(this).attr('src'));
|
|
|
926 |
} else if ($(this).hasClass('b64-canvas')) {
|
|
|
927 |
b64.push($(this).data('b64'));
|
|
|
928 |
}
|
|
|
929 |
});
|
|
|
930 |
return b64;
|
|
|
931 |
}
|
|
|
932 |
|
|
|
933 |
function supprimerObs() {
|
|
|
934 |
var obsId = $(this).val();
|
|
|
935 |
// Problème avec IE 6 et 7
|
|
|
936 |
if (obsId == 'Supprimer') {
|
|
|
937 |
obsId = $(this).attr('title');
|
|
|
938 |
}
|
|
|
939 |
obsNbre = obsNbre - 1;
|
|
|
940 |
$('.obs-nbre').text(obsNbre);
|
|
|
941 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
942 |
|
|
|
943 |
$('.obs'+obsId).remove();
|
|
|
944 |
$('#liste-obs').removeData('obsId' + obsId);
|
|
|
945 |
}
|
|
|
946 |
|
|
|
947 |
function initialiserObs() {
|
|
|
948 |
obsNbre = 0;
|
|
|
949 |
$('.obs-nbre').text(obsNbre);
|
|
|
950 |
$('.obs-nbre').triggerHandler('changement');
|
|
|
951 |
$('#liste-obs').removeData();
|
|
|
952 |
$('.obs').remove();
|
|
|
953 |
$('#dialogue-bloquer-creer-obs').hide();
|
|
|
954 |
}
|
|
|
955 |
|
|
|
956 |
|
|
|
957 |
function defilerMiniatures(element) {
|
1540 |
jpm |
958 |
var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
|
1537 |
jpm |
959 |
miniatureSelectionne.removeClass('miniature-selectionnee');
|
|
|
960 |
miniatureSelectionne.addClass('miniature-cachee');
|
|
|
961 |
var miniatureAffichee = miniatureSelectionne;
|
|
|
962 |
|
|
|
963 |
if(element.hasClass('defilement-miniatures-gauche')) {
|
|
|
964 |
if(miniatureSelectionne.prev('.miniature').length != 0) {
|
|
|
965 |
miniatureAffichee = miniatureSelectionne.prev('.miniature');
|
|
|
966 |
} else {
|
1540 |
jpm |
967 |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
|
1537 |
jpm |
968 |
}
|
|
|
969 |
} else {
|
|
|
970 |
if(miniatureSelectionne.next('.miniature').length != 0) {
|
|
|
971 |
miniatureAffichee = miniatureSelectionne.next('.miniature');
|
|
|
972 |
} else {
|
1540 |
jpm |
973 |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
|
1537 |
jpm |
974 |
}
|
|
|
975 |
}
|
|
|
976 |
miniatureAffichee.addClass('miniature-selectionnee');
|
|
|
977 |
miniatureAffichee.removeClass('miniature-cachee');
|
|
|
978 |
}
|
|
|
979 |
|
|
|
980 |
//+---------------------------------------------------------------------------------------------------------+
|
|
|
981 |
// AUTO-COMPLÉTION Noms Scientifiques
|
|
|
982 |
|
|
|
983 |
function ajouterAutocompletionNoms() {
|
|
|
984 |
$('#taxon').autocomplete({
|
|
|
985 |
source: function(requete, add){
|
|
|
986 |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
|
|
|
987 |
|
|
|
988 |
var url = getUrlAutocompletionNomsSci();
|
|
|
989 |
$.getJSON(url, function(data) {
|
|
|
990 |
console.log(data);
|
|
|
991 |
var suggestions = traiterRetourNomsSci(data);
|
|
|
992 |
add(suggestions);
|
|
|
993 |
});
|
|
|
994 |
},
|
|
|
995 |
html: true
|
|
|
996 |
});
|
|
|
997 |
|
1540 |
jpm |
998 |
$('#taxon').bind('autocompleteselect', function(event, ui) {
|
|
|
999 |
$('#taxon').data(ui.item);
|
1537 |
jpm |
1000 |
if (ui.item.retenu == true) {
|
1540 |
jpm |
1001 |
$('#taxon').addClass('ns-retenu');
|
1537 |
jpm |
1002 |
} else {
|
1540 |
jpm |
1003 |
$('#taxon').removeClass('ns-retenu');
|
1537 |
jpm |
1004 |
}
|
|
|
1005 |
});
|
|
|
1006 |
}
|
|
|
1007 |
|
|
|
1008 |
function getUrlAutocompletionNomsSci() {
|
1540 |
jpm |
1009 |
var mots = $('#taxon').val(),
|
|
|
1010 |
url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_PROJET);
|
1537 |
jpm |
1011 |
url = url.replace('{masque}', mots);
|
|
|
1012 |
return url;
|
|
|
1013 |
}
|
|
|
1014 |
|
|
|
1015 |
function traiterRetourNomsSci(data) {
|
1540 |
jpm |
1016 |
var suggestions = [];
|
1537 |
jpm |
1017 |
if (data.resultat != undefined) {
|
|
|
1018 |
$.each(data.resultat, function(i, val) {
|
|
|
1019 |
val.nn = i;
|
1540 |
jpm |
1020 |
var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
|
|
|
1021 |
nomRet: '', numNomRet: '', famille: '', retenu: false
|
1537 |
jpm |
1022 |
};
|
|
|
1023 |
if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
|
1540 |
jpm |
1024 |
nom.label = '...';
|
1537 |
jpm |
1025 |
nom.value = $('#taxon').val();
|
|
|
1026 |
suggestions.push(nom);
|
|
|
1027 |
return false;
|
|
|
1028 |
} else {
|
|
|
1029 |
nom.label = val.nom_sci_complet;
|
|
|
1030 |
nom.value = val.nom_sci_complet;
|
|
|
1031 |
nom.nt = val.num_taxonomique;
|
|
|
1032 |
nom.nomSel = val.nom_sci;
|
|
|
1033 |
nom.nomSelComplet = val.nom_sci_complet;
|
|
|
1034 |
nom.numNomSel = val.nn;
|
|
|
1035 |
nom.nomRet = val.nom_retenu_complet;
|
1540 |
jpm |
1036 |
nom.numNomRet = val['nom_retenu.id'];
|
1537 |
jpm |
1037 |
nom.famille = val.famille;
|
|
|
1038 |
nom.retenu = (val.retenu == 'false') ? false : true;
|
|
|
1039 |
|
|
|
1040 |
suggestions.push(nom);
|
1540 |
jpm |
1041 |
}
|
1537 |
jpm |
1042 |
});
|
|
|
1043 |
}
|
|
|
1044 |
return suggestions;
|
|
|
1045 |
}
|
|
|
1046 |
|
|
|
1047 |
/*
|
|
|
1048 |
* jQuery UI Autocomplete HTML Extension
|
|
|
1049 |
*
|
|
|
1050 |
* Copyright 2010, Scott González (http://scottgonzalez.com)
|
|
|
1051 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
1052 |
*
|
|
|
1053 |
* http://github.com/scottgonzalez/jquery-ui-extensions
|
|
|
1054 |
*
|
|
|
1055 |
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
|
|
|
1056 |
*/
|
1540 |
jpm |
1057 |
(function($) {
|
1537 |
jpm |
1058 |
var proto = $.ui.autocomplete.prototype,
|
|
|
1059 |
initSource = proto._initSource;
|
|
|
1060 |
|
1540 |
jpm |
1061 |
function filter(array, term) {
|
|
|
1062 |
var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
|
|
|
1063 |
return $.grep(array, function(value) {
|
|
|
1064 |
return matcher.test($('<div>').html(value.label || value.value || value).text());
|
1537 |
jpm |
1065 |
});
|
|
|
1066 |
}
|
|
|
1067 |
|
1540 |
jpm |
1068 |
$.extend(proto, {
|
1537 |
jpm |
1069 |
_initSource: function() {
|
1540 |
jpm |
1070 |
if (this.options.html && $.isArray(this.options.source)) {
|
1537 |
jpm |
1071 |
this.source = function( request, response ) {
|
1540 |
jpm |
1072 |
response(filter(this.options.source, request.term));
|
1537 |
jpm |
1073 |
};
|
|
|
1074 |
} else {
|
1540 |
jpm |
1075 |
initSource.call(this);
|
1537 |
jpm |
1076 |
}
|
|
|
1077 |
},
|
1540 |
jpm |
1078 |
_renderItem: function(ul, item) {
|
1537 |
jpm |
1079 |
if (item.retenu == true) {
|
1540 |
jpm |
1080 |
item.label = '<strong>'+item.label+'</strong>';
|
1537 |
jpm |
1081 |
}
|
|
|
1082 |
|
1540 |
jpm |
1083 |
return $('<li></li>')
|
|
|
1084 |
.data('item.autocomplete', item)
|
|
|
1085 |
.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
|
|
|
1086 |
.appendTo(ul);
|
1537 |
jpm |
1087 |
}
|
|
|
1088 |
});
|
1540 |
jpm |
1089 |
})(jQuery);
|