Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 914 → Rev 915

/trunk/widget/modules/carto/squelettes/scripts/carto.js
31,17 → 31,17
name: "OSM",
maxZoom: 19
});
 
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
var station = {'commune':'', 'obsNbre':0};
var obsStation = new Array();
var obsPage = new Array();
/*+--------------------------------------------------------------------------------------------------------+*/
// INITIALISATION DU CODE
 
 
//Déclenchement d'actions quand JQuery et le document HTML sont OK
$(document).ready(function() {
initialiserWidget();
});
/*+--------------------------------------------------------------------------------------------------------+*/
// FONCTIONS
 
function initialiserWidget() {
afficherStats();
54,6 → 54,9
rafraichirCarte();
}
 
/*+--------------------------------------------------------------------------------------------------------+*/
// AFFICHAGE GÉNÉRAL
 
function afficherStats() {
// Ajout du nombre de communes où des observations ont eu lieu
$('#commune-nbre').append(obs.stats.communes.formaterNombre());
63,6 → 66,9
$('.plantes-nbre').append(plantesNbre.formaterNombre());
}
 
/*+--------------------------------------------------------------------------------------------------------+*/
// CARTE
 
function initialiserAffichageCarte() {
$('#carte').height($(window).height() - 35);
$('#carte').width($(window).width() - 24);
72,16 → 78,6
}
}
 
function initialiserAffichagePanneauLateral() {
$('#panneau-lateral').height($(window).height() - 35);
if (nt == '*') {
$('#pl-ouverture').bind('click', afficher);
$('#pl-fermeture').bind('click', cacher);
$('.taxon').live('click', filtrerParTaxon);
}
}
 
function initialiserCarte() {
map = new google.maps.Map(document.getElementById('carte'), carteOptions);
// Ajout de la couche OSM à la carte
88,10 → 84,6
map.mapTypes.set('OSM', osmMapType);
}
 
function initialiserInfoBulle() {
google.maps.event.addListener(infoBulle, 'domready', modifierContenuInfoBulle);
google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
}
 
