Subversion Repositories eFlore/Applications.cel

Rev

Rev 939 | Rev 950 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 939 Rev 941
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
-
 
3
// Mettre à true pour afficher les messages de débogage
-
 
4
var DEBUG = true; 
3
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
5
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
4
var pointsOrigine = null;
6
var pointsOrigine = null;
5
var boundsOrigine = null;
7
var boundsOrigine = null;
6
var markerClusterer = null;
8
var markerClusterer = null;
7
var map = null;
9
var map = null;
8
var infoBulle = new google.maps.InfoWindow();
10
var infoBulle = new google.maps.InfoWindow();
9
var pointClique = null;
11
var pointClique = null;
10
var carteCentre = new google.maps.LatLng(46.4, 3.10);
12
var carteCentre = new google.maps.LatLng(46.4, 3.10);
11
var carteOptions = {
13
var carteOptions = {
12
	zoom: 6,
14
	zoom: 6,
13
	mapTypeId: google.maps.MapTypeId.ROADMAP,
15
	mapTypeId: google.maps.MapTypeId.ROADMAP,
14
	mapTypeControlOptions: {
16
	mapTypeControlOptions: {
15
		mapTypeIds: ['OSM', 
17
		mapTypeIds: ['OSM', 
16
		             google.maps.MapTypeId.ROADMAP, 
18
		             google.maps.MapTypeId.ROADMAP, 
17
		             google.maps.MapTypeId.HYBRID, 
19
		             google.maps.MapTypeId.HYBRID, 
18
		             google.maps.MapTypeId.SATELLITE, 
20
		             google.maps.MapTypeId.SATELLITE, 
19
		             google.maps.MapTypeId.TERRAIN]
21
		             google.maps.MapTypeId.TERRAIN]
20
	}
22
	}
21
};			
23
};			
22
var ctaLayer = null;
24
var ctaLayer = null;
23
var osmMapType = new google.maps.ImageMapType({
25
var osmMapType = new google.maps.ImageMapType({
24
	getTileUrl: function(coord, zoom) {
26
	getTileUrl: function(coord, zoom) {
25
		return "http://tile.openstreetmap.org/" +
27
		return "http://tile.openstreetmap.org/" +
26
		zoom + "/" + coord.x + "/" + coord.y + ".png";
28
		zoom + "/" + coord.x + "/" + coord.y + ".png";
27
	},
29
	},
28
	tileSize: new google.maps.Size(256, 256),
30
	tileSize: new google.maps.Size(256, 256),
29
	isPng: true,
31
	isPng: true,
30
	alt: "OpenStreetMap",
32
	alt: "OpenStreetMap",
31
	name: "OSM",
33
	name: "OSM",
32
	maxZoom: 19
34
	maxZoom: 19
33
});
35
});
34
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
36
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
35
var station = {'commune':'', 'obsNbre':0};
37
var station = {'commune':'', 'obsNbre':0};
36
var obsStation = new Array();
38
var obsStation = new Array();
37
var obsPage = new Array();
39
var obsPage = new Array();
38
var taxonsCarte = new Array();
40
var taxonsCarte = new Array();
39
/*+--------------------------------------------------------------------------------------------------------+*/
41
/*+--------------------------------------------------------------------------------------------------------+*/
40
// INITIALISATION DU CODE
42
// INITIALISATION DU CODE
41
 
43
 
42
//Déclenchement d'actions quand JQuery et le document HTML sont OK
44
//Déclenchement d'actions quand JQuery et le document HTML sont OK
43
$(document).ready(function() {
45
$(document).ready(function() {
44
	initialiserWidget();
46
	initialiserWidget();
45
});
47
});
46
 
48
 
47
function initialiserWidget() {
49
function initialiserWidget() {
48
	afficherStats();
50
	afficherStats();
49
	initialiserAffichageCarte();
51
	initialiserAffichageCarte();
50
	initialiserAffichagePanneauLateral();
52
	initialiserAffichagePanneauLateral();
51
	
53
	
52
	initialiserCarte();
54
	initialiserCarte();
53
	initialiserInfoBulle();
55
	initialiserInfoBulle();
-
 
56
	initialiserFormulaireContact();
54
	chargerLimitesCommunales();
57
	chargerLimitesCommunales();
55
	rafraichirCarte();
58
	rafraichirCarte();
56
}
59
}
57
 
60
 
58
/*+--------------------------------------------------------------------------------------------------------+*/
61
/*+--------------------------------------------------------------------------------------------------------+*/
59
// AFFICHAGE GÉNÉRAL
62
// AFFICHAGE GÉNÉRAL
60
 
63
 
61
function afficherStats() {
64
function afficherStats() {
62
	// Ajout du nombre de communes où des observations ont eu lieu
65
	// Ajout du nombre de communes où des observations ont eu lieu
63
	$('#commune-nbre').text(stations.stats.communes.formaterNombre());
66
	$('#commune-nbre').text(stations.stats.communes.formaterNombre());
64
	// Ajout du nombre d'observations
67
	// Ajout du nombre d'observations
65
	$('#obs-nbre').text(stations.stats.observations.formaterNombre());
68
	$('#obs-nbre').text(stations.stats.observations.formaterNombre());
66
}
69
}
67
 
