Subversion Repositories eFlore/Applications.cel

Rev

Rev 1244 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1244 jpm 1
//+----------------------------------------------------------------------------------------------------------+
2
// Initialisation de Jquery mobile
3
$(document).bind("mobileinit", function(){
4
  $.mobile.defaultPageTransition = "fade";
5
});
6
 
7
//+----------------------------------------------------------------------------------------------------------+
8
// Géolocalisation
9
var gps = navigator.geolocation;
10
 
11
$(document).ready(function() {
12
	$('#geolocaliser').on('click', geolocaliser);
13
});
14
 
15
function geolocaliser(event) {
16
	if (gps) {
17
	    navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc);
18
	} else {
19
	    var erreur = {code:'0', message:'Géolocalisation non supportée par le navigateur'};
20
	    surErreurGeoloc(erreur);
21
	}
22
 
23
	event.stopPropagation();
24
	event.preventDefault();
25
}
26
function surSuccesGeoloc(position){
27
	if (position){
28
        var lat = position.coords.latitude;
29
        var lng = position.coords.longitude;
30
        $('#lat').val(lat);
31
        $('#lng').val(lng);
32
    }
33
}
34
function surErreurGeoloc(error){
35
	alert("Echec de la géolocalisation, code: " + error.code + " message: "+ error.message);
36
}
37
//+----------------------------------------------------------------------------------------------------------+
38
// Local Storage
39
var bdd = window.localStorage;
40
bdd.clear();
41
$(document).ready(function() {
42
	$('#sauver-obs').on('click', ajouterObs);
43
	$('body').on('pageshow', '#liste', chargerListeObs);
44
});
45
 
46
function ajouterObs(event) {
47
	var obs = {num:0, date:'', lat:'', lng:'', nom:''};
48
	obs.num = (bdd.length + 1);
49
	obs.date = $('#date').val();
50
	obs.lat = $('#lat').val();
51
	obs.lng = $('#lng').val();
52
	obs.nom = $('#nom').val();
53
 
54
	var cle = 'obs'+obs.num;
55
	var val = JSON.stringify(obs);
56
	bdd.setItem(cle, val);
57
 
1248 jpm 58
	var txt = 'Observation n°'+obs.num+'/'+bdd.length+' créée';
59
	$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
60
		.fadeIn("slow")
61
		.delay(1600)
62
		.fadeOut("slow");
63
 
1244 jpm 64
	event.stopPropagation();
65
	event.preventDefault();
66
}
67
 
1248 jpm 68
function supprimerObs(event) {
69
	var cle = 'obs'+obs.num;
70
	bdd.removeItem(cle);
71
 
72
	var txt = 'Observation n°'+obs.num+' supprimée';
73
	$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
74
		.fadeIn("slow")
75
		.delay(1600)
76
		.fadeOut("slow");
77
 
78
	event.stopPropagation();
79
	event.preventDefault();
80
}
81
 
1244 jpm 82
function chargerListeObs() {
83
	$('#liste-obs').empty();
84
	var nbre = bdd.length;
85
	for (var i = 0; i < nbre; i++) {
86
		var cle = 'obs'+(i+1);
87
		var obs = JSON.parse(bdd.getItem(cle));
1248 jpm 88
		$('#liste-obs').append(
89
			'<li>'+
90
				'<img src="http://www.tela-botanica.org/widget-test:cel:modules/saisie/squelettes/defaut/img/icones/pasdephoto.png" />'+
91
				'<a href="#'+cle+'" data-split-icon="next" data-split-theme="a" title="Voir la fiche" data-obs-num="'+obs.num+'">'+
92
					'<strong>'+obs.nom+'</strong> observé le '+obs.date+' à lat : '+obs.lat+' lng : '+obs.lng+
93
				'</a>'+
94
				'<a href="#" title="Supprimer l\'observation" data-obs-num="'+obs.num+'">'+
95
					'Supprimer'+
96
				'</a>'+
97
			'</li>'
1244 jpm 98
		);
99
	}
100
	$('#liste-obs').listview('refresh');
101
}
102
 
103
 
104
//+----------------------------------------------------------------------------------------------------------+
105
// Manifest Cache
106
var appCache = window.applicationCache;
107
 
108
$(document).ready(function() {
109
	appCache.addEventListener('updateready', function() {
110
		alert('Mise à jour :'+appCache.status);
111
	});
112
	if (appCache.status === appCache.UPDATEREADY) {
113
		surMiseAJourCache();
114
	}
115
});
116
 
117
function surMiseAJourCache() {
118
	// Browser downloaded a new app cache.
119
    // Swap it in and reload the page to get the new hotness.
120
	appCache.swapCache();
121
    if (confirm('A new version of this site is available. Load it?')) {
122
      window.location.reload();
123
    }
124
}