function chargerLimitesCommunales() {
if (urlsLimitesCommunales != null) {
120,7 → 112,6
google.maps.event.addListener(point, 'click', function() {
pointClique = this;
infoBulle.open(map, this);
var limites = map.getBounds();
129,8 → 120,8
var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
map.panTo(centreSudLatLng);
afficherMsgChargement();
chargerFormatObs(this.stationId, '*');
afficherInfoBulle();
lancerChargementObs();
});
points.push(point);
144,17 → 135,179
executerMarkerClusterer(points, bounds);
}
 
function modifierContenuInfoBulle() {
// Onglet Tableau : Jquery => TableSorter
if ($("#observations table").get() != '') {
ajouterTableauTriable("#observations table");
function deplacerCartePointClique() {
map.panTo(pointClique.position);
}
 
function executerMarkerClusterer(points, bounds) {
if (markerClusterer) {
markerClusterer.clearMarkers();
}
// Onglet Liste : Jquery => FancyBox
if ($("#observations ol").get() != '') {
markerClusterer = new MarkerClusterer(map, points);
map.fitBounds(bounds);
}
 
/*+--------------------------------------------------------------------------------------------------------+*/
// INFO BULLE
 
function initialiserInfoBulle() {
google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
}
 
function afficherInfoBulle() {
var obsHtml = $("#tpl-obs").html();
infoBulle.setContent(obsHtml);
}
 
function afficherMessageChargement(element) {
if ($('#chargement').get() == '') {
$('#tpl-chargement').tmpl().appendTo(element);
}
}
 
function supprimerMessageChargement() {
$('#chargement').remove();
}
 
function lancerChargementObs() {
var urlObsNbre = urlObsStation;
urlObsNbre = urlObsNbre.replace(/\{action\}/g, 'observations-nombre');
urlObsNbre = urlObsNbre.replace(/\{stationId\}/g, pointClique.stationId);
console.log("Lancement recup nombre");
$.getJSON(urlObsNbre, function(infos){
console.log("Lancement charger obs");
chargerObs(0, infos.obsNbre);
station = infos;
actualiserPagineur();
creerTitreInfoBulle();
});
}
 
function actualiserPagineur() {
pagineur.stationId = pointClique.stationId;
pagineur.total = station.obsNbre;
console.log(pagineur.total);
if (pagineur.total > 4) {
pagineur.format = 'tableau';
} else {
pagineur.format = 'liste';
}
}
 
function chargerObs(depart, total) {
if (depart < total) {
var limite = 300;
if (depart == 0) {
obsStation = new Array();
}
console.log("Chargement de "+depart+" à "+(depart+limite));
var urlObs = urlObsStation+'&start={start}&limit='+limite;
urlObs = urlObs.replace(/\{action\}/g, 'observations');
urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
urlObs = urlObs.replace(/\{start\}/g, depart);
$.getJSON(urlObs, function(observations){
obsStation = obsStation.concat(observations.observations);
console.log("Chargement ok");
chargerObs(depart+limite, total);
});
} else {
if (pagineur.limite < total) {
afficherPagination();
} else {
surClicPagePagination(0, null);
}
}
}
 
 
function afficherPagination(observations) {
$(".navigation").pagination(pagineur.total, {
items_per_page:pagineur.limite,
callback:surClicPagePagination,
next_text:'Suivant',
prev_text:'Précédent',
prev_show_always:false,
num_edge_entries:1,
num_display_entries:5,
load_first_page:true
});
}
 
function surClicPagePagination(pageIndex, paginationConteneur) {
var index = pageIndex * pagineur.limite;
var indexMax = index + pagineur.limite;
pagineur.depart = index;
obsPage = new Array();
for(index; index < indexMax; index++) {
obsPage.push(obsStation[index]);
}
supprimerMessageChargement();
mettreAJourObservations();
return false;
}
 
function mettreAJourObservations() {
$("#obs-"+pagineur.format+"-lignes").empty();
$("#obs-vue-"+pagineur.format).css('display', 'block');
$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
// Actualisation de Fancybox
if (pagineur.format == 'liste') {
ajouterGaleriePhoto("a.cel-img");
}
}
 
function creerTitreInfoBulle() {
$("#obs-total").append(station.obsNbre);
$("#obs-commune").append(station.commune);
}
 
function initialiserContenuInfoBulle() {
afficherOnglets();
afficherMessageChargement('#observations');
ajouterTableauTriable("#obs-tableau");
afficherTextStationId();
corrigerLargeurInfoWindow();
}
 
function afficherOnglets() {
var $tabs = $('#obs').tabs();
$('#obs').bind('tabsselect', function(event, ui) {
if (ui.panel.id == 'obs-vue-tableau') {
surClicAffichageTableau();
} else if (ui.panel.id == 'obs-vue-liste') {
surClicAffichageListe();
}
});
$tabs.tabs('select', "#obs-vue-"+pagineur.format);
}
 
function afficherTextStationId() {
$('#obs-station-id').text(pointClique.stationId);
}
 
function corrigerLargeurInfoWindow() {
$("#info-bulle").width($("#info-bulle").width() - 16);
}
 
function surClicAffichageTableau(event) {
console.log('tableau');
pagineur.format = 'tableau';
mettreAJourObservations();
mettreAJourTableauTriable("#obs-tableau");
}
 
function surClicAffichageListe(event) {
console.log('liste');
pagineur.format = 'liste';
mettreAJourObservations();
ajouterGaleriePhoto("a.cel-img");
}
 
function ajouterTableauTriable(element) {
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
161,14 → 314,14
// Définition d'un id unique pour ce parsseur
id: 'date_cel',
is: function(s) {
// retourne false si le parsseur n'est pas autodétecté
return false;
// doit retourner false si le parsseur n'est pas autodétecté
return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
},
format: function(s) {
format: function(date) {
// Transformation date jj/mm/aaaa en aaaa/mm/jj
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
// Remplace la date par un nombre de millisecondes pour trier numériquement
return $.tablesorter.formatFloat(new Date(s).getTime());
return $.tablesorter.formatFloat(new Date(date).getTime());
},
// set type, either numeric or text
type: 'numeric'
175,100 → 328,60
});
$(element).tablesorter({
headers: {
1: {
sorter:'date_cel'
}
}
});
1: {
sorter:'date_cel'
}
}
});
}
 
function mettreAJourTableauTriable(element) {
$(element).trigger('update');
}
 