70
 
68
/*+--------------------------------------------------------------------------------------------------------+*/
71
/*+--------------------------------------------------------------------------------------------------------+*/
69
// CARTE
72
// CARTE
70
 
73
 
71
function initialiserAffichageCarte() {
74
function initialiserAffichageCarte() {
72
	$('#carte').height($(window).height() - 35);
75
	$('#carte').height($(window).height() - 35);
73
	$('#carte').width($(window).width() - 24);
76
	$('#carte').width($(window).width() - 24);
74
	
77
	
75
	if (nt != '*') {
78
	if (nt != '*') {
76
		$('#carte').css('left', 0);
79
		$('#carte').css('left', 0);
77
	}
80
	}
78
}
81
}
79
 
82
 
80
function initialiserCarte() {
83
function initialiserCarte() {
81
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
84
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
82
	// Ajout de la couche OSM à la carte
85
	// Ajout de la couche OSM à la carte
83
	map.mapTypes.set('OSM', osmMapType);
86
	map.mapTypes.set('OSM', osmMapType);
84
}
87
}
85
 
88
 
86
 
89
 
87
function chargerLimitesCommunales() {
90
function chargerLimitesCommunales() {
88
	if (urlsLimitesCommunales != null) {
91
	if (urlsLimitesCommunales != null) {
89
		for (urlId in urlsLimitesCommunales) { 
92
		for (urlId in urlsLimitesCommunales) { 
90
			var url = urlsLimitesCommunales[urlId];
93
			var url = urlsLimitesCommunales[urlId];
91
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
94
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
92
			ctaLayer.setMap(map);
95
			ctaLayer.setMap(map);
93
		}
96
		}
94
	}
97
	}
95
}
98
}
96
 
99
 
97
function rafraichirCarte() {
100
function rafraichirCarte() {
98
	var points = [];
101
	var points = [];
99
	var bounds = new google.maps.LatLngBounds();
102
	var bounds = new google.maps.LatLngBounds();
100
	for (var i = 0; i < stations.stats.communes; ++i) {
103
	for (var i = 0; i < stations.stats.communes; ++i) {
101
		var maLatLng = new google.maps.LatLng(stations.points[i].coord_x, stations.points[i].coord_y);
104
		var maLatLng = new google.maps.LatLng(stations.points[i].coord_x, stations.points[i].coord_y);
102
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
105
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
103
		var point = new google.maps.Marker({
106
		var point = new google.maps.Marker({
104
			position: maLatLng,
107
			position: maLatLng,
105
			map: map,
108
			map: map,
106
			icon: pointImage,
109
			icon: pointImage,
107
			stationId: stations.points[i].id
110
			stationId: stations.points[i].id
108
		});
111
		});
109
 
112
 
110
		bounds.extend(maLatLng);
113
		bounds.extend(maLatLng);
111
		
114
		
112
		google.maps.event.addListener(point, 'click', function() {
115
		google.maps.event.addListener(point, 'click', function() {
113
			pointClique =  this;
116
			pointClique =  this;
114
			infoBulle.open(map, this);
117
			infoBulle.open(map, this);
115
			
118
			
116
			var limites = map.getBounds();
119
			var limites = map.getBounds();
117
			var centre = limites.getCenter();
120
			var centre = limites.getCenter();
118
			var nordEst = limites.getNorthEast();
121
			var nordEst = limites.getNorthEast();
119
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
122
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
120
			map.panTo(centreSudLatLng);
123
			map.panTo(centreSudLatLng);
121
			
124
			
122
			afficherInfoBulle();
125
			afficherInfoBulle();
123
			chargerObs(0, 0);
126
			chargerObs(0, 0);
124
		});
127
		});
125
		
128
		
126
		points.push(point);
129
		points.push(point);
127
	}
130
	}
128
 
131
 
129
	if (pointsOrigine == null && boundsOrigine == null) {
132
	if (pointsOrigine == null && boundsOrigine == null) {
130
		pointsOrigine = points;
133
		pointsOrigine = points;
131
		boundsOrigine = bounds;
134
		boundsOrigine = bounds;
132
	}
135
	}
133
	
136
	
134
	executerMarkerClusterer(points, bounds);
137
	executerMarkerClusterer(points, bounds);
135
}
138
}
136
 
139
 
137
function deplacerCartePointClique() {
140
function deplacerCartePointClique() {
138
	map.panTo(pointClique.position);
141
	map.panTo(pointClique.position);
139
}
142
}
140
 
143
 
141
function executerMarkerClusterer(points, bounds) {
144
function executerMarkerClusterer(points, bounds) {
142
	if (markerClusterer) {
145
	if (markerClusterer) {
143
		markerClusterer.clearMarkers();
146
		markerClusterer.clearMarkers();
144
	}
147
	}
145
	markerClusterer = new MarkerClusterer(map, points);
148
	markerClusterer = new MarkerClusterer(map, points);
146
	map.fitBounds(bounds);
149
	map.fitBounds(bounds);
147
}
150
}
148
 
151
 
149
/*+--------------------------------------------------------------------------------------------------------+*/
152
/*+--------------------------------------------------------------------------------------------------------+*/
150
// INFO BULLE
153
// INFO BULLE
151
 
