Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1561 → Rev 1562

/trunk/widget/modules/saisie/squelettes/florileges/css/florileges.css
60,47 → 60,28
}
/*+--------------------------------------------------------------------------------------------------------+*/
/* Gestion des photos */
.miniature{
 
/* Form d'ajout des photos */
#form-upload .miniature {
float: left;
height: 130px;
padding-left: 15px;
padding-right: 15px;
margin: 5px;
}
.miniature-img {
#form-upload .miniature-img {
display: block;
height: 100px;
}
.miniature img {
display: block;
}
.miniature-chargement {
#form-upload .miniature-chargement {
height:100px;
width: 100px;
}
.defilement-miniatures-gauche, .defilement-miniatures-droite {
float: left;
font-size: 1.2em;
font-weight: bold;
height: 62px;
margin: 5px;
padding-top: 30px;
width: 12px;
}
.defilement-miniatures {
width: 210px;
}
.defilement-miniatures-cache {
 
/* Bouton de sélection des fichiers */
#fichier {
visibility: hidden;
height:0;
width:0;
}
.miniature-cachee {
display: none;
}
.miniature-selectionnee {
display: block;
width: 90px;
}
#fichier {
display: none;
}
#photos-conteneur {
height: 120px;
}
128,6 → 109,87
border-radius: 8px;
}
 
/* Images d'une observation */
.obs .obs-miniatures {
min-width: 150px;
margin-right: 5px;
}
.obs .miniature {
display: block;
height: 100px;
margin: 0 auto;
}
.defilement {
position: relative;
padding: 8px 0;
background-color:#524C47;
}
.defilement-control-zone {
display: block;
position: absolute;
top: 0;
width: 50%;
height: 116px;
}
.defilement-control-zone.gauche{
left: 0;
}
.defilement-control-zone.droite {
right: 0;
}
.defilement-control {
display: block;
position: absolute;
top: 35%;
width:20px;
height: 20px;
line-height: 20px;
font-size: 17px;
font-weight: 100;
text-align: center;
border: 3px solid white;
border-radius: 20px;
color: white;
opacity: 1;
background: none repeat scroll 0 0 #524C47;
}
.defilement-control.gauche {
left: 3%;
}
.defilement-control.droite {
right: 3%;
}
 
.defilement-miniatures-cache {
visibility: hidden;
}
.obs .miniature-cachee {
display: none;
}
 
.defilement-indicateurs {
list-style: none outside none;
margin: 0;
position: absolute;
left: 0;
bottom: 2px;
z-index: 5;
}
.defilement-indicateurs li {
background-color: rgba(255, 255, 255, 0.25);
border-radius: 2px;
border: 1px solid lightgrey;
display: block;
float: left;
height: 4px;
margin-left: 2px;
text-indent: -999px;
width: 4px;
}
.defilement-indicateurs .active {
background-color: #FFFFFF;
}
 
/*+--------------------------------------------------------------------------------------------------------+*/
/* Correction style CSS Bootstrap */
.well {
167,8 → 229,6
}
 
