Subversion Repositories eFlore/Applications.cel

Rev

Rev 1344 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1344 Rev 1552
Line 1... Line 1...
1
//+----------------------------------------------------------------------------------------------------------+
1
//+----------------------------------------------------------------------------------------------------------+
2
// Initialisation de Jquery mobile
2
// Initialisation de Jquery mobile
3
$(document).bind("mobileinit", function(){
3
$(document).bind('mobileinit', function() {
4
  $.mobile.defaultPageTransition = "fade";
4
	$.mobile.defaultPageTransition = 'fade';
-
 
5
});
-
 
6
$(document).on('online', function(event) {
-
 
7
	console.log('online');
-
 
8
	miseAJourObs();
5
});
9
});
6
 
-
 
7
//+----------------------------------------------------------------------------------------------------------+
10
//+----------------------------------------------------------------------------------------------------------+
8
// Géolocalisation
11
// Gestion des paramètres URL
9
var gps = navigator.geolocation;
12
$.urlParam = function(name){
-
 
13
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
-
 
14
	return decodeURIComponent(results[1]) || 0;
-
 
15
}
-
 
16
function recupererParametresUrl() {
-
 
17
	$('#referentiel').val($.urlParam('ref'));
-
 
18
	$('#nom').val($.urlParam('nom_sci'));
-
 
19
	$('#nom-sci-select').val($.urlParam('nom_sci'));
-
 
20
	$('#num-nom-select').val($.urlParam('num_nom'));
10
 
21
}
11
$(document).ready(function() {
22
$(document).ready(function() {
-
 
23
	$('body').on('pageshow', '#saisie', function(event) {
-
 
24
		obtenirPosition(event);
-
 
25
		recupererParametresUrl();
-
 
26
	});
12
	$('#geolocaliser').on('click', geolocaliser);	
27
	$('#geolocaliser').on('click', obtenirPosition);
-
 
28
	
-
 
29
	$('body').on('pageshow', '#infos', obtenirDate);
13
});
30
});
-
 
31
//+----------------------------------------------------------------------------------------------------------+
-
 
32
// Géolocalisation et date du jour
-
 
33
var gps = navigator.geolocation;
Line -... Line 34...
-
 
34
 
-
 
35
function obtenirPosition(event) {
-
 
36
	event.stopImmediatePropagation();
-
 
37
	event.stopPropagation();
-
 
38
	event.preventDefault();
-
 
39
	
-
 
40
	obtenirDate();
-
 
41
	geolocaliser();
14
 
42
}
15
function geolocaliser(event) {
43
function geolocaliser() {
16
	if (gps) {
44
	if (gps) {
17
	    navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc);
45
	    navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc);
18
	} else {
46
	} else {
19
	    var erreur = {code:'0', message:'Géolocalisation non supportée par le navigateur'};
47
	    var erreur = {code:'0', message: 'Géolocalisation non supportée par le navigateur'};
20
	    surErreurGeoloc(erreur);
48
	    surErreurGeoloc(erreur);
21
	}
-
 
22
	
-
 
23
	event.stopPropagation();
-
 
24
	event.preventDefault();
49
	}
25
}
50
}
26
function surSuccesGeoloc(position){
51
function surSuccesGeoloc(position){
27
	if (position){
52
	if (position) {
28
        var lat = position.coords.latitude;
53
		var lat = position.coords.latitude;
29
        var lng = position.coords.longitude;
54
		var lng = position.coords.longitude;
30
        $('#lat').val(lat);
55
		$('#lat').html(lat);
-
 
56
		$('#lng').html(lng);
-
 
57
 
-
 
58
		console.log('Geolocation SUCCESS');
-
 
59
		var url_service = SERVICE_NOM_COMMUNE_URL;
-
 
60
		var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);
-
 
61
		var jqxhr = $.getJSON(urlNomCommuneFormatee, function(data) {
-
 
62
			console.log('NOM_COMMUNE found.');
-
 
63
			$('#location').html(data['nom']);
-
 
64
			$('#code_insee').val(data['codeINSEE']);
-
 
65
		})
-
 
66
		.complete(function() { 
-
 
67
			var texte = ($('#location').html() == '') ? TEXTE_HORS_LIGNE : $('#location').html();
-
 
68
			$('#location').html(texte);
-
 
69
		})
31
        $('#lng').val(lng);
70
		;
32
    }
71
	}
33
}
72
}
34
function surErreurGeoloc(error){
73
function surErreurGeoloc(error){
35
	alert("Echec de la géolocalisation, code: " + error.code + " message: "+ error.message);
74
	alert('Echec de la géolocalisation, code: ' + error.code + ' message: '+ error.message);
-
 
75
}
-
 
76
 
-
 
77
function obtenirDate() {
-
 
78
	var d = new Date();
-
 
79
	var jour = d.getDate();
-
 
80
	var mois = d.getMonth()+1;
-
 
81
	var annee = d.getFullYear();
-
 
82
	var aujourdhui = 
-
 
83
		( (''+jour).length < 2 ? '0' : '') + jour + '/' +
-
 
84
		( (''+mois).length < 2 ? '0' : '') + mois + '/' +
-
 
85
		annee;
-
 
86
	$('#date').val(aujourdhui);
-
 
87
	$('#annee').html(annee);
36
}
88
} 
37
//+----------------------------------------------------------------------------------------------------------+
89
//+----------------------------------------------------------------------------------------------------------+
38
// Local Storage
-
 