154
 
152
function initialiserInfoBulle() {
155
function initialiserInfoBulle() {
153
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
156
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
154
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
157
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
155
}
158
}
156
 
159
 
157
function afficherInfoBulle() {
160
function afficherInfoBulle() {
158
	var obsHtml = $("#tpl-obs").html();
161
	var obsHtml = $("#tpl-obs").html();
159
	infoBulle.setContent(obsHtml);
162
	infoBulle.setContent(obsHtml);
160
}
163
}
161
 
164
 
162
function afficherMessageChargement(element) {
165
function afficherMessageChargement(element) {
163
	if ($('#chargement').get() == '') {
166
	if ($('#chargement').get() == '') {
164
		$('#tpl-chargement').tmpl().appendTo(element);
167
		$('#tpl-chargement').tmpl().appendTo(element);
165
	}
168
	}
166
}
169
}
167
 
170
 
168
function supprimerMessageChargement() {
171
function supprimerMessageChargement() {
169
	$('#chargement').remove();
172
	$('#chargement').remove();
170
}
173
}
171
 
174
 
172
function chargerObs(depart, total) {
175
function chargerObs(depart, total) {
173
	if (depart == 0 || depart < total) {
176
	if (depart == 0 || depart < total) {
174
		var limite = 300;
177
		var limite = 300;
175
		if (depart == 0) {
178
		if (depart == 0) {
176
			obsStation = new Array();
179
			obsStation = new Array();
177
		}
180
		}
178
		console.log("Chargement de "+depart+" à "+(depart+limite));
181
		console.log("Chargement de "+depart+" à "+(depart+limite));
179
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
182
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
180
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
183
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
181
		urlObs = urlObs.replace(/\{nt\}/g, nt);
184
		urlObs = urlObs.replace(/\{nt\}/g, nt);
182
		urlObs = urlObs.replace(/\{start\}/g, depart);
185
		urlObs = urlObs.replace(/\{start\}/g, depart);
183
		
186
		
184
		$.getJSON(urlObs, function(observations){
187
		$.getJSON(urlObs, function(observations){
185
			obsStation = obsStation.concat(observations.observations);
188
			obsStation = obsStation.concat(observations.observations);
186
			if (depart == 0) {
189
			if (depart == 0) {
187
				actualiserInfosStation(observations);
190
				actualiserInfosStation(observations);
188
				actualiserPagineur();
191
				actualiserPagineur();
189
				creerTitreInfoBulle();
192
				creerTitreInfoBulle();
190
			}
193
			}
191
			console.log("Chargement ok");
194
			console.log("Chargement ok");
192
			chargerObs(depart+limite, station.obsNbre);
195
			chargerObs(depart+limite, station.obsNbre);
193
		});
196
		});
194
	} else {
197
	} else {
195
		if (pagineur.limite < total) {
198
		if (pagineur.limite < total) {
196
			afficherPagination();
199
			afficherPagination();
197
		} else {
200
		} else {
198
			surClicPagePagination(0, null);
201
			surClicPagePagination(0, null);
199
			selectionnerOnglet("#obs-vue-"+pagineur.format);
202
			selectionnerOnglet("#obs-vue-"+pagineur.format);
200
		}
203
		}
201
	}
204
	}
202
}
205
}
203
 
206
 
204
function actualiserInfosStation(infos) {
207
function actualiserInfosStation(infos) {
205
	station.commune = infos.commune;
208
	station.commune = infos.commune;
206
	station.obsNbre = infos.total;
209
	station.obsNbre = infos.total;
207
}
210
}
208
 
211
 
209
function actualiserPagineur() {
212
function actualiserPagineur() {
210
	pagineur.stationId = pointClique.stationId;
213
	pagineur.stationId = pointClique.stationId;
211
	pagineur.total = station.obsNbre;
214
	pagineur.total = station.obsNbre;
212
	console.log("Total pagineur: "+pagineur.total);
215
	console.log("Total pagineur: "+pagineur.total);
213
	if (pagineur.total > 4) {
216
	if (pagineur.total > 4) {
214
		pagineur.format = 'tableau';
217
		pagineur.format = 'tableau';
215
	} else {
218
	} else {
216
		pagineur.format = 'liste';
219
		pagineur.format = 'liste';
217
	}
220
	}
218
}
221
}
219
 
222
 
220
function afficherPagination(observations) {
223
function afficherPagination(observations) {
221
	$(".navigation").pagination(pagineur.total, {
224
	$(".navigation").pagination(pagineur.total, {
222
		items_per_page:pagineur.limite,
225
		items_per_page:pagineur.limite,
223
		callback:surClicPagePagination,
226
		callback:surClicPagePagination,
224
		next_text:'Suivant',
227
		next_text:'Suivant',
225
		prev_text:'Précédent',
228
		prev_text:'Précédent',
226
		prev_show_always:false,
229
		prev_show_always:false,
227
		num_edge_entries:1,
230
		num_edge_entries:1,
228
		num_display_entries:5,
231
		num_display_entries:5,
229
		load_first_page:true
232
		load_first_page:true
230
	});
233
	});
231
}
234
}
232
 
235
 
