| 2688 |
mathias |
1 |
/**
|
|
|
2 |
* Constructeur WidgetSaisie par défaut
|
|
|
3 |
*/
|
|
|
4 |
function WidgetSaisie() {
|
|
|
5 |
this.obsNbre = 0;
|
|
|
6 |
this.nbObsEnCours = 1;
|
|
|
7 |
this.totalObsATransmettre = 0;
|
|
|
8 |
this.nbObsTransmises = 0;
|
|
|
9 |
this.map = null;
|
|
|
10 |
this.marker = null;
|
| 2736 |
mathias |
11 |
this.latLng = null; // position en cours
|
| 2688 |
mathias |
12 |
this.geocoder = null;
|
| 2700 |
mathias |
13 |
this.debug = null;
|
|
|
14 |
this.html5 = null;
|
|
|
15 |
this.tagProjet = null;
|
|
|
16 |
this.tagImg = null;
|
|
|
17 |
this.tagObs = null;
|
|
|
18 |
this.separationTagImg = null;
|
|
|
19 |
this.separationTagObs = null;
|
|
|
20 |
this.obsId = null;
|
|
|
21 |
this.serviceSaisieUrl = null;
|
|
|
22 |
this.serviceObsUrl = null;
|
|
|
23 |
this.nomSciReferentiel = null;
|
| 2707 |
mathias |
24 |
this.especeImposee = false;
|
| 2700 |
mathias |
25 |
this.infosEspeceImposee = null;
|
|
|
26 |
this.autocompletionElementsNbre = null;
|
|
|
27 |
this.referentielImpose = null;
|
|
|
28 |
this.serviceAutocompletionNomSciUrl = null;
|
|
|
29 |
this.serviceAutocompletionNomSciUrlTpl = null;
|
|
|
30 |
this.obsMaxNbre = null;
|
|
|
31 |
this.dureeMessage = null;
|
|
|
32 |
this.serviceAnnuaireIdUrl = null;
|
|
|
33 |
this.serviceNomCommuneUrl = null;
|
|
|
34 |
this.serviceNomCommuneUrlAlt = null;
|
|
|
35 |
this.googleMapMarqueurUrl = null;
|
|
|
36 |
this.chargementIconeUrl = null;
|
|
|
37 |
this.chargementImageIconeUrl = null;
|
|
|
38 |
this.calendrierIconeUrl = null;
|
|
|
39 |
this.pasDePhotoIconeUrl = null;
|
| 2688 |
mathias |
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Initialisation du widget
|
|
|
44 |
*/
|
|
|
45 |
WidgetSaisie.prototype.init = function() {
|
|
|
46 |
this.initCarto();
|
|
|
47 |
this.initForm();
|
|
|
48 |
this.initEvts();
|
| 2707 |
mathias |
49 |
this.requeterIdentite();
|
| 2688 |
mathias |
50 |
};
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Initialise la cartographie
|
|
|
54 |
*/
|
|
|
55 |
WidgetSaisie.prototype.initCarto = function() {
|
|
|
56 |
this.initialiserGoogleMap();
|
|
|
57 |
this.initialiserAutocompleteCommune();
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Initialise le formulaire, les validateurs, les listes de complétion...
|
|
|
62 |
*/
|
|
|
63 |
WidgetSaisie.prototype.initForm = function() {
|
| 2700 |
mathias |
64 |
if (this.obsId != '') {
|
| 2707 |
mathias |
65 |
console.log('obsId: (' + typeof obsId + ') : ' + obsId);
|
| 2697 |
mathias |
66 |
this.chargerInfoObs();
|
| 2688 |
mathias |
67 |
}
|
|
|
68 |
|
| 2707 |
mathias |
69 |
this.configurerDatePicker('#date');
|
| 2688 |
mathias |
70 |
this.ajouterAutocompletionNoms();
|
|
|
71 |
this.configurerFormValidator();
|
|
|
72 |
this.definirReglesFormValidator();
|
|
|
73 |
|
| 2700 |
mathias |
74 |
if(this.especeImposee) {
|
| 2688 |
mathias |
75 |
$("#taxon").attr("disabled", "disabled");
|
|
|
76 |
$("#taxon-input-groupe").attr("title","");
|
|
|
77 |
var infosAssociee = {
|
| 2700 |
mathias |
78 |
label : this.infosEspeceImposee.nom_sci_complet,
|
|
|
79 |
value : this.infosEspeceImposee.nom_sci_complet,
|
|
|
80 |
nt : this.infosEspeceImposee.num_taxonomique,
|
|
|
81 |
nomSel : this.infosEspeceImposee.nom_sci,
|
|
|
82 |
nomSelComplet : this.infosEspeceImposee.nom_sci_complet,
|
|
|
83 |
numNomSel : this.infosEspeceImposee.id,
|
|
|
84 |
nomRet : this.infosEspeceImposee["nom_retenu.libelle"],
|
|
|
85 |
numNomRet : this.infosEspeceImposee["nom_retenu.id"],
|
|
|
86 |
famille : this.infosEspeceImposee.famille,
|
|
|
87 |
retenu : (this.infosEspeceImposee.retenu == 'false') ? false : true
|
| 2688 |
mathias |
88 |
};
|
|
|
89 |
$("#taxon").data(infosAssociee);
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Initialise les écouteurs d'événements
|
|
|
95 |
*/
|
|
|
96 |
WidgetSaisie.prototype.initEvts = function() {
|
|
|
97 |
var lthis = this;
|
|
|
98 |
$('body').on('click', '.effacer-miniature', function() {
|
|
|
99 |
$(this).parent().remove();
|
| 1210 |
jpm |
100 |
});
|
| 1524 |
aurelien |
101 |
$("#fichier").bind('change', function (e) {
|
|
|
102 |
arreter(e);
|
| 2328 |
jpm |
103 |
var options = {
|
| 2688 |
mathias |
104 |
success: lthis.afficherMiniature.bind(lthis), // post-submit callback
|
| 2328 |
jpm |
105 |
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
|
|
|
106 |
resetForm: true // reset the form after successful submit
|
| 1524 |
aurelien |
107 |
};
|
| 2700 |
mathias |
108 |
$("#miniature").append('<img id="miniature-chargement" class="miniature" alt="chargement" src="'+this.chargementImageIconeUrl+'"/>');
|
| 1524 |
aurelien |
109 |
$("#ajouter-obs").attr('disabled', 'disabled');
|
| 2688 |
mathias |
110 |
if(lthis.verifierFormat($("#fichier").val())) {
|
| 1524 |
aurelien |
111 |
$("#form-upload").ajaxSubmit(options);
|
|
|
112 |
} else {
|
| 2005 |
aurelien |
113 |
$('#form-upload')[0].reset();
|
| 1524 |
aurelien |
114 |
window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+ $("#fichier").attr("accept"));
|
| 1210 |
jpm |
115 |
}
|
| 1524 |
aurelien |
116 |
return false;
|
|
|
117 |
});
|
| 2697 |
mathias |
118 |
// identité
|
| 2688 |
mathias |
119 |
$("#courriel").on('blur', this.requeterIdentite.bind(this));
|
|
|
120 |
$("#courriel").on('keypress', this.testerLancementRequeteIdentite.bind(this));
|
|
|
121 |
$(".alert .close").on('click', this.fermerPanneauAlert);
|
| 2707 |
mathias |
122 |
$(".has-tooltip").tooltip('enable');
|
| 2688 |
mathias |
123 |
$("#btn-aide").on('click', this.basculerAffichageAide);
|
|
|
124 |
$("#prenom").on("change", this.formaterPrenom.bind(this));
|
|
|
125 |
$("#nom").on("change", this.formaterNom.bind(this));
|
| 2328 |
jpm |
126 |
|
| 2688 |
mathias |
127 |
$("#courriel_confirmation").on('paste', this.bloquerCopierCollerCourriel.bind(this));
|
| 2711 |
mathias |
128 |
$(".afficher-coord").on('click', this.basculerAffichageCoord.bind(this));
|
| 2688 |
mathias |
129 |
$("#ajouter-obs").on('click', this.ajouterObs.bind(this));
|
|
|
130 |
$(".obs-nbre").on('changement', this.surChangementNbreObs.bind(this));
|
|
|
131 |
$("body").on('click', ".supprimer-obs", function() {
|
|
|
132 |
var that = this,
|
|
|
133 |
suppObs = lthis.supprimerObs.bind(lthis);
|
|
|
134 |
// bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
|
|
|
135 |
suppObs(that);
|
|
|
136 |
});
|
|
|
137 |
$("#transmettre-obs").on('click', this.transmettreObs.bind(this));
|
|
|
138 |
$("#referentiel").on('change', this.surChangementReferentiel.bind(this));
|
| 2328 |
jpm |
139 |
|
| 2688 |
mathias |
140 |
$("body").on('click', ".defilement-miniatures-gauche", function(event) {
|
|
|
141 |
event.preventDefault();
|
|
|
142 |
lthis.defilerMiniatures($(this));
|
| 1524 |
aurelien |
143 |
});
|
| 2688 |
mathias |
144 |
$("body").on('click', ".defilement-miniatures-droite", function(event) {
|
|
|
145 |
event.preventDefault();
|
|
|
146 |
lthis.defilerMiniatures($(this));
|
|
|
147 |
});
|
| 2700 |
mathias |
148 |
|
|
|
149 |
// fermeture fenêtre
|
|
|
150 |
if (this.debug == false) {
|
|
|
151 |
$(window).on('beforeunload', function(event) {
|
|
|
152 |
return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.';
|
|
|
153 |
});
|
|
|
154 |
}
|
| 2707 |
mathias |
155 |
|
|
|
156 |
// Autocompletion du champ adresse
|
|
|
157 |
$("#carte-recherche").on('focus', function() {
|
|
|
158 |
$(this).select();
|
|
|
159 |
});
|
|
|
160 |
$("#carte-recherche").on('mouseup', function(event) {// Pour Safari...
|
|
|
161 |
event.preventDefault();
|
|
|
162 |
});
|
|
|
163 |
$("#carte-recherche").keypress(function(e) {
|
|
|
164 |
if (e.which == 13) {
|
|
|
165 |
e.preventDefault();
|
|
|
166 |
}
|
|
|
167 |
});
|
| 2688 |
mathias |
168 |
}
|
| 1249 |
jpm |
169 |
|
| 2688 |
mathias |
170 |
/**
|
|
|
171 |
* Retourne true si l'extension de l'image "nom" est .jpg ou .jpeg
|
|
|
172 |
*/
|
|
|
173 |
WidgetSaisie.prototype.verifierFormat = function(nom) {
|
| 1524 |
aurelien |
174 |
var parts = nom.split('.');
|
|
|
175 |
extension = parts[parts.length - 1];
|
|
|
176 |
return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
|
| 2688 |
mathias |
177 |
};
|
| 1210 |
jpm |
178 |
|
| 2688 |
mathias |
179 |
/**
|
|
|
180 |
* Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
|
|
|
181 |
*/
|
|
|
182 |
WidgetSaisie.prototype.afficherMiniature = function(reponse) {
|
| 2700 |
mathias |
183 |
if (this.debug) {
|
| 1210 |
jpm |
184 |
var debogage = $("debogage", reponse).text();
|
| 1822 |
aurelien |
185 |
//console.log("Débogage upload : "+debogage);
|
| 1210 |
jpm |
186 |
}
|
|
|
187 |
var message = $("message", reponse).text();
|
|
|
188 |
if (message != '') {
|
|
|
189 |
$("#miniature-msg").append(message);
|
|
|
190 |
} else {
|
| 2688 |
mathias |
191 |
$("#miniatures").append(this.creerWidgetMiniature(reponse));
|
| 1210 |
jpm |
192 |
}
|
| 2328 |
jpm |
193 |
$('#ajouter-obs').removeAttr('disabled');
|
| 2688 |
mathias |
194 |
};
|
| 1210 |
jpm |
195 |
|
| 2688 |
mathias |
196 |
/**
|
|
|
197 |
* Crée la miniature d'une image temporaire (formulaire), avec le bouton pour l'effacer
|
|
|
198 |
*/
|
|
|
199 |
WidgetSaisie.prototype.creerWidgetMiniature = function(reponse) {
|
| 1524 |
aurelien |
200 |
var miniatureUrl = $("miniature-url", reponse).text();
|
|
|
201 |
var imgNom = $("image-nom", reponse).text();
|
| 2328 |
jpm |
202 |
var html =
|
| 1524 |
aurelien |
203 |
'<div class="miniature">'+
|
|
|
204 |
'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
|
|
|
205 |
'<button class="effacer-miniature" type="button">Effacer</button>'+
|
|
|
206 |
'</div>'
|
|
|
207 |
return html;
|
| 2688 |
mathias |
208 |
};
|
| 1524 |
aurelien |
209 |
|
| 2688 |
mathias |
210 |
/**
|
| 2707 |
mathias |
211 |
* Efface une miniature (formulaire)
|
|
|
212 |
*/
|
|
|
213 |
WidgetSaisie.prototype.supprimerMiniature = function(miniature) {
|
|
|
214 |
miniature.parents('.miniature').remove();
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
/**
|
| 2688 |
mathias |
218 |
* Efface toutes les miniatures (formulaire)
|
|
|
219 |
*/
|
|
|
220 |
WidgetSaisie.prototype.supprimerMiniatures = function() {
|
| 1524 |
aurelien |
221 |
$("#miniatures").empty();
|
| 1210 |
jpm |
222 |
$("#miniature-msg").empty();
|
| 2688 |
mathias |
223 |
};
|
| 1210 |
jpm |
224 |
|
| 2688 |
mathias |
225 |
/**
|
|
|
226 |
* Initialise l'autocomplétion de la commune, en fonction du référentiel
|
|
|
227 |
*/
|
|
|
228 |
WidgetSaisie.prototype.initialiserAutocompleteCommune = function() {
|
| 2136 |
mathias |
229 |
var geocoderOptions = {
|
| 2688 |
mathias |
230 |
},
|
|
|
231 |
addressSuffix = '',
|
|
|
232 |
lthis = this;
|
| 1210 |
jpm |
233 |
|
| 2700 |
mathias |
234 |
switch(this.nomSciReferentiel) {
|
| 2125 |
mathias |
235 |
case 'isfan':
|
| 2136 |
mathias |
236 |
// Si des résultats se trouvent dans ce rectangle, ils apparaîtront en premier.
|
|
|
237 |
// Ça marche moyen...
|
|
|
238 |
geocoderOptions.bounds = new google.maps.LatLngBounds(
|
|
|
239 |
new google.maps.LatLng(20.756114, -22.023927),
|
|
|
240 |
new google.maps.LatLng(38.065392, 33.78662)
|
|
|
241 |
);
|
|
|
242 |
break;
|
| 2155 |
mathias |
243 |
case 'apd':
|
| 2136 |
mathias |
244 |
geocoderOptions.bounds = new google.maps.LatLngBounds(
|
|
|
245 |
new google.maps.LatLng(-6.708254, -26.154786),
|
|
|
246 |
new google.maps.LatLng(27.488781, 30.490722)
|
|
|
247 |
);
|
|
|
248 |
break;
|
|
|
249 |
case 'bdtfx':
|
|
|
250 |
case 'bdtxa':
|
|
|
251 |
geocoderOptions.region = 'fr';
|
|
|
252 |
addressSuffix = ', France';
|
| 2125 |
mathias |
253 |
}
|
| 2709 |
mathias |
254 |
|
|
|
255 |
$("#carte-recherche").autocomplete({
|
|
|
256 |
//Cette partie utilise geocoder pour extraire des valeurs d'adresse
|
|
|
257 |
source: function(request, response) {
|
|
|
258 |
geocoderOptions.address = request.term + addressSuffix;
|
|
|
259 |
lthis.geocoder.geocode( geocoderOptions, function(results, status) {
|
|
|
260 |
if (status == google.maps.GeocoderStatus.OK) {
|
|
|
261 |
response($.map(results, function(item) {
|
|
|
262 |
var retour = {
|
|
|
263 |
label: item.formatted_address,
|
|
|
264 |
value: item.formatted_address,
|
|
|
265 |
latitude: item.geometry.location.lat(),
|
|
|
266 |
longitude: item.geometry.location.lng()
|
|
|
267 |
};
|
|
|
268 |
return retour;
|
|
|
269 |
}));
|
|
|
270 |
} else {
|
|
|
271 |
lthis.afficherErreurGoogleMap(status);
|
|
|
272 |
}
|
|
|
273 |
});
|
|
|
274 |
},
|
|
|
275 |
// Cette partie est executee a la selection d'une adresse
|
|
|
276 |
select: function(event, ui) {
|
| 2736 |
mathias |
277 |
lthis.latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
|
|
|
278 |
lthis.deplacerMarker(lthis.latLng);
|
| 2709 |
mathias |
279 |
}
|
|
|
280 |
});
|
| 2127 |
mathias |
281 |
};
|
| 2125 |
mathias |
282 |
|
| 2688 |
mathias |
283 |
WidgetSaisie.prototype.afficherErreurGoogleMap = function(status) {
|
| 2700 |
mathias |
284 |
if (this.debug) {
|
| 1576 |
jpm |
285 |
$('#dialogue-google-map .contenu').empty().append(
|
|
|
286 |
'<pre class="msg-erreur">'+
|
|
|
287 |
"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
|
|
|
288 |
'</pre>');
|
| 2700 |
mathias |
289 |
this.afficherPanneau('#dialogue-google-map');
|
| 1576 |
jpm |
290 |
}
|
| 2688 |
mathias |
291 |
};
|
| 1576 |
jpm |
292 |
|
| 2688 |
mathias |
293 |
WidgetSaisie.prototype.surDeplacementMarker = function() {
|
| 2736 |
mathias |
294 |
this.latLng = this.marker.getPosition();
|
|
|
295 |
this.trouverCommune(this.latLng);
|
| 2688 |
mathias |
296 |
this.mettreAJourMarkerPosition(this.marker.getPosition());
|
|
|
297 |
};
|
| 1249 |
jpm |
298 |
|
| 2688 |
mathias |
299 |
WidgetSaisie.prototype.surClickDansCarte = function(event) {
|
| 2736 |
mathias |
300 |
this.latLng = event.latLng;
|
|
|
301 |
this.deplacerMarker(this.latLng);
|
| 2688 |
mathias |
302 |
};
|
| 1249 |
jpm |
303 |
|
| 2688 |
mathias |
304 |
/**
|
|
|
305 |
* Place le marqueur aux coordonnées indiquées dans les champs "latitude" et "longitude"
|
|
|
306 |
*/
|
|
|
307 |
WidgetSaisie.prototype.geolocaliser = function() {
|
| 1249 |
jpm |
308 |
var latitude = $('#latitude').val();
|
|
|
309 |
var longitude = $('#longitude').val();
|
| 2688 |
mathias |
310 |
this.latLng = new google.maps.LatLng(latitude, longitude);
|
|
|
311 |
this.deplacerMarker(this.latLng);
|
|
|
312 |
};
|
| 1249 |
jpm |
313 |
|
| 2715 |
mathias |
314 |
WidgetSaisie.prototype.initialiserGoogleMap = function(localisationNavigateur) {
|
|
|
315 |
// par défaut on tente de localiser le navigateur (avec son sextant)
|
|
|
316 |
if (localisationNavigateur === undefined) {
|
|
|
317 |
localisationNavigateur = true;
|
|
|
318 |
}
|
|
|
319 |
|
| 2713 |
mathias |
320 |
var lthis = this;
|
| 2688 |
mathias |
321 |
var latLng,
|
|
|
322 |
zoomDefaut;
|
| 2553 |
mathias |
323 |
// Carte @TODO mettre ça dans la config
|
| 2700 |
mathias |
324 |
if(this.nomSciReferentiel == 'bdtre') {
|
| 2688 |
mathias |
325 |
latLng = new google.maps.LatLng(-21.10, 55.30);// Réunion
|
|
|
326 |
zoomDefaut = 7;
|
| 2700 |
mathias |
327 |
} else if(this.nomSciReferentiel == 'lbf') {
|
| 2688 |
mathias |
328 |
latLng = new google.maps.LatLng(33.72211, 35.8603);// Liban
|
|
|
329 |
zoomDefaut = 7;
|
| 2700 |
mathias |
330 |
} else if(this.nomSciReferentiel == 'bdtxa') {
|
| 2688 |
mathias |
331 |
latLng = new google.maps.LatLng(14.6, -61.08334);// Fort-De-France
|
|
|
332 |
zoomDefaut = 8;
|
| 2700 |
mathias |
333 |
} else if(this.nomSciReferentiel == 'isfan') {
|
| 2688 |
mathias |
334 |
latLng = new google.maps.LatLng(29.28358, 10.21884);// Afrique du Nord
|
|
|
335 |
zoomDefaut = 4;
|
| 2700 |
mathias |
336 |
} else if(this.nomSciReferentiel == 'apd') {
|
| 2688 |
mathias |
337 |
latLng = new google.maps.LatLng(8.75624, 1.80176);// Afrique de l'Ouest et du Centre
|
|
|
338 |
zoomDefaut = 4;
|
| 1476 |
aurelien |
339 |
} else {
|
| 2736 |
mathias |
340 |
latLng = new google.maps.LatLng(46.30871, 2.54395);// Centre de la France - @WARNING Prémilhat !! :)
|
| 2688 |
mathias |
341 |
zoomDefaut = 5;
|
| 1476 |
aurelien |
342 |
}
|
| 2328 |
jpm |
343 |
|
| 1210 |
jpm |
344 |
var options = {
|
| 1476 |
aurelien |
345 |
zoom: zoomDefaut,
|
| 1210 |
jpm |
346 |
center: latLng,
|
|
|
347 |
mapTypeId: google.maps.MapTypeId.HYBRID,
|
|
|
348 |
mapTypeControlOptions: {
|
|
|
349 |
mapTypeIds: ['OSM', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]}
|
|
|
350 |
};
|
|
|
351 |
|
|
|
352 |
// Ajout de la couche OSM à la carte
|
|
|
353 |
osmMapType = new google.maps.ImageMapType({
|
|
|
354 |
getTileUrl: function(coord, zoom) {
|
|
|
355 |
return "http://tile.openstreetmap.org/" +
|
|
|
356 |
zoom + "/" + coord.x + "/" + coord.y + ".png";
|
|
|
357 |
},
|
|
|
358 |
tileSize: new google.maps.Size(256, 256),
|
|
|
359 |
isPng: true,
|
|
|
360 |
alt: 'OpenStreetMap',
|
|
|
361 |
name: 'OSM',
|
|
|
362 |
maxZoom: 19
|
|
|
363 |
});
|
| 2328 |
jpm |
364 |
|
| 1210 |
jpm |
365 |
// Création de la carte Google
|
| 2688 |
mathias |
366 |
this.map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
|
|
|
367 |
this.map.mapTypes.set('OSM', osmMapType);
|
| 2328 |
jpm |
368 |
|
| 1216 |
jpm |
369 |
// Création du Geocoder
|
| 2688 |
mathias |
370 |
this.geocoder = new google.maps.Geocoder();
|
| 2328 |
jpm |
371 |
|
| 1210 |
jpm |
372 |
// Marqueur google draggable
|
| 2688 |
mathias |
373 |
this.marker = new google.maps.Marker({
|
|
|
374 |
map: this.map,
|
| 1210 |
jpm |
375 |
draggable: true,
|
|
|
376 |
title: 'Ma station',
|
| 2700 |
mathias |
377 |
icon: this.googleMapMarqueurUrl,
|
| 1210 |
jpm |
378 |
position: latLng
|
|
|
379 |
});
|
| 2328 |
jpm |
380 |
|
| 2688 |
mathias |
381 |
this.initialiserMarker(latLng);
|
| 2328 |
jpm |
382 |
|
| 2715 |
mathias |
383 |
// Tentative de geocalisation depuis le navigateur
|
|
|
384 |
if (localisationNavigateur && navigator.geolocation) {
|
| 1210 |
jpm |
385 |
navigator.geolocation.getCurrentPosition(function(position) {
|
|
|
386 |
var latitude = position.coords.latitude;
|
|
|
387 |
var longitude = position.coords.longitude;
|
| 2713 |
mathias |
388 |
lthis.latLng = new google.maps.LatLng(latitude, longitude);
|
| 2714 |
mathias |
389 |
lthis.deplacerMarker(lthis.latLng);
|
| 1210 |
jpm |
390 |
});
|
|
|
391 |
}
|
| 2127 |
mathias |
392 |
|
|
|
393 |
// intéraction carte
|
| 2688 |
mathias |
394 |
$("#geolocaliser").on('click', this.geolocaliser.bind(this));
|
|
|
395 |
google.maps.event.addListener(this.marker, 'dragend', this.surDeplacementMarker.bind(this));
|
|
|
396 |
google.maps.event.addListener(this.map, 'click', this.surClickDansCarte.bind(this));
|
|
|
397 |
};
|
| 1210 |
jpm |
398 |
|
| 2688 |
mathias |
399 |
WidgetSaisie.prototype.initialiserMarker = function(latLng) {
|
|
|
400 |
if (this.marker != undefined) {
|
|
|
401 |
this.marker.setPosition(latLng);
|
|
|
402 |
this.map.setCenter(latLng);
|
| 2710 |
mathias |
403 |
this.mettreAJourMarkerPosition(latLng);
|
| 1485 |
aurelien |
404 |
}
|
| 2688 |
mathias |
405 |
};
|
| 1485 |
aurelien |
406 |
|
| 2688 |
mathias |
407 |
WidgetSaisie.prototype.deplacerMarker = function(latLng) {
|
|
|
408 |
if (this.marker != undefined) {
|
|
|
409 |
this.marker.setPosition(latLng);
|
|
|
410 |
this.map.setCenter(latLng);
|
|
|
411 |
this.mettreAJourMarkerPosition(latLng);
|
|
|
412 |
this.trouverCommune(latLng);
|
| 1210 |
jpm |
413 |
}
|
| 2688 |
mathias |
414 |
};
|
| 1210 |
jpm |
415 |
|
| 2688 |
mathias |
416 |
WidgetSaisie.prototype.mettreAJourMarkerPosition = function(latLng) {
|
| 1210 |
jpm |
417 |
var lat = latLng.lat().toFixed(5);
|
| 2328 |
jpm |
418 |
var lng = latLng.lng().toFixed(5);
|
| 2688 |
mathias |
419 |
this.remplirChampLatitude(lat);
|
|
|
420 |
this.remplirChampLongitude(lng);
|
|
|
421 |
};
|
| 1210 |
jpm |
422 |
|
| 2688 |
mathias |
423 |
WidgetSaisie.prototype.remplirChampLatitude = function(latDecimale) {
|
| 1210 |
jpm |
424 |
var lat = Math.round(latDecimale * 100000) / 100000;
|
|
|
425 |
$('#latitude').val(lat);
|
| 2688 |
mathias |
426 |
};
|
| 1210 |
jpm |
427 |
|
| 2688 |
mathias |
428 |
WidgetSaisie.prototype.remplirChampLongitude = function(lngDecimale) {
|
| 1210 |
jpm |
429 |
var lng = Math.round(lngDecimale * 100000) / 100000;
|
|
|
430 |
$('#longitude').val(lng);
|
| 2688 |
mathias |
431 |
};
|
| 1210 |
jpm |
432 |
|
| 2688 |
mathias |
433 |
WidgetSaisie.prototype.trouverCommune = function(pos) {
|
| 2736 |
mathias |
434 |
if (this.latLng == null) { // tentative de protection contre le démon de Prémilhat
|
|
|
435 |
return;
|
|
|
436 |
}
|
| 2700 |
mathias |
437 |
var lthis = this;
|
| 1210 |
jpm |
438 |
$(function() {
|
| 2328 |
jpm |
439 |
|
| 2700 |
mathias |
440 |
var url_service = lthis.serviceNomCommuneUrl;
|
| 2328 |
jpm |
441 |
|
| 1476 |
aurelien |
442 |
var urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
|
| 1210 |
jpm |
443 |
$.ajax({
|
|
|
444 |
url : urlNomCommuneFormatee,
|
|
|
445 |
type : "GET",
|
|
|
446 |
dataType : "jsonp",
|
|
|
447 |
beforeSend : function() {
|
| 2328 |
jpm |
448 |
$(".commune-info").empty();
|
| 1220 |
jpm |
449 |
$("#dialogue-erreur .alert-txt").empty();
|
| 1210 |
jpm |
450 |
},
|
|
|
451 |
success : function(data, textStatus, jqXHR) {
|
|
|
452 |
$(".commune-info").empty();
|
|
|
453 |
$("#commune-nom").append(data.nom);
|
|
|
454 |
$("#commune-code-insee").append(data.codeINSEE);
|
|
|
455 |
$("#marqueur-commune").data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
|
|
|
456 |
},
|
|
|
457 |
statusCode : {
|
|
|
458 |
500 : function(jqXHR, textStatus, errorThrown) {
|
| 2700 |
mathias |
459 |
if (this.debug) {
|
| 1220 |
jpm |
460 |
$("#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>');
|
| 1210 |
jpm |
461 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
462 |
var erreurMsg = "";
|
|
|
463 |
if (reponse != null) {
|
|
|
464 |
$.each(reponse, function (cle, valeur) {
|
|
|
465 |
erreurMsg += valeur + "<br />";
|
|
|
466 |
});
|
|
|
467 |
}
|
| 2328 |
jpm |
468 |
|
| 1220 |
jpm |
469 |
$("#dialogue-erreur .alert-txt").append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
|
| 1210 |
jpm |
470 |
}
|
|
|
471 |
}
|
|
|
472 |
},
|
|
|
473 |
error : function(jqXHR, textStatus, errorThrown) {
|
| 2700 |
mathias |
474 |
if (this.debug) {
|
| 2707 |
mathias |
475 |
$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la recherche de la commune.</p>');
|
| 1210 |
jpm |
476 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
477 |
var erreurMsg = "";
|
|
|
478 |
if (reponse != null) {
|
|
|
479 |
$.each(reponse, function (cle, valeur) {
|
|
|
480 |
erreurMsg += valeur + "<br />";
|
|
|
481 |
});
|
|
|
482 |
}
|
| 2328 |
jpm |
483 |
|
| 1220 |
jpm |
484 |
$("#dialogue-erreur .alert-txt").append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
|
| 1210 |
jpm |
485 |
}
|
|
|
486 |
},
|
|
|
487 |
complete : function(jqXHR, textStatus) {
|
| 1249 |
jpm |
488 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
489 |
if (debugMsg != '') {
|
| 2700 |
mathias |
490 |
if (this.debug) {
|
| 1220 |
jpm |
491 |
$("#dialogue-erreur .alert-txt").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
|
| 1210 |
jpm |
492 |
}
|
|
|
493 |
}
|
|
|
494 |
if ($("#dialogue-erreur .msg").length > 0) {
|
| 1220 |
jpm |
495 |
$("#dialogue-erreur").show();
|
| 1210 |
jpm |
496 |
}
|
|
|
497 |
}
|
|
|
498 |
});
|
|
|
499 |
});
|
| 2688 |
mathias |
500 |
};
|
| 1249 |
jpm |
501 |
|
| 2688 |
mathias |
502 |
WidgetSaisie.prototype.testerLancementRequeteIdentite = function(event) {
|
| 1249 |
jpm |
503 |
if (event.which == 13) {
|
| 2688 |
mathias |
504 |
this.requeterIdentite();
|
|
|
505 |
this.event.preventDefault();
|
|
|
506 |
this.event.stopPropagation();
|
| 1249 |
jpm |
507 |
}
|
| 2688 |
mathias |
508 |
};
|
| 1249 |
jpm |
509 |
|
| 2688 |
mathias |
510 |
WidgetSaisie.prototype.requeterIdentite = function() {
|
|
|
511 |
var lthis = this;
|
| 1249 |
jpm |
512 |
var courriel = $("#courriel").val();
|
| 2701 |
mathias |
513 |
var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;
|
| 2709 |
mathias |
514 |
if (courriel != '') {
|
|
|
515 |
$.ajax({
|
|
|
516 |
url : urlAnnuaire,
|
|
|
517 |
type : "GET",
|
|
|
518 |
success : function(data, textStatus, jqXHR) {
|
| 2710 |
mathias |
519 |
if (lthis.debug) {
|
|
|
520 |
console.log('SUCCESS: '+textStatus);
|
|
|
521 |
}
|
| 2709 |
mathias |
522 |
if (data != undefined && data[courriel] != undefined) {
|
|
|
523 |
var infos = data[courriel];
|
| 2710 |
mathias |
524 |
lthis.surSuccesCompletionCourriel(infos, courriel);
|
| 2709 |
mathias |
525 |
} else {
|
|
|
526 |
lthis.surErreurCompletionCourriel();
|
|
|
527 |
}
|
|
|
528 |
},
|
|
|
529 |
error : function(jqXHR, textStatus, errorThrown) {
|
| 2710 |
mathias |
530 |
if (lthis.debug) {
|
|
|
531 |
console.log('ERREUR: '+textStatus);
|
|
|
532 |
}
|
| 2688 |
mathias |
533 |
lthis.surErreurCompletionCourriel();
|
| 2709 |
mathias |
534 |
},
|
|
|
535 |
complete : function(jqXHR, textStatus) {
|
| 2710 |
mathias |
536 |
if (lthis.debug) {
|
|
|
537 |
console.log('COMPLETE: '+textStatus);
|
|
|
538 |
}
|
| 2709 |
mathias |
539 |
// @TODO harmoniser class="hidden" VS style="display:none;"
|
|
|
540 |
$("#zone-prenom-nom").removeClass("hidden").show();
|
|
|
541 |
$("#zone-courriel-confirmation").removeClass("hidden").show();
|
| 1241 |
jpm |
542 |
}
|
| 2709 |
mathias |
543 |
});
|
|
|
544 |
}
|
| 2688 |
mathias |
545 |
};
|
| 1210 |
jpm |
546 |
|
| 2710 |
mathias |
547 |
WidgetSaisie.prototype.surSuccesCompletionCourriel = function(infos, courriel) {
|
|
|
548 |
$("#id_utilisateur").val(infos.id);
|
|
|
549 |
$("#prenom").val(infos.prenom);
|
|
|
550 |
$("#nom").val(infos.nom);
|
|
|
551 |
$("#courriel_confirmation").val(courriel);
|
|
|
552 |
$("#prenom, #nom, #courriel_confirmation").attr('disabled', 'disabled');
|
|
|
553 |
this.focusChampFormulaire();
|
|
|
554 |
this.masquerPanneau("#dialogue-courriel-introuvable");
|
|
|
555 |
};
|
| 2707 |
mathias |
556 |
|
| 2688 |
mathias |
557 |
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
|
| 1249 |
jpm |
558 |
$("#prenom, #nom, #courriel_confirmation").val('');
|
|
|
559 |
$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
|
| 2700 |
mathias |
560 |
this.afficherPanneau("#dialogue-courriel-introuvable");
|
| 2688 |
mathias |
561 |
};
|
| 2256 |
aurelien |
562 |
|
| 2710 |
mathias |
563 |
WidgetSaisie.prototype.focusChampFormulaire = function() {
|
|
|
564 |
$("#date").focus();
|
|
|
565 |
};
|
|
|
566 |
|
| 2688 |
mathias |
567 |
WidgetSaisie.prototype.chargerInfoObs = function() {
|
| 2700 |
mathias |
568 |
var urlObs = this.serviceObsUrl + '/' + this.obsId;
|
| 2707 |
mathias |
569 |
var lthis = this;
|
| 2256 |
aurelien |
570 |
$.ajax({
|
|
|
571 |
url: urlObs,
|
|
|
572 |
type: 'GET',
|
|
|
573 |
success: function(data, textStatus, jqXHR) {
|
|
|
574 |
if (data != undefined && data != "") {
|
| 2688 |
mathias |
575 |
this.prechargerForm(data);
|
| 2707 |
mathias |
576 |
} else {
|
|
|
577 |
lthis.surErreurChargementInfosObs();
|
| 2328 |
jpm |
578 |
}
|
| 2256 |
aurelien |
579 |
},
|
|
|
580 |
error: function(jqXHR, textStatus, errorThrown) {
|
| 2707 |
mathias |
581 |
lthis.surErreurChargementInfosObs();
|
| 2256 |
aurelien |
582 |
}
|
|
|
583 |
});
|
| 2688 |
mathias |
584 |
};
|
| 2256 |
aurelien |
585 |
|
| 2707 |
mathias |
586 |
// @TODO faire mieux que ça !
|
|
|
587 |
WidgetSaisie.prototype.surErreurChargementInfosObs = function() {
|
|
|
588 |
alert("Erreur lors du chargement de l'observation");
|
|
|
589 |
}
|
|
|
590 |
|
| 2688 |
mathias |
591 |
WidgetSaisie.prototype.prechargerForm = function(data) {
|
| 2328 |
jpm |
592 |
|
| 2256 |
aurelien |
593 |
$("#milieu").val(data.milieu);
|
| 2328 |
jpm |
594 |
|
| 2256 |
aurelien |
595 |
$("#carte-recherche").val(data.zoneGeo);
|
|
|
596 |
$("#commune-nom").text(data.zoneGeo);
|
| 2328 |
jpm |
597 |
|
| 2257 |
aurelien |
598 |
if(data.hasOwnProperty("codeZoneGeo")) {
|
|
|
599 |
// TODO: trouver un moyen qui fonctionne lorsqu'on aura d'autres référentiels que INSEE
|
|
|
600 |
$("#commune-code-insee").text(data.codeZoneGeo.replace('INSEE-C:', ''));
|
|
|
601 |
}
|
| 2328 |
jpm |
602 |
|
| 2256 |
aurelien |
603 |
if(data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude")) {
|
|
|
604 |
var latLng = new google.maps.LatLng(data.latitude, data.longitude);
|
| 2688 |
mathias |
605 |
this.mettreAJourMarkerPosition(latLng);
|
|
|
606 |
this.marker.setPosition(latLng);
|
|
|
607 |
this.map.setCenter(latLng);
|
|
|
608 |
this.map.setZoom(16);
|
| 2256 |
aurelien |
609 |
}
|
| 2688 |
mathias |
610 |
};
|
| 2256 |
aurelien |
611 |
|
| 2688 |
mathias |
612 |
WidgetSaisie.prototype.configurerFormValidator = function() {
|
| 1210 |
jpm |
613 |
$.validator.addMethod(
|
| 2328 |
jpm |
614 |
"dateCel",
|
|
|
615 |
function (value, element) {
|
|
|
616 |
return value == "" || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
|
|
|
617 |
},
|
| 1213 |
jpm |
618 |
"Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.");
|
| 1210 |
jpm |
619 |
$.extend($.validator.defaults, {
|
|
|
620 |
errorClass: "control-group error",
|
|
|
621 |
validClass: "control-group success",
|
|
|
622 |
errorElement: "span",
|
| 1213 |
jpm |
623 |
highlight: function(element, errorClass, validClass) {
|
| 1210 |
jpm |
624 |
if (element.type === 'radio') {
|
|
|
625 |
this.findByName(element.name).parent("div").parent("div").removeClass(validClass).addClass(errorClass);
|
| 2328 |
jpm |
626 |
} else {
|
| 1210 |
jpm |
627 |
$(element).parent("div").parent("div").removeClass(validClass).addClass(errorClass);
|
|
|
628 |
}
|
|
|
629 |
},
|
| 1213 |
jpm |
630 |
unhighlight: function(element, errorClass, validClass) {
|
| 1210 |
jpm |
631 |
if (element.type === 'radio') {
|
|
|
632 |
this.findByName(element.name).parent("div").parent("div").removeClass(errorClass).addClass(validClass);
|
|
|
633 |
} else {
|
| 1213 |
jpm |
634 |
if ($(element).attr('id') == 'taxon') {
|
| 1493 |
aurelien |
635 |
if ($("#taxon").val() != '') {
|
|
|
636 |
// Si le taxon n'est pas lié au référentiel, on vide le data associé
|
| 2688 |
mathias |
637 |
if ($("#taxon").data("value") != $("#taxon").val()) {
|
| 1493 |
aurelien |
638 |
$("#taxon").data("numNomSel","");
|
|
|
639 |
$("#taxon").data("nomRet","");
|
|
|
640 |
$("#taxon").data("numNomRet","");
|
|
|
641 |
$("#taxon").data("nt","");
|
|
|
642 |
$("#taxon").data("famille","");
|
| 1213 |
jpm |
643 |
}
|
| 1493 |
aurelien |
644 |
$("#taxon-input-groupe").removeClass(errorClass).addClass(validClass);
|
|
|
645 |
$(element).next(" span.help-inline").remove();
|
| 1213 |
jpm |
646 |
}
|
|
|
647 |
} else {
|
|
|
648 |
$(element).parent("div").parent("div").removeClass(errorClass).addClass(validClass);
|
|
|
649 |
$(element).next(" span.help-inline").remove();
|
|
|
650 |
}
|
| 1210 |
jpm |
651 |
}
|
|
|
652 |
}
|
|
|
653 |
});
|
| 2688 |
mathias |
654 |
};
|
| 1249 |
jpm |
655 |
|
| 2688 |
mathias |
656 |
WidgetSaisie.prototype.definirReglesFormValidator = function() {
|
| 1210 |
jpm |
657 |
$("#form-observateur").validate({
|
|
|
658 |
rules: {
|
|
|
659 |
courriel : {
|
|
|
660 |
required : true,
|
|
|
661 |
email : true},
|
|
|
662 |
courriel_confirmation : {
|
|
|
663 |
required : true,
|
|
|
664 |
equalTo: "#courriel"}
|
|
|
665 |
}
|
|
|
666 |
});
|
|
|
667 |
$("#form-station").validate({
|
|
|
668 |
rules: {
|
|
|
669 |
latitude : {
|
|
|
670 |
range: [-90, 90]},
|
|
|
671 |
longitude : {
|
|
|
672 |
range: [-180, 180]}
|
|
|
673 |
}
|
|
|
674 |
});
|
|
|
675 |
$("#form-obs").validate({
|
|
|
676 |
rules: {
|
| 1213 |
jpm |
677 |
date : "dateCel",
|
| 1210 |
jpm |
678 |
taxon : "required"
|
|
|
679 |
}
|
|
|
680 |
});
|
| 2688 |
mathias |
681 |
};
|
| 1249 |
jpm |
682 |
|
| 2707 |
mathias |
683 |
WidgetSaisie.prototype.configurerDatePicker = function(selector) {
|
| 1249 |
jpm |
684 |
$.datepicker.setDefaults($.datepicker.regional["fr"]);
|
| 2707 |
mathias |
685 |
$(selector).datepicker({
|
| 1990 |
jpm |
686 |
dateFormat: "dd/mm/yy",
|
|
|
687 |
maxDate: new Date,
|
| 1249 |
jpm |
688 |
showOn: "button",
|
| 1990 |
jpm |
689 |
buttonImageOnly: true,
|
| 2700 |
mathias |
690 |
buttonImage: this.calendrierIconeUrl,
|
| 1249 |
jpm |
691 |
buttonText: "Afficher le calendrier pour saisir la date.",
|
| 2707 |
mathias |
692 |
showButtonPanel: true,
|
|
|
693 |
onSelect: function(date) {
|
|
|
694 |
$(this).valid();
|
|
|
695 |
}
|
| 1210 |
jpm |
696 |
});
|
| 2707 |
mathias |
697 |
$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
|
| 2688 |
mathias |
698 |
};
|
| 1249 |
jpm |
699 |
|
| 2688 |
mathias |
700 |
WidgetSaisie.prototype.fermerPanneauAlert = function() {
|
| 1249 |
jpm |
701 |
$(this).parentsUntil(".zone-alerte", ".alert").hide();
|
| 2688 |
mathias |
702 |
};
|
| 1249 |
jpm |
703 |
|
| 2688 |
mathias |
704 |
WidgetSaisie.prototype.formaterNom = function() {
|
| 1249 |
jpm |
705 |
$(this).val($(this).val().toUpperCase());
|
| 2688 |
mathias |
706 |
};
|
| 1249 |
jpm |
707 |
|
| 2688 |
mathias |
708 |
WidgetSaisie.prototype.formaterPrenom = function() {
|
| 1249 |
jpm |
709 |
var prenom = new Array();
|
|
|
710 |
var mots = $(this).val().split(' ');
|
|
|
711 |
for (var i = 0; i < mots.length; i++) {
|
|
|
712 |
var mot = mots[i];
|
|
|
713 |
if (mot.indexOf('-') >= 0) {
|
|
|
714 |
var prenomCompose = new Array();
|
|
|
715 |
var motsComposes = mot.split('-');
|
|
|
716 |
for (var j = 0; j < motsComposes.length; j++) {
|
|
|
717 |
var motSimple = motsComposes[j];
|
|
|
718 |
var motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
|
|
|
719 |
prenomCompose.push(motMajuscule);
|
|
|
720 |
}
|
|
|
721 |
prenom.push(prenomCompose.join('-'));
|
|
|
722 |
} else {
|
|
|
723 |
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
|
|
|
724 |
prenom.push(motMajuscule);
|
|
|
725 |
}
|
|
|
726 |
}
|
|
|
727 |
$(this).val(prenom.join(' '));
|
| 2688 |
mathias |
728 |
};
|
| 1249 |
jpm |
729 |
|
| 2688 |
mathias |
730 |
WidgetSaisie.prototype.basculerAffichageAide = function() {
|
| 1249 |
jpm |
731 |
if ($(this).hasClass('btn-warning')) {
|
| 2707 |
mathias |
732 |
$(".has-tooltip").tooltip('enable');
|
| 1249 |
jpm |
733 |
$(this).removeClass('btn-warning').addClass('btn-success');
|
|
|
734 |
$('#btn-aide-txt', this).text("Désactiver l'aide");
|
|
|
735 |
} else {
|
| 2707 |
mathias |
736 |
$(".has-tooltip").tooltip('disable');
|
| 1249 |
jpm |
737 |
$(this).removeClass('btn-success').addClass('btn-warning');
|
|
|
738 |
$('#btn-aide-txt', this).text("Activer l'aide");
|
|
|
739 |
}
|
| 2688 |
mathias |
740 |
};
|
| 1249 |
jpm |
741 |
|
| 2688 |
mathias |
742 |
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
|
| 2700 |
mathias |
743 |
this.afficherPanneau("#dialogue-bloquer-copier-coller");
|
| 1249 |
jpm |
744 |
return false;
|
| 2688 |
mathias |
745 |
};
|
| 1249 |
jpm |
746 |
|
| 2688 |
mathias |
747 |
WidgetSaisie.prototype.basculerAffichageCoord = function() {
|
| 1249 |
jpm |
748 |
$("a.afficher-coord").toggle();
|
|
|
749 |
$("#coordonnees-geo").toggle('slow');
|
|
|
750 |
//valeur false pour que le lien ne soit pas suivi
|
|
|
751 |
return false;
|
| 2688 |
mathias |
752 |
};
|
| 1249 |
jpm |
753 |
|
| 2688 |
mathias |
754 |
/**
|
|
|
755 |
* Ajoute une observation saisie dans le formulaire à la liste des observations à transmettre
|
|
|
756 |
*/
|
|
|
757 |
WidgetSaisie.prototype.ajouterObs = function() {
|
| 2710 |
mathias |
758 |
// Fermeture automatique des dialogue de transmission de données
|
|
|
759 |
// @WARNING TEST
|
|
|
760 |
$('#dialogue-obs-transaction-ko').hide();
|
|
|
761 |
$('#dialogue-obs-transaction-ok').hide();
|
|
|
762 |
|
| 2688 |
mathias |
763 |
if (this.validerFormulaire() == true) {
|
|
|
764 |
this.obsNbre = this.obsNbre + 1;
|
|
|
765 |
$(".obs-nbre").text(this.obsNbre);
|
| 1249 |
jpm |
766 |
$(".obs-nbre").triggerHandler('changement');
|
| 2688 |
mathias |
767 |
this.afficherObs();
|
|
|
768 |
this.stockerObsData();
|
|
|
769 |
this.supprimerMiniatures();
|
| 2700 |
mathias |
770 |
if(! this.especeImposee) {
|
| 1856 |
aurelien |
771 |
$("#taxon").val("");
|
|
|
772 |
$("#taxon").data("numNomSel",undefined);
|
|
|
773 |
}
|
| 2688 |
mathias |
774 |
$('#barre-progression-upload').attr('aria-valuemax', this.obsNbre);
|
|
|
775 |
$('#barre-progression-upload .sr-only').text('0/'+this.obsNbre+" observations transmises");
|
| 1249 |
jpm |
776 |
} else {
|
| 2700 |
mathias |
777 |
this.afficherPanneau('#dialogue-form-invalide');
|
| 1249 |
jpm |
778 |
}
|
| 2688 |
mathias |
779 |
};
|
| 1249 |
jpm |
780 |
|
| 2688 |
mathias |
781 |
/**
|
|
|
782 |
* Affiche une observation dans la liste des observations à transmettre
|
|
|
783 |
*/
|
|
|
784 |
WidgetSaisie.prototype.afficherObs = function() {
|
| 2746 |
aurelien |
785 |
|
|
|
786 |
var commune = $("#commune-nom").text();
|
|
|
787 |
commune = commune.trim() != "" ? commune : $("#carte-recherche").val();
|
|
|
788 |
|
|
|
789 |
var code_insee = $('#commune-code-insee').text();
|
|
|
790 |
code_insee = code_insee.trim() != "" ? "("+code_insee+")" : "";
|
|
|
791 |
|
|
|
792 |
console.log(commune+' - '+code_insee);
|
|
|
793 |
|
| 1249 |
jpm |
794 |
$("#liste-obs").prepend(
|
| 2688 |
mathias |
795 |
'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">'+
|
| 1249 |
jpm |
796 |
'<div class="span12">'+
|
| 1253 |
jpm |
797 |
'<div class="well">'+
|
| 2707 |
mathias |
798 |
'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
|
| 1253 |
jpm |
799 |
'title="Supprimer cette observation de la liste à transmettre">'+
|
| 2688 |
mathias |
800 |
'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
|
| 1249 |
jpm |
801 |
'<i class="icon-trash icon-white"></i>'+
|
|
|
802 |
'</button>'+
|
| 2328 |
jpm |
803 |
'</div> '+
|
|
|
804 |
'<div class="row-fluid">'+
|
| 1249 |
jpm |
805 |
'<div class="thumbnail span2">'+
|
| 2688 |
mathias |
806 |
this.ajouterImgMiniatureAuTransfert()+
|
| 1240 |
jpm |
807 |
'</div>'+
|
| 1249 |
jpm |
808 |
'<div class="span9">'+
|
|
|
809 |
'<ul class="unstyled">'+
|
|
|
810 |
'<li>'+
|
|
|
811 |
'<span class="nom-sci">'+$("#taxon").val()+'</span> '+
|
| 2688 |
mathias |
812 |
this.ajouterNumNomSel()+'<span class="referentiel-obs">'+
|
| 2700 |
mathias |
813 |
($("#taxon").data("numNomSel") == undefined ? '' : '['+ this.nomSciReferentiel +']')+'</span>'+
|
| 1249 |
jpm |
814 |
' observé à '+
|
| 2746 |
aurelien |
815 |
'<span class="commune">'+commune+'</span> '+
|
|
|
816 |
code_insee+' ['+$("#latitude").val()+' / '+$("#longitude").val()+']'+
|
| 1249 |
jpm |
817 |
' le '+
|
|
|
818 |
'<span class="date">'+$("#date").val()+'</span>'+
|
|
|
819 |
'</li>'+
|
|
|
820 |
'<li>'+
|
|
|
821 |
'<span>Lieu-dit :</span> '+$('#lieudit').val()+' '+
|
|
|
822 |
'<span>Station :</span> '+$('#station').val()+' '+
|
|
|
823 |
'<span>Milieu :</span> '+$('#milieu').val()+' '+
|
|
|
824 |
'</li>'+
|
|
|
825 |
'<li>'+
|
|
|
826 |
'Commentaires : <span class="discretion">'+$("#notes").val()+'</span>'+
|
|
|
827 |
'</li>'+
|
|
|
828 |
'</ul>'+
|
|
|
829 |
'</div>'+
|
| 1237 |
jpm |
830 |
'</div>'+
|
| 1249 |
jpm |
831 |
'</div>'+
|
|
|
832 |
'</div>'+
|
|
|
833 |
'</div>');
|
| 2707 |
mathias |
834 |
$('#zone-liste-obs').removeClass("hidden").show();
|
| 2688 |
mathias |
835 |
};
|
| 1249 |
jpm |
836 |
|
| 2688 |
mathias |
837 |
WidgetSaisie.prototype.stockerObsData = function() {
|
|
|
838 |
var lthis = this;
|
| 2746 |
aurelien |
839 |
|
|
|
840 |
var commune = $("#commune-nom").text();
|
|
|
841 |
commune = commune.trim() == "" ? commune : $("#carte-recherche").val();
|
|
|
842 |
|
| 2688 |
mathias |
843 |
$("#liste-obs").data('obsId'+this.obsNbre, {
|
| 2328 |
jpm |
844 |
'date' : $("#date").val(),
|
| 2710 |
mathias |
845 |
'notes' : $("#notes").val().trim(),
|
| 2328 |
jpm |
846 |
|
| 1249 |
jpm |
847 |
'nom_sel' : $("#taxon").val(),
|
|
|
848 |
'num_nom_sel' : $("#taxon").data("numNomSel"),
|
|
|
849 |
'nom_ret' : $("#taxon").data("nomRet"),
|
|
|
850 |
'num_nom_ret' : $("#taxon").data("numNomRet"),
|
|
|
851 |
'num_taxon' : $("#taxon").data("nt"),
|
|
|
852 |
'famille' : $("#taxon").data("famille"),
|
| 2700 |
mathias |
853 |
'referentiel' : ($("#taxon").data("numNomSel") == undefined ? '' : lthis.nomSciReferentiel),
|
| 2328 |
jpm |
854 |
|
| 1249 |
jpm |
855 |
'latitude' : $("#latitude").val(),
|
|
|
856 |
'longitude' : $("#longitude").val(),
|
| 2746 |
aurelien |
857 |
'commune_nom' : commune,
|
| 1249 |
jpm |
858 |
'commune_code_insee' : $("#commune-code-insee").text(),
|
| 1251 |
jpm |
859 |
'lieudit' : $("#lieudit").val(),
|
| 1249 |
jpm |
860 |
'station' : $("#station").val(),
|
|
|
861 |
'milieu' : $("#milieu").val(),
|
| 2328 |
jpm |
862 |
|
| 1249 |
jpm |
863 |
//Ajout des champs images
|
| 2688 |
mathias |
864 |
'image_nom' : lthis.getNomsImgsOriginales(),
|
| 2709 |
mathias |
865 |
'image_b64' : lthis.getB64ImgsOriginales(),
|
|
|
866 |
|
|
|
867 |
// Ajout des champs étendus de l'obs
|
|
|
868 |
'obs_etendue': lthis.getObsChpEtendus()
|
| 1210 |
jpm |
869 |
});
|
| 2688 |
mathias |
870 |
};
|
| 1249 |
jpm |
871 |
|
| 2709 |
mathias |
872 |
/**
|
|
|
873 |
* Retourne un Array contenant les valeurs des champs étendus
|
|
|
874 |
*/
|
|
|
875 |
WidgetSaisie.prototype.getObsChpEtendus = function() {
|
|
|
876 |
var champs = [];
|
|
|
877 |
|
|
|
878 |
$('.obs-chp-etendu').each(function() {
|
|
|
879 |
var valeur = $(this).val(),
|
|
|
880 |
cle = $(this).attr('name'),
|
|
|
881 |
label = $(this).data('label');
|
|
|
882 |
if (valeur != '') {
|
|
|
883 |
var chpEtendu = {cle: cle, label: label, valeur: valeur};
|
|
|
884 |
champs.push(chpEtendu);
|
|
|
885 |
}
|
|
|
886 |
});
|
|
|
887 |
return champs;
|
|
|
888 |
}
|
|
|
889 |
|
| 2688 |
mathias |
890 |
WidgetSaisie.prototype.surChangementReferentiel = function() {
|
| 2700 |
mathias |
891 |
this.nomSciReferentiel = $('#referentiel').val();
|
| 1476 |
aurelien |
892 |
$('#taxon').val('');
|
| 2688 |
mathias |
893 |
this.initialiserAutocompleteCommune();
|
| 2715 |
mathias |
894 |
this.initialiserGoogleMap(false);
|
| 2688 |
mathias |
895 |
};
|
| 1476 |
aurelien |
896 |
|
| 2688 |
mathias |
897 |
WidgetSaisie.prototype.surChangementNbreObs = function() {
|
|
|
898 |
if (this.obsNbre == 0) {
|
| 1249 |
jpm |
899 |
$("#transmettre-obs").attr('disabled', 'disabled');
|
|
|
900 |
$("#ajouter-obs").removeAttr('disabled');
|
| 2700 |
mathias |
901 |
} else if (this.obsNbre > 0 && this.obsNbre < this.obsMaxNbre) {
|
| 1249 |
jpm |
902 |
$("#transmettre-obs").removeAttr('disabled');
|
|
|
903 |
$("#ajouter-obs").removeAttr('disabled');
|
| 2700 |
mathias |
904 |
} else if (this.obsNbre >= this.obsMaxNbre) {
|
| 1249 |
jpm |
905 |
$("#ajouter-obs").attr('disabled', 'disabled');
|
| 2700 |
mathias |
906 |
this.afficherPanneau("#dialogue-bloquer-creer-obs");
|
| 1249 |
jpm |
907 |
}
|
| 2688 |
mathias |
908 |
};
|
| 1249 |
jpm |
909 |
|
| 2688 |
mathias |
910 |
WidgetSaisie.prototype.transmettreObs = function() {
|
| 1249 |
jpm |
911 |
var observations = $("#liste-obs").data();
|
| 2710 |
mathias |
912 |
if (this.debug) {
|
|
|
913 |
console.log(observations);
|
|
|
914 |
}
|
| 1249 |
jpm |
915 |
if (observations == undefined || jQuery.isEmptyObject(observations)) {
|
| 2700 |
mathias |
916 |
this.afficherPanneau("#dialogue-zero-obs");
|
| 1249 |
jpm |
917 |
} else {
|
| 2688 |
mathias |
918 |
this.nbObsEnCours = 1;
|
|
|
919 |
this.nbObsTransmises = 0;
|
|
|
920 |
this.totalObsATransmettre = $.map(observations, function(n, i) { return i; }).length;
|
|
|
921 |
this.depilerObsPourEnvoi();
|
| 2110 |
aurelien |
922 |
}
|
|
|
923 |
return false;
|
| 2688 |
mathias |
924 |
};
|
| 2110 |
aurelien |
925 |
|
| 2688 |
mathias |
926 |
WidgetSaisie.prototype.depilerObsPourEnvoi = function() {
|
| 2110 |
aurelien |
927 |
var observations = $("#liste-obs").data();
|
|
|
928 |
// la boucle est factice car on utilise un tableau
|
|
|
929 |
// dont on a besoin de n'extraire que le premier élément
|
|
|
930 |
// or javascript n'a pas de méthode cross browsers pour extraire les clés
|
|
|
931 |
// TODO: utiliser var.keys quand ça sera plus répandu
|
|
|
932 |
// ou bien utiliser un vrai tableau et pas un objet
|
| 2328 |
jpm |
933 |
for (var obsNum in observations) {
|
| 2697 |
mathias |
934 |
var obsATransmettre = {
|
| 2700 |
mathias |
935 |
'projet' : this.tagProjet,
|
|
|
936 |
'tag-obs' : this.tagObs,
|
|
|
937 |
'tag-img' : this.tagImg
|
| 2688 |
mathias |
938 |
};
|
| 2697 |
mathias |
939 |
var utilisateur = {
|
|
|
940 |
id_utilisateur : $("#id_utilisateur").val(),
|
|
|
941 |
prenom : $("#prenom").val(),
|
|
|
942 |
nom : $("#nom").val(),
|
|
|
943 |
courriel : $("#courriel").val()
|
|
|
944 |
};
|
| 2110 |
aurelien |
945 |
obsATransmettre['utilisateur'] = utilisateur;
|
|
|
946 |
obsATransmettre[obsNum] = observations[obsNum];
|
|
|
947 |
var idObsNumerique = obsNum.replace('obsId', '');
|
|
|
948 |
if(idObsNumerique != "") {
|
| 2688 |
mathias |
949 |
this.envoyerObsAuCel(idObsNumerique, obsATransmettre);
|
| 2110 |
aurelien |
950 |
}
|
| 2328 |
jpm |
951 |
|
| 2110 |
aurelien |
952 |
break;
|
| 1249 |
jpm |
953 |
}
|
| 2688 |
mathias |
954 |
};
|
| 1249 |
jpm |
955 |
|
| 2688 |
mathias |
956 |
WidgetSaisie.prototype.mettreAJourProgression = function() {
|
|
|
957 |
this.nbObsTransmises++;
|
|
|
958 |
var pct = (this.nbObsTransmises/this.totalObsATransmettre)*100;
|
|
|
959 |
$('#barre-progression-upload').attr('aria-valuenow', this.nbObsTransmises);
|
| 2110 |
aurelien |
960 |
$('#barre-progression-upload').attr('style', "width: "+pct+"%");
|
| 2688 |
mathias |
961 |
$('#barre-progression-upload .sr-only').text(this.nbObsTransmises+"/"+this.totalObsATransmettre+" observations transmises");
|
| 2110 |
aurelien |
962 |
|
| 2688 |
mathias |
963 |
if(this.obsNbre == 0) {
|
| 2110 |
aurelien |
964 |
$('.progress').removeClass('active');
|
|
|
965 |
$('.progress').removeClass('progress-striped');
|
|
|
966 |
}
|
| 2688 |
mathias |
967 |
};
|
| 2110 |
aurelien |
968 |
|
| 2688 |
mathias |
969 |
WidgetSaisie.prototype.envoyerObsAuCel = function(idObs, observation) {
|
|
|
970 |
var lthis = this;
|
| 1249 |
jpm |
971 |
var erreurMsg = "";
|
|
|
972 |
$.ajax({
|
| 2700 |
mathias |
973 |
url : lthis.serviceSaisieUrl,
|
| 1249 |
jpm |
974 |
type : "POST",
|
| 2110 |
aurelien |
975 |
data : observation,
|
| 1249 |
jpm |
976 |
dataType : "json",
|
|
|
977 |
beforeSend : function() {
|
| 1251 |
jpm |
978 |
$("#dialogue-obs-transaction-ko").hide();
|
|
|
979 |
$("#dialogue-obs-transaction-ok").hide();
|
| 2697 |
mathias |
980 |
$('.alert-txt').empty();
|
| 2709 |
mathias |
981 |
$(".alert-txt .msg-erreur").remove();
|
|
|
982 |
$(".alert-txt .msg-debug").remove();
|
| 1249 |
jpm |
983 |
$("#chargement").show();
|
|
|
984 |
},
|
|
|
985 |
success : function(data, textStatus, jqXHR) {
|
| 2110 |
aurelien |
986 |
// mise à jour du nombre d'obs à transmettre
|
|
|
987 |
// et suppression de l'obs
|
| 2688 |
mathias |
988 |
lthis.supprimerObsParId(idObs);
|
| 2700 |
mathias |
989 |
lthis.nbObsEnCours++;
|
| 2110 |
aurelien |
990 |
// mise à jour du statut
|
| 2688 |
mathias |
991 |
lthis.mettreAJourProgression();
|
| 2700 |
mathias |
992 |
if(lthis.obsNbre > 0) {
|
| 2110 |
aurelien |
993 |
// dépilement de la suivante
|
| 2688 |
mathias |
994 |
lthis.depilerObsPourEnvoi();
|
| 2110 |
aurelien |
995 |
}
|
| 1249 |
jpm |
996 |
},
|
|
|
997 |
statusCode : {
|
|
|
998 |
500 : function(jqXHR, textStatus, errorThrown) {
|
|
|
999 |
erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
|
|
|
1000 |
}
|
|
|
1001 |
},
|
|
|
1002 |
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
1003 |
erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
|
|
|
1004 |
try {
|
|
|
1005 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
1006 |
if (reponse != null) {
|
|
|
1007 |
$.each(reponse, function (cle, valeur) {
|
|
|
1008 |
erreurMsg += valeur + "\n";
|
|
|
1009 |
});
|
|
|
1010 |
}
|
|
|
1011 |
} catch(e) {
|
| 2700 |
mathias |
1012 |
erreurMsg += "Erreur inconnue: " + jqXHR.responseText;
|
| 1249 |
jpm |
1013 |
}
|
|
|
1014 |
},
|
|
|
1015 |
complete : function(jqXHR, textStatus) {
|
|
|
1016 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
| 2328 |
jpm |
1017 |
|
| 1249 |
jpm |
1018 |
if (erreurMsg != '') {
|
| 2700 |
mathias |
1019 |
if (this.debug) {
|
| 1249 |
jpm |
1020 |
$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
|
|
|
1021 |
$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
|
| 1210 |
jpm |
1022 |
}
|
| 1901 |
mathias |
1023 |
var hrefCourriel = "mailto:cel_remarques@tela-botanica.org?"+
|
| 2700 |
mathias |
1024 |
"subject=Dysfonctionnement du widget de saisie "+ this.tagProjet +
|
| 1902 |
mathias |
1025 |
"&body="+erreurMsg+"%0D%0ADébogage :%0D%0A"+debugMsg;
|
| 2328 |
jpm |
1026 |
|
| 2110 |
aurelien |
1027 |
// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
|
|
|
1028 |
$('#obs'+idObs+' div div').addClass('obs-erreur');
|
|
|
1029 |
window.location.hash = "obs"+idObs;
|
| 2328 |
jpm |
1030 |
|
| 1249 |
jpm |
1031 |
$('#dialogue-obs-transaction-ko .alert-txt').append($("#tpl-transmission-ko").clone()
|
|
|
1032 |
.find('.courriel-erreur')
|
|
|
1033 |
.attr('href', hrefCourriel)
|
|
|
1034 |
.end()
|
|
|
1035 |
.html());
|
|
|
1036 |
$("#dialogue-obs-transaction-ko").show();
|
| 2110 |
aurelien |
1037 |
$("#chargement").hide();
|
| 2688 |
mathias |
1038 |
lthis.initialiserBarreProgression();
|
| 1249 |
jpm |
1039 |
} else {
|
| 2700 |
mathias |
1040 |
if (lthis.debug) {
|
| 1249 |
jpm |
1041 |
$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
|
|
|
1042 |
}
|
| 2700 |
mathias |
1043 |
if(lthis.obsNbre == 0) {
|
| 2110 |
aurelien |
1044 |
setTimeout(function() {
|
|
|
1045 |
$("#chargement").hide();
|
|
|
1046 |
$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
|
|
|
1047 |
$("#dialogue-obs-transaction-ok").show();
|
| 2117 |
aurelien |
1048 |
window.location.hash = "dialogue-obs-transaction-ok";
|
| 2688 |
mathias |
1049 |
lthis.initialiserObs();
|
| 2110 |
aurelien |
1050 |
}, 1500);
|
| 2328 |
jpm |
1051 |
|
|
|
1052 |
}
|
| 1251 |
jpm |
1053 |
}
|
| 1210 |
jpm |
1054 |
}
|
|
|
1055 |
});
|
| 2688 |
mathias |
1056 |
};
|
| 1210 |
jpm |
1057 |
|
| 2688 |
mathias |
1058 |
WidgetSaisie.prototype.validerFormulaire = function() {
|
| 1210 |
jpm |
1059 |
$observateur = $("#form-observateur").valid();
|
|
|
1060 |
$station = $("#form-station").valid();
|
|
|
1061 |
$obs = $("#form-obs").valid();
|
|
|
1062 |
return ($observateur == true && $station == true && $obs == true) ? true : false;
|
| 2688 |
mathias |
1063 |
};
|
| 1210 |
jpm |
1064 |
|
| 2688 |
mathias |
1065 |
WidgetSaisie.prototype.getNomsImgsOriginales = function() {
|
| 1524 |
aurelien |
1066 |
var noms = new Array();
|
|
|
1067 |
$(".miniature-img").each(function() {
|
|
|
1068 |
noms.push($(this).attr('alt'));
|
|
|
1069 |
});
|
|
|
1070 |
return noms;
|
| 2688 |
mathias |
1071 |
};
|
| 1524 |
aurelien |
1072 |
|
| 2688 |
mathias |
1073 |
WidgetSaisie.prototype.getB64ImgsOriginales = function() {
|
| 1524 |
aurelien |
1074 |
var b64 = new Array();
|
|
|
1075 |
$(".miniature-img").each(function() {
|
|
|
1076 |
if ($(this).hasClass('b64')) {
|
|
|
1077 |
b64.push($(this).attr('src'));
|
|
|
1078 |
} else if ($(this).hasClass('b64-canvas')) {
|
|
|
1079 |
b64.push($(this).data('b64'));
|
|
|
1080 |
}
|
|
|
1081 |
});
|
|
|
1082 |
|
| 1210 |
jpm |
1083 |
return b64;
|
| 2688 |
mathias |
1084 |
};
|
| 1210 |
jpm |
1085 |
|
| 2688 |
mathias |
1086 |
WidgetSaisie.prototype.supprimerObs = function(selector) {
|
|
|
1087 |
var obsId = $(selector).val();
|
| 1210 |
jpm |
1088 |
// Problème avec IE 6 et 7
|
|
|
1089 |
if (obsId == "Supprimer") {
|
| 2688 |
mathias |
1090 |
obsId = $(selector).attr("title");
|
| 1210 |
jpm |
1091 |
}
|
| 2688 |
mathias |
1092 |
this.supprimerObsParId(obsId);
|
|
|
1093 |
};
|
| 2110 |
aurelien |
1094 |
|
| 2688 |
mathias |
1095 |
WidgetSaisie.prototype.supprimerObsParId = function(obsId) {
|
|
|
1096 |
this.obsNbre = this.obsNbre - 1;
|
|
|
1097 |
$(".obs-nbre").text(this.obsNbre);
|
| 1237 |
jpm |
1098 |
$(".obs-nbre").triggerHandler('changement');
|
| 1215 |
jpm |
1099 |
$('.obs'+obsId).remove();
|
| 1210 |
jpm |
1100 |
$("#liste-obs").removeData('obsId'+obsId);
|
| 2688 |
mathias |
1101 |
};
|
| 1210 |
jpm |
1102 |
|
| 2688 |
mathias |
1103 |
WidgetSaisie.prototype.initialiserBarreProgression = function() {
|
| 2110 |
aurelien |
1104 |
$('#barre-progression-upload').attr('aria-valuenow', 0);
|
|
|
1105 |
$('#barre-progression-upload').attr('style', "width: 0%");
|
|
|
1106 |
$('#barre-progression-upload .sr-only').text("0/0 observations transmises");
|
|
|
1107 |
$('.progress').addClass('active');
|
|
|
1108 |
$('.progress').addClass('progress-striped');
|
| 2688 |
mathias |
1109 |
};
|
| 2110 |
aurelien |
1110 |
|
| 2688 |
mathias |
1111 |
WidgetSaisie.prototype.initialiserObs = function() {
|
|
|
1112 |
this.obsNbre = 0;
|
|
|
1113 |
this.nbObsTransmises = 0;
|
|
|
1114 |
this.nbObsEnCours = 0;
|
|
|
1115 |
this.totalObsATransmettre = 0;
|
|
|
1116 |
this.initialiserBarreProgression();
|
|
|
1117 |
$(".obs-nbre").text(this.obsNbre);
|
| 1249 |
jpm |
1118 |
$(".obs-nbre").triggerHandler('changement');
|
|
|
1119 |
$("#liste-obs").removeData();
|
|
|
1120 |
$('.obs').remove();
|
|
|
1121 |
$("#dialogue-bloquer-creer-obs").hide();
|
| 2688 |
mathias |
1122 |
};
|
| 1231 |
jpm |
1123 |
|
| 2688 |
mathias |
1124 |
/**
|
|
|
1125 |
* Ajoute une boîte de miniatures avec défilement des images,
|
|
|
1126 |
* pour une obs de la liste des obs à transmettre
|
|
|
1127 |
*/
|
|
|
1128 |
WidgetSaisie.prototype.ajouterImgMiniatureAuTransfert = function() {
|
|
|
1129 |
var html = '',
|
|
|
1130 |
miniatures = '',
|
|
|
1131 |
premiere = true;
|
| 1524 |
aurelien |
1132 |
if ($("#miniatures img").length >= 1) {
|
|
|
1133 |
$("#miniatures img").each(function() {
|
|
|
1134 |
var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee';
|
|
|
1135 |
premiere = false;
|
| 2688 |
mathias |
1136 |
var css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
|
|
|
1137 |
src = $(this).attr("src"),
|
|
|
1138 |
alt = $(this).attr("alt"),
|
|
|
1139 |
//miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
|
|
|
1140 |
miniature = '<div class="'+css+' '+visible+'" alt="'+alt+'" style="background-image: url('+src+')" ></div>';
|
| 1524 |
aurelien |
1141 |
miniatures += miniature;
|
|
|
1142 |
});
|
|
|
1143 |
visible = ($("#miniatures img").length > 1) ? '' : 'defilement-miniatures-cache';
|
| 2328 |
jpm |
1144 |
var html =
|
| 1524 |
aurelien |
1145 |
'<div class="defilement-miniatures">'+
|
|
|
1146 |
'<a href="#" class="defilement-miniatures-gauche '+visible+'"><</a>'+
|
|
|
1147 |
miniatures+
|
|
|
1148 |
'<a href="#" class="defilement-miniatures-droite '+visible+'">></a>'+
|
|
|
1149 |
'</div>';
|
| 1237 |
jpm |
1150 |
} else {
|
| 2700 |
mathias |
1151 |
html = '<img class="miniature" alt="Aucune photo"src="'+ this.pasDePhotoIconeUrl +'" />';
|
| 1210 |
jpm |
1152 |
}
|
| 1524 |
aurelien |
1153 |
return html;
|
| 2688 |
mathias |
1154 |
};
|
| 1210 |
jpm |
1155 |
|
| 2688 |
mathias |
1156 |
WidgetSaisie.prototype.defilerMiniatures = function(element) {
|
| 2328 |
jpm |
1157 |
|
| 2688 |
mathias |
1158 |
var miniatureSelectionne = element.siblings("div.miniature-selectionnee");
|
| 1524 |
aurelien |
1159 |
miniatureSelectionne.removeClass('miniature-selectionnee');
|
|
|
1160 |
miniatureSelectionne.addClass('miniature-cachee');
|
|
|
1161 |
var miniatureAffichee = miniatureSelectionne;
|
| 2328 |
jpm |
1162 |
|
| 1524 |
aurelien |
1163 |
if(element.hasClass('defilement-miniatures-gauche')) {
|
|
|
1164 |
if(miniatureSelectionne.prev('.miniature').length != 0) {
|
|
|
1165 |
miniatureAffichee = miniatureSelectionne.prev('.miniature');
|
|
|
1166 |
} else {
|
|
|
1167 |
miniatureAffichee = miniatureSelectionne.siblings(".miniature").last();
|
|
|
1168 |
}
|
|
|
1169 |
} else {
|
|
|
1170 |
if(miniatureSelectionne.next('.miniature').length != 0) {
|
|
|
1171 |
miniatureAffichee = miniatureSelectionne.next('.miniature');
|
|
|
1172 |
} else {
|
|
|
1173 |
miniatureAffichee = miniatureSelectionne.siblings(".miniature").first();
|
|
|
1174 |
}
|
|
|
1175 |
}
|
| 1822 |
aurelien |
1176 |
//console.log(miniatureAffichee);
|
| 1524 |
aurelien |
1177 |
miniatureAffichee.addClass('miniature-selectionnee');
|
|
|
1178 |
miniatureAffichee.removeClass('miniature-cachee');
|
| 2688 |
mathias |
1179 |
};
|
| 1524 |
aurelien |
1180 |
|
| 2688 |
mathias |
1181 |
WidgetSaisie.prototype.ajouterNumNomSel = function() {
|
| 1240 |
jpm |
1182 |
var nn = '';
|
|
|
1183 |
if ($("#taxon").data("numNomSel") == undefined) {
|
|
|
1184 |
nn = '<span class="alert-error">[non lié au référentiel]</span>';
|
|
|
1185 |
} else {
|
|
|
1186 |
nn = '<span class="nn">[nn'+$("#taxon").data("numNomSel")+']</span>';
|
|
|
1187 |
}
|
|
|
1188 |
return nn;
|
| 2688 |
mathias |
1189 |
};
|
| 1240 |
jpm |
1190 |
|
| 2688 |
mathias |
1191 |
WidgetSaisie.prototype.ajouterAutocompletionNoms = function() {
|
|
|
1192 |
var lthis = this;
|
| 1210 |
jpm |
1193 |
$('#taxon').autocomplete({
|
| 2328 |
jpm |
1194 |
source: function(requete, add){
|
| 1210 |
jpm |
1195 |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
|
|
|
1196 |
requete = "";
|
| 2343 |
aurelien |
1197 |
if($("#referentiel").val() != "autre") {
|
| 2688 |
mathias |
1198 |
var url = lthis.getUrlAutocompletionNomsSci();
|
| 2343 |
aurelien |
1199 |
$.getJSON(url, requete, function(data) {
|
| 2688 |
mathias |
1200 |
var suggestions = lthis.traiterRetourNomsSci(data);
|
| 2343 |
aurelien |
1201 |
add(suggestions);
|
|
|
1202 |
});
|
|
|
1203 |
}
|
| 1210 |
jpm |
1204 |
},
|
|
|
1205 |
html: true
|
|
|
1206 |
});
|
| 2328 |
jpm |
1207 |
|
| 1213 |
jpm |
1208 |
$( "#taxon" ).bind("autocompleteselect", function(event, ui) {
|
| 1215 |
jpm |
1209 |
$("#taxon").data(ui.item);
|
|
|
1210 |
if (ui.item.retenu == true) {
|
|
|
1211 |
$("#taxon").addClass('ns-retenu');
|
|
|
1212 |
} else {
|
|
|
1213 |
$("#taxon").removeClass('ns-retenu');
|
|
|
1214 |
}
|
| 1213 |
jpm |
1215 |
});
|
| 2688 |
mathias |
1216 |
};
|
| 1210 |
jpm |
1217 |
|
| 2688 |
mathias |
1218 |
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
|
| 1215 |
jpm |
1219 |
var mots = $('#taxon').val();
|
| 2700 |
mathias |
1220 |
var url = this.serviceAutocompletionNomSciUrlTpl.replace('{referentiel}', this.nomSciReferentiel);
|
| 1476 |
aurelien |
1221 |
url = url.replace('{masque}', mots);
|
| 1210 |
jpm |
1222 |
return url;
|
| 2688 |
mathias |
1223 |
};
|
| 1210 |
jpm |
1224 |
|
| 2688 |
mathias |
1225 |
WidgetSaisie.prototype.traiterRetourNomsSci = function(data) {
|
| 2328 |
jpm |
1226 |
var suggestions = [];
|
| 1210 |
jpm |
1227 |
if (data.resultat != undefined) {
|
|
|
1228 |
$.each(data.resultat, function(i, val) {
|
|
|
1229 |
val.nn = i;
|
| 2328 |
jpm |
1230 |
var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '',
|
| 1215 |
jpm |
1231 |
nomRet : '', numNomRet : '', famille : '', retenu : false
|
|
|
1232 |
};
|
| 2700 |
mathias |
1233 |
if (suggestions.length >= this.autocompletionElementsNbre) {
|
| 1213 |
jpm |
1234 |
nom.label = "...";
|
|
|
1235 |
nom.value = $('#taxon').val();
|
|
|
1236 |
suggestions.push(nom);
|
|
|
1237 |
return false;
|
|
|
1238 |
} else {
|
| 1231 |
jpm |
1239 |
nom.label = val.nom_sci_complet;
|
|
|
1240 |
nom.value = val.nom_sci_complet;
|
| 1215 |
jpm |
1241 |
nom.nt = val.num_taxonomique;
|
|
|
1242 |
nom.nomSel = val.nom_sci;
|
|
|
1243 |
nom.nomSelComplet = val.nom_sci_complet;
|
|
|
1244 |
nom.numNomSel = val.nn;
|
| 1237 |
jpm |
1245 |
nom.nomRet = val.nom_retenu_complet;
|
| 1220 |
jpm |
1246 |
nom.numNomRet = val["nom_retenu.id"];
|
| 1231 |
jpm |
1247 |
nom.famille = val.famille;
|
| 2243 |
mathias |
1248 |
// Tester dans ce sens, permet de considérer "absent" comme "false" => est-ce opportun ?
|
|
|
1249 |
// en tout cas c'est harmonisé avec le CeL
|
|
|
1250 |
nom.retenu = (val.retenu == 'true') ? true : false;
|
| 2328 |
jpm |
1251 |
|
| 1213 |
jpm |
1252 |
suggestions.push(nom);
|
| 2328 |
jpm |
1253 |
}
|
| 1210 |
jpm |
1254 |
});
|
|
|
1255 |
}
|
| 2328 |
jpm |
1256 |
|
| 1210 |
jpm |
1257 |
return suggestions;
|
| 2688 |
mathias |
1258 |
};
|
| 1210 |
jpm |
1259 |
|
| 2700 |
mathias |
1260 |
WidgetSaisie.prototype.afficherPanneau = function(selecteur) {
|
|
|
1261 |
$(selecteur).fadeIn("slow").delay(this.dureeMessage).fadeOut("slow");
|
| 2701 |
mathias |
1262 |
};
|
| 2700 |
mathias |
1263 |
|
| 2701 |
mathias |
1264 |
WidgetSaisie.prototype.masquerPanneau = function(selecteur) {
|
|
|
1265 |
$(selecteur).hide();
|
|
|
1266 |
};
|
|
|
1267 |
|
| 2697 |
mathias |
1268 |
// lib hors objet --
|
|
|
1269 |
|
|
|
1270 |
/**
|
|
|
1271 |
* Stope l'évènement courant quand on clique sur un lien.
|
|
|
1272 |
* Utile pour Chrome, Safari...
|
|
|
1273 |
*/
|
|
|
1274 |
function arreter(evenement) {
|
|
|
1275 |
if (evenement.stopPropagation) {
|
|
|
1276 |
evenement.stopPropagation();
|
|
|
1277 |
}
|
|
|
1278 |
if (evenement.preventDefault) {
|
|
|
1279 |
evenement.preventDefault();
|
|
|
1280 |
}
|
|
|
1281 |
return false;
|
|
|
1282 |
}
|
|
|
1283 |
|
|
|
1284 |
/**
|
|
|
1285 |
* Extrait les données de désinsectisation d'une requête AJAX de jQuery
|
|
|
1286 |
* @param jqXHR
|
|
|
1287 |
* @returns {String}
|
|
|
1288 |
*/
|
|
|
1289 |
function extraireEnteteDebug(jqXHR) {
|
|
|
1290 |
var msgDebug = '';
|
|
|
1291 |
if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
|
|
|
1292 |
var debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
|
|
|
1293 |
if (debugInfos != null) {
|
|
|
1294 |
$.each(debugInfos, function (cle, valeur) {
|
|
|
1295 |
msgDebug += valeur + "\n";
|
|
|
1296 |
});
|
|
|
1297 |
}
|
|
|
1298 |
}
|
|
|
1299 |
return msgDebug;
|
|
|
1300 |
}
|
|
|
1301 |
|
| 1210 |
jpm |
1302 |
/*
|
|
|
1303 |
* jQuery UI Autocomplete HTML Extension
|
|
|
1304 |
*
|
|
|
1305 |
* Copyright 2010, Scott González (http://scottgonzalez.com)
|
|
|
1306 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
1307 |
*
|
|
|
1308 |
* http://github.com/scottgonzalez/jquery-ui-extensions
|
| 2328 |
jpm |
1309 |
*
|
| 1210 |
jpm |
1310 |
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
|
|
|
1311 |
*/
|
|
|
1312 |
(function( $ ) {
|
| 1215 |
jpm |
1313 |
var proto = $.ui.autocomplete.prototype,
|
|
|
1314 |
initSource = proto._initSource;
|
| 2328 |
jpm |
1315 |
|
| 2688 |
mathias |
1316 |
WidgetSaisie.prototype.filter = function( array, term ) {
|
| 1215 |
jpm |
1317 |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
|
|
|
1318 |
return $.grep( array, function(value) {
|
|
|
1319 |
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
|
|
|
1320 |
});
|
|
|
1321 |
}
|
| 2328 |
jpm |
1322 |
|
| 1215 |
jpm |
1323 |
$.extend( proto, {
|
|
|
1324 |
_initSource: function() {
|
|
|
1325 |
if ( this.options.html && $.isArray(this.options.source) ) {
|
|
|
1326 |
this.source = function( request, response ) {
|
|
|
1327 |
response( filter( this.options.source, request.term ) );
|
|
|
1328 |
};
|
|
|
1329 |
} else {
|
|
|
1330 |
initSource.call( this );
|
|
|
1331 |
}
|
|
|
1332 |
},
|
|
|
1333 |
_renderItem: function( ul, item) {
|
|
|
1334 |
if (item.retenu == true) {
|
|
|
1335 |
item.label = "<strong>"+item.label+"</strong>";
|
|
|
1336 |
}
|
| 2328 |
jpm |
1337 |
|
| 1215 |
jpm |
1338 |
return $( "<li></li>" )
|
|
|
1339 |
.data( "item.autocomplete", item )
|
|
|
1340 |
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
|
|
|
1341 |
.appendTo( ul );
|
|
|
1342 |
}
|
| 1210 |
jpm |
1343 |
});
|
|
|
1344 |
})( jQuery );
|