function ajouterGaleriePhoto(element) {
$(element).fancybox({
transitionIn : 'elastic',
transitionOut : 'elastic',
speedIn : 600,
speedOut : 200,
overlayShow : true
}).live('click', function(e) {
if (e.stopPropagation) {
e.stopPropagation();
transitionIn:'elastic',
transitionOut:'elastic',
speedIn :600,
speedOut:200,
overlayShow:true,
titleShow:true,
titlePosition:'inside',
titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
motif.exec(titre);
var id = RegExp.$1;
var info = $('#cel-info-'+id).clone().html();
var tpl =
'<div class="cel-legende">'+
'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+
(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
'<\/div>';
return tpl;
}
return false;
});
}).live('click', function(e) {
if (e.stopPropagation) {
e.stopPropagation();
}
return false;
});
}
 
function deplacerCartePointClique() {
map.panTo(pointClique.position);
}
/*+--------------------------------------------------------------------------------------------------------+*/
// PANNEAU LATÉRAL
 
function executerMarkerClusterer(points, bounds) {
if (markerClusterer) {
markerClusterer.clearMarkers();
}
markerClusterer = new MarkerClusterer(map, points);
map.fitBounds(bounds);
}
 
function afficherMsgChargement() {
var chargement = document.getElementById('chargement').cloneNode(true);
chargement.setAttribute('id', 'chargement-copie');
infoBulle.setContent(chargement);
}
 
var pagineur = {'limite':150, 'obsTotal':0, 'stationId':null, 'format':null};
 
function handlePaginationClick(new_page_index, pagination_container) {
$('.obs-liste-conteneur').css('display', 'none');
$('#chargement').clone().attr('id', 'chargement-copie').appendTo('#observations').css('display', 'block');
console.log($('#chargement').get());
function initialiserAffichagePanneauLateral() {
$('#panneau-lateral').height($(window).height() - 35);
var start = new_page_index * pagineur.limite;
var url = urlObs+
'&format='+pagineur.format+
'&station='+pagineur.stationId+
'&start='+start+
'&limit='+pagineur.limite;
$.get(url, function(observations) {
$('#chargement-copie').remove();
$('.obs-liste-conteneur').css('display', 'block');
$('#obs-liste').empty();
$('#obs-liste').append(observations);
});
return false;
}
 
function chargerFormatObs(stationId, format) {
pagineur.obsTotal = parseInt($('#obs-total').text());
pagineur.stationId = stationId;
pagineur.format = format;
var start = 1 * pagineur.limite;
var url = urlStation+
'&format='+format+
'&station='+stationId+
'&start='+start+
'&limit='+pagineur.limite;
$.get(url, function(observations){
infoBulle.setContent(observations);
// First Parameter: number of items
// Second Parameter: options object
$("#pagination").pagination(pagineur.obsTotal, {
items_per_page:pagineur.limite,
callback:handlePaginationClick
});
});
}
 
function arreter(event) {
if (event.stopPropagation) {
event.stopPropagation();
} else if (window.event) {
window.event.cancelBubble = true;
if (nt == '*') {
$('#pl-ouverture').bind('click', afficherPanneauLateral);
$('#pl-fermeture').bind('click', cacherPanneauLateral);
$('.taxon').live('click', filtrerParTaxon);
}
return false;
}
 
function afficher() {
function afficherPanneauLateral() {
$('#panneau-lateral').width(300);
$('#pl-contenu').css('display', 'block');
$('#pl-ouverture').css('display', 'none');
278,7 → 391,7
google.maps.event.trigger(map, 'resize');
};
 
function cacher() {
function cacherPanneauLateral() {
$('#panneau-lateral').width(24);
$('#pl-contenu').css('display', 'none');
$('#pl-ouverture').css('display', 'block');
313,6 → 426,18
}
};
 
/*+--------------------------------------------------------------------------------------------------------+*/
// FONCTIONS UTILITAIRES
 
function arreter(event) {
if (event.stopPropagation) {
event.stopPropagation();
} else if (window.event) {
window.event.cancelBubble = true;
}
return false;
}
 
/**
* +-------------------------------------+
* Number.prototype.formaterNombre
386,4 → 511,16
_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
}
return _sRetour;
}
 
function debug(objet) {
var msg = '';
if (objet != null) {
$.each(objet, function (cle, valeur) {
msg += cle+":"+valeur + "\n";
});
} else {
msg = "La variable vaut null.";
}
console.log(msg);
}