233
function surClicPagePagination(pageIndex, paginationConteneur) {
236
function surClicPagePagination(pageIndex, paginationConteneur) {
234
	var index = pageIndex * pagineur.limite;
237
	var index = pageIndex * pagineur.limite;
235
	var indexMax = index + pagineur.limite;
238
	var indexMax = index + pagineur.limite;
236
	pagineur.depart = index;
239
	pagineur.depart = index;
237
	obsPage = new Array();
240
	obsPage = new Array();
238
    for(index; index < indexMax; index++) {
241
    for(index; index < indexMax; index++) {
239
    	obsPage.push(obsStation[index]);
242
    	obsPage.push(obsStation[index]);
240
    }
243
    }
241
    
244
    
242
    supprimerMessageChargement();
245
    supprimerMessageChargement();
243
    mettreAJourObservations();
246
    mettreAJourObservations();
244
	return false;
247
	return false;
245
}
248
}
246
 
249
 
247
function mettreAJourObservations() {
250
function mettreAJourObservations() {
248
	$("#obs-"+pagineur.format+"-lignes").empty();
251
	$("#obs-"+pagineur.format+"-lignes").empty();
249
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
252
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
250
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
253
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
251
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
254
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
252
	
255
	
253
	// Actualisation de Fancybox
256
	// Actualisation de Fancybox
-
 
257
	ajouterFomulaireContact("a.contact");
254
	if (pagineur.format == 'liste') {
258
	if (pagineur.format == 'liste') {
255
		ajouterGaleriePhoto("a.cel-img");
259
		ajouterGaleriePhoto("a.cel-img");
256
	}
260
	}
257
}
261
}
258
 
262
 
259
function creerTitreInfoBulle() {
263
function creerTitreInfoBulle() {
260
	$("#obs-total").append(station.obsNbre);
264
	$("#obs-total").append(station.obsNbre);
261
	$("#obs-commune").append(station.commune);	
265
	$("#obs-commune").append(station.commune);	
262
}
266
}
263
 
267
 
264
function initialiserContenuInfoBulle() {
268
function initialiserContenuInfoBulle() {
265
	afficherOnglets();
269
	afficherOnglets();
266
	afficherMessageChargement('#observations');
270
	afficherMessageChargement('#observations');
267
	ajouterTableauTriable("#obs-tableau");
271
	ajouterTableauTriable("#obs-tableau");
268
	afficherTextStationId();
272
	afficherTextStationId();
269
	corrigerLargeurInfoWindow();
273
	corrigerLargeurInfoWindow();
270
}
274
}
271
 
275
 
272
function afficherOnglets() {
276
function afficherOnglets() {
273
	var $tabs = $('#obs').tabs();
277
	var $tabs = $('#obs').tabs();
274
	$('#obs').bind('tabsselect', function(event, ui) {
278
	$('#obs').bind('tabsselect', function(event, ui) {
275
		if (ui.panel.id == 'obs-vue-tableau') {
279
		if (ui.panel.id == 'obs-vue-tableau') {
276
			surClicAffichageTableau();
280
			surClicAffichageTableau();
277
		} else if (ui.panel.id == 'obs-vue-liste') {
281
		} else if (ui.panel.id == 'obs-vue-liste') {
278
			surClicAffichageListe();
282
			surClicAffichageListe();
279
		}
283
		}
280
	});
284
	});
281
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
285
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
282
}
286
}
283
 
287
 
284
function selectionnerOnglet(onglet) {
288
function selectionnerOnglet(onglet) {
285
	$('#obs').tabs('select', onglet);
289
	$('#obs').tabs('select', onglet);
286
}
290
}
287
 
291
 
288
function afficherTextStationId() {
292
function afficherTextStationId() {
289
	$('#obs-station-id').text(pointClique.stationId);
293
	$('#obs-station-id').text(pointClique.stationId);
290
}
294
}
291
 
295
 
292
function corrigerLargeurInfoWindow() {
296
function corrigerLargeurInfoWindow() {
293
	$("#info-bulle").width($("#info-bulle").width() - 16);
297
	$("#info-bulle").width($("#info-bulle").width() - 16);
294
}
298
}
295
 
299
 
296
function surClicAffichageTableau(event) {
300
function surClicAffichageTableau(event) {
297
	console.log('tableau');
301
	console.log('tableau');
298
	pagineur.format = 'tableau';
302
	pagineur.format = 'tableau';
299
	mettreAJourObservations();
303
	mettreAJourObservations();
300
	mettreAJourTableauTriable("#obs-tableau");
304
	mettreAJourTableauTriable("#obs-tableau");
301
}
305
}
302
 
306
 
303
function surClicAffichageListe(event) {
307
function surClicAffichageListe(event) {
304
	console.log('liste');
308
	console.log('liste');
305
	pagineur.format = 'liste';
309
	pagineur.format = 'liste';
306
	mettreAJourObservations();
310
	mettreAJourObservations();
307
	ajouterGaleriePhoto("a.cel-img");
311
	ajouterGaleriePhoto("a.cel-img");
308
}
312
}
309
 
313
 