/* Géolocalisation */
 
 
#map-canvas {
height: 240px;
margin-bottom:5px;
218,9 → 278,13
}
label.error {
font-weight: bold;
font-style:italic;
color: #B94A48;
padding: 0 8px;
}
.control-group.error label {
font-weight: bold;
}
.error .horizontal-slider{
background: #B94A48;
}
236,12 → 300,7
/*+--------------------------------------------------------------------------------------------------------+*/
/* SLIDERs */
.slider-on {
display:inline;
height:0;
width:0;
margin:0;
padding:0;
visibility: hidden;
display:none;
}
.slider-holder {
height: 25px;
/trunk/widget/modules/saisie/squelettes/florileges/florileges.tpl.html
27,6 → 27,7
<!-- Jquery Plugins -->
<!-- Jquery Validate : nécessaire pour la validation des formulaires -->
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/validate/1.11.1/additional-methods.min.js"></script>
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/validate/1.11.1/messages_fr.js"></script>
<!-- Jquery Form :nécessaire pour l'upload des images -->
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/form/3.32/jquery.form.min.js"></script>
126,7 → 127,7
"Florilèges"-RUES. Cette interface vous permet d'enregistrer vos
observations de terrain et de les partager simplement
(sous <a href="http://creativecommons.org/licenses/by-sa/2.0/fr/">licence CC-BY-SA</a>)
avec <a href="http://www.plante-et-cite.fr">Plante & Cité</a>,
avec <a href="http://www.plante-et-cite.fr">Plante &amp; Cité</a>,
<a href="http://www.tela-botanica.org/site:accueil">le réseau Tela Botanica</a>
et <a href="http://sauvagesdemarue.mnhn.fr">le programme Sauvage de ma Rue</a>.
</p>
638,7 → 639,7
<strong class="obligatoire">*</strong>
Milieux
</label>
<div class="controls">
<div id="milieux-controls" class="controls">
<div class="input-prepend">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
649,43 → 650,43
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li>
<label class="checkbox">
<input name="milieux" type="checkbox" value="chemin"/>
<input name="milieux[]" class="cb-milieux" type="checkbox" value="chemin"/>
chemin
</label>
</li>
<li>
<label class="checkbox">
<input name="milieux" type="checkbox" value="fissures"/>
<input name="milieux[]" class="cb-milieux" type="checkbox" value="fissures"/>
fissures
</label>
</li>
<li>
<label class="checkbox">
<input name="milieux" type="checkbox" value="haie"/>
<input name="milieux[]" class="cb-milieux" type="checkbox" value="haie"/>
haie
</label>
</li>
<li>
<label class="checkbox">
<input name="milieux" type="checkbox" value="mur"/>
<input name="milieux[]" class="cb-milieux" type="checkbox" value="mur"/>
mur
</label>
</li>
<li>
<label class="checkbox">
<input name="milieux" type="checkbox" value="pelouse"/>
<input name="milieux[]" class="cb-milieux" type="checkbox" value="pelouse"/>
pelouse
</label>
</li>
<li>
<label class="checkbox">
<input name="milieux" type="checkbox" value="pied d'arbre"/>
<input name="milieux[]" class="cb-milieux" type="checkbox" value="pied d'arbre"/>
pied d'arbre
</label>
</li>
<li>
<label class="checkbox">
<input name="milieux" type="checkbox" value="plate bande"/>
<input name="milieux[]" class="cb-milieux" type="checkbox" value="plate bande"/>
plate bande
</label>
</li>
834,13 → 835,12
<p class="miniature-info" class="discretion help-inline">Les photos doivent être au format JPEG et ne doivent pas excéder 5Mo chacunes.</p>
<div id ="photos-conteneur">
<div id="photo-placeholder" rel="tooltip"
title="Cliquez pour ajouter une photo de votre observation. Elle doit être au
title="Cliquez pour ajouter une photo de votre observation. Elle doit être au
format JPEG et ne doit pas excéder 5Mo."></div>
<div id="miniatures"></div>
<p class="miniature-msg" class="span12">&nbsp;</p>
<input type="file" id="fichier" name="fichier" accept="image/jpeg" />
<input type="hidden" name="MAX_FILE_SIZE" value="5242880"/>
<div id="miniatures">
</div>
<p class="miniature-msg" class="span12">&nbsp;</p>
</div>
</div>
</div>
/trunk/widget/modules/saisie/squelettes/florileges/js/florileges.js
43,77 → 43,89
}
 
//+----------------------------------------------------------------------------------------------------------+
//UPLOAD PHOTO : Traitement de l'image
//FORM IDENTITE : gestion de l'observateur
 