39
var bdd = window.localStorage;
-
 
40
bdd.clear();
90
// Local Storage
41
$(document).ready(function() {
91
$(document).ready(function() {
-
 
92
	$('#sauver-obs').on('click', ajouterObs);
42
	$('#sauver-obs').on('click', ajouterObs);
93
	$('#valider_photos').on('click', ajoutPhoto);
-
 
94
	$('body').on('pageshow', '#liste', chargerListeObs);
43
	$('body').on('pageshow', '#liste', chargerListeObs);
95
	$('body').on('pageshow', '#transmission', miseAJourObs);
Line -... Line 96...
-
 
96
});
-
 
97
 
-
 
98
var bdd = window.localStorage,
-
 
99
	index_obs = (bdd.getItem('index_obs') == null) ? 1 : bdd.getItem('index_obs'),
-
 
100
	index_photos = (bdd.getItem('index_photos') == null) ? 1 : bdd.getItem('index_photos');
-
 
101
alert('space used:'+JSON.stringify(bdd).length);
-
 
102
//bdd.clear();
44
});
103
 
-
 
104
console.log(bdd);
-
 
105
function ajouterObs(event) {
-
 
106
	if ($('#nom').val() != '') {
-
 
107
		var obs = {
-
 
108
			num:TEXTE_OBS, 
-
 
109
			maj:0,
-
 
110
			date:'', 
45
 
111
			referentiel:'',
-
 
112
			lat:'', lng:'', 
-
 
113
			commune:'', code_insee: 0,
-
 
114
			nom:'', 
-
 
115
			nom_sci_selec:'', 
-
 
116
			nn_select:'',
-
 
117
			nom_sci_retenu:'',
-
 
118
			nn_retenu:'',
-
 
119
			num_taxon:'', 
-
 
120
			famille:''
46
function ajouterObs(event) {
121
		};
47
	var obs = {num:0, date:'', lat:'', lng:'', nom:''};
122
		
-
 
123
		obs.num += index_obs++;
48
	obs.num = (bdd.length + 1);
124
		obs.date = $('#date').val();
49
	obs.date = $('#date').val();
125
		obs.referentiel = $('#referentiel').val();
-
 
126
		obs.lat = $('#lat').html();
-
 
127
		obs.lng = $('#lng').html();
50
	obs.lat = $('#lat').val();
128
		obs.commune = $('#location').html();
-
 
129
		obs.code_insee = $('#code_insee').val();
-
 
130
		obs.nom = $('#nom').val();
-
 
131
		obs.referentiel = $('#referentiel').val();
51
	obs.lng = $('#lng').val();
132
		obs.nom_sci_selec = $('#nom_sci_select').val();
52
	obs.nom = $('#nom').val();
133
		obs.nn_select = $('#num_nom_select').val();
-
 
134
		
-
 
135
		var cle = obs.num;
-
 
136
		sauvegarderObs(cle, obs);
-
 
137
		bdd.setItem('index_obs', index_obs);
-
 
138
	/*	
-
 
139
		var txt = 'Observation n°'+obs.num+'/'+bdd.length+' créée';
-
 
140
		$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
-
 
141
			.fadeIn("slow")
-
 
142
			.delay(1600)
-
 
143
			.fadeOut("slow");
-
 
144
	*/	
-
 
145
		$.mobile.changePage('#liste');
-
 
146
		effacerFormulaire();
-
 
147
		event.stopPropagation();
-
 
148
		event.preventDefault();
-
 
149
	} else {
-
 
150
		$.mobile.changePage('#saisie');
-
 
151
		event.stopPropagation();
-
 
152
		event.preventDefault();
-
 
153
	}
-
 
154
}
53
	
155
 
-
 
156
function sauvegarderObs(cle, obs) {
-
 
157
	var val = JSON.stringify(obs);
54
	var cle = 'obs'+obs.num;
158
 
-
 
159
	alert('space used:'+JSON.stringify(bdd).length+'_'+(JSON.stringify(bdd).length+val.length));
-
 
160
	bdd.setItem(cle, val);
-
 
161
}
-
 
162
 
-
 
163
function effacerFormulaire() {
-
 
164
	$('#lat').html('');
-
 
165
	$('#lng').html('');
-
 
166
	$('#location').html('');
-
 
167
}
-
 
168
 
-
 
169
function chargerListeObs() {
-
 
170
	$('#liste_obs').empty();
-
 
171
	
-
 
172
	var nbre = bdd.length;
-
 
173
	for (var i = 0; i < nbre; i++) {
-
 
174
		var cle = bdd.key(i);
-
 
175
		if (cle.indexOf(TEXTE_OBS) !== -1) {
-
 
176
			var obs = JSON.parse(bdd.getItem(cle));
-
 
177
			console.log(obs);
-
 
178
			$('#liste_obs').prepend(
-
 
179
				'<li>'+
-
 
180
					obs.num + ' (Nbre photos : ' + compterPhotos(obs.num) + ')<br />' + 
-
 
181
					'<a href="#" onclick="detailsObs(this);" data-split-icon="next" data-split-theme="a" title="Voir la fiche" data-obs-num="'+obs.num+'">'+
-
 
182
						'<strong>'+obs.nom+'</strong> <br />'+obs.date+' à '+obs.commune+
-
 
183
					'</a>'+
-
 
184
					'<a href="#" onclick="supprimerObs(this);" title="Supprimer l\'observation" ' +
-
 
185
						'data-obs-num="'+obs.num+'">'+
-
 
186
						'Supprimer'+
-
 
187
					'</a>'+
-
 
188
				'</li>'
-
 
189
			);
-
 
190
		}
-
 
191
		$('#liste_obs').listview('refresh');
-
 
192
	}
-
 
193
}
-
 
194
 
-
 
195
function compterPhotos(num_obs) {
-
 
196
	var compteur = 0;
-
 
197
	if (num_obs != '') {
-
 
198
		var nbre = bdd.length;
-
 
199
		for (var i = 0; i < nbre; i++) {
-
 
200
			var cle = bdd.key(i);
-
 
201
			if (cle.indexOf(TEXTE_PHOTO) !== -1) {
-
 
202
				var photo = JSON.parse(bdd.getItem(cle));
-
 
203
				if (photo.parent == num_obs) {
-
 
204
					compteur++;
-
 
205
				}
-
 
206
			}
-
 
207
		}
-
 
208
	}
-
 
209
	return compteur;
-
 
210
}
-
 
211
 
-
 
212
function supprimerObs(data) {
-
 
213
	var cle_obs = data.getAttribute('data-obs-num'),
-
 
214
		obs = JSON.parse(bdd.getItem(cle_obs)),
-
 
215
		nbre = bdd.length,
-
 
216
		a_supprimer = new Array();
-
 
217
	for (var i = 0; i < nbre; i++) {
-
 
218
		var cle = bdd.key(i);
-
 
219
		if (cle.indexOf(TEXTE_PHOTO) !== -1) {
-
 
220
			var photo = JSON.parse(bdd.getItem(cle));
-
 
221
			if (photo.parent == obs.num) {
-
 
222
				a_supprimer.push(photo.num);
-
 
223
			}
-
 
224
		}
-
 
225
	}
-
 
226
	for (var c = 0; c < a_supprimer.length; c++) {
-
 
227
		bdd.removeItem(a_supprimer[c]);
Line 55... Line 228...
55
	var val = JSON.stringify(obs);
228
	}
56
	bdd.setItem(cle, val);
229
	bdd.removeItem(cle_obs);
57
	
230
	
58
	var txt = 'Observation n°'+obs.num+'/'+bdd.length+' créée';
231
	var txt = obs.num + ' supprimée.';
59
	$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
232
	$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
Line -... Line 233...
-
 
233
		.fadeIn(0)
-
 
234
		.delay(1600)
-
 
235
		.fadeOut('slow');
-
 
236
	
-
 
237
	chargerListeObs();
-
 
238
}
-
 
239
 
-
 
240
function detailsObs(data) {
-
 
241
	var num_obs = data.getAttribute('data-obs-num');
-
 
242
	var obs = JSON.parse(bdd.getItem(num_obs));
-
 
243
	$('#id_obs').html(obs.num);
60
		.fadeIn("slow")
244
	
61
		.delay(1600)
245
	var texte = '<strong>' + obs.nom + '</strong> vue le ' + obs.date;
62
		.fadeOut("slow");
246
	texte += (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') ? '' :  ' <br /> à ' + obs.commune;
Line 63... Line 247...
63
	
247
	$('#details_obs').html(texte);
-
 
248
	$.mobile.changePage('#observation');
-
 
249
	afficherPhotos(obs.num);
-
 
250
}
-
 
251
 
-
 
252
function ajoutPhoto() {
-
 
253
	var id_obs = $('#id_obs').html();
-
 
254
	if (id_obs != '') {
-
 
255
		$.each($('#pic').get(0).files, function(index, valeur) {
-
 
256
			var reader = new FileReader(),
-
 
257
				binary, base64;
-
 
258
			reader.addEventListener('loadend', function (evt) {
-
 
259
				binary = reader.result; // binary data (stored as string), unsafe for most actions
-
 
260
				base64 = btoa(binary); 	// base64 data, safer but takes up more memory
-
 
261
				
-
 
262
				var photo = {
-
 
263
					num:TEXTE_PHOTO, 
-
 
264
					nom: '',
-
 
265
					parent:'',
-
 
266
					base64:0
-
 
267
				};
64
	event.stopPropagation();
268
				photo.num += index_photos++;
-
 
269
				photo.nom = valeur.name;
-
 
270
				photo.parent = id_obs;
-
 
271
				photo.base64 = base64;
-
 
272
				
-
 
273
				var cle = photo.num;
-
 
274
				sauvegarderObs(cle, photo);
-
 
275
				bdd.setItem('index_photos', index_photos);
-
 
276
				afficherPhotos(id_obs);
-
 
277
			}, false);
-
 
278
			reader.readAsBinaryString(valeur);
-
 
279
		});
-
 
280
	}
-
 
281
}
-
 
282
 
-
 
283
function afficherPhotos(num_obs) {
-
 
284
	$('#pic').val('');
-
 
285
	$('#photos_obs').empty();
-
 
286
	if (num_obs != '') {
-
 
287
		var nbre = bdd.length;
-
 
288
		for (var i = 0; i < nbre; i++) {
-
 
289
			var cle = bdd.key(i);
-
 
290
			if (cle.indexOf(TEXTE_PHOTO) !== -1) {
-
 
291
				var photo = JSON.parse(bdd.getItem(cle));
-
 
292
				if (photo.parent == num_obs) {
-
 
293
					$('#photos_obs').prepend(
-
 
294
						'<li>'+
-
 
295
							'<a href="#'+photo.num+'" data-rel="popup" data-role="button" data-inline="true">' +
-
 
296
								'<img src="data:image/png;base64,' + photo.base64 + '" />' +
-
 
297
								photo.nom + 
-
 
298
							'</a>' +
-
 
299
							'<a href="#" onclick="supprimerPhoto(this);" title="Supprimer la photo" ' +
-
 
300
								'data-icon="delete" data-photo-num="' + photo.num + '"' + 
-
 
301
								'data-photo-parent="' + num_obs + '" data-theme="c">'+
-
 
302
								'Supprimer cette photo'+
-
 
303
							'</a>'+
-
 
304
						'</li>'
-
 
305
					);
-
 
306
				}
-
 
307
			}
-
 
308
			$('#photos_obs').listview('refresh');
-
 
309
		}
-
 
310
	}
-
 
311
}
-
 
312
 
-
 
313
function compterPhotos(num_obs) {
-
 
314
	var compteur = 0;
-
 
315
	if (num_obs != '') {
-
 
316
		var nbre = bdd.length;
-
 
317
		for (var i = 0; i < nbre; i++) {
-
 
318
			var cle = bdd.key(i);
-
 
319
			if (cle.indexOf(TEXTE_PHOTO) !== -1) {
-
 
320
				var photo = JSON.parse(bdd.getItem(cle));
-
 
321
				if (photo.parent == num_obs) {
-
 
322
					compteur++;
-
 
323
				}
-
 
324
			}
-
 
325
		}
-
 
326
	}
-
 
327
	return compteur;
-
 
328
}
65
	event.preventDefault();
329
 
66
}
330
function supprimerPhoto(data) {
67
 
331
	var cle_photo = data.getAttribute('data-photo-num'),
68
function supprimerObs(event) {
332
		parent = data.getAttribute('data-photo-parent'),
69
	var cle = 'obs'+obs.num;
333
		photo = JSON.parse(bdd.getItem(cle_photo));
70
	bdd.removeItem(cle);
334
	bdd.removeItem(cle_photo);
71
	
335
	
Line 72... Line 336...
72
	var txt = 'Observation n°'+obs.num+' supprimée';
336
	var txt = photo.num + ' supprimée.';
73
	$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
-
 
74
		.fadeIn("slow")
337
	$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
Line 75... Line 338...
75
		.delay(1600)
338
		.fadeIn(0)
76
		.fadeOut("slow");
339
		.delay(1600)
77
	
340
		.fadeOut('slow');
78
	event.stopPropagation();
341
	
79
	event.preventDefault();
342
	afficherPhotos(parent);
-
 
343
}
80
}
344
 
-
 
345
function miseAJourObs() {
81
 
346
	console.log('majObs');
-
 
347
	var nbre = bdd.length;
-
 
348
	for (var i = 0; i < nbre; i++) {
-
 
349
		var cle = bdd.key(i);
-
 
350
		if (cle.indexOf(TEXTE_OBS) !== -1) {
-
 
351
			var obs = JSON.parse(bdd.getItem(cle));
-
 
352
			
-
 
353
			if (obs.maj == 0) {
-
 
354
				var maj = 1;
-
 
355
				
-
 
356
				if (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') {
-
 
357
					var url_service = SERVICE_NOM_COMMUNE_URL;
-
 
358
					var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);
-
 
359
					jQuery.ajax({
-
 
360
						url: urlNomCommuneFormatee,
-
 
361
						success: function(data) {
82
function chargerListeObs() {
362
							obs.commune = data['nom'];
-
 
363
							obs.code_insee = data['codeINSEE'];
-
 
364
						 },
-
 
365
						 error: function() {
-
 
366
							 maj = 0;
83
	$('#liste-obs').empty();
367
						 },
-
 
368
						async: false
-
 
369
				   });
-
 
370
				}
-
 
371
				
-
 
372
				if (obs.nom_sci_retenu == '') {
-
 
373
					jQuery.ajax({
-
 
374
						url:	'/service:eflore:0.1/' + obs.referentiel + '/noms?'
-
 
375
								 + 'masque.nn=' + obs.nn_select
-
 
376
								 + '&retour.champs=num_taxonomique',
-
 
377
						success: function(data) {
-
 
378
							var cle = '',
84
	var nbre = bdd.length;
379
								compteur = 0;
-
 
380
							for (name in data['resultat']) {
85
	for (var i = 0; i < nbre; i++) {
381
								if (compteur == 0) {
-
 
382
									cle = name;
-
 
383
								}
-
 
384
								compteur++;
-
 
385
							}
-
 
386
							obs.num_taxon = data['resultat'][cle]['num_taxonomique'];
-
 
387
							jQuery.ajax({
-
 
388
								url: 	'/service:eflore:0.1/' + obs.referentiel + '/noms?'
-
 
389
										 + 'masque.nt=' + obs.num_taxon
-
 
390
										 + '&retour.champs=famille'
86
		var cle = 'obs'+(i+1);
391
										 + '&retour.tri=retenu',
-
 
392
								success: function(data) {
-
 
393
									var cle = '',
-
 
394
										compteur = 0;
87
		var obs = JSON.parse(bdd.getItem(cle));
395
									for (name in data['resultat']) {
-
 
396
										if (compteur == 0) {
-
 
397
											cle = name;
-
 
398
										}
88
		$('#liste-obs').append(
399
										compteur++;
89
			'<li>'+
400
									}
-
 
401
									obs.famille = data['resultat'][cle]['famille'];
90
				'<img src="http://www.tela-botanica.org/widget-test:cel:modules/saisie/squelettes/defaut/img/icones/pasdephoto.png" />'+
402
									obs.nom_sci_retenu = data['resultat'][cle]['nom_sci'];
-
 
403
									obs.nn_retenu = cle;
-
 
404
								 },
-
 
405
								 error: function() {
-
 
406
									 maj = 0;
-
 
407
								 },
-
 
408
								async:   false
-
 
409
							});
-
 
410
						 },
-
 
411
						async:   false
-
 
412
					});
-
 
413
				}
-
 
414
				
-
 
415
				obs.maj = maj;
-
 
416
			}
-
 
417
			
-
 
418
			sauvegarderObs(obs.num, obs);
-
 
419
		}
-
 
420
	}
-
 
421
}
-
 
422
 
-
 
423
function transmettreObs() {
91
				'<a href="#'+cle+'" data-split-icon="next" data-split-theme="a" title="Voir la fiche" data-obs-num="'+obs.num+'">'+
424
	if ($('#courriel').val() == $('#courriel_confirmation').val() && $('#courriel').val() != '') {
-
 
425
		var nbre = bdd.length;
-
 
426
		for (var i = 0; i < nbre; i++) {
-
 
427
			var cle = bdd.key(i);
-
 
428
			if (cle.indexOf('obs') !== -1) {
-
 
429
				var obs = JSON.parse(bdd.getItem(cle));
-
 
430
				stockerObsData(obs);
-
 
431
			}
-
 
432
		}
-
 
433
		var observations = $('#details_obs').data();
-
 
434
		console.log(observations);
-
 
435
		
-
 
436
		if (observations == undefined || jQuery.isEmptyObject(observations)) {
-
 
437
			//afficherPanneau("#dialogue-zero-obs");
-
 
438
		} else {
-
 
439
			observations['projet'] = TAG_PROJET;
-
 
440
			observations['tag-obs'] = '';
-
 
441
			observations['tag-img'] = '';
-
 
442
			
-
 
443
			var utilisateur = new Object();
-
 
444
			utilisateur.id_utilisateur = $('#id_utilisateur').val();
-
 
445
			utilisateur.prenom = $('#prenom_utilisateur').val();
-
 
446
			utilisateur.nom = $('#nom_utilisateur').val();
-
 
447
			utilisateur.courriel = $('#courriel').val();
-
 
448
			observations['utilisateur'] = utilisateur;
-
 
449
			envoyerObsAuCel(observations);
-
 
450
		}
-
 
451
	}
-
 
452
}
-
 
453
 
-
 
454
function stockerObsData(obs) {
-
 
455
	var nbre = bdd.length,
-
 
456
		img_noms = new Array(),
-
 
457
		img_codes = new Array();
-
 
458
	for (var i = 0; i < nbre; i++) {
-
 
459
		var cle = bdd.key(i);
92
					'<strong>'+obs.nom+'</strong> observé le '+obs.date+' à lat : '+obs.lat+' lng : '+obs.lng+
460
		if (cle.indexOf(TEXTE_PHOTO) !== -1) {
-
 
461
			var photo = JSON.parse(bdd.getItem(cle));
93
				'</a>'+
462
			if (photo.parent == obs.num) {
-
 
463
				img_noms.push(photo.nom);
-
 
464
				img_codes.push(photo.base64);
-
 
465
			}
-
 
466
		}
-
 
467
	}
-
 
468
	
-
 
469
	$('#details_obs').data(obs.num, {
-
 
470
		'date' : obs.date, 
-
 
471
		'notes' : '',
-
 
472
		
-
 
473
		'nom_sel' : obs.nom,
-
 
474
		'num_nom_sel' : obs.nn_select,
-
 
475
		'nom_ret' : obs.nom_sci_retenu,
-
 
476
		'num_nom_ret' : obs.nn_retenu,
-
 
477
		'num_taxon' : obs.num_taxon,
-
 
478
		'famille' : obs.famille,
-
 
479
		'referentiel' : obs.referentiel,
-
 
480
		
-
 
481
		'latitude' : obs.lat,
-
 
482
		'longitude' : obs.lng,
-
 
483
		'commune_nom' : obs.commune,
-
 
484
		'commune_code_insee' : obs.code_insee,
-
 
485
		'lieudit' : '',
94
				'<a href="#" title="Supprimer l\'observation" data-obs-num="'+obs.num+'">'+
486
		'station' : '',
Line -... Line 487...
-
 
487
		'milieu' : '',
-
 
488
		
-
 
489
		//Ajout des champs images
-
 
490
		'image_nom' : img_noms,
-
 
491
		'image_b64' : img_codes 
-
 
492
	});
-
 
493
}
-
 
494
 
-
 
495
 
-
 
496
function envoyerObsAuCel(observations) {
-
 
497
/*
-
 
498
	var erreurMsg = "";
-
 
499
	$.ajax({
-
 
500
		url : SERVICE_SAISIE_URL,
-
 
501
		type : "POST",
-
 
502
		data : observations,
-
 
503
		dataType : "json",
-
 
504
		beforeSend : function() {
-
 
505
			$("#dialogue-obs-transaction-ko").hide();
-
 
506
			$("#dialogue-obs-transaction-ok").hide();
-
 
507
			$(".alert-txt .msg").remove();	
-
 
508
			$(".alert-txt .msg-erreur").remove();
-
 
509
			$(".alert-txt .msg-debug").remove();
-
 
510
			$("#chargement").show();
-
 
511
		},
-
 
512
		success : function(data, textStatus, jqXHR) {
-
 
513
			$('#dialogue-obs-transaction-ok .alert-txt').append($("#tpl-transmission-ok").clone().html());
-
 
514
			supprimerMiniatures();
-
 
515
		},
-
 
516
		statusCode : {
-
 
517
			500 : function(jqXHR, textStatus, errorThrown) {
-
 
518
				erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
519
		    }
-
 
520
		},
-
 
521
		error : function(jqXHR, textStatus, errorThrown) {
-
 
522
			erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
523
			try {
-
 
524
				reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
525
				if (reponse != null) {
-
 
526
					$.each(reponse, function (cle, valeur) {
-
 
527
						erreurMsg += valeur + "\n";
-
 
528
					});
-
 
529
				}
-
 
530
			} catch(e) {
-
 
531
				erreurMsg += "L'erreur n'était pas en JSON.";
-
 
532
			}
-
 
533
		},
-
 
534
		complete : function(jqXHR, textStatus) {
-
 
535
			$("#chargement").hide();
-
 
536
			var debugMsg = extraireEnteteDebug(jqXHR);
-
 
537
			
-
 
538
			if (erreurMsg != '') {
-
 
539
				if (DEBUG) {
-
 
540
					$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
-
 
541
					$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
-
 
542
				}
-
 
543
				var hrefCourriel = "mailto:cel@tela-botanica.org?"+
-
 
544
					"subject=Disfonctionnement du widget de saisie "+TAG_PROJET+
-
 
545
					"&body="+erreurMsg+"\nDébogage :\n"+debugMsg;
-
 
546
				
-
 
547
				$('#dialogue-obs-transaction-ko .alert-txt').append($("#tpl-transmission-ko").clone()
-
 
548
					.find('.courriel-erreur')
-
 
549
					.attr('href', hrefCourriel)
-
 
550
					.end()
-
 
551
					.html());
-
 
552
				$("#dialogue-obs-transaction-ko").show();
-
 
553
			} else {
-
 
554
				if (DEBUG) {
-
 
555
					$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
95
					'Supprimer'+
556
				}
96
				'</a>'+
557
				$("#dialogue-obs-transaction-ok").show();
97
			'</li>'
558
			}
98
		);
-
 
99
	}
559
			initialiserObs();
100
	$('#liste-obs').listview('refresh');
560
		}
101
}
561
	});
102
 
562
*/
103
 
563
}
104
//+----------------------------------------------------------------------------------------------------------+
564
 
105
// Manifest Cache
565
//+----------------------------------------------------------------------------------------------------------+
106
var appCache = window.applicationCache;
566
// Manifest Cache
Line 107... Line 567...
107
 
567
var appCache = window.applicationCache;
108
$(document).ready(function() {
568
$(document).ready(function() {
109
	appCache.addEventListener('updateready', function() {
569
	appCache.addEventListener('updateready', function() {
110
		alert('Mise à jour :'+appCache.status);
570
		alert('Mise à jour :'+appCache.status);
111
	});  
-
 
112
	if (appCache.status === appCache.UPDATEREADY) {  
-
 
113
		surMiseAJourCache();
-
 
114
	}
-
 
115
});
571
	});
-
 
572
	if (appCache.status === appCache.UPDATEREADY) {  
-
 
573
		surMiseAJourCache();
-
 
574
	}
-
 
575
});
-
 
576
 
-
 
577
function surMiseAJourCache() {  
-
 
578
	// Browser downloaded a new app cache.
-
 
579
	// Swap it in and reload the page to get the new hotness.
-
 
580
	appCache.swapCache();
-
 
581
	if (confirm('A new version of this site is available. Load it ?')) {
-
 
582
		window.location.reload();
-
 
583
	}
-
 
584
}
-
 
585
 
-
 
586
 
-
 
587
//+----------------------------------------------------------------------------------------------------------+
-
 
588
//Transmission données
-
 
589
function verifierConnexion() {
-
 
590
	return ( ('onLine' in navigator) && (navigator.onLine));
-
 
591
}
-
 
592
 
-
 
593
//+---------------------------------------------------------------------------------------------------------+
-
 
594
//IDENTITÉ
-
 
595
$(document).ready(function() {
-
 
596
	$('#courriel').on('blur', requeterIdentite);
-
 
597
	$('#courriel').on('keypress', function(event) {
-
 
598
		if (event.which == 13) {
-
 
599
			testerLancementRequeteIdentite(event);
-
 
600
		}
-
 
601
	});
-
 
602
	$('#valider_courriel').on('vmousedown', testerLancementRequeteIdentite);
-
 
603
	$('body').on('pageshow', '#transmission', testerLancementRequeteIdentite);
-
 
604
});
-
 
605
 
-
 
606
function testerLancementRequeteIdentite(event) {	
-
 
607
	if (bdd.getItem('courriel') != null) {
-
 
608
		$('#courriel').val(bdd.getItem('courriel'));
-
 
609
	}
-
 
610
	
-
 
611
	requeterIdentite();
-
 
612
	event.preventDefault();
-
 
613
	event.stopPropagation();
-
 
614
}
-
 
615
 
-
 
616
function requeterIdentite() {
-
 
617
	var courriel = $('#courriel').val();
-
 
618
	if (courriel != '') {
-
 
619
		miseAJourCourriel();
-
 
620
		var urlAnnuaire = SERVICE_ANNUAIRE + courriel;	//http://localhost/applications/annuaire/jrest/
-
 
621
		$.ajax({
-
 
622
			url : urlAnnuaire,
-
 
623
			type : 'GET',
-
 
624
			success : function(data, textStatus, jqXHR) {
-
 
625
				console.log('Annuaire SUCCESS : ' + textStatus);
-
 
626
				if (data != undefined && data[courriel] != undefined) {
-
 
627
					var infos = data[courriel];
-
 
628
					$('#id_utilisateur').val(infos.id);
-
 
629
					$('#prenom_utilisateur').val(infos.prenom);
-
 
630
					$('#nom_utilisateur').val(infos.nom);
-
 
631
					$('#courriel_confirmation').val(courriel);
-
 
632
					$('#prenom_utilisateur, #nom_utilisateur, #courriel_confirmation').attr('disabled', 'disabled');
-
 
633
				} else {
-
 
634
					surErreurCompletionCourriel();
-
 
635
				}
-
 
636
			},
-
 
637
			error : function(jqXHR, textStatus, errorThrown) {
-
 
638
				console.log('Annuaire ERREUR : ' + textStatus);
-
 
639
				surErreurCompletionCourriel();
-
 
640
			},
-
 
641
			complete : function(jqXHR, textStatus) {
-
 
642
				console.log('Annuaire COMPLETE : ' + textStatus);
-
 
643
				$('#zone_prenom_nom').removeClass('hidden');
-
 
644
				$('#zone_courriel_confirmation').removeClass('hidden');
-
 
645
			}
-
 
646
		});
-
 
647
	}
-
 
648
}
-
 
649
 
-
 
650
function surErreurCompletionCourriel() {