310
function ajouterTableauTriable(element) {
314
function ajouterTableauTriable(element) {
311
	// add parser through the tablesorter addParser method 
315
	// add parser through the tablesorter addParser method 
312
	$.tablesorter.addParser({ 
316
	$.tablesorter.addParser({ 
313
		// Définition d'un id unique pour ce parsseur 
317
		// Définition d'un id unique pour ce parsseur 
314
		id: 'date_cel', 
318
		id: 'date_cel', 
315
		is: function(s) { 
319
		is: function(s) { 
316
			// doit retourner false si le parsseur n'est pas autodétecté
320
			// doit retourner false si le parsseur n'est pas autodétecté
317
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
321
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
318
		}, 
322
		}, 
319
		format: function(date) { 
323
		format: function(date) { 
320
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
324
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
321
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
325
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
322
			// Remplace la date par un nombre de millisecondes pour trier numériquement
326
			// Remplace la date par un nombre de millisecondes pour trier numériquement
323
			return $.tablesorter.formatFloat(new Date(date).getTime());
327
			return $.tablesorter.formatFloat(new Date(date).getTime());
324
		}, 
328
		}, 
325
		// set type, either numeric or text 
329
		// set type, either numeric or text 
326
		type: 'numeric' 
330
		type: 'numeric' 
327
	});
331
	});
328
	$(element).tablesorter({ 
332
	$(element).tablesorter({ 
329
        headers: { 
333
        headers: { 
330
			1: { 
334
			1: { 
331
            	sorter:'date_cel' 
335
            	sorter:'date_cel' 
332
        	} 
336
        	} 
333
    	} 
337
    	} 
334
	});
338
	});
335
}
339
}
336
 
340
 
337
function mettreAJourTableauTriable(element) {
341
function mettreAJourTableauTriable(element) {
338
	$(element).trigger('update');
342
	$(element).trigger('update');
339
}
343
}
340
 
344
 
341
function ajouterGaleriePhoto(element) {
345
function ajouterGaleriePhoto(element) {
342
	$(element).fancybox({
346
	$(element).fancybox({
343
		transitionIn:'elastic',
347
		transitionIn:'elastic',
344
		transitionOut:'elastic',
348
		transitionOut:'elastic',
345
		speedIn	:600, 
349
		speedIn	:600, 
346
		speedOut:200,
350
		speedOut:200,
347
		overlayShow:true,
351
		overlayShow:true,
348
		titleShow:true,
352
		titleShow:true,
349
		titlePosition:'inside',
353
		titlePosition:'inside',
350
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
354
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
351
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
355
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
352
			motif.exec(titre);
356
			motif.exec(titre);
353
			var id = RegExp.$1;
357
			var id = RegExp.$1;
354
			var info = $('#cel-info-'+id).clone().html();
358
			var info = $('#cel-info-'+id).clone().html();
355
			var tpl = 
359
			var tpl = 
356
				'<div class="cel-legende">'+
360
				'<div class="cel-legende">'+
357
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
361
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
358
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
362
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
359
				'<\/div>';
363
				'<\/div>';
360
			return tpl;
364
			return tpl;
361
		}
365
		}
362
		}).live('click', function(e) {
366
		}).live('click', function(e) {
363
			if (e.stopPropagation) {
367
			if (e.stopPropagation) {
364
				e.stopPropagation();
368
				e.stopPropagation();
365
			}
369
			}
366
			return false;
370
			return false;
367
		});
371
		});
368
}
372
}
-
 
373
 
-
 
374
function ajouterFomulaireContact(element) {
-
 
375
	$(element).fancybox({
-
 
376
		transitionIn:'elastic',
-
 
377
		transitionOut:'elastic',
-
 
378
		speedIn	:600, 
-
 
379
		speedOut:200,
-
 
380
		scrolling: 'no',
-
 
381
		titleShow: false,
-
 
382
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
-
 
383
			var element = selectedArray[selectedIndex];
-
 
384
 
-
 
385
			var motif = / contributeur-([0-9]+)$/;
-
 
386
			motif.exec($(element).attr('class'));
-
 
387
			var id = RegExp.$1;
-
 
388
			console.log('Destinataire id : '+id);
-
 
389
			$("#fc_destinataire_id").attr('value', id);
-
 
390
		
-
 
391
			var motif = / obs-([0-9]+) /;
-
 
392
			motif.exec($(element).attr('class'));
-
 
393
			var id = RegExp.$1;
-
 
394
			console.log('Obs id : '+id);
-
 
395
			chargerInfoObsPourMessage(id);
-
 
396
		},
-
 
397
		onCleanup: function() {
-
 
398
			console.log('Avant fermeture fancybox');
-
 
399
			$("#fc_destinataire_id").attr('value', '');
-
 
400
			$("#fc_sujet").attr('value', '');
-
 
401
			$("#fc_message").text('');
-
 
402
		},
-
 
403
		onClosed: function(e) {
-
 
404
			console.log('Fermeture fancybox');
-
 
405
			if (e.stopPropagation) {
-
 
406
				e.stopPropagation();
-
 
407
			}
-
 
408
			return false;
-
 
409
		}
-
 
410
	});
-
 
411
}
-
 
412
 
-
 