$(document).ready(function() {
$('.effacer-miniature').click(function () {
supprimerMiniatures($(this));
});
$('#photo-placeholder').click(function(event) {
$('#fichier').click();
});
$('#fichier').bind('change', function (e) {
arreter(e);
var options = {
success: afficherMiniature, // 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="'+CHARGEMENT_IMAGE_URL+'"/>');
$('#ajouter-obs').attr('disabled', 'disabled');
if(verifierFormat($('#fichier').val())) {
$('#form-upload').ajaxSubmit(options);
} else {
window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+ $('#fichier').attr('accept'));
}
return false;
});
$('.effacer-miniature').on('click', function() {
$(this).parent().remove();
});
$('#courriel').on('blur', requeterIdentite);
$('#courriel').on('keypress', testerLancementRequeteIdentite);
});
 
function verifierFormat(nom) {
var parts = nom.split('.');
extension = parts[parts.length - 1];
return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
function testerLancementRequeteIdentite(event) {
if (event.which == 13) {
requeterIdentite();
event.preventDefault();
event.stopPropagation();
}
}
 
function afficherMiniature(reponse) {
if (DEBUG) {
var debogage = $('debogage', reponse).text();
console.log('Débogage upload : ' + debogage);
}
var message = $('message', reponse).text();
if (message != '') {
$('#miniature-msg').append(message);
} else {
$('#miniatures').append(creerWidgetMiniature(reponse));
}
$('#ajouter-obs').removeAttr('disabled');
function requeterIdentite() {
var courriel = $('#courriel').val();
//TODO: mettre ceci en paramètre de config
var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL + courriel;
$.ajax({
url: urlAnnuaire,
type: 'GET',
success: function(data, textStatus, jqXHR) {
console.log('SUCCESS:'+textStatus);
if (data != undefined && data[courriel] != undefined) {
var infos = data[courriel];
$('#id_utilisateur').val(infos.id);
$('#prenom').val(infos.prenom);
$('#nom').val(infos.nom);
$('#courriel_confirmation').val(courriel);
$('#prenom, #nom, #courriel_confirmation').attr('disabled', 'disabled');
$('#date').focus();
} else {
surErreurCompletionCourriel();
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('ERREUR :'+textStatus);
surErreurCompletionCourriel();
},
complete: function(jqXHR, textStatus) {
console.log('COMPLETE :'+textStatus);
$('#zone-prenom-nom').removeClass('hidden');
$('#zone-courriel-confirmation').removeClass('hidden');
}
});
}
 
function creerWidgetMiniature(reponse) {
var miniatureUrl = $('miniature-url', reponse).text(),
imgNom = $('image-nom', reponse).text(),
html =
'<div class="miniature">'+
'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
'<button class="effacer-miniature" type="button">Effacer</button>'+
'</div>'
return html;
function surErreurCompletionCourriel() {
$('#prenom, #nom, #courriel_confirmation').val('');
$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
afficherPanneau('#dialogue-courriel-introuvable');
}
 
function supprimerMiniatures() {
$('#miniatures').empty();
$('#miniature-msg').empty();
function formaterNom() {
$(this).val($(this).val().toUpperCase());
}
 
function formaterPrenom() {
var prenom = new Array(),
mots = $(this).val().split(' ');
for (var i = 0; i < mots.length; i++) {
var mot = mots[i];
if (mot.indexOf('-') >= 0) {
var prenomCompose = new Array(),
motsComposes = mot.split('-');
for (var j = 0; j < motsComposes.length; j++) {
var motSimple = motsComposes[j],
motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
prenomCompose.push(motMajuscule);
}
prenom.push(prenomCompose.join('-'));
} else {
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
prenom.push(motMajuscule);
}
}
$(this).val(prenom.join(' '));
}
 
//+----------------------------------------------------------------------------------------------------------+
// GOOGLE MAP
 
var map,
marker,
latLng,
165,9 → 177,9
$('#geolocaliser').on('click', geolocaliser);
google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
//google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
google.maps.event.addListener(map, 'click', surClickDansCarte);
//google.maps.event.addListener(map, 'click', surClickDansCarte);
});
 
function initialiserGoogleMap(){
185,7 → 197,7
google.maps.MapTypeId.SATELLITE,
google.maps.MapTypeId.TERRAIN]}
};
 
// Ajout de la couche OSM à la carte
osmMapType = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
346,62 → 358,196
});
});
}
 
 
//+---------------------------------------------------------------------------------------------------------+
// IDENTITÉ
$(document).ready(function() {
$('#courriel').on('blur', requeterIdentite);
$('#courriel').on('keypress', testerLancementRequeteIdentite);
});
//AUTO-COMPLÉTION Noms Scientifiques
 
