New file |
0,0 → 1,920 |
// Héritage !! |
function WidgetSaisieSauvages() { |
this.markerDeb = undefined; |
this.latLngDeb = undefined; |
this.markerFin = undefined; |
this.latLngCentre = undefined; |
this.latLngFin = undefined; |
this.ligneRue = undefined; |
this.premierDeplacement = true; |
this.valeurChamp = ""; |
this.avertissementDeuxPhotosAffiche = false; |
this.googleMapMarqueurDebutUrl = null; |
this.googleMapMarqueurFinUrl = null; |
this.ville = null; |
this.supprimerIconeUrl = null; |
this.serviceTraceRueUrl = null; |
this.taxons = {}; |
this.listeRues = {}; |
this.indexRueSelectionnee = 0; |
this.requeteRechercheRue = null; |
this.aucuneRueSelectionnee = "Aucune rue sélectionnée"; |
this.nomDeRueInconnue = "Nom de rue inconnu"; |
} |
WidgetSaisieSauvages.prototype = new WidgetSaisie(); |
|
// surcharge |
WidgetSaisieSauvages.prototype.initCarto = function() { |
this.initialiserGoogleMap(); |
this.afficherEtapeGeolocalisation(1); |
this.latLng = true; // patch cracra pour éviter de surcharger trouvercommune() |
|
var lthis = this; |
$('#carte-recherche').autocomplete({ |
//Cette partie utilise geocoder pour extraire des valeurs d'adresse |
source: function(request, response) { |
lthis.geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) { |
if (status == google.maps.GeocoderStatus.OK) { |
response($.map(results, function(item) { |
var rue = ""; |
$.each(item.address_components, function(){ |
if (this.types[0] == "route" || this.types[0] == "street_address" ) { |
rue = this.short_name; |
} |
}); |
var retour = { |
label: item.formatted_address, |
value: rue, |
latitude: item.geometry.location.lat(), |
longitude: item.geometry.location.lng() |
}; |
return retour; |
})); |
} else { |
lthis.afficherErreurGoogleMap(status); |
} |
}); |
}, |
// Cette partie est executee a la selection d'une adresse |
select: function(event, ui) { |
var nouvellePosition = new google.maps.LatLng(ui.item.latitude, ui.item.longitude); |
lthis.initialiserMarkerDeb(); |
lthis.deplacerMarkerDeb(nouvellePosition); |
lthis.map.setZoom(16); |
lthis.afficherEtapeGeolocalisation(2); |
} |
}); |
}; |
|
//surcharge |
WidgetSaisieSauvages.prototype.initForm = function() { |
// super() à la main - toute autre manière de faire est über-komplex |
WidgetSaisie.prototype.initForm.call(this); |
|
this.surChangementTaxonListe(); |
$('#taxon-liste').on('change', this.surChangementTaxonListe); |
if (this.debug) { |
console.log('Selected taxon:'+$('#taxon-liste option:selected').val()); |
} |
$('#taxon-liste').on('blur', this.surChangementValeurTaxon); |
$('#taxon').on('blur', this.surChangementValeurTaxon); |
}; |
|
//surcharge |
WidgetSaisieSauvages.prototype.initEvts = function() { |
var lthis = this; |
// super() à la main - toute autre manière de faire est über-komplex |
WidgetSaisie.prototype.initEvts.call(this); |
|
$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) { |
event.stopPropagation(); |
}); |
$('#fichier').off(); // elever l'écouteur d'événements de base |
$('#fichier').on('click change', function(event) { |
|
if($("#photos-conteneur #miniatures .miniature").length == 1 && ! lthis.avertissementDeuxPhotosAffiche) { |
messageAvertissement = "Attention: \n"+ |
"Sélectionnez uniquement les photos correspondantes à une seule plante \n"+ |
"(c'est à dire correspondant à un seul individu d'une espèce donnée) \n"+ |
"vue dans le tronçon de rue inventoriée "; |
if(window.confirm(messageAvertissement)) { |
lthis.avertissementDeuxPhotosAffiche = true; |
return true; |
} else { |
return false; |
} |
} |
if ($(this).val().length > 0) { |
arreter(event); |
var options = { |
success: lthis.afficherMiniature.bind(lthis), // post-submit callback |
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) |
resetForm: true // reset the form after successful submit |
}; |
$('#miniature').append( |
'<img id="miniature-chargement" class="miniature" alt="chargement" src="'+ this.chargementImageIconeUrl +'"/>'); |
$('#ajouter-obs').attr('disabled', 'disabled'); |
if (lthis.verifierFormat($(this).val())) { |
$('#form-upload').ajaxSubmit(options); |
} else { |
$('#form-upload')[0].reset(); |
window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+ $('#fichier').attr('accept')); |
} |
return false; |
} |
}); |
|
$('.cb-milieux').on('click', function(event) { |
$(this).valid(); |
event.stopPropagation(); |
}); |
|
// Défilement des photos |
$('body').on('click', '.defilement-control-zone', function(event) { |
lthis.defilerMiniatures($(this)); |
}); |
$('body').on('mouseover', '.defilement-control-zone', function(event) { |
$('.defilement-control', this).removeClass('hidden'); |
}); |
$('body').on('mouseout', '.defilement-control-zone', function(event) { |
$('.defilement-control', this).addClass('hidden'); |
}); |
|
$('#photo-placeholder').click(function(event) { |
$('#fichier').click(); |
}); |
$('#geolocaliser').on('click', this.geolocaliser.bind(this)); |
|
$('.navigation-rue').on('click', this.surClicRueSuivantPrecedent.bind(this)); |
}; |
|
WidgetSaisieSauvages.prototype.montrerFormIdentite = function() { |
$('#zone-courriel-confirmation, #zone-prenom-nom').css('display', 'block'); |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.initialiserGoogleMap = function() { |
var lthis = this; |
this.latLngDeb = new google.maps.LatLng(48.8543, 2.3483);// Paris |
if (this.ville == 'Marseille') { |
this.latLngDeb = new google.maps.LatLng(43.29545, 5.37458); |
} else if (this.ville == 'Montpellier') { |
this.latLngDeb = new google.maps.LatLng(43.61077, 3.87672); |
} |
var options = { |
zoom: 16, |
center: this.latLngDeb, |
mapTypeId: google.maps.MapTypeId.HYBRID, |
mapTypeControlOptions: { |
mapTypeIds: ['OSM', |
google.maps.MapTypeId.ROADMAP, |
google.maps.MapTypeId.HYBRID, |
google.maps.MapTypeId.SATELLITE, |
google.maps.MapTypeId.TERRAIN]} |
}; |
|
// Ajout de la couche OSM à la carte |
osmMapType = new google.maps.ImageMapType({ |
getTileUrl: function(coord, zoom) { |
return 'http://tile.openstreetmap.org/' + zoom + '/' + coord.x + '/' + coord.y + '.png'; |
}, |
tileSize: new google.maps.Size(256, 256), |
isPng: true, |
alt: 'OpenStreetMap', |
name: 'OSM', |
maxZoom: 19 |
}); |
|
// Création de la carte Google |
this.map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas |
this.map.mapTypes.set('OSM', osmMapType); |
|
// Ajout de l'évènment sur click dans Carte |
google.maps.event.addListener(this.map, 'click', this.surClickDansCarte.bind(this)); |
|
// Lorsque la carte est chargée, on vérifie si on peut précharger des données |
google.maps.event.addListenerOnce(this.map, 'idle', function(){ |
// Initialisation du marker de début de rue |
lthis.initialiserMarkerDeb(); |
if (this.obsId == '') { |
// Tentative de geocalisation si aucune obs à précharger |
lthis.tenterGeolocalisation(); |
} |
}); |
|
// Création du Geocoder |
this.geocoder = new google.maps.Geocoder(); |
}; |
|
WidgetSaisieSauvages.prototype.surClickDansCarte = function(event) { |
this.latLngDeb = event.latLng; |
this.deplacerMarkerDeb(this.latLngDeb); |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.prechargerForm = function(data) { |
|
$('#carte-recherche').val(data.zoneGeo); |
$('#commune-nom').text(data.zoneGeo); |
|
if(data.hasOwnProperty("codeZoneGeo")) { |
$('#commune-code-insee').text(data.codeZoneGeo.replace('INSEE-C:', '')); |
} |
|
var pos = new google.maps.LatLng(data.latitude, data.longitude); |
|
if(data.hasOwnProperty("extension")) { |
this.initialiserMarkerFin(); |
|
// cas des obs florilèges qui apparaissent aussi comme des obs sauvages |
// mais qui n'ont pas de coté de rue |
if(data.extension.hasOwnProperty("coteRue")) { |
$('#rue_cote option[value='+data.extension.coteRue.valeur+']').attr("selected", "selected"); |
} |
|
var deb = new google.maps.LatLng(data.extension.latitudeDebutRue.valeur, data.extension.longitudeDebutRue.valeur); |
var fin = new google.maps.LatLng(data.extension.latitudeFinRue.valeur, data.extension.longitudeFinRue.valeur); |
|
this.mettreAJourMarkerPosition(pos); |
|
this.deplacerMarkerDeb(deb); |
this.deplacerMarkerFin(fin); |
this.afficherEtapeGeolocalisation(4); |
|
var latlngbounds = new google.maps.LatLngBounds(); |
latlngbounds.extend(deb); |
latlngbounds.extend(fin); |
this.map.setCenter(latlngbounds.getCenter()); |
this.map.fitBounds(latlngbounds); |
} else if(data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude")) { |
this.deplacerMarkerDeb(pos); |
} |
}; |
|
WidgetSaisieSauvages.prototype.initialiserMarkerDeb = function() { |
this.premierDeplacement = true; |
if (this.markerDeb == undefined) { |
// Marqueur de début de Rue |
this.markerDeb = new google.maps.Marker({ |
map: this.map, |
draggable: true, |
title: 'Début de la portion de rue étudiée', |
icon: this.googleMapMarqueurDebutUrl, |
position: this.latLngDeb |
}); |
google.maps.event.addListener(this.markerDeb, 'dragend', this.surDeplacementMarkerDeb.bind(this)); |
} |
|
this.latLngFin = this.latLngDeb; |
if (this.markerFin != undefined) { |
this.markerFin.setMap(null); |
} |
this.latLngCentre = this.latLngDeb; |
if (this.ligneRue != undefined) { |
this.ligneRue.setMap(null); |
} |
}; |
|
WidgetSaisieSauvages.prototype.surDeplacementMarkerDeb = function() { |
this.latLngDeb = this.markerDeb.getPosition(); |
this.deplacerMarkerDeb(this.latLngDeb); |
}; |
|
WidgetSaisieSauvages.prototype.deplacerMarkerDeb = function(nouvellePosition) { |
|
// Annulation d'une éventuelle recherche de rue déjà en cours |
this.annulerRechercherRue(); |
|
this.latLngDeb = nouvellePosition; |
this.markerDeb.setPosition(this.latLngDeb); |
this.map.setCenter(this.latLngDeb); |
this.mettreAJourMarkerPosition(this.latLngDeb); |
this.trouverCommune(this.latLngDeb); |
|
var nouvellePositionFin = new google.maps.LatLng(this.latLngDeb.lat(), this.latLngDeb.lng() + 0.0010); |
this.initialiserMarkerFin(); |
this.deplacerMarkerFin(nouvellePositionFin) |
this.afficherEtapeGeolocalisation(3); |
}; |
|
WidgetSaisieSauvages.prototype.initialiserMarkerFin = function() { |
if (this.markerFin == undefined) { |
this.markerFin = new google.maps.Marker({ |
map: this.map, |
draggable: true, |
title: 'Fin de la portion de rue étudiée', |
icon: this.googleMapMarqueurFinUrl, |
position: this.latLngFin |
}); |
google.maps.event.addListener(this.markerFin, 'dragend', this.surDeplacementMarkerFin.bind(this)); |
} else { |
this.markerFin.setMap(null); |
} |
}; |
|
WidgetSaisieSauvages.prototype.deplacerMarkerFin = function(nouvellePosition) { |
this.latLngFin = nouvellePosition; |
this.markerFin.setMap(this.map); |
this.markerFin.setPosition(this.latLngFin); |
this.dessinerLigneRue(this.latLngDeb, this.latLngFin); |
}; |
|
WidgetSaisieSauvages.prototype.surDeplacementMarkerFin = function() { |
// Annulation d'une éventuelle recherche déjà en cours |
this.annulerRechercherRue(); |
this.rechercherRue(); |
}; |
|
WidgetSaisieSauvages.prototype.surClicRueSuivantPrecedent = function(event) { |
event.preventDefault(); |
if($(event.target).hasClass("navigation-rue-suivant")) { |
this.indexRueSelectionnee = this.indexRueSelectionnee < this.listeRues.length - 1 ? this.indexRueSelectionnee + 1 : 0; |
} else { |
this.indexRueSelectionnee = this.indexRueSelectionnee > 0 ? this.indexRueSelectionnee - 1 : this.listeRues.length - 1; |
} |
this.mettreRueEnValeur(this.listeRues[this.indexRueSelectionnee]); |
} |
|
WidgetSaisieSauvages.prototype.afficherChargementRechercheRue = function() { |
this.ligneRue.setMap(null); |
var img = '<img src="'+this.chargementImageIconeUrl+'" />'; |
$('#indication-nom-rue-nom').html(img+" Recherche de la rue en cours"); |
$('#indication-nom-rue').css('visibility','visible'); |
$('#indication-nom-rue').effect("highlight", {}, 500); |
$(".navigation-rue").toggle(false); |
} |
|
WidgetSaisieSauvages.prototype.rechercherRue = function() { |
this.afficherChargementRechercheRue(); |
|
var params = "latitude_debut="+this.markerDeb.getPosition().lat()+"&longitude_debut="+this.markerDeb.getPosition().lng()+ |
"&latitude_fin="+this.markerFin.getPosition().lat()+"&longitude_fin="+this.markerFin.getPosition().lng(); |
var lthis = this; |
|
this.requeteRechercheRue = $.getJSON(this.serviceTraceRueUrl+'?'+params, function(data) { |
$('#indication-nom-rue-nom').html(""); |
lthis.listeRues = data.elements; |
var coordDeb = {"lat" : lthis.markerDeb.getPosition().lat(), "lon" : lthis.markerDeb.getPosition().lng()}; |
var coordFin = {"lat" : lthis.markerFin.getPosition().lat(), "lon" : lthis.markerFin.getPosition().lng()}; |
var tags = {"name" : lthis.aucuneRueSelectionnee}; |
var pasDeRue = {"geometry" : [coordDeb, coordFin], "tags" : tags}; |
lthis.listeRues.push(pasDeRue); |
lthis.indexRueSelectionnee = 0; |
lthis.mettreRueEnValeur(lthis.listeRues[0]); |
}); |
} |
|
WidgetSaisieSauvages.prototype.annulerRechercherRue = function() { |
if(this.requeteRechercheRue != null) { |
this.requeteRechercheRue.abort(); |
this.requeteRechercheRue = null; |
$('#indication-nom-rue').css('visibility','hidden'); |
} |
} |
|
|
WidgetSaisieSauvages.prototype.mettreRueEnValeur = function(rue) { |
this.afficherIndicationRue(rue['tags']['name']); |
this.afficherTraceRue(rue['geometry']); |
this.afficherEtapeGeolocalisation(4); |
} |
|
WidgetSaisieSauvages.prototype.afficherIndicationRue = function(indication) { |
indication = !!indication ? indication : this.nomDeRueInconnue; |
$('#indication-nom-rue-nom').html(indication); |
$('#indication-nom-rue').css('visibility','visible'); |
$('#indication-nom-rue').effect("highlight", {}, 500); |
$(".navigation-rue").toggle(this.listeRues.length > 1); |
} |
|
WidgetSaisieSauvages.prototype.afficherTraceRue = function(rue) { |
|
if (this.ligneRue != undefined) { |
this.ligneRue.setMap(null); |
} |
|
var cheminRue = new Array(); |
if(rue.length > 0) { |
$.each(rue, function(index, value) { |
cheminRue.push(new google.maps.LatLng(value['lat'], value['lon'])); |
}); |
|
this.ligneRue = new google.maps.Polyline({ |
path: cheminRue, |
strokeColor: "#FF0000", |
strokeOpacity: 1.0, |
strokeWeight: 2 |
}); |
|
this.ligneRue.setMap(this.map); |
} |
}; |
|
WidgetSaisieSauvages.prototype.dessinerLigneRue = function(pointDebut, pointFin) { |
if (this.ligneRue != undefined) { |
this.ligneRue.setMap(null); |
} |
|
this.ligneRue = new google.maps.Polyline({ |
path: [pointDebut, pointFin], |
strokeColor: "#FF0000", |
strokeOpacity: 1.0, |
strokeWeight: 2 |
}); |
|
this.ligneRue.setMap(this.map); |
}; |
|
WidgetSaisieSauvages.prototype.afficherCentreRue = function() { |
this.latLngDeb = this.markerDeb.getPosition(); |
this.latLngFin = this.markerFin.getPosition(); |
this.latLngCentre = new google.maps.LatLng((this.latLngFin.lat() + this.latLngDeb.lat())/2, (this.latLngFin.lng() + this.latLngDeb.lng())/2); |
this.mettreAJourMarkerPosition(this.latLngCentre); |
}; |
|
WidgetSaisieSauvages.prototype.afficherEtapeGeolocalisation = function(numEtape) { |
$('.liste_indication_geolocalisation').children().hide(); |
$('.liste_indication_geolocalisation :nth-child('+numEtape+')').show(); |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.geolocaliser = function(event) { |
var latitude = $('#latitude').val(), |
longitude = $('#longitude').val(), |
nouvellePosition = new google.maps.LatLng(latitude, longitude); |
this.initialiserMarkerDeb(); |
this.deplacerMarkerDeb(nouvellePosition); |
this.afficherEtapeGeolocalisation(2); |
this.map.setZoom(16); |
arreter(event); |
}; |
|
WidgetSaisieSauvages.prototype.tenterGeolocalisation = function() { |
var lthis = this; |
if (navigator.geolocation) { |
navigator.geolocation.getCurrentPosition(function(position) { |
var latitude = position.coords.latitude, |
longitude = position.coords.longitude, |
nouvellePosition = new google.maps.LatLng(latitude, longitude); |
lthis.initialiserMarkerDeb(); |
lthis.deplacerMarkerDeb(nouvellePosition); |
lthis.map.setZoom(16); |
}); |
} |
}; |
|
/** |
* AUTO-COMPLÉTION Noms Scientifiques => OK |
* sélectionne un nom et puis qu'on le remplacer par un nom non valide |
* Garder la trace de la valeur permet de vider le nn lorsqu'on |
*/ |
WidgetSaisieSauvages.prototype.ajouterAutocompletionNoms = function() { |
var lthis = this; |
$('#taxon').autocomplete({ |
source: function(requete, add){ |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté |
|
var url = lthis.getUrlAutocompletionNomsSci(); |
$.getJSON(url, function(data) { |
var suggestions = lthis.traiterRetourNomsSci(data); |
add(suggestions); |
}); |
}, |
html: true |
}); |
|
$('#taxon').bind('autocompleteselect', function(event, ui) { |
$('#taxon').data(ui.item); |
lthis.valeurChamp = $('#taxon').val(); |
if (ui.item.retenu == true) { |
$('#taxon').addClass('ns-retenu'); |
} else { |
$('#taxon').removeClass('ns-retenu'); |
} |
}); |
|
$('#taxon').bind('keypress', function() { |
if(lthis.valeurChamp != $('#taxon').val()) { |
$('#taxon').data('numNomSel', ''); |
} |
lthis.valeurChamp = $('#taxon').val(); |
}); |
}; |
|
WidgetSaisieSauvages.prototype.getUrlAutocompletionNomsSci = function() { |
var mots = $('#taxon').val(), |
url = this.serviceAutocompletionNomSciUrlTpl.replace('{referentiel}', this.nomSciReferentiel); |
url = url.replace('{masque}', mots); |
return url; |
}; |
|
WidgetSaisieSauvages.prototype.traiterRetourNomsSci = function(data) { |
var suggestions = []; |
if (data.resultat != undefined) { |
$.each(data.resultat, function(i, val) { |
val.nn = i; |
var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '', |
nomRet: '', numNomRet: '', famille: '', retenu: false |
}; |
if (suggestions.length >= this.autocompletionElementsNbre) { |
nom.label = '...'; |
nom.value = $('#taxon').val(); |
suggestions.push(nom); |
return false; |
} else { |
nom.label = val.nom_sci_complet; |
nom.value = val.nom_sci_complet; |
nom.nt = val.num_taxonomique; |
nom.nomSel = val.nom_sci; |
nom.nomSelComplet = val.nom_sci_complet; |
nom.numNomSel = val.nn; |
nom.nomRet = val.nom_retenu_complet; |
nom.numNomRet = val['nom_retenu.id']; |
nom.famille = val.famille; |
nom.retenu = (val.retenu == 'false') ? false : true; |
|
suggestions.push(nom); |
} |
}); |
} |
return suggestions; |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.configurerFormValidator = function() { |
$.validator.addMethod( |
'dateCel', |
function (value, element) { |
return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value)); |
}, |
'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.'); |
|
$.extend($.validator.defaults, { |
ignore: [],// Forcer Jquery Validate à examiner les éléments avec en display:none; |
highlight: function(element) { |
$(element).closest('.control-group').removeClass('success').addClass('error'); |
}, |
success: function(element) { |
element.text('OK!').addClass('valid'); |
element.closest('.control-group').removeClass('error').addClass('success'); |
|
if (element.attr('id') == 'taxon' && $('#taxon').val() != '') { |
// Si le taxon n'est pas lié au référentiel, on vide le data associé |
if ($('#taxon').data('value') != $('#taxon').val()) { |
$('#taxon').data('numNomSel', ''); |
$('#taxon').data('nomRet', ''); |
$('#taxon').data('numNomRet', ''); |
$('#taxon').data('nt', ''); |
$('#taxon').data('famille', ''); |
} |
} |
} |
}); |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.definirReglesFormValidator = function() { |
$('#form-observateur').validate({ |
rules: { |
courriel: { |
required: true, |
email: true}, |
courriel_confirmation: { |
required: true, |
equalTo: '#courriel'}, |
prenom: { |
required: true}, |
nom: { |
required: true} |
} |
}); |
$('#form-obs').validate({ |
rules: { |
station: { |
required: true}, |
latitude : { |
required: true, |
range: [-90, 90]}, |
longitude: { |
required: true, |
range: [-180, 180]}, |
date: { |
required: true, |
'dateCel' : true}, |
coteRue: { |
required: true}, |
'taxon-liste': { |
required: true}, |
'milieux[]': { |
required: true, |
minlength: 1} |
}, |
errorPlacement: function(error, element) { |
if (element.attr('name') == 'date') { |
element.parent('.input-prepend').after(error); |
} else if (element.attr('name') == 'milieux[]') { |
error.insertAfter('#milieux-controls'); |
} else { |
error.insertAfter(element); |
} |
}, |
messages: { |
'milieu[]': 'Vous devez sélectionner au moins un milieu' |
} |
}); |
}; |
|
WidgetSaisieSauvages.prototype.validerFormulaire = function() { |
var observateur = $('#form-observateur').valid(), |
obs = $('#form-obs').valid(), |
debRue = (this.latLngDeb == undefined || this.latLngDeb == this.latLngFin) ? false : true, |
finRue = (this.latLngFin == undefined || this.latLngDeb == this.latLngFin) ? false : true; |
var ok = (observateur && obs && debRue && finRue) ? true : false; |
//console.log('observateur:'+observateur+'-obs:'+obs+'-debRue:'+debRue+'('+latLngDeb+')-finRue:'+finRue+'('+latLngDeb+')'); |
return ok; |
}; |
|
WidgetSaisieSauvages.prototype.surChangementTaxonListe = function() { |
if ($('#taxon-liste').val() === '?') { |
$('#taxon-input-groupe').removeClass('hidden'); |
} else { |
$('#taxon-input-groupe').addClass('hidden'); |
} |
}; |
|
WidgetSaisieSauvages.prototype.surChangementValeurTaxon = function() { |
var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false; |
var nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'); |
var numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(); |
|
// Un nom non valide entraine automatiquement une certitude "à déterminer" |
if(nomSpecial || !numNomSel) { |
$('#certitude-adeterminer').attr('checked', 'checked'); |
} else { |
$('#certitude-adeterminer').removeAttr('checked'); |
} |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.ajouterObs = function() { |
if (this.validerFormulaire() == true) { |
this.obsNbre = this.obsNbre + 1; |
$('.obs-nbre').text(this.obsNbre); |
$('.obs-nbre').triggerHandler('changement'); |
this.afficherObs(); |
this.stockerObsData(); |
this.supprimerMiniatures(); |
} else { |
// Affichage de tous les panneau cachés avec champ obligatoire |
var debRue = (this.latLngDeb == undefined || this.latLngDeb == this.latLngFin) ? false : true, |
finRue = (this.latLngFin == undefined || this.latLngDeb == this.latLngFin) ? false : true; |
if (debRue == false || finRue == false) { |
this.afficherPanneau('#dialogue-form-invalide-rue'); |
} else { |
this.afficherPanneau('#dialogue-form-invalide'); |
} |
this.montrerFormIdentite(); |
} |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.afficherObs = function() { |
var numNomSel = ($('#taxon-liste').val() == '?') ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(), |
nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'), |
taxon = ($('#taxon-liste').val() == '?') ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'), |
referentiel = (numNomSel == undefined) ? '' : '['+ this.nomSciReferentiel +']', |
commune = $('#commune-nom').text(), |
codeInsee = $('#commune-code-insee').text(), |
station = this.getValeurStation(), |
lat = $('input[name="latitude"]').val(), |
lng = $('input[name="longitude"]').val(), |
date = $('#date').val(), |
milieux = this.getMilieux(), |
notes = (nomSpecial ? this.taxons[numNomSel]['nom_fr'] + ".<br />" : '') + $('#notes').val(); |
|
$('#liste-obs').prepend( |
'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">' + |
'<div class="span12">' + |
'<div class="well">' + |
'<div class="obs-action pull-right has-tooltip" data-placement="bottom" ' + |
'title="Supprimer cette observation de la liste à transmettre">' + |
'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">' + |
'<i class="icon-trash icon-white"></i>' + |
'</button>' + |
'</div> ' + |
'<div class="row-fluid">' + |
'<div class="span2 obs-miniatures">' + |
this.ajouterImgMiniatureAuTransfert() + |
'</div>'+ |
'<div class="span7">' + |
'<ul class="unstyled">' + |
'<li>'+ |
'<span class="nom-sci">' + taxon + '</span> ' + |
this.formaterNumNomSel(numNomSel) + |
' observé à <br />' + |
'<span class="commune">' + commune + '</span> ' + |
'(' + codeInsee + '), ' + |
'<span class="station">' + station + '</span><br /> ' + |
' le ' + |
'<span class="date">' + date + '</span>' + |
'</li>' + |
'<li>' + |
'Milieux : ' + milieux + ' ' + ' ; ' + |
'</li>' + |
'<li>' + |
'Notes : ' + notes + |
'</li>' + |
'</ul>' + |
'</div>' + |
'</div>' + |
'</div>' + |
'</div>'+ |
'</div>'); |
$('#zone-liste-obs').removeClass("hidden"); |
}; |
|
WidgetSaisieSauvages.prototype.getValeurStation = function() { |
var station = ""; |
var valeurSelectionnee = $("#indication-nom-rue-nom").text().trim(); |
if(valeurSelectionnee == this.aucuneRueSelectionnee || valeurSelectionnee == this.nomDeRueInconnue) { |
station = $('input[name="adresse"]').val().trim() |
} else { |
station = $("#indication-nom-rue-nom").text().trim(); |
} |
|
return station; |
} |
|
WidgetSaisieSauvages.prototype.getMilieux = function() { |
var milieuxStr = '', |
milieux = []; |
$('.cb-milieux:checked').each(function() { |
milieux.push($(this).val()); |
}); |
|
milieuxStr = Array.prototype.slice.call(milieux).join(', '); |
return milieuxStr; |
}; |
|
WidgetSaisieSauvages.prototype.ajouterImgMiniatureAuTransfert = function() { |
var html = '', |
miniatures = '', |
indicateurs = '', |
premiere = true, |
numero = 1; |
if ($('#miniatures img').length == 0) { |
html = '<img class="miniature" alt="Aucune photo"src="'+ this.pasDePhotoIconeUrl +'" />'; |
} else if ($('#miniatures img').length >= 1) { |
$('#miniatures img').each(function() { |
var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee', |
css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature', |
src = $(this).attr('src'), |
alt = $(this).attr('alt'); |
|
var miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />'; |
miniatures += miniature; |
|
var indicateurActif = premiere ? 'active' : ''; |
var indicateur = '<li class="' + indicateurActif + '" data-numero="' + numero++ + '"></li>'; |
indicateurs += indicateur; |
|
premiere = false; |
}); |
|
if ($('#miniatures img').length == 1) { |
html = miniatures; |
} else { |
html = |
'<div class="defilement">' + |
miniatures + |
'<a class="defilement-control-zone gauche">' + |
' <span class="defilement-control gauche hidden"><</span>' + |
'</a>' + |
'<a class="defilement-control-zone droite">' + |
' <span class="defilement-control droite hidden">></span>' + |
'</a>' + |
'<ol class="defilement-indicateurs">' + indicateurs + '</ol>' + |
'</div>'; |
} |
} |
return html; |
}; |
|
WidgetSaisieSauvages.prototype.defilerMiniatures = function(element) { |
var miniatureSelectionne = element.siblings('img.miniature-selectionnee'); |
miniatureSelectionne.removeClass('miniature-selectionnee').addClass('miniature-cachee'); |
var miniatureAffichee = miniatureSelectionne; |
|
var indicateurActif = element.parent().find('.defilement-indicateurs .active'); |
indicateurActif.removeClass('active'); |
|
if (element.hasClass('defilement-control-zone') && element.hasClass('gauche')) { |
if (miniatureSelectionne.prev('.miniature').length != 0) { |
miniatureAffichee = miniatureSelectionne.prev('.miniature'); |
indicateurActif.prev().addClass('active'); |
} else { |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').last(); |
indicateurActif.siblings().last().addClass('active'); |
} |
} else { |
if (miniatureSelectionne.next('.miniature').length != 0) { |
miniatureAffichee = miniatureSelectionne.next('.miniature'); |
indicateurActif.next().addClass('active'); |
} else { |
miniatureAffichee = miniatureSelectionne.siblings('.miniature').first(); |
indicateurActif.siblings().first().addClass('active'); |
} |
} |
miniatureAffichee.addClass('miniature-selectionnee').removeClass('miniature-cachee'); |
}; |
|
WidgetSaisieSauvages.prototype.formaterNumNomSel = function(numNomSel) { |
var nn = ''; |
if (numNomSel == undefined) { |
nn = '<span class="alert-error">[non lié au référentiel]</span>'; |
} else { |
nn = '<span class="nn">[nn'+numNomSel+']</span>'; |
} |
return nn; |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.surChangementReferentiel = function() { |
this.nomSciReferentiel = $('#referentiel').val(); |
$('#taxon').val(''); |
}; |
|
// surcharge |
WidgetSaisieSauvages.prototype.stockerObsData = function() { |
var lthis = this; |
var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false; |
nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'), |
numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val(); |
var nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'), |
nomRet = nomHorsListe ? $('#taxon').data('nomRet') : this.taxons[numNomSel]['nom_ret'], |
numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : this.taxons[numNomSel]['num_nom_ret'], |
numTaxon = nomHorsListe ? $('#taxon').data('nt') : this.taxons[numNomSel]['num_taxon'], |
famille = nomHorsListe ? $('#taxon').data('famille') : this.taxons[numNomSel]['famille'], |
referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel, |
notes = (nomSpecial ? this.taxons[numNomSel]['nom_fr'] + '. ' : '') + $('#notes').val(); |
|
certitude = $('input[name=certitude]:checked').val(); |
certitude = (certitude == undefined) ? '' : certitude; |
|
$('#liste-obs').data('obsId'+this.obsNbre, { |
'date': $('#date').val(), |
'notes': notes, |
|
'station': this.getValeurStation(), |
'latitude': $('#latitude').val(), |
'longitude': $('#longitude').val(), |
'commune_nom': $('#commune-nom').text(), |
'commune_code_insee': $('#commune-code-insee').text(), |
|
'nom_sel': nomSel, |
'num_nom_sel': numNomSel, |
'nom_ret': nomRet, |
'num_nom_ret': numNomRet, |
'num_taxon': numTaxon, |
'famille': famille, |
'referentiel': referentiel, |
'certitude': certitude, |
'milieu': lthis.getMilieux(), |
|
// Ajout des champs images |
'image_nom': lthis.getNomsImgsOriginales(), |
|
// Ajout des champs étendus de l'obs |
'obs_etendue': lthis.getObsChpEtendus() |
}); |
if (this.debug) { |
console.log($('#liste-obs').data('obsId'+this.obsNbre)); |
} |
}; |
|
WidgetSaisieSauvages.prototype.getObsChpEtendus = function() { |
var champs = []; |
if (this.latLngDeb != undefined) { |
var latitudeDebutRue = {cle: 'latitudeDebutRue', label: 'Latitude du début de la rue', valeur: this.latLngDeb.lat().toFixed(5)}; |
champs.push(latitudeDebutRue); |
var longitudeDebutRue = {cle: 'longitudeDebutRue', label: 'Longitude du début de la rue', valeur: this.latLngDeb.lng().toFixed(5)}; |
champs.push(longitudeDebutRue); |
} |
if (this.latLngFin != undefined) { |
var latitudeFinRue = {cle: 'latitudeFinRue', label: 'Latitude de fin de la rue', valeur: this.latLngFin.lat().toFixed(5)}; |
champs.push(latitudeFinRue); |
var longitudeFinRue = {cle: 'longitudeFinRue', label: 'Longitude de fin de la rue', valeur: this.latLngFin.lng().toFixed(5)}; |
champs.push(longitudeFinRue); |
} |
|
$('.obs-chp-etendu').each(function() { |
var valeur = $(this).val(), |
cle = $(this).attr('name'), |
label = $(this).data('label'); |
if (valeur != '') { |
var chpEtendu = {cle: cle, label: label, valeur: valeur}; |
champs.push(chpEtendu); |
} |
}); |
return champs; |
}; |