413
function chargerInfoObsPourMessage(idObs) {
-
 
414
	var sujet = "Remarque sur l'observation #"+idObs;
-
 
415
	var message = "--\nConcerne l'observation de "+ 
-
 
416
		' "'+trim($("#cel-obs-"+idObs+" .nom-sci").text())+'" '+
-
 
417
		'du "'+trim($("#cel-obs-"+idObs+" .date").text())+'" '+
-
 
418
		'au lieu "'+trim($("#cel-obs-"+idObs+" .lieu").text())+'".';
-
 
419
	$("#fc_sujet").attr('value', sujet);
-
 
420
	$("#fc_message").text(message);
-
 
421
}
-
 
422
 
-
 
423
function initialiserFormulaireContact() {
-
 
424
	console.log('Initialisation du form contact');
-
 
425
	$("#form-contact").validate({
-
 
426
		rules: {
-
 
427
			fc_sujet : "required",
-
 
428
			fc_message : "required",
-
 
429
			fc_courriel : {
-
 
430
			required : true,
-
 
431
			email : true}
-
 
432
		}
-
 
433
	});
-
 
434
	$("#form-contact").bind("submit", envoyerCourriel);
-
 
435
	$("#fc_annuler").bind("click", function() {console.log('clic annuler');$.fancybox.close();});
-
 
436
	
-
 
437
}
-
 
438
 
-
 
439
function envoyerCourriel() {
-
 
440
	console.log('Formulaire soumis');
-
 
441
	if ($("#form-contact").valid()) {
-
 
442
		console.log('Formulaire valide');
-
 
443
		//$.fancybox.showActivity();
-
 
444
		var destinataireId = $("#fc_destinataire_id").attr('value');
-
 
445
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
-
 
446
		var erreurMsg = "";
-
 
447
		var donnees = new Array();
-
 
448
		$.each($(this).serializeArray(), function (index, champ) {
-
 
449
			var cle = champ.name;
-
 
450
			cle = cle.replace(/^fc_/, '');
-
 
451
			console.log('Clé:'+cle);
-
 
452
			donnees[index] = {'name':cle,'value':champ.value};
-
 
453
		});
-
 
454
		$.ajax({
-
 
455
			type : "POST",
-
 
456
			cache : false,
-
 
457
			url : urlMessage,
-
 
458
			data : donnees,
-
 
459
			beforeSend : function() {
-
 
460
				$(".msg").remove();
-
 
461
			},
-
 
462
			success : function(data) {
-
 
463
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
-
 
464
			},
-
 
465
			error : function(jqXHR, textStatus, errorThrown) {
-
 
466
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
467
				reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
468
				if (reponse != null) {
-
 
469
					$.each(reponse, function (cle, valeur) {
-
 
470
						erreurMsg += valeur + "\n";
-
 
471
					});
-
 
472
				}				
-
 
473
			},
-
 
474
			complete : function(jqXHR, textStatus) {
-
 
475
				var debugMsg = '';
-
 
476
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
-
 
477
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
-
 
478
					if (debugInfos != null) {
-
 
479
						$.each(debugInfos, function (cle, valeur) {
-
 
480
							debugMsg += valeur + "\n";
-
 
481
						});
-
 
482
					}
-
 
483
				}
-
 
484
				if (erreurMsg != '') {
-
 
485
					$("#fc-zone-dialogue").append('<p class="msg">'+
-
 
486
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
-
 
487
							'Vous pouvez signaler le disfonctionnement à <a href="'+
-
 
488
							'mailto:cel@tela-botanica.org'+'?'+
-
 
489
							'subject=Disfonctionnement du widget de Cartographie'+
-
 
490
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
-
 
491
							'">cel@tela-botanica.org</a>.'+
-
 
492
							'</p>');
-
 
493
				}
-
 
494
				if (DEBUG) {
-
 
495
					console.log('Débogage : '+debugMsg);
-
 
496
				}
-
 
497
				console.log('Débogage : '+debugMsg);
-
 
498
				console.log('Erreur : '+erreurMsg);
-
 
499
			}
-
 
500
		});
-
 
501
	}
-
 
502
	return false;
369
 
503
}
370
/*+--------------------------------------------------------------------------------------------------------+*/
504
/*+--------------------------------------------------------------------------------------------------------+*/
371
// PANNEAU LATÉRAL
505
// PANNEAU LATÉRAL
372
 
506
 
373
function initialiserAffichagePanneauLateral() {
507
function initialiserAffichagePanneauLateral() {
374
	$('#panneau-lateral').height($(window).height() - 35);
508
	$('#panneau-lateral').height($(window).height() - 35);
375
	
509
	
376
	if (nt == '*') {
510
	if (nt == '*') {
377
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
511
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
378
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
512
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
379
	}
513
	}
380
	chargerTaxons(0, 0);
514
	chargerTaxons(0, 0);
381
}
515
}
382
 
516
 