function testerLancementRequeteIdentite(event) {
if (event.which == 13) {
requeterIdentite();
event.preventDefault();
event.stopPropagation();
function ajouterAutocompletionNoms() {
$('#taxon').autocomplete({
source: function(requete, add){
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
var url = getUrlAutocompletionNomsSci();
$.getJSON(url, function(data) {
console.log(data);
var suggestions = traiterRetourNomsSci(data);
add(suggestions);
});
},
html: true
});
$('#taxon').bind('autocompleteselect', function(event, ui) {
$('#taxon').data(ui.item);
if (ui.item.retenu == true) {
$('#taxon').addClass('ns-retenu');
} else {
$('#taxon').removeClass('ns-retenu');
}
});
}
 
function getUrlAutocompletionNomsSci() {
var mots = $('#taxon').val(),
url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_PROJET);
url = url.replace('{masque}', mots);
return url;
}
 
function traiterRetourNomsSci(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 >= AUTOCOMPLETION_ELEMENTS_NBRE) {
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;
}
 
function requeterIdentite() {
var courriel = $('#courriel').val();
//TODO: mettre ceci en paramètre de config
var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL + courriel;
$.ajax({
url: urlAnnuaire,
type: 'GET',
success: function(data, textStatus, jqXHR) {
console.log('SUCCESS:'+textStatus);
if (data != undefined && data[courriel] != undefined) {
var infos = data[courriel];
$('#id_utilisateur').val(infos.id);
$('#prenom').val(infos.prenom);
$('#nom').val(infos.nom);
$('#courriel_confirmation').val(courriel);
$('#prenom, #nom, #courriel_confirmation').attr('disabled', 'disabled');
$('#date').focus();
/*
* jQuery UI Autocomplete HTML Extension
*
* Copyright 2010, Scott González (http://scottgonzalez.com)
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* http://github.com/scottgonzalez/jquery-ui-extensions
*
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
*/
(function($) {
var proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;
function filter(array, term) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
return $.grep(array, function(value) {
return matcher.test($('<div>').html(value.label || value.value || value).text());
});
}
$.extend(proto, {
_initSource: function() {
if (this.options.html && $.isArray(this.options.source)) {
this.source = function( request, response ) {
response(filter(this.options.source, request.term));
};
} else {
surErreurCompletionCourriel();
initSource.call(this);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('ERREUR :'+textStatus);
surErreurCompletionCourriel();
},
complete: function(jqXHR, textStatus) {
console.log('COMPLETE :'+textStatus);
$('#zone-prenom-nom').removeClass('hidden');
$('#zone-courriel-confirmation').removeClass('hidden');
_renderItem: function(ul, item) {
if (item.retenu == true) {
item.label = '<strong>'+item.label+'</strong>';
}
return $('<li></li>')
.data('item.autocomplete', item)
.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
.appendTo(ul);
}
});
})(jQuery);
 
//+----------------------------------------------------------------------------------------------------------+
//UPLOAD PHOTO : Traitement de l'image
$(document).ready(function() {
$('body').on('click', '.effacer-miniature', function(event) {
supprimerMiniature($(this));
});
$('#photo-placeholder').click(function(event) {
$('#fichier').click();
});
$('#fichier').bind('change', function (e) {
arreter(e);
var options = {
success: afficherMiniature, // 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="'+CHARGEMENT_IMAGE_URL+'"/>');
$('#ajouter-obs').attr('disabled', 'disabled');
if (verifierFormat($('#fichier').val())) {
$('#form-upload').ajaxSubmit(options);
} else {
window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+ $('#fichier').attr('accept'));
}
return false;
});
$('.effacer-miniature').on('click', function() {
$(this).parent().remove();
});
});
 
function verifierFormat(nom) {
var parts = nom.split('.');
extension = parts[parts.length - 1];
return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
}
 
function surErreurCompletionCourriel() {
$('#prenom, #nom, #courriel_confirmation').val('');
$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
afficherPanneau('#dialogue-courriel-introuvable');
function afficherMiniature(reponse) {
if (DEBUG) {
var debogage = $('debogage', reponse).text();
console.log('Débogage upload : ' + debogage);
}
var message = $('message', reponse).text();
if (message != '') {
$('#miniature-msg').append(message);
} else {
$('#miniatures').append(creerWidgetMiniature(reponse));
}
$('#ajouter-obs').removeAttr('disabled');
}
 
function creerWidgetMiniature(reponse) {
var miniatureUrl = $('miniature-url', reponse).text(),
imgNom = $('image-nom', reponse).text(),
html =
'<div class="miniature">'+
'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
'<button class="btn effacer-miniature" type="button">Effacer</button>'+
'</div>'
return html;
}
 
function supprimerMiniature(miniature) {
miniature.parents('.miniature').remove();
}
 
function supprimerMiniatures() {
$('#miniatures').empty();
$('#miniature-msg').empty();
}
 
 
//+---------------------------------------------------------------------------------------------------------+
// FORMULAIRE
var obsNbre = 0;
// FORMULAIRE : traitements génériques
 
$(document).ready(function() {
// Sliders
442,7 → 588,26
configurerFormValidator();
definirReglesFormValidator();
$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
event.stopPropagation();
});
$('.cb-milieux').on('click', function(event) {
$(this).valid();
event.stopPropagation();
});
$('input#hauteur-plante').on('blur', function() {
// if there's a bad value
var valeur = $(this).val();
console.log(valeur);
if (! valeur.match(/^[0-9]+$/)) {
// replace it with nothing
var nouvelleValeur = valeur.replace(/[^0-9]/g, '');
$(this).val(nouvelleValeur);
}
});
$('#courriel_confirmation').on('paste', bloquerCopierCollerCourriel);
$('a.afficher-coord').on('click', basculerAffichageCoord);
455,30 → 620,16
$('#transmettre-obs').on('click', transmettreObs);
$('body').on('click', '.defilement-miniatures-gauche', function(event) {
event.preventDefault();
$('body').on('click', '.defilement-control-zone', function(event) {
defilerMiniatures($(this));
});
$('body').on('click', '.defilement-miniatures-droite', function(event) {
event.preventDefault();
defilerMiniatures($(this));
$('body').on('mouseover', '.defilement-control-zone', function(event) {
$('.defilement-control', this).removeClass('hidden');
});
$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
event.stopPropagation();
$('body').on('mouseout', '.defilement-control-zone', function(event) {
$('.defilement-control', this).addClass('hidden');
});
$('input#hauteur-plante').on('blur', function() {
// if there's a bad value
var valeur = $(this).val();
console.log(valeur);
if (! valeur.match(/^[0-9]+$/)) {
// replace it with nothing
var nouvelleValeur = valeur.replace(/[^0-9]/g, '');
$(this).val(nouvelleValeur);
}
});
});
 
function transformerEnSlider(selector) {
493,9 → 644,13
max: el.options.length,
range: 'min',
value: el.selectedIndex + 1,
slide: function( event, ui ) {
slide: function(event, ui) {
el.selectedIndex = ui.value - 1;
slider.find('a').text(el.options[el.selectedIndex].text);
$(selector + ' option[selected="selected"]').removeAttr('selected');
$(selector + ' :nth-child('+ui.value+')').attr('selected', 'selected')
$(selector).valid();
},
stop: function() {
$(el).change();
528,6 → 683,22
});
}
 
function configurerDatePicker(selector) {
$.datepicker.setDefaults($.datepicker.regional['fr']);
$(selector).datepicker({
dateFormat: 'dd/mm/yy',
showOn: 'button',
buttonImageOnly: true,
buttonImage: CALENDRIER_ICONE_URL,
buttonText: 'Afficher le calendrier pour saisir la date.',
showButtonPanel: true,
onSelect: function(date) {
$(this).valid();
}
});
$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
}
 
function configurerFormValidator() {
$.validator.addMethod(
'dateCel',
535,26 → 706,13
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.');
$.validator.addMethod(
'chckMilieux',
function(value, element) {
var ok = $('input[name="milieux"]:checked').length > 0 ? true : false;
console.log('Check Milieux : ' + ok);
return ok;
},
'Veuillez sélectionner au moins une case à cocher.');
$.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');
console.log('KO:'+$(element).attr('name')+' / nbre: '+$(element).length);
},
success: function(element) {
console.log('OK:'+element.before+' / nbre: '+$(element).length);
console.log(element);
element.text('OK!').addClass('valid');
element.closest('.control-group').removeClass('error').addClass('success');
620,66 → 778,51
'dateCel' : true},
dateDerniereIntervention: {
required: true}
}
},
errorPlacement: function(error, element) {
if (element.attr('name') == 'date') {
element.parent('.input-prepend').after(error);
} else {
error.insertAfter(element);
}
}
});
$('#form-obs').validate({
rules: {
'taxon-liste': {
required: true},
milieux: {
chckMilieux:true},
'milieux[]': {
required: true,
minlength: 1},
hauteurPlante: {
required: true,
digits: true},
resistanceTraitementPhyto: {
required: true}
}
},
errorPlacement: function(error, element) {
if (element.attr('name') == 'milieux[]') {
error.insertAfter('#milieux-controls');
} else {
error.insertAfter(element);
}
}
});
}
 
function configurerDatePicker(selector) {
$.datepicker.setDefaults($.datepicker.regional['fr']);
$(selector).datepicker({
dateFormat: 'dd/mm/yy',
showOn: 'button',
buttonImageOnly: true,
buttonImage: CALENDRIER_ICONE_URL,
buttonText: 'Afficher le calendrier pour saisir la date.',
showButtonPanel: true
});
$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
function validerFormulaire() {
var observateur = $('#form-observateur').valid(),
station = $('#form-site').valid(),
date = $('#form-date').valid(),
obs = $('#form-obs').valid();
return (observateur == true && station == true && obs == true && date == true) ? true : false;
}
 
 
function fermerPanneauAlert() {
$(this).parentsUntil('.zone-alerte', '.alert').hide();
}
 
function formaterNom() {
$(this).val($(this).val().toUpperCase());
}
 
function formaterPrenom() {
var prenom = new Array(),
mots = $(this).val().split(' ');
for (var i = 0; i < mots.length; i++) {
var mot = mots[i];
if (mot.indexOf('-') >= 0) {
var prenomCompose = new Array(),
motsComposes = mot.split('-');
for (var j = 0; j < motsComposes.length; j++) {
var motSimple = motsComposes[j],
motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
prenomCompose.push(motMajuscule);
}
prenom.push(prenomCompose.join('-'));
} else {
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
prenom.push(motMajuscule);
}
}
$(this).val(prenom.join(' '));
}
 
function basculerAffichageAide() {
if ($(this).hasClass('btn-warning')) {
$('[rel=tooltip]').tooltip('enable');
704,6 → 847,12
return false;
}
 
 
//+----------------------------------------------------------------------------------------------------------+
// CRÉER OBS : Gestion des obs
 
var obsNbre = 0;
 
function ajouterObs() {
if (validerFormulaire() == true) {
obsNbre = obsNbre + 1;
742,10 → 891,10
'</button>'+
'</div> '+
'<div class="row-fluid">'+
'<div class="thumbnail span2">'+
'<div class="span2 obs-miniatures">'+
ajouterImgMiniatureAuTransfert()+
'</div>'+
'<div class="span9">'+
'<div class="span8">'+
'<ul class="unstyled">'+
'<li>'+
'<span class="nom-sci">' + taxon + '</span> ' +
758,7 → 907,7
'<span class="date">' + date + '</span>' +
'</li>' +
'<li>' +
'<span>Site :</span> ' + site + ' ' +
'<span>Site :</span> ' + site + ' ' + ' ; ' +
'<span>Milieu :</span> ' + milieux + ' ' +
'</li>' +
'<li>' +
775,7 → 924,7
function getMilieux() {
var milieuxStr = '',
milieux = [];
$('input:checkbox[name="milieux"]:checked').each(function() {
$('input:checkbox[name="milieux[]"]:checked').each(function() {
milieux.push($(this).val());
});
786,33 → 935,78
function ajouterImgMiniatureAuTransfert() {
var html = '',
miniatures = '',
premiere = true;
if ($('#miniatures img').length >= 1) {
indicateurs = '',
premiere = true,
numero = 1;
if ($('#miniatures img').length == 0) {
html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
} 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;
miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
miniatures += miniature;
});
visible = ($('#miniatures img').length > 1) ? '' : 'defilement-miniatures-cache';
var html =
'<div class="defilement-miniatures">'+
'<a href="#" class="defilement-miniatures-gauche '+visible+'">&#60;</a>'+
miniatures+
'<a href="#" class="defilement-miniatures-droite '+visible+'">&#62;</a>'+
'</div>';
} else {
html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
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">&#60;</span>' +
'</a>' +
'<a class="defilement-control-zone droite">' +
' <span class="defilement-control droite hidden">&#62;</span>' +
'</a>' +
'<ol class="defilement-indicateurs">' + indicateurs + '</ol>' +
'</div>';
}
}
return html;
}
 
function defilerMiniatures(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');
console.log(indicateurActif)
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');
}
 
function formaterNumNomSel(numNomSel) {
var nn = '';
if (numNomSel == undefined) {
nn = '<span class="alert-error">[non lié au référentiel]</span>';
} else {
868,6 → 1062,52
}
}
 
function supprimerObs() {
var obsId = $(this).val();
// Problème avec IE 6 et 7
if (obsId == 'Supprimer') {
obsId = $(this).attr('title');
}
obsNbre = obsNbre - 1;
$('.obs-nbre').text(obsNbre);
$('.obs-nbre').triggerHandler('changement');
$('.obs'+obsId).remove();
$('#liste-obs').removeData('obsId' + obsId);
}
 
function initialiserObs() {
obsNbre = 0;
$('.obs-nbre').text(obsNbre);
$('.obs-nbre').triggerHandler('changement');
$('#liste-obs').removeData();
$('.obs').remove();
$('#dialogue-bloquer-creer-obs').hide();
}
 
function getNomsImgsOriginales() {
var noms = new Array();
$('.miniature-img').each(function() {
noms.push($(this).attr('alt'));
});
return noms;
}
 
function getB64ImgsOriginales() {
var b64 = new Array();
$('.miniature-img').each(function() {
if ($(this).hasClass('b64')) {
b64.push($(this).attr('src'));
} else if ($(this).hasClass('b64-canvas')) {
b64.push($(this).data('b64'));
}
});
return b64;
}
 
//+----------------------------------------------------------------------------------------------------------+
// TRANSFERER OBS : envoie des obs au CEL
 
function transmettreObs() {
var observations = $('#liste-obs').data();
console.log(observations);
955,190 → 1195,4
initialiserObs();
}
});
}
 
function validerFormulaire() {
var observateur = $('#form-observateur').valid(),
station = $('#form-site').valid(),
date = $('#form-date').valid(),
obs = $('#form-obs').valid();
return (observateur == true && station == true && obs == true && date == true) ? true : false;
}
 
function getNomsImgsOriginales() {
var noms = new Array();
$('.miniature-img').each(function() {
noms.push($(this).attr('alt'));
});
return noms;
}
 
function getB64ImgsOriginales() {
var b64 = new Array();
$('.miniature-img').each(function() {
if ($(this).hasClass('b64')) {
b64.push($(this).attr('src'));
} else if ($(this).hasClass('b64-canvas')) {
b64.push($(this).data('b64'));
}
});
return b64;
}
 
function supprimerObs() {
var obsId = $(this).val();
// Problème avec IE 6 et 7
if (obsId == 'Supprimer') {
obsId = $(this).attr('title');
}
obsNbre = obsNbre - 1;
$('.obs-nbre').text(obsNbre);
$('.obs-nbre').triggerHandler('changement');
$('.obs'+obsId).remove();
$('#liste-obs').removeData('obsId' + obsId);
}
 
function initialiserObs() {
obsNbre = 0;
$('.obs-nbre').text(obsNbre);
$('.obs-nbre').triggerHandler('changement');
$('#liste-obs').removeData();
$('.obs').remove();
$('#dialogue-bloquer-creer-obs').hide();
}
 
 
function defilerMiniatures(element) {
var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
miniatureSelectionne.removeClass('miniature-selectionnee');
miniatureSelectionne.addClass('miniature-cachee');
var miniatureAffichee = miniatureSelectionne;
if(element.hasClass('defilement-miniatures-gauche')) {
if(miniatureSelectionne.prev('.miniature').length != 0) {
miniatureAffichee = miniatureSelectionne.prev('.miniature');
} else {
miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
}
} else {
if(miniatureSelectionne.next('.miniature').length != 0) {
miniatureAffichee = miniatureSelectionne.next('.miniature');
} else {
miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
}
}
miniatureAffichee.addClass('miniature-selectionnee');
miniatureAffichee.removeClass('miniature-cachee');
}
 
//+---------------------------------------------------------------------------------------------------------+
// AUTO-COMPLÉTION Noms Scientifiques
 
function ajouterAutocompletionNoms() {
$('#taxon').autocomplete({
source: function(requete, add){
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
var url = getUrlAutocompletionNomsSci();
$.getJSON(url, function(data) {
console.log(data);
var suggestions = traiterRetourNomsSci(data);
add(suggestions);
});
},
html: true
});
$('#taxon').bind('autocompleteselect', function(event, ui) {
$('#taxon').data(ui.item);
if (ui.item.retenu == true) {
$('#taxon').addClass('ns-retenu');
} else {
$('#taxon').removeClass('ns-retenu');
}
});
}
 
function getUrlAutocompletionNomsSci() {
var mots = $('#taxon').val(),
url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_PROJET);
url = url.replace('{masque}', mots);
return url;
}
 
function traiterRetourNomsSci(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 >= AUTOCOMPLETION_ELEMENTS_NBRE) {
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;
}
 
/*
* jQuery UI Autocomplete HTML Extension
*
* Copyright 2010, Scott González (http://scottgonzalez.com)
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* http://github.com/scottgonzalez/jquery-ui-extensions
*
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
*/
(function($) {
var proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;
function filter(array, term) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
return $.grep(array, function(value) {
return matcher.test($('<div>').html(value.label || value.value || value).text());
});
}
$.extend(proto, {
_initSource: function() {
if (this.options.html && $.isArray(this.options.source)) {
this.source = function( request, response ) {
response(filter(this.options.source, request.term));
};
} else {
initSource.call(this);
}
},
_renderItem: function(ul, item) {
if (item.retenu == true) {
item.label = '<strong>'+item.label+'</strong>';
}
return $('<li></li>')
.data('item.autocomplete', item)
.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
.appendTo(ul);
}
});
})(jQuery);
}