383
function chargerTaxons(depart, total) {
517
function chargerTaxons(depart, total) {
384
	if (depart == 0 || depart < total) {
518
	if (depart == 0 || depart < total) {
385
		var limite = 7000;
519
		var limite = 7000;
386
		console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
520
		console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
387
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
521
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
388
		urlTax = urlTax.replace(/\{start\}/g, depart);
522
		urlTax = urlTax.replace(/\{start\}/g, depart);
389
		$.getJSON(urlTax, function(infos) {
523
		$.getJSON(urlTax, function(infos) {
390
			taxonsCarte = taxonsCarte.concat(infos.taxons);
524
			taxonsCarte = taxonsCarte.concat(infos.taxons);
391
			console.log("Nbre taxons :"+taxonsCarte.length);
525
			console.log("Nbre taxons :"+taxonsCarte.length);
392
			chargerTaxons(depart+limite, infos.total);
526
			chargerTaxons(depart+limite, infos.total);
393
		});
527
		});
394
	} else {
528
	} else {
395
		if (nt == '*') {
529
		if (nt == '*') {
396
			afficherTaxons();
530
			afficherTaxons();
397
		} else {
531
		} else {
398
			afficherNomPlante();
532
			afficherNomPlante();
399
		}
533
		}
400
	}
534
	}
401
}
535
}
402
 
536
 
403
function afficherTaxons() {
537
function afficherTaxons() {
404
	// Ajout du nombre de plantes au titre
538
	// Ajout du nombre de plantes au titre
405
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
539
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
406
	
540
	
407
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
541
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
408
	$('.taxon').live('click', filtrerParTaxon);
542
	$('.taxon').live('click', filtrerParTaxon);
409
}
543
}
410
 
544
 
411
function afficherNomPlante() {
545
function afficherNomPlante() {
412
	if (nt != '*') {
546
	if (nt != '*') {
413
		var taxon = taxonsCarte[0];
547
		var taxon = taxonsCarte[0];
414
		$('.plante-titre').text('pour '+taxon.nom);
548
		$('.plante-titre').text('pour '+taxon.nom);
415
	}
549
	}
416
}
550
}
417
 
551
 
418
function afficherPanneauLateral() {
552
function afficherPanneauLateral() {
419
	$('#panneau-lateral').width(300);
553
	$('#panneau-lateral').width(300);
420
	$('#pl-contenu').css('display', 'block');
554
	$('#pl-contenu').css('display', 'block');
421
	$('#pl-ouverture').css('display', 'none');
555
	$('#pl-ouverture').css('display', 'none');
422
	$('#pl-fermeture').css('display', 'block');
556
	$('#pl-fermeture').css('display', 'block');
423
	$('#carte').css('left', '300px');
557
	$('#carte').css('left', '300px');
424
 
558
 
425
	google.maps.event.trigger(map, 'resize');
559
	google.maps.event.trigger(map, 'resize');
426
};
560
};
427
 
561
 
428
function cacherPanneauLateral() {
562
function cacherPanneauLateral() {
429
	$('#panneau-lateral').width(24);
563
	$('#panneau-lateral').width(24);
430
	$('#pl-contenu').css('display', 'none');
564
	$('#pl-contenu').css('display', 'none');
431
	$('#pl-ouverture').css('display', 'block');
565
	$('#pl-ouverture').css('display', 'block');
432
	$('#pl-fermeture').css('display', 'none');
566
	$('#pl-fermeture').css('display', 'none');
433
	$('#carte').css('left', '24px');
567
	$('#carte').css('left', '24px');
434
	
568
	
435
	google.maps.event.trigger(map, 'resize');
569
	google.maps.event.trigger(map, 'resize');
436
};
570
};
437
 
571
 
438
function ouvrirPopUp(url, nom) {
572
function ouvrirPopUp(url, nom) {
439
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
573
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
440
};
574
};
441
 
575
 
442
function filtrerParTaxon() {
576
function filtrerParTaxon() {
443
	var ntAFiltrer = $('.nt', this).text();
577
	var ntAFiltrer = $('.nt', this).text();
444
	infoBulle.close();
578
	infoBulle.close();
445
	$('#taxon-'+nt).removeClass('taxon-actif');
579
	$('#taxon-'+nt).removeClass('taxon-actif');
446
	if (nt == ntAFiltrer) {
580
	if (nt == ntAFiltrer) {
447
		nt = '*';
581
		nt = '*';
448
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
582
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
449
	} else {
583
	} else {
450
		var url = stationsUrl+'&'+
584
		var url = stationsUrl+'&'+
451
			'num_taxon='+ntAFiltrer+'&'+
585
			'num_taxon='+ntAFiltrer+'&'+
452
			'formatRetour=jsonP'+'&'+
586
			'formatRetour=jsonP'+'&'+
453
			'callback=?';
587
			'callback=?';
454
		$.getJSON(url, function (stationsFiltrees) {
588
		$.getJSON(url, function (stationsFiltrees) {
455
			stations = stationsFiltrees;
589
			stations = stationsFiltrees;
456
			nt = ntAFiltrer;
590
			nt = ntAFiltrer;
457
			$('#taxon-'+nt).addClass('taxon-actif');
591
			$('#taxon-'+nt).addClass('taxon-actif');
458
			rafraichirCarte();
592
			rafraichirCarte();
459
		});
593
		});
460
	}
594
	}
461
};
595
};
462
 
596
 
463
/*+--------------------------------------------------------------------------------------------------------+*/
597
/*+--------------------------------------------------------------------------------------------------------+*/
464
// FONCTIONS UTILITAIRES
598
// FONCTIONS UTILITAIRES
465
 
599
 
466
function arreter(event) {
600
function arreter(event) {
467
	if (event.stopPropagation) {
601
	if (event.stopPropagation) {
468
		event.stopPropagation();
602
		event.stopPropagation();
469
	} else if (window.event) {
603
	} else if (window.event) {
470
		window.event.cancelBubble = true;
604
		window.event.cancelBubble = true;
471
	}
605
	}
472
	return false;
606
	return false;
473
}
607
}
474
 
608
 
475
/**
609
/**
476
 * +-------------------------------------+
610
 * +-------------------------------------+
477
 * Number.prototype.formaterNombre
611
 * Number.prototype.formaterNombre
478
 * +-------------------------------------+
612
 * +-------------------------------------+
479
 * Params (facultatifs):
613
 * Params (facultatifs):
480
 * - Int decimales: nombre de decimales (exemple: 2)
614
 * - Int decimales: nombre de decimales (exemple: 2)
481
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
615
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
482
 * - String separateurMilliers: comme son nom l'indique
616
 * - String separateurMilliers: comme son nom l'indique
483
 * Returns:
617
 * Returns:
484
 * - String chaine formatee
618
 * - String chaine formatee
485
 * @author	::mastahbenus::
619
 * @author	::mastahbenus::
486
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
620
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
487
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
621
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
488
 */
622
 */
489
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
623
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
490
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
624
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
491
	
625
	
492
	function is_int(nbre) {
626
	function is_int(nbre) {
493
		nbre = nbre.replace(',', '.');
627
		nbre = nbre.replace(',', '.');
494
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
628
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
495
	}
629
	}
496
 
630
 
497
	if (decimales == undefined) {
631
	if (decimales == undefined) {
498
		if (is_int(_sNombre)) {
632
		if (is_int(_sNombre)) {
499
			decimales = 0;
633
			decimales = 0;
500
		} else {
634
		} else {
501
			decimales = 2;
635
			decimales = 2;
502
		}
636
		}
503
	}
637
	}
504
	if (signe == undefined) {
638
	if (signe == undefined) {
505
		if (is_int(_sNombre)) {
639
		if (is_int(_sNombre)) {
506
			signe = '';
640
			signe = '';
507
		} else {
641
		} else {
508
			signe = '.';
642
			signe = '.';
509
		}
643
		}
510
	}
644
	}
511
	if (separateurMilliers == undefined) {
645
	if (separateurMilliers == undefined) {
512
		separateurMilliers = ' ';
646
		separateurMilliers = ' ';
513
	}
647
	}
514
	
648
	
515
	function separeMilliers (sNombre) {
649
	function separeMilliers (sNombre) {
516
		var sRetour = "";
650
		var sRetour = "";
517
		while (sNombre.length % 3 != 0) {
651
		while (sNombre.length % 3 != 0) {
518
			sNombre = "0"+sNombre;
652
			sNombre = "0"+sNombre;
519
		}
653
		}
520
		for (i = 0; i < sNombre.length; i += 3) {
654
		for (i = 0; i < sNombre.length; i += 3) {
521
			if (i == sNombre.length-1) separateurMilliers = '';
655
			if (i == sNombre.length-1) separateurMilliers = '';
522
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
656
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
523
		}
657
		}
524
		while (sRetour.substr(0, 1) == "0") {
658
		while (sRetour.substr(0, 1) == "0") {
525
			sRetour = sRetour.substr(1);
659
			sRetour = sRetour.substr(1);
526
		}
660
		}
527
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
661
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
528
	}
662
	}
529
	
663
	
530
	if (_sNombre.indexOf('.') == -1) {
664
	if (_sNombre.indexOf('.') == -1) {
531
		for (i = 0; i < decimales; i++) {
665
		for (i = 0; i < decimales; i++) {
532
			_sDecimales += "0";
666
			_sDecimales += "0";
533
		}
667
		}
534
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
668
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
535
	} else {
669
	} else {
536
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
670
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
537
		if (sDecimalesTmp.length > decimales) {
671
		if (sDecimalesTmp.length > decimales) {
538
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
672
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
539
			var nDiv = 1;
673
			var nDiv = 1;
540
			for (i = 0; i < nDecimalesManquantes; i++) {
674
			for (i = 0; i < nDecimalesManquantes; i++) {
541
				nDiv *= 10;
675
				nDiv *= 10;
542
			}
676
			}
543
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
677
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
544
		}
678
		}
545
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
679
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
546
	}
680
	}
547
	return _sRetour;
681
	return _sRetour;
548
}
682
}
549
 
683
 
550
function debug(objet) {
684
function debug(objet) {
551
	var msg = '';
685
	var msg = '';
552
	if (objet != null) {
686
	if (objet != null) {
553
		$.each(objet, function (cle, valeur) {
687
		$.each(objet, function (cle, valeur) {
554
			msg += cle+":"+valeur + "\n";
688
			msg += cle+":"+valeur + "\n";
555
		});
689
		});
556
	} else {
690
	} else {
557
		msg = "La variable vaut null.";
691
		msg = "La variable vaut null.";
558
	}
692
	}
559
	console.log(msg);
693
	console.log(msg);
-
 
694
}
-
 
695
 
-
 
696
function trim (chaine) {
-
 
697
	return chaine.replace(/^\s+/g, '').replace(/\s+$/g, '');
560
}
698
}
561
699