Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1831 Rev 2325
1
//+----------------------------------------------------------------------------------------------------------+
1
//+----------------------------------------------------------------------------------------------------------+
2
// Initialisation de Jquery mobile
2
// Initialisation de Jquery mobile
3
$(document).on('mobileinit', function() {
3
$(document).on('mobileinit', function() {
4
	$.mobile.defaultPageTransition = 'fade';
4
	$.mobile.defaultPageTransition = 'fade';
5
});
5
});
6
$(document).on('online', function(event) {
6
$(document).on('online', function(event) {
7
	console.log('online');
7
	console.log('online');
8
	miseAJourObs();
8
	miseAJourObs();
9
});
9
});
10
 
10
 
11
function changerPage(id, event) {
11
function changerPage(id, event) {
12
	$.mobile.changePage(id);
12
	$.mobile.changePage(id);
13
	event.stopPropagation();
13
	event.stopPropagation();
14
	event.preventDefault();
14
	event.preventDefault();
15
}
15
}
16
//+----------------------------------------------------------------------------------------------------------+
16
//+----------------------------------------------------------------------------------------------------------+
17
// Gestion des paramètres URL
17
// Gestion des paramètres URL
18
var modal_recherche = false;
18
var modal_recherche = false;
19
$.urlParam = function(name){
19
$.urlParam = function(name){
20
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
20
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
21
	return (results == null) ? 0 : decodeURIComponent(results[1]);
21
	return (results == null) ? 0 : decodeURIComponent(results[1]);
22
}
22
}
23
function recupererParametresUrl() {
23
function recupererParametresUrl() {
24
	$('#referentiel').val(($.urlParam('ref') == 0) ? NOM_SCI_REFERENTIEL : $.urlParam('ref'));
24
	$('#referentiel').val(($.urlParam('ref') == 0) ? NOM_SCI_REFERENTIEL : $.urlParam('ref'));
25
	$('#nom').html(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));
25
	$('#nom').html(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));
26
	$('#nom-sci-select').val(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));
26
	$('#nom-sci-select').val(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));
27
	$('#num-nom-select').val(($.urlParam('num_nom') == 0) ? 0 : $.urlParam('num_nom'));
27
	$('#num-nom-select').val(($.urlParam('num_nom') == 0) ? 0 : $.urlParam('num_nom'));
28
}
28
}
29
$(document).ready(function() {
29
$(document).ready(function() {
30
	$('#geolocaliser').on('vclick', obtenirPosition);
30
	$('#geolocaliser').on('vclick', obtenirPosition);
31
	
31
	
32
	$('body').on('pagebeforeshow', '#infos', obtenirDate);
32
	$('body').on('pagebeforeshow', '#infos', obtenirDate);
33
	$('body').on('pageshow', '#saisie', function(event) {
33
	$('body').on('pageshow', '#saisie', function(event) {
34
		if (!modal_recherche) {
34
		if (!modal_recherche) {
35
			obtenirPosition(event);
35
			obtenirPosition(event);
36
			recupererParametresUrl();
36
			recupererParametresUrl();
37
		} else {
37
		} else {
38
			modal_recherche = false;
38
			modal_recherche = false;
39
		}
39
		}
40
	});
40
	});
41
	$('body').on('pagehide', '#saisie-popup', function() {
41
	$('body').on('pagehide', '#saisie-popup', function() {
42
		modal_recherche = true;
42
		modal_recherche = true;
43
	});	
43
	});	
44
});
44
});
45
 
45
 
46
//+----------------------------------------------------------------------------------------------------------+
46
//+----------------------------------------------------------------------------------------------------------+
47
// Géolocalisation et date du jour
47
// Géolocalisation et date du jour
48
var gps = navigator.geolocation;
48
var gps = navigator.geolocation;
49
 
49
 
50
function obtenirPosition(event) {
50
function obtenirPosition(event) {
51
	event.stopImmediatePropagation();
51
	event.stopImmediatePropagation();
52
	event.stopPropagation();
52
	event.stopPropagation();
53
	event.preventDefault();
53
	event.preventDefault();
54
	
54
	
55
	obtenirDate();
55
	obtenirDate();
56
	geolocaliser();
56
	geolocaliser();
57
}
57
}
58
function geolocaliser() {
58
function geolocaliser() {
59
	if (gps) {
59
	if (gps) {
60
	    navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc);
60
	    navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc);
61
	} else {
61
	} else {
62
	    var erreur = {code:'0', message: 'Géolocalisation non supportée par le navigateur'};
62
	    var erreur = {code:'0', message: 'Géolocalisation non supportée par le navigateur'};
63
	    surErreurGeoloc(erreur);
63
	    surErreurGeoloc(erreur);
64
	}
64
	}
65
}
65
}
66
function surSuccesGeoloc(position){
66
function surSuccesGeoloc(position){
67
	if (position) {
67
	if (position) {
68
		var lat = position.coords.latitude;
68
		var lat = position.coords.latitude;
69
		var lng = position.coords.longitude;
69
		var lng = position.coords.longitude;
70
		$('#lat').html(lat);
70
		$('#lat').html(lat);
71
		$('#lng').html(lng);
71
		$('#lng').html(lng);
72
 
72
 
73
		console.log('Geolocation SUCCESS');
73
		console.log('Geolocation SUCCESS');
74
		var url_service = SERVICE_NOM_COMMUNE_URL;
74
		var url_service = SERVICE_NOM_COMMUNE_URL;
75
		var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);
75
		var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);
76
		$.ajax({
76
		$.ajax({
77
			url : urlNomCommuneFormatee,
77
			url : urlNomCommuneFormatee,
78
			type : 'GET',
78
			type : 'GET',
79
			dataType : 'jsonp',
79
			dataType : 'jsonp',
80
			success : function(data) {
80
			success : function(data) {
81
				console.log('NOM_COMMUNE found.');
81
				console.log('NOM_COMMUNE found.');
82
				$('#location').html(data['nom']);
82
				$('#location').html(data['nom']);
83
				$('#code-insee').val(data['codeINSEE']);
83
				$('#code-insee').val(data['codeINSEE']);
84
			},
84
			},
85
			complete : function() { 
85
			complete : function() { 
86
				var texte = ($('#location').html() == '') ? TEXTE_HORS_LIGNE : $('#location').html();
86
				var texte = ($('#location').html() == '') ? TEXTE_HORS_LIGNE : $('#location').html();
87
				$('#location').html(texte);
87
				$('#location').html(texte);
88
			}
88
			}
89
		});
89
		});
90
	}
90
	}
91
}
91
}
92
function surErreurGeoloc(error){
92
function surErreurGeoloc(error){
93
	alert('Echec de la géolocalisation, code: ' + error.code + ' message: '+ error.message);
93
	alert('Echec de la géolocalisation, code: ' + error.code + ' message: '+ error.message);
94
}
94
}
95
 
95
 
96
function obtenirDate() {
96
function obtenirDate() {
97
	var d = new Date();
97
	var d = new Date();
98
	var jour = d.getDate();
98
	var jour = d.getDate();
99
	var mois = d.getMonth()+1;
99
	var mois = d.getMonth()+1;
100
	var annee = d.getFullYear();
100
	var annee = d.getFullYear();
101
	var aujourdhui = 
101
	var aujourdhui = 
102
		( (''+jour).length < 2 ? '0' : '') + jour + '/' +
102
		( (''+jour).length < 2 ? '0' : '') + jour + '/' +
103
		( (''+mois).length < 2 ? '0' : '') + mois + '/' +
103
		( (''+mois).length < 2 ? '0' : '') + mois + '/' +
104
		annee;
104
		annee;
105
	$('#date').html(aujourdhui);
105
	$('#date').html(aujourdhui);
106
	$('#annee').html(annee);
106
	$('#annee').html(annee);
107
} 
107
} 
108
//+----------------------------------------------------------------------------------------------------------+
108
//+----------------------------------------------------------------------------------------------------------+
109
// Local Storage
109
// Local Storage
110
$(document).ready(function() {
110
$(document).ready(function() {
111
	$('#sauver-obs').on('click', ajouterObs);
111
	$('#sauver-obs').on('click', ajouterObs);
112
	$('#valider-photos').on('click', ajoutPhoto);
112
	$('#valider-photos').on('click', ajoutPhoto);
113
	$('body').on('pageshow', '#liste', chargerListeObs);
113
	$('body').on('pageshow', '#liste', chargerListeObs);
114
	$('body').on('pageshow', '#transmission', miseAJourObs);
114
	$('body').on('pageshow', '#transmission', miseAJourObs);
115
});
115
});
116
 
116
 
117
var bdd = window.localStorage,
117
var bdd = window.localStorage,
118
	index_obs = (bdd.getItem('index_obs') == null) ? 1 : bdd.getItem('index_obs'),
118
	index_obs = (bdd.getItem('index_obs') == null) ? 1 : bdd.getItem('index_obs'),
119
	index_photos = (bdd.getItem('index_photos') == null) ? 1 : bdd.getItem('index_photos');
119
	index_photos = (bdd.getItem('index_photos') == null) ? 1 : bdd.getItem('index_photos');
120
//bdd.clear();
120
//bdd.clear();
121
 
121
 
122
 
122
 
123
var db;
123
var db;
124
function initOpenDB() {
124
function initOpenDB() {
125
	try {
125
	try {
126
		if (!window.openDatabase) {
126
		if (!window.openDatabase) {
127
			//alert("L'ajout de photos n'est pas supporté.");
127
			//alert("L'ajout de photos n'est pas supporté.");
128
		} else {
128
		} else {
129
			var shortName = 'CEL';
129
			var shortName = 'CEL';
130
			var version = '1.0';
130
			var version = '1.0';
131
			var displayName = 'TB | CEL web';
131
			var displayName = 'TB | CEL web';
132
			var maxSize = 1024 * 1024;
132
			var maxSize = 1024 * 1024;
133
			db = openDatabase(shortName, version, displayName, maxSize);
133
			db = openDatabase(shortName, version, displayName, maxSize);
134
			console.log(displayName + ' ' + maxSize);
134
			console.log(displayName + ' ' + maxSize);
135
			return db;
135
			return db;
136
		}
136
		}
137
	} catch (e) {
137
	} catch (e) {
138
		if (e == 2) {
138
		if (e == 2) {
139
			//alert("Invalid database version.");
139
			//alert("Invalid database version.");
140
		} else {
140
		} else {
141
			//alert("Unknown error " + e + ".");
141
			//alert("Unknown error " + e + ".");
142
		}
142
		}
143
		return;
143
		return;
144
	}
144
	}
145
}
145
}
146
initOpenDB();
146
initOpenDB();
147
if (db !== undefined) {
147
if (db !== undefined) {
148
	db.transaction(function(tx) {
148
	db.transaction(function(tx) {
149
		//tx.executeSql('DROP TABLE IMG');
149
		//tx.executeSql('DROP TABLE IMG');
150
		tx.executeSql('CREATE TABLE IF NOT EXISTS IMG (id unique, num unique, nom, parent, base64, miniature)');
150
		tx.executeSql('CREATE TABLE IF NOT EXISTS IMG (id unique, num unique, nom, parent, base64, miniature)');
151
	});
151
	});
152
}
152
}
153
 
153
 
154
console.log(bdd);
154
console.log(bdd);
155
function ajouterObs(event) {
155
function ajouterObs(event) {
156
	if ($('#nom').html() != '') {
156
	if ($('#nom').html() != '') {
157
		var obs = {
157
		var obs = {
158
			num:TEXTE_OBS, 
158
			num:TEXTE_OBS, 
159
			maj:0,
159
			maj:0,
160
			date:'', 
160
			date:'', 
161
			referentiel:'',
161
			referentiel:'',
162
			lat:'', lng:'', 
162
			lat:'', lng:'', 
163
			commune:'', code_insee: 0,
163
			commune:'', code_insee: 0,
164
			nom:'', 
164
			nom:'', 
165
			nom_sci_select:'', 
165
			nom_sci_select:'', 
166
			nn_select:'',
166
			nn_select:'',
167
			nom_sci_retenu:'',
167
			nom_sci_retenu:'',
168
			nn_retenu:'',
168
			nn_retenu:'',
169
			num_taxon:'', 
169
			num_taxon:'', 
170
			famille:''
170
			famille:''
171
		};
171
		};
172
		
172
		
173
		obs.num += index_obs++;
173
		obs.num += index_obs++;
174
		obs.date = $('#date').html();
174
		obs.date = $('#date').html();
175
		obs.referentiel = $('#referentiel').val();
175
		obs.referentiel = $('#referentiel').val();
176
		obs.lat = $('#lat').html();
176
		obs.lat = $('#lat').html();
177
		obs.lng = $('#lng').html();
177
		obs.lng = $('#lng').html();
178
		obs.commune = $('#location').html();
178
		obs.commune = $('#location').html();
179
		obs.code_insee = $('#code-insee').val();
179
		obs.code_insee = $('#code-insee').val();
180
		obs.nom = $('#nom').html();
180
		obs.nom = $('#nom').html();
181
		obs.referentiel = $('#referentiel').val();
181
		obs.referentiel = $('#referentiel').val();
182
		obs.nom_sci_select = $('#nom-sci-select').val();
182
		obs.nom_sci_select = $('#nom-sci-select').val();
183
		obs.nn_select = $('#num-nom-select').val();
183
		obs.nn_select = $('#num-nom-select').val();
184
		
184
		
185
		var cle = obs.num;
185
		var cle = obs.num;
186
		sauvegarderObs(cle, obs);
186
		sauvegarderObs(cle, obs);
187
		bdd.setItem('index_obs', index_obs);
187
		bdd.setItem('index_obs', index_obs);
188
		effacerFormulaire();
188
		effacerFormulaire();
189
		changerPage('#liste', event);
189
		changerPage('#liste', event);
190
	} else {
190
	} else {
191
		var txt = 'Aucune espèce saisie !';
191
		var txt = 'Aucune espèce saisie !';
192
		$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>')
192
		$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>')
193
			.fadeIn(0)
193
			.fadeIn(0)
194
			.delay(1600)
194
			.delay(1600)
195
			.fadeOut('slow');
195
			.fadeOut('slow');
196
		changerPage('#saisie', event);
196
		changerPage('#saisie', event);
197
	}
197
	}
198
}
198
}
199
 
199
 
200
function sauvegarderObs(cle, obs) {
200
function sauvegarderObs(cle, obs) {
201
	var val = JSON.stringify(obs),
201
	var val = JSON.stringify(obs),
202
		poids = JSON.stringify(bdd).length + val.length;
202
		poids = JSON.stringify(bdd).length + val.length;
203
	if (poids > 2621940) {
203
	if (poids > 2621940) {
204
		$('#cache-plein').popup('open');
204
		$('#cache-plein').popup('open');
205
	}
205
	}
206
	bdd.setItem(cle, val);
206
	bdd.setItem(cle, val);
207
}
207
}
208
 
208
 
209
function effacerFormulaire() {
209
function effacerFormulaire() {
210
    $('#lat').html('');
210
    $('#lat').html('');
211
    $('#lng').html('');
211
    $('#lng').html('');
212
    $('#location').html('');
212
    $('#location').html('');
213
}
213
}
214
 
214
 
215
function chargerListeObs() {
215
function chargerListeObs() {
216
	$('#liste-obs').empty();
216
	$('#liste-obs').empty();
217
	
217
	
218
	var nbre = bdd.length;
218
	var nbre = bdd.length;
219
	for (var i = 0; i < nbre; i++) {
219
	for (var i = 0; i < nbre; i++) {
220
		var cle = bdd.key(i);
220
		var cle = bdd.key(i);
221
		if (cle.indexOf(TEXTE_OBS) !== -1) {
221
		if (cle.indexOf(TEXTE_OBS) !== -1) {
222
			var obs = JSON.parse(bdd.getItem(cle));
222
			var obs = JSON.parse(bdd.getItem(cle));
223
			console.log(obs);
223
			console.log(obs);
224
			$('#liste-obs').prepend(
224
			$('#liste-obs').prepend(
225
				'<li>'+
225
				'<li>'+
226
					'<a href="#" onclick="detailsObs(this);" data-split-icon="next" data-split-theme="a" title="Voir la fiche" data-obs-num="' + obs.num + '">' +
226
					'<a href="#" onclick="detailsObs(this);" data-split-icon="next" data-split-theme="a" title="Voir la fiche" data-obs-num="' + obs.num + '">' +
227
						'<strong>' + obs.nom + '</strong> <br />' + obs.date +
227
						'<strong>' + obs.nom + '</strong> <br />' + obs.date +
228
						((obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') ? '' :  (' à ' + obs.commune)) +
228
						((obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') ? '' :  (' à ' + obs.commune)) +
229
					'</a>'+
229
					'</a>'+
230
					'<a href="#" onclick="supprimerObs(this);" title="Supprimer l\'observation" ' +
230
					'<a href="#" onclick="supprimerObs(this);" title="Supprimer l\'observation" ' +
231
						'data-obs-num="' + obs.num + '">' +
231
						'data-obs-num="' + obs.num + '">' +
232
						'Supprimer'+
232
						'Supprimer'+
233
					'</a>'+
233
					'</a>'+
234
				'</li>'
234
				'</li>'
235
			);
235
			);
236
		}
236
		}
237
		$('#liste-obs').listview('refresh');
237
		$('#liste-obs').listview('refresh');
238
	}
238
	}
239
}
239
}
240
 
240
 
241
function supprimerObs(data) {
241
function supprimerObs(data) {
242
	var cle_obs = data.getAttribute('data-obs-num'),
242
	var cle_obs = data.getAttribute('data-obs-num'),
243
		obs = JSON.parse(bdd.getItem(cle_obs)),
243
		obs = JSON.parse(bdd.getItem(cle_obs)),
244
		nbre = bdd.length,
244
		nbre = bdd.length,
245
		a_supprimer = new Array();
245
		a_supprimer = new Array();
246
	
246
	
247
	if (db !== undefined) {
247
	if (db !== undefined) {
248
		db.transaction(function(tx) {
248
		db.transaction(function(tx) {
249
			tx.executeSql('DELETE FROM IMG WHERE parent LIKE ?', [cle_obs]);
249
			tx.executeSql('DELETE FROM IMG WHERE parent LIKE ?', [cle_obs]);
250
		});
250
		});
251
	}
251
	}
252
	bdd.removeItem(cle_obs);
252
	bdd.removeItem(cle_obs);
253
	
253
	
254
	var txt = 'Observation n°' + obs.num.substring(TEXTE_OBS.length) + ' supprimée.';
254
	var txt = 'Observation n°' + obs.num.substring(TEXTE_OBS.length) + ' supprimée.';
255
	$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>')
255
	$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>')
256
		.fadeIn(0)
256
		.fadeIn(0)
257
		.delay(1600)
257
		.delay(1600)
258
		.fadeOut('slow');
258
		.fadeOut('slow');
259
	
259
	
260
	chargerListeObs();
260
	chargerListeObs();
261
}
261
}
262
 
262
 
263
function detailsObs(data) {
263
function detailsObs(data) {
264
	if (db !== undefined) {
264
	if (db !== undefined) {
265
		var num_obs = data.getAttribute('data-obs-num');
265
		var num_obs = data.getAttribute('data-obs-num');
266
		var obs = JSON.parse(bdd.getItem(num_obs));
266
		var obs = JSON.parse(bdd.getItem(num_obs));
267
		$('#id-obs').html(obs.num);
267
		$('#id-obs').html(obs.num);
268
		
268
		
269
		var texte = '<strong>' + obs.nom + '</strong> vue le ' + obs.date;
269
		var texte = '<strong>' + obs.nom + '</strong> vue le ' + obs.date;
270
		texte += (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') ? '' :  ' à ' + obs.commune;
270
		texte += (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') ? '' :  ' à ' + obs.commune;
271
		$('#details-obs').html(texte);
271
		$('#details-obs').html(texte);
272
		$.mobile.changePage('#observation');
272
		$.mobile.changePage('#observation');
273
		afficherPhotos(obs.num);
273
		afficherPhotos(obs.num);
274
	} else {
274
	} else {
275
		var texte ='L\'accès à l\'ajout de photos n\'est pas supporté.';
275
		var texte ='L\'accès à l\'ajout de photos n\'est pas supporté.';
276
		$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + texte + '</p>')
276
		$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + texte + '</p>')
277
			.fadeIn(0)
277
			.fadeIn(0)
278
			.delay(1600)
278
			.delay(1600)
279
			.fadeOut('slow');
279
			.fadeOut('slow');
280
	}
280
	}
281
}
281
}
282
 
282
 
283
function ajoutPhoto() {
283
function ajoutPhoto() {
284
	var id_obs = $('#id-obs').html();
284
	var id_obs = $('#id-obs').html();
285
	if (id_obs != '') {
285
	if (id_obs != '') {
286
		$.each($('#pic').get(0).files, function(index, valeur) {
286
		$.each($('#pic').get(0).files, function(index, valeur) {
287
			//*
287
			//*
288
			var reader = new FileReader();
288
			var reader = new FileReader();
289
			reader.addEventListener('loadend', function () {
289
			reader.addEventListener('loadend', function () {
290
				var photo_nom = valeur.name,
290
				var photo_nom = valeur.name,
291
					arr_nom = photo_nom.split("."),
291
					arr_nom = photo_nom.split("."),
292
					dernier = arr_nom.length - 1;
292
					dernier = arr_nom.length - 1;
293
				if (arr_nom[dernier].toUpperCase() != "JPG" && arr_nom[dernier].toUpperCase() != "JPEG") {
293
				if (arr_nom[dernier].toUpperCase() != "JPG" && arr_nom[dernier].toUpperCase() != "JPEG") {
294
					$('#pic').val('');
294
					$('#pic').val('');
295
					var txt = 'Seuls les fichiers .JPG ou .JPEG sont acceptés.';
295
					var txt = 'Seuls les fichiers .JPG ou .JPEG sont acceptés.';
296
					$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>')
296
					$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>')
297
						.fadeIn(0)
297
						.fadeIn(0)
298
						.delay(1600)
298
						.delay(1600)
299
						.fadeOut('slow');
299
						.fadeOut('slow');
300
				} else {
300
				} else {
301
					var photo = {
301
					var photo = {
302
						num: TEXTE_PHOTO, 
302
						num: TEXTE_PHOTO, 
303
						nom: '',
303
						nom: '',
304
						parent: '',
304
						parent: '',
305
						base64: 0,
305
						base64: 0,
306
						miniature: ''
306
						miniature: ''
307
					};
307
					};
308
					photo.num += index_photos++;
308
					photo.num += index_photos++;
309
					photo.nom = photo_nom;
309
					photo.nom = photo_nom;
310
					photo.parent = id_obs;
310
					photo.parent = id_obs;
311
					photo.base64 = reader.result;
311
					photo.base64 = reader.result;
312
					bdd.setItem('index_photos', index_photos);
312
					bdd.setItem('index_photos', index_photos);
313
					
313
					
314
					var img = new Image(),
314
					var img = new Image(),
315
						miniature = null;
315
						miniature = null;
316
					img.src = photo.base64;
316
					img.src = photo.base64;
317
					img.alt = photo.nom;
317
					img.alt = photo.nom;
318
					img.onload = function() {
318
					img.onload = function() {
319
						miniature = transformerImgEnCanvas(this, 100, 100, false, 'white');
319
						miniature = transformerImgEnCanvas(this, 100, 100, false, 'white');
320
						
320
						
321
						db.transaction(function(tx) {  
321
						db.transaction(function(tx) {  
322
							tx.executeSql('SELECT * FROM IMG', [], function(tx, results) {
322
							tx.executeSql('SELECT * FROM IMG', [], function(tx, results) {
323
								var taille = results.rows.length + 1;
323
								var taille = results.rows.length + 1;
324
								tx.executeSql(
324
								tx.executeSql(
325
									'INSERT INTO IMG' 
325
									'INSERT INTO IMG' 
326
									+ ' (id, parent, nom, base64, num, miniature)'
326
									+ ' (id, parent, nom, base64, num, miniature)'
327
									+ ' VALUES (?, ?, ?, ?, ?, ?)', 
327
									+ ' VALUES (?, ?, ?, ?, ?, ?)', 
328
									[taille, photo.parent, photo.nom, photo.base64, photo.num, miniature]);
328
									[taille, photo.parent, photo.nom, photo.base64, photo.num, miniature]);
329
							});
329
							});
330
						});
330
						});
331
						afficherPhotos(id_obs);
331
						afficherPhotos(id_obs);
332
					}
332
					}
333
				}
333
				}
334
			}, false);
334
			}, false);
335
			reader.readAsDataURL(valeur);
335
			reader.readAsDataURL(valeur);
336
		});
336
		});
337
	}
337
	}
338
}
338
}
339
 
339
 
340
function afficherPhotos(num_obs) {
340
function afficherPhotos(num_obs) {
341
	$('#pic').val('');
341
	$('#pic').val('');
342
	$('#photos-obs').empty();
342
	$('#photos-obs').empty();
343
	if (num_obs != '') {
343
	if (num_obs != '') {
344
		db.readTransaction(function(tx) {
344
		db.readTransaction(function(tx) {
345
			tx.executeSql('SELECT * FROM IMG WHERE parent LIKE ?', [num_obs], function(tx, results) {
345
			tx.executeSql('SELECT * FROM IMG WHERE parent LIKE ?', [num_obs], function(tx, results) {
346
				var nbre = results.rows.length;
346
				var nbre = results.rows.length;
347
				for (var i = 0; i < nbre; i++) {
347
				for (var i = 0; i < nbre; i++) {
348
					photo = results.rows.item(i);
348
					photo = results.rows.item(i);
349
					$('#photos-obs').prepend(
349
					$('#photos-obs').prepend(
350
						'<li>'+
350
						'<li>'+
351
							'<a href="#" onclick="afficherVue(this);" data-ajax="false" data-role="button" data-inline="true" data-photo-num="' + photo.num + '">' +
351
							'<a href="#" onclick="afficherVue(this);" data-ajax="false" data-role="button" data-inline="true" data-photo-num="' + photo.num + '">' +
352
								'<img src="' + photo.miniature + '" />' +
352
								'<img src="' + photo.miniature + '" />' +
353
								photo.nom + 
353
								photo.nom + 
354
							'</a>' +
354
							'</a>' +
355
							'<a href="#" onclick="supprimerPhoto(this);" title="Supprimer la photo" ' +
355
							'<a href="#" onclick="supprimerPhoto(this);" title="Supprimer la photo" ' +
356
								'data-icon="delete" data-photo-num="' + photo.num + '" data-photo-parent="' + num_obs + '"' + 
356
								'data-icon="delete" data-photo-num="' + photo.num + '" data-photo-parent="' + num_obs + '"' + 
357
								'data-theme="c">' +
357
								'data-theme="c">' +
358
								'Supprimer cette photo' +
358
								'Supprimer cette photo' +
359
							'</a>' +
359
							'</a>' +
360
						'</li>'
360
						'</li>'
361
					);
361
					);
362
				}
362
				}
363
				$('#photos-obs').listview('refresh');
363
				$('#photos-obs').listview('refresh');
364
			}, null);
364
			}, null);
365
		});
365
		});
366
	}
366
	}
367
}
367
}
368
 
368
 
369
function afficherVue(data) {
369
function afficherVue(data) {
370
	var cle_photo = data.getAttribute('data-photo-num');
370
	var cle_photo = data.getAttribute('data-photo-num');
371
	db.readTransaction(function(tx) {  
371
	db.readTransaction(function(tx) {  
372
		tx.executeSql('SELECT * FROM IMG WHERE num LIKE ?', [cle_photo], function(tx, results) {
372
		tx.executeSql('SELECT * FROM IMG WHERE num LIKE ?', [cle_photo], function(tx, results) {
373
			var photo = results.rows.item(0);
373
			var photo = results.rows.item(0);
374
			$('#photo-zoom-infos').html('<img class="photo-popup" width="80%" src="' + photo.base64 + '" />');
374
			$('#photo-zoom-infos').html('<img class="photo-popup" width="80%" src="' + photo.base64 + '" />');
375
			$('#photo-zoom')
375
			$('#photo-zoom')
376
				.popup('open')
376
				.popup('open')
377
				.on('popupafterclose', function(event) {
377
				.on('popupafterclose', function(event) {
378
					event.stopImmediatePropagation();
378
					event.stopImmediatePropagation();
379
					event.stopPropagation();
379
					event.stopPropagation();
380
					event.preventDefault();
380
					event.preventDefault();
381
				});
381
				});
382
		});
382
		});
383
	});	
383
	});	
384
}
384
}
385
 
385
 
386
function supprimerPhoto(data) {
386
function supprimerPhoto(data) {
387
	var cle_photo = data.getAttribute('data-photo-num'),
387
	var cle_photo = data.getAttribute('data-photo-num'),
388
		parent = data.getAttribute('data-photo-parent');
388
		parent = data.getAttribute('data-photo-parent');
389
	db.transaction(function(tx) {
389
	db.transaction(function(tx) {
390
		tx.executeSql('DELETE FROM IMG WHERE num LIKE ?', [cle_photo]);
390
		tx.executeSql('DELETE FROM IMG WHERE num LIKE ?', [cle_photo]);
391
	});
391
	});
392
/*	
392
/*	
393
	var txt = photo.num + ' supprimée.';
393
	var txt = photo.num + ' supprimée.';
394
	$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
394
	$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>')
395
		.fadeIn(0)
395
		.fadeIn(0)
396
		.delay(1600)
396
		.delay(1600)
397
		.fadeOut('slow');
397
		.fadeOut('slow');
398
*/
398
*/
399
	afficherPhotos(parent);
399
	afficherPhotos(parent);
400
}
400
}
401
 
401
 
402
function miseAJourObs() {
402
function miseAJourObs() {
403
	console.log('majObs');
403
	console.log('majObs');
404
	var nbre = bdd.length;
404
	var nbre = bdd.length;
405
	for (var i = 0; i < nbre; i++) {
405
	for (var i = 0; i < nbre; i++) {
406
		var cle = bdd.key(i);
406
		var cle = bdd.key(i);
407
		if (cle.indexOf(TEXTE_OBS) !== -1) {
407
		if (cle.indexOf(TEXTE_OBS) !== -1) {
408
			var obs = JSON.parse(bdd.getItem(cle));
408
			var obs = JSON.parse(bdd.getItem(cle));
409
			
409
			
410
			if (obs.maj == 0) {
410
			if (obs.maj == 0) {
411
				var maj = 1;
411
				var maj = 1;
412
				
412
				
413
				if (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') {
413
				if (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') {
414
					var url_service = SERVICE_NOM_COMMUNE_URL;
414
					var url_service = SERVICE_NOM_COMMUNE_URL;
415
					var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);
415
					var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng);
416
					jQuery.ajax({
416
					jQuery.ajax({
417
						url: urlNomCommuneFormatee,
417
						url: urlNomCommuneFormatee,
418
						type : 'GET',
418
						type : 'GET',
419
						dataType : 'jsonp',
419
						dataType : 'jsonp',
420
						success: function(data) {
420
						success: function(data) {
421
							obs.commune = data['nom'];
421
							obs.commune = data['nom'];
422
							obs.code_insee = data['codeINSEE'];
422
							obs.code_insee = data['codeINSEE'];
423
						 },
423
						 },
424
						 error: function() {
424
						 error: function() {
425
							 maj = 0;
425
							 maj = 0;
426
						 },
426
						 },
427
						async: false
427
						async: false
428
				   });
428
				   });
429
				}
429
				}
430
				
430
				
431
				if (obs.nom_sci_retenu == '') {
431
				if (obs.nom_sci_retenu == '') {
432
					jQuery.ajax({
432
					jQuery.ajax({
433
						url:	'/service:eflore:0.1/' + obs.referentiel + '/noms?'
433
						url:	'/service:eflore:0.1/' + obs.referentiel + '/noms?'
434
								 + 'masque.nn=' + obs.nn_select
434
								 + 'masque.nn=' + obs.nn_select
435
								 + '&retour.champs=num_taxonomique',
435
								 + '&retour.champs=num_taxonomique',
436
						success: function(data) {
436
						success: function(data) {
437
							var cle = '',
437
							var cle = '',
438
								compteur = 0;
438
								compteur = 0;
439
							for (name in data['resultat']) {
439
							for (name in data['resultat']) {
440
								if (compteur == 0) {
440
								if (compteur == 0) {
441
									cle = name;
441
									cle = name;
442
								}
442
								}
443
								compteur++;
443
								compteur++;
444
							}
444
							}
445
							obs.num_taxon = data['resultat'][cle]['num_taxonomique'];
445
							obs.num_taxon = data['resultat'][cle]['num_taxonomique'];
446
							jQuery.ajax({
446
							jQuery.ajax({
447
								url: 	'/service:eflore:0.1/' + obs.referentiel + '/noms?'
447
								url: 	'/service:eflore:0.1/' + obs.referentiel + '/noms?'
448
										 + 'masque.nt=' + obs.num_taxon
448
										 + 'masque.nt=' + obs.num_taxon
449
										 + '&retour.champs=famille'
449
										 + '&retour.champs=famille'
450
										 + '&retour.tri=retenu',
450
										 + '&retour.tri=retenu',
451
								type : 'GET',
451
								type : 'GET',
452
								dataType : 'jsonp',
452
								dataType : 'jsonp',
453
								success: function(data) {
453
								success: function(data) {
454
									var cle = '';
454
									var cle = '';
455
									for (name in data['resultat']) {
455
									for (name in data['resultat']) {
456
										if (data['resultat'][name]['retenu'] == 'true') {
456
										if (data['resultat'][name]['retenu'] == 'true') {
457
											cle = name;
457
											cle = name;
458
											break;
458
											break;
459
										}
459
										}
460
									}
460
									}
461
									obs.famille = data['resultat'][cle]['famille'];
461
									obs.famille = data['resultat'][cle]['famille'];
462
									obs.nom_sci_retenu = data['resultat'][cle]['nom_sci'];
462
									obs.nom_sci_retenu = data['resultat'][cle]['nom_sci'];
463
									obs.nn_retenu = cle;
463
									obs.nn_retenu = cle;
464
								 },
464
								 },
465
								 error: function() {
465
								 error: function() {
466
									 maj = 0;
466
									 maj = 0;
467
								 },
467
								 },
468
								async:   false
468
								async:   false
469
							});
469
							});
470
						 },
470
						 },
471
						async:   false
471
						async:   false
472
					});
472
					});
473
				}
473
				}
474
				
474
				
475
				obs.maj = maj;
475
				obs.maj = maj;
476
			}
476
			}
477
			
477
			
478
			sauvegarderObs(obs.num, obs);
478
			sauvegarderObs(obs.num, obs);
479
		}
479
		}
480
	}
480
	}
481
}
481
}
482
 
482
 
483
//+----------------------------------------------------------------------------------------------------------+
483
//+----------------------------------------------------------------------------------------------------------+
484
// Gestion des photos
484
// Gestion des photos
485
function transformerImgEnCanvas(img, thumbwidth, thumbheight, crop, background) {
485
function transformerImgEnCanvas(img, thumbwidth, thumbheight, crop, background) {
486
	var canvas = document.getElementById('photo-canvas');
486
	var canvas = document.getElementById('photo-canvas');
487
	canvas.width = thumbwidth;
487
	canvas.width = thumbwidth;
488
	canvas.height = thumbheight;
488
	canvas.height = thumbheight;
489
	var dimensions = calculerDimensions(img.width, img.height, thumbwidth, thumbheight);
489
	var dimensions = calculerDimensions(img.width, img.height, thumbwidth, thumbheight);
490
	if (crop) {
490
	if (crop) {
491
		canvas.width = dimensions.w;
491
		canvas.width = dimensions.w;
492
		canvas.height = dimensions.h;
492
		canvas.height = dimensions.h;
493
		dimensions.x = 0;
493
		dimensions.x = 0;
494
		dimensions.y = 0;
494
		dimensions.y = 0;
495
	}
495
	}
496
	cx = canvas.getContext('2d');
496
	cx = canvas.getContext('2d');
497
	cx.clearRect(0, 0, thumbwidth, thumbheight);
497
	cx.clearRect(0, 0, thumbwidth, thumbheight);
498
	if (background !== 'transparent') {
498
	if (background !== 'transparent') {
499
		cx.fillStyle = background;
499
		cx.fillStyle = background;
500
		cx.fillRect(0, 0, thumbwidth, thumbheight);
500
		cx.fillRect(0, 0, thumbwidth, thumbheight);
501
	}
501
	}
502
	
502
	
503
	cx.drawImage(img, dimensions.x, dimensions.y, dimensions.w, dimensions.h);
503
	cx.drawImage(img, dimensions.x, dimensions.y, dimensions.w, dimensions.h);
504
	return afficherMiniature(canvas);
504
	return afficherMiniature(canvas);
505
}
505
}
506
 
506
 
507
function calculerDimensions(imagewidth, imageheight, thumbwidth, thumbheight) {
507
function calculerDimensions(imagewidth, imageheight, thumbwidth, thumbheight) {
508
	var w = 0, h = 0, x = 0, y = 0, zoom = 1,
508
	var w = 0, h = 0, x = 0, y = 0, zoom = 1,
509
	    widthratio = imagewidth / thumbwidth,
509
	    widthratio = imagewidth / thumbwidth,
510
	    heightratio = imageheight / thumbheight,
510
	    heightratio = imageheight / thumbheight,
511
	    maxratio = Math.max(widthratio, heightratio);
511
	    maxratio = Math.max(widthratio, heightratio);
512
	    
512
	    
513
	if (maxratio > 1) {
513
	if (maxratio > 1) {
514
	    w = imagewidth / maxratio;
514
	    w = imagewidth / maxratio;
515
	    h = imageheight / maxratio;
515
	    h = imageheight / maxratio;
516
	} else {
516
	} else {
517
	    w = imagewidth;
517
	    w = imagewidth;
518
	    h = imageheight;
518
	    h = imageheight;
519
	}
519
	}
520
	x = (thumbwidth - w) / 2;
520
	x = (thumbwidth - w) / 2;
521
	y = (thumbheight - h) / 2;
521
	y = (thumbheight - h) / 2;
522
	
522
	
523
	zoom = (maxratio > 10) ? (2.6*(maxratio / 10)) : 1;
523
	zoom = (maxratio > 10) ? (2.6*(maxratio / 10)) : 1;
524
	h *= zoom;
524
	h *= zoom;
525
	
525
	
526
	return {w:w, h:h, x:x, y:y};
526
	return {w:w, h:h, x:x, y:y};
527
}
527
}
528
 
528
 
529
function afficherMiniature(canvas) {
529
function afficherMiniature(canvas) {
530
	return canvas.toDataURL('image/jpeg' , 0.8);
530
	return canvas.toDataURL('image/jpeg' , 0.8);
531
}
531
}
532
 
532
 
533
//+----------------------------------------------------------------------------------------------------------+
533
//+----------------------------------------------------------------------------------------------------------+
534
// Autocomplétion des noms latins
534
// Autocomplétion des noms latins
535
var recherche = '';
535
var recherche = '';
536
$(document).on('pageinit', '#saisie', function() {
536
$(document).on('pageinit', '#saisie', function() {
537
    $('#liste-noms-latins').on('listviewbeforefilter', function(e, data) {
537
    $('#liste-noms-latins').on('listviewbeforefilter', function(e, data) {
538
        var $input = $(data.input);
538
        var $input = $(data.input);
539
        recherche = $input.val();
539
        recherche = $input.val();
540
        
540
        
541
		$input.keyup(function() {
541
		$input.keyup(function() {
542
			clearTimeout($.data(this, 'timer'));
542
			clearTimeout($.data(this, 'timer'));
543
			var wait = setTimeout(lancerRecherche, DELAI_RECHERCHE);
543
			var wait = setTimeout(lancerRecherche, DELAI_RECHERCHE);
544
			$(this).data('timer', wait);
544
			$(this).data('timer', wait);
545
		});	
545
		});	
546
    });
546
    });
547
});
547
});
548
 
548
 
549
function lancerRecherche() {
549
function lancerRecherche() {
550
	var $ul = $('#liste-noms-latins'),
550
	var $ul = $('#liste-noms-latins'),
551
		html = '';
551
		html = '';
552
    $ul.html('');
552
    $ul.html('');
553
    
553
    
554
	if (recherche && recherche.length > 2) {		
554
	if (recherche && recherche.length > 2) {		
555
		afficherChargement();
555
		afficherChargement();
556
		$ul.html('<li><div class="ui-loader"><span class="ui-icon ui-icon-loading"></span></div></li>');
556
		$ul.html('<li><div class="ui-loader"><span class="ui-icon ui-icon-loading"></span></div></li>');
557
		$ul.listview('refresh');	
557
		$ul.listview('refresh');	
558
		$.ajax({ })
558
		$.ajax({ })
559
		.then(function() {
559
		.then(function() {
560
			for (index in BDTFX) {
560
			for (index in BDTFX) {
561
				var espece = BDTFX[index],
561
				var espece = BDTFX[index],
562
					nom_sci = espece['nom_sci'],
562
					nom_sci = espece['nom_sci'],
563
					num_nom = espece['num_nom'],
563
					num_nom = espece['num_nom'],
564
					auteur = espece['auteur'],
564
					auteur = espece['auteur'],
565
					annee = espece['annee'],
565
					annee = espece['annee'],
566
					nom_sci_complet = nom_sci + ((auteur == '' || auteur == null) ? '' : (' ' + auteur)) + ((annee == '' || annee == null) ? '' : (' (' + annee + ')'));
566
					nom_sci_complet = nom_sci + ((auteur == '' || auteur == null) ? '' : (' ' + auteur)) + ((annee == '' || annee == null) ? '' : (' (' + annee + ')'));
567
				
567
				
568
				if (nom_sci !== '') {
568
				if (nom_sci !== '') {
569
					var arr_nom_sci = nom_sci.split(' '),
569
					var arr_nom_sci = nom_sci.split(' '),
570
						arr_recherche = recherche.split(' ');
570
						arr_recherche = recherche.split(' ');
571
				
571
				
572
					if (arr_nom_sci[1] !== undefined) {
572
					if (arr_nom_sci[1] !== undefined) {
573
						nom_sci_recherche = arr_nom_sci[1];
573
						nom_sci_recherche = arr_nom_sci[1];
574
						
574
						
575
						if (arr_nom_sci[1].toLowerCase() == 'x') {
575
						if (arr_nom_sci[1].toLowerCase() == 'x') {
576
							nom_sci_recherche = arr_nom_sci[2];
576
							nom_sci_recherche = arr_nom_sci[2];
577
						}
577
						}
578
					} else {
578
					} else {
579
						nom_sci_recherche = arr_nom_sci[0];
579
						nom_sci_recherche = arr_nom_sci[0];
580
					}
580
					}
581
					
581
					
582
					if ((arr_nom_sci[0].toLowerCase().substring(0, arr_recherche[0].length)) == arr_recherche[0].toLowerCase()) {
582
					if ((arr_nom_sci[0].toLowerCase().substring(0, arr_recherche[0].length)) == arr_recherche[0].toLowerCase()) {
583
						var flag = true;
583
						var flag = true;
584
						if (arr_recherche[1] !== undefined) {
584
						if (arr_recherche[1] !== undefined) {
585
							flag = ( (nom_sci_recherche.toLowerCase().substring(0, arr_recherche[1].length)) == arr_recherche[1].toLowerCase() );
585
							flag = ( (nom_sci_recherche.toLowerCase().substring(0, arr_recherche[1].length)) == arr_recherche[1].toLowerCase() );
586
						}
586
						}
587
						
587
						
588
						if (flag) {
588
						if (flag) {
589
							html += '<li>' 
589
							html += '<li>' 
590
									+ '<a href="#" data-nom-sci="' + nom_sci + '" data-num-nom="' + num_nom + '" '
590
									+ '<a href="#" data-nom-sci="' + nom_sci + '" data-num-nom="' + num_nom + '" '
591
										+ ' data-auteur="' + auteur + '" data-nom-sci-complet="' + nom_sci_complet 
591
										+ ' data-auteur="' + auteur + '" data-nom-sci-complet="' + nom_sci_complet 
-
 
592
										+ '" data-nom-sci-referentiel="bdtfx"' 
592
										+ '" class="noms-latins" >'
593
										+ '" class="noms-latins" >'
593
									+ nom_sci_complet
594
									+ nom_sci_complet
594
									+ '</a>'
595
									+ '</a>'
595
								+ '</li>';
596
								+ '</li>';
596
						}
597
						}
597
					}
598
					}
598
				}
599
				}
599
			}
600
			}
600
			$.mobile.loading('hide');
601
			$.mobile.loading('hide');
601
			$ul.html(html);
602
			$ul.html(html);
602
			$ul.listview('refresh');
603
			$ul.listview('refresh');
603
			$ul.trigger('updatelayout');
604
			$ul.trigger('updatelayout');
604
			$('.noms-latins').on('click', choisirEspece);
605
			$('.noms-latins').on('click', choisirEspece);
605
		});
606
		});
606
	}
607
	}
607
}
608
}
608
 
609
 
609
function afficherChargement() {
610
function afficherChargement() {
610
	var $this = $('#recherche-chargement'),
611
	var $this = $('#recherche-chargement'),
611
		theme = $this.jqmData('theme') || $.mobile.loader.prototype.options.theme,
612
		theme = $this.jqmData('theme') || $.mobile.loader.prototype.options.theme,
612
		msg = $this.jqmData('msgtext') || $.mobile.loader.prototype.options.text,
613
		msg = $this.jqmData('msgtext') || $.mobile.loader.prototype.options.text,
613
		textVisible = $this.jqmData('textvisible') || $.mobile.loader.prototype.options.textVisible,
614
		textVisible = $this.jqmData('textvisible') || $.mobile.loader.prototype.options.textVisible,
614
		textonly = !!$this.jqmData('textonly');
615
		textonly = !!$this.jqmData('textonly');
615
		html = $this.jqmData('html') || '';
616
		html = $this.jqmData('html') || '';
616
		
617
		
617
	$.mobile.loading('show', {
618
	$.mobile.loading('show', {
618
		text: msg,
619
		text: msg,
619
		textVisible: textVisible,
620
		textVisible: textVisible,
620
		theme: theme,
621
		theme: theme,
621
		textonly: textonly,
622
		textonly: textonly,
622
		html: html
623
		html: html
623
	});
624
	});
624
 }
625
 }
625
 
626
 
626
function choisirEspece(event) {
627
function choisirEspece(event) {
627
	var espece = event.currentTarget,
628
	var espece = event.currentTarget,
628
		auteur = espece.getAttribute('data-auteur'),
629
		auteur = espece.getAttribute('data-auteur'),
-
 
630
		referentiel = espece.getAttribute('data-nom-sci-referentiel'),
629
		nom_sci = espece.getAttribute('data-nom-sci'),
631
		nom_sci = espece.getAttribute('data-nom-sci'),
630
		nom_sci_complet = espece.getAttribute('data-nom-sci-complet')
632
		nom_sci_complet = espece.getAttribute('data-nom-sci-complet')
631
		num_nom = espece.getAttribute('data-num-nom');
633
		num_nom = espece.getAttribute('data-num-nom');
632
		
634
		
633
	$('#nom').html(nom_sci_complet);
635
	$('#nom').html(nom_sci_complet);
-
 
636
	$('#referentiel').val(referentiel);
634
	$('#nom-sci-select').val(nom_sci);
637
	$('#nom-sci-select').val(nom_sci);
635
	$('#num-nom-select').val(num_nom);
638
	$('#num-nom-select').val(num_nom);
636
	$('#liste-noms-latins').html('');
639
	$('#liste-noms-latins').html('');
637
	$('#saisie-popup').dialog('close');
640
	$('#saisie-popup').dialog('close');
638
}
641
}
639
 
642
 
640
//+----------------------------------------------------------------------------------------------------------+
643
//+----------------------------------------------------------------------------------------------------------+
641
// Manifest Cache
644
// Manifest Cache
642
var appCache = window.applicationCache;
645
var appCache = window.applicationCache;
643
appCache.addEventListener('updateready', function() {
646
appCache.addEventListener('updateready', function() {
644
	if (appCache.status === appCache.UPDATEREADY) {  
647
	if (appCache.status === appCache.UPDATEREADY) {  
645
		surMiseAJourCache();
648
		surMiseAJourCache();
646
	}
649
	}
647
});
650
});
648
 
651
 
649
function surMiseAJourCache() {  
652
function surMiseAJourCache() {  
650
	appCache.swapCache();
653
	appCache.swapCache();
651
	if (confirm('Une nouvelle version de ce site est disponible. Mettre à jour ?')) {
654
	if (confirm('Une nouvelle version de ce site est disponible. Mettre à jour ?')) {
652
	  window.location.reload();
655
	  window.location.reload();
653
	}  
656
	}  
654
}
657
}
655
 
658
 
656
//+----------------------------------------------------------------------------------------------------------+
659
//+----------------------------------------------------------------------------------------------------------+
657
//Transmission données
660
//Transmission données
658
$(document).ready(function() {
661
$(document).ready(function() {
659
	$('#transmettre-obs').on('click', transmettreObs);
662
	$('#transmettre-obs').on('click', transmettreObs);
660
});
663
});
661
 
664
 
662
function transmettreObs() {
665
function transmettreObs() {
663
	var msg = '';
666
	var msg = '';
664
	if (recupererStatutIdentite() == 'true') {
667
	if (recupererStatutIdentite() == 'true') {
665
		if (verifierConnexion()) {
668
		if (verifierConnexion()) {
666
			var nbre = bdd.length;
669
			var nbre = bdd.length;
667
			for (var i = 0; i < nbre; i++) {
670
			for (var i = 0; i < nbre; i++) {
668
				var cle = bdd.key(i);
671
				var cle = bdd.key(i);
669
				if (cle.indexOf('obs') !== -1) {
672
				if (cle.indexOf('obs') !== -1) {
670
					var obs = JSON.parse(bdd.getItem(cle));
673
					var obs = JSON.parse(bdd.getItem(cle));
671
					stockerObsData(obs);
674
					stockerObsData(obs);
672
				}
675
				}
673
			}
676
			}
674
			
677
			
675
			var observations = $('#details-obs').data();
678
			var observations = $('#details-obs').data();
676
			if (observations == undefined || jQuery.isEmptyObject(observations)) {
679
			if (observations == undefined || jQuery.isEmptyObject(observations)) {
677
				msg = 'Aucune observation à transmettre.';
680
				msg = 'Aucune observation à transmettre.';
678
			} else {
681
			} else {
679
				msg = 'Transmission en cours...';
682
				msg = 'Transmission en cours...';
680
				observations['projet'] = TAG_PROJET;
683
				observations['projet'] = TAG_PROJET;
681
				observations['tag-obs'] = '';
684
				observations['tag-obs'] = '';
682
				observations['tag-img'] = '';
685
				observations['tag-img'] = '';
683
				
686
				
684
				var utilisateur = new Object();
687
				var utilisateur = new Object();
685
				utilisateur.id_utilisateur = ($('#id-utilisateur').val() == '') ? bdd.getItem('utilisateur.id') : $('#id-utilisateur').val();
688
				utilisateur.id_utilisateur = ($('#id-utilisateur').val() == '') ? bdd.getItem('utilisateur.id') : $('#id-utilisateur').val();
686
				utilisateur.prenom = ($('#prenom-utilisateur').val() == '') ? bdd.getItem('utilisateur.prenom') : $('#prenom-utilisateur').val();
689
				utilisateur.prenom = ($('#prenom-utilisateur').val() == '') ? bdd.getItem('utilisateur.prenom') : $('#prenom-utilisateur').val();
687
				utilisateur.nom = ($('#nom-utilisateur').val() == '') ? bdd.getItem('utilisateur.nom') : $('#nom-utilisateur').val();
690
				utilisateur.nom = ($('#nom-utilisateur').val() == '') ? bdd.getItem('utilisateur.nom') : $('#nom-utilisateur').val();
688
				utilisateur.courriel = ($('#courriel').val() == '') ? bdd.getItem('utilisateur.courriel') : $('#courriel').val();
691
				utilisateur.courriel = ($('#courriel').val() == '') ? bdd.getItem('utilisateur.courriel') : $('#courriel').val();
689
				observations['utilisateur'] = utilisateur;
692
				observations['utilisateur'] = utilisateur;
690
				envoyerObsAuCel(observations);
693
				envoyerObsAuCel(observations);
691
			}
694
			}
692
		} else {
695
		} else {
693
			msg = 'Aucune connexion disponible. Merci de réessayer ultérieurement.';
696
			msg = 'Aucune connexion disponible. Merci de réessayer ultérieurement.';
694
		}
697
		}
695
	} else {
698
	} else {
696
		msg = 'Merci de vérifier et de confirmer votre adresse e-mail avant de transmettre vos observations.';
699
		msg = 'Merci de vérifier et de confirmer votre adresse e-mail avant de transmettre vos observations.';
697
	}
700
	}
698
	
701
	
699
	if (msg != '') {
702
	if (msg != '') {
700
		$('#identification-infos').html('<p class="reponse">' + msg + '</p>')
703
		$('#identification-infos').html('<p class="reponse">' + msg + '</p>')
701
			.fadeIn(0)
704
			.fadeIn(0)
702
			.delay(2000)
705
			.delay(2000)
703
			.fadeOut('slow');
706
			.fadeOut('slow');
704
	}
707
	}
705
}
708
}
706
 
709
 
707
function verifierConnexion() {
710
function verifierConnexion() {
708
	return ( ('onLine' in navigator) && (navigator.onLine));
711
	return ( ('onLine' in navigator) && (navigator.onLine));
709
}
712
}
710
 
713
 
711
function stockerObsData(obs) {
714
function stockerObsData(obs) {
712
	var img_noms = new Array(),
715
	var img_noms = new Array(),
713
		img_codes = new Array();
716
		img_codes = new Array();
714
	if (db !== undefined) {
717
	if (db !== undefined) {
715
		db.transaction(function(tx) {
718
		db.transaction(function(tx) {
716
			tx.executeSql('SELECT * FROM IMG WHERE parent LIKE ?', [obs.num], function(tx, results) {
719
			tx.executeSql('SELECT * FROM IMG WHERE parent LIKE ?', [obs.num], function(tx, results) {
717
				var nbre = results.rows.length;
720
				var nbre = results.rows.length;
718
				for (var i = 0; i < nbre; i++) {
721
				for (var i = 0; i < nbre; i++) {
719
					photo = results.rows.item(i);
722
					photo = results.rows.item(i);
720
					img_noms.push(photo.nom);
723
					img_noms.push(photo.nom);
721
					img_codes.push(photo.base64);
724
					img_codes.push(photo.base64);
722
				}
725
				}
723
			}, null);
726
			}, null);
724
		});	
727
		});	
725
	}
728
	}
726
 
729
 
727
	$('#details-obs').data(obs.num, {
730
	$('#details-obs').data(obs.num, {
728
		'date' : obs.date, 
731
		'date' : obs.date, 
729
		'notes' : '',
732
		'notes' : '',
730
		
733
		
731
		'nom_sel' : obs.nom,
734
		'nom_sel' : obs.nom,
732
		'num_nom_sel' : obs.nn_select,
735
		'num_nom_sel' : obs.nn_select,
733
		'nom_ret' : obs.nom_sci_retenu,
736
		'nom_ret' : obs.nom_sci_retenu,
734
		'num_nom_ret' : obs.nn_retenu,
737
		'num_nom_ret' : obs.nn_retenu,
735
		'num_taxon' : obs.num_taxon,
738
		'num_taxon' : obs.num_taxon,
736
		'famille' : obs.famille,
739
		'famille' : obs.famille,
737
		'referentiel' : obs.referentiel,
740
		'referentiel' : obs.referentiel,
738
		
741
		
739
		'latitude' : obs.lat,
742
		'latitude' : obs.lat,
740
		'longitude' : obs.lng,
743
		'longitude' : obs.lng,
741
		'commune_nom' : obs.commune,
744
		'commune_nom' : obs.commune,
742
		'commune_code_insee' : obs.code_insee,
745
		'commune_code_insee' : obs.code_insee,
743
		'lieudit' : '',
746
		'lieudit' : '',
744
		'station' : '',
747
		'station' : '',
745
		'milieu' : '',
748
		'milieu' : '',
746
		
749
		
747
		//Ajout des champs images
750
		//Ajout des champs images
748
		'image_nom' : img_noms,
751
		'image_nom' : img_noms,
749
		'image_b64' : img_codes 
752
		'image_b64' : img_codes 
750
	});
753
	});
751
}
754
}
752
 
755
 
753
 
756
 
754
function envoyerObsAuCel(observations) {
757
function envoyerObsAuCel(observations) {
755
	//console.log(observations);
758
	//console.log(observations);
756
	var erreurMsg = "";
759
	var erreurMsg = "";
757
	$.ajax({
760
	$.ajax({
758
		url : SERVICE_SAISIE_URL,
761
		url : SERVICE_SAISIE_URL,
759
		type : "POST",
762
		type : "POST",
760
		data : observations,
763
		data : observations,
761
		dataType : "json",
764
		dataType : "json",
762
		beforeSend : function() {
765
		beforeSend : function() {
763
			console.log('before send');
766
			console.log('before send');
764
		},
767
		},
765
		success : function(data, textStatus, jqXHR) {
768
		success : function(data, textStatus, jqXHR) {
766
			console.log('Transmission SUCCESS.');
769
			console.log('Transmission SUCCESS.');
767
		},
770
		},
768
		statusCode : {
771
		statusCode : {
769
			500 : function(jqXHR, textStatus, errorThrown) {
772
			500 : function(jqXHR, textStatus, errorThrown) {
770
				erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
773
				erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
771
		    }
774
		    }
772
		},
775
		},
773
		error : function(jqXHR, textStatus, errorThrown) {
776
		error : function(jqXHR, textStatus, errorThrown) {
774
			erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
777
			erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
775
			try {
778
			try {
776
				reponse = jQuery.parseJSON(jqXHR.responseText);
779
				reponse = jQuery.parseJSON(jqXHR.responseText);
777
				if (reponse != null) {
780
				if (reponse != null) {
778
					$.each(reponse, function (cle, valeur) {
781
					$.each(reponse, function (cle, valeur) {
779
						erreurMsg += valeur + "\n";
782
						erreurMsg += valeur + "\n";
780
					});
783
					});
781
				}
784
				}
782
			} catch(e) {
785
			} catch(e) {
783
				erreurMsg += "L'erreur n'était pas en JSON.";
786
				erreurMsg += "L'erreur n'était pas en JSON.";
784
			}
787
			}
785
		},
788
		},
786
		complete : function(jqXHR, textStatus) {
789
		complete : function(jqXHR, textStatus) {
787
			console.log('complete');
790
			console.log('complete');
788
			console.log(jqXHR);
791
			console.log(jqXHR);
789
		}
792
		}
790
	});
793
	});
791
}
794
}
792
 
795
 
793
//+---------------------------------------------------------------------------------------------------------+
796
//+---------------------------------------------------------------------------------------------------------+
794
//IDENTITÉ
797
//IDENTITÉ
795
$(document).ready(function() {
798
$(document).ready(function() {
796
	$('#courriel').on('blur', requeterIdentite);
799
	$('#courriel').on('blur', requeterIdentite);
797
	$('#courriel').on('keypress', function(event) {
800
	$('#courriel').on('keypress', function(event) {
798
		if (event.which == 13) {
801
		if (event.which == 13) {
799
			requeterIdentite();
802
			requeterIdentite(event);
800
		}
803
		}
801
	});
804
	});
802
	
805
	
803
	$('body').on('pagebeforeshow', '#transmission', completerCompte);
806
	$('body').on('pagebeforeshow', '#transmission', completerCompte);
804
	$('body').on('pagebeforeshow', '#identification-popup', testerLancementRequeteIdentite);
807
	$('body').on('pagebeforeshow', '#identification-popup', testerLancementRequeteIdentite);
805
	
808
	
806
	$('#valider-courriel').on('vmousedown', requeterIdentite);
809
	$('#valider-courriel').on('vmousedown', requeterIdentite);
807
	$('#valider-identification').on('vmousedown', confirmerIdentification);
810
	$('#valider-identification').on('vmousedown', confirmerIdentification);
808
});
811
});
809
 
812
 
810
function completerCompte() {
813
function completerCompte() {
811
	if (bdd.getItem('utilisateur.courriel') != null) {
814
	if (bdd.getItem('utilisateur.courriel') != null) {
812
		var courriel = bdd.getItem('utilisateur.courriel');
815
		var courriel = bdd.getItem('utilisateur.courriel');
813
		$('#identification-texte').html(TEXTE_OUI_COMPTE);
816
		$('#identification-texte').html(TEXTE_OUI_COMPTE);
814
		$('#utilisateur-compte').html(courriel);
817
		$('#utilisateur-compte').html(courriel);
815
		$('#identification-btn * .ui-btn-text').html('Modifier le compte');
818
		$('#identification-btn * .ui-btn-text').html('Modifier le compte');
816
	} else {
819
	} else {
817
		$('#identification-texte').html(TEXTE_NON_COMPTE);
820
		$('#identification-texte').html(TEXTE_NON_COMPTE);
818
		$('#identification-btn * .ui-btn-text').html('Ajouter un compte');
821
		$('#identification-btn * .ui-btn-text').html('Ajouter un compte');
819
	}
822
	}
820
}
823
}
821
 
824
 
822
function testerLancementRequeteIdentite(event) {	
825
function testerLancementRequeteIdentite(event) {	
823
	if (bdd.getItem('utilisateur.courriel') != null) {
826
	if (bdd.getItem('utilisateur.courriel') != null) {
824
		var courriel = bdd.getItem('utilisateur.courriel');
827
		var courriel = bdd.getItem('utilisateur.courriel');
825
		$('#courriel').val(courriel);
828
		$('#courriel').val(courriel);
826
		
829
		
827
		if (recupererStatutIdentite() == 'true') {
830
		if (recupererStatutIdentite() == 'true') {
828
			$('#courriel-confirmation').val(courriel);
831
			$('#courriel-confirmation').val(courriel);
829
		}
832
		}
830
	}
833
	}
831
	if (bdd.getItem('utilisateur.nom') != null) {
834
	if (bdd.getItem('utilisateur.nom') != null) {
832
		$('#nom-utilisateur').val(bdd.getItem('utilisateur.nom'));
835
		$('#nom-utilisateur').val(bdd.getItem('utilisateur.nom'));
833
	}
836
	}
834
	if (bdd.getItem('utilisateur.prenom') != null) {
837
	if (bdd.getItem('utilisateur.prenom') != null) {
835
		$('#prenom-utilisateur').val(bdd.getItem('utilisateur.prenom'));
838
		$('#prenom-utilisateur').val(bdd.getItem('utilisateur.prenom'));
836
	}
839
	}
837
	if (bdd.getItem('utilisateur.id') != null) {
840
	if (bdd.getItem('utilisateur.id') != null) {
838
		$('#id-utilisateur').val(bdd.getItem('utilisateur.id'));
841
		$('#id-utilisateur').val(bdd.getItem('utilisateur.id'));
839
	}
842
	}
840
	
843
	
841
	event.preventDefault();
844
	event.preventDefault();
842
	event.stopPropagation();
845
	event.stopPropagation();
843
}
846
}
844
 
847
 
845
function recupererStatutIdentite() {
848
function recupererStatutIdentite() {
846
	return bdd.getItem('utilisateur.identite');
849
	return bdd.getItem('utilisateur.identite');
847
}
850
}
848
 
851
 
849
function confirmerIdentification(event) {
852
function confirmerIdentification(event) {
850
	confirmerCourriel();
853
	confirmerCourriel();
851
	changerPage('#transmission', event);
854
	changerPage('#transmission', event);
852
}
855
}
853
 
856
 
854
function confirmerCourriel() {
857
function confirmerCourriel() {
855
	bdd.setItem('utilisateur.identite', false);
858
	bdd.setItem('utilisateur.identite', false);
856
	if (validerCourriel($('#courriel').val())) {
859
	if (validerCourriel($('#courriel').val())) {
857
		if ($('#courriel').val() == $('#courriel-confirmation').val()) {
860
		if ($('#courriel').val() == $('#courriel-confirmation').val()) {
858
			bdd.setItem('utilisateur.identite', true);
861
			bdd.setItem('utilisateur.identite', true);
859
		}
862
		}
860
	} else  {
863
	} else  {
861
		$('#identification-infos').html('<p class="reponse">Adresse e-mail invalide.</p>')
864
		$('#identification-infos').html('<p class="reponse">Adresse e-mail invalide.</p>')
862
			.fadeIn(0)
865
			.fadeIn(0)
863
			.delay(2000)
866
			.delay(2000)
864
			.fadeOut('slow');
867
			.fadeOut('slow');
865
	}
868
	}
866
}
869
}
867
 
870
 
868
function requeterIdentite(event) {
871
function requeterIdentite(event) {
869
	var courriel = $('#courriel').val();
872
	var courriel = $('#courriel').val();
870
	if (validerCourriel(courriel)) {
873
	if (validerCourriel(courriel)) {
871
		miseAJourCourriel();
874
		miseAJourCourriel();
872
		var urlAnnuaire = SERVICE_ANNUAIRE + courriel;
875
		var urlAnnuaire = SERVICE_ANNUAIRE + courriel;
873
		$.ajax({
876
		$.ajax({
874
			url : urlAnnuaire,
877
			url : urlAnnuaire,
875
			type : 'GET',
878
			type : 'GET',
876
			success : function(data, textStatus, jqXHR) {
879
			success : function(data, textStatus, jqXHR) {
877
				console.log('Annuaire SUCCESS : ' + textStatus);
880
				console.log('Annuaire SUCCESS : ' + textStatus);
878
				if (data != undefined && data[courriel] != undefined) {
881
				if (data != undefined && data[courriel] != undefined) {
879
					var infos = data[courriel];
882
					var infos = data[courriel];
880
					$('#id-utilisateur').val(infos.id);
883
					$('#id-utilisateur').val(infos.id);
881
					$('#prenom-utilisateur').val(infos.prenom);
884
					$('#prenom-utilisateur').val(infos.prenom);
882
					$('#nom-utilisateur').val(infos.nom);
885
					$('#nom-utilisateur').val(infos.nom);
883
					$('#courriel-confirmation').val(courriel);
886
					$('#courriel-confirmation').val(courriel);
884
					$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').attr('disabled', 'disabled');
887
					$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').attr('disabled', 'disabled');
885
					
888
					
886
					if ($('#courriel-memoire').is(':checked')) {
889
					if ($('#courriel-memoire').is(':checked')) {
887
						bdd.setItem('utilisateur.prenom',  $("#prenom-utilisateur").val());
890
						bdd.setItem('utilisateur.prenom',  $("#prenom-utilisateur").val());
888
						bdd.setItem('utilisateur.nom',  $("#nom-utilisateur").val());
891
						bdd.setItem('utilisateur.nom',  $("#nom-utilisateur").val());
889
						bdd.setItem('utilisateur.id',  $("#id-utilisateur").val());
892
						bdd.setItem('utilisateur.id',  $("#id-utilisateur").val());
890
					}
893
					}
891
				} else {
894
				} else {
892
					surErreurCompletionCourriel();
895
					surErreurCompletionCourriel();
893
				}
896
				}
894
			},
897
			},
895
			error : function(jqXHR, textStatus, errorThrown) {
898
			error : function(jqXHR, textStatus, errorThrown) {
896
				console.log('Annuaire ERREUR : ' + textStatus);
899
				console.log('Annuaire ERREUR : ' + textStatus);
897
				surErreurCompletionCourriel();
900
				surErreurCompletionCourriel();
898
			},
901
			},
899
			complete : function(jqXHR, textStatus) {
902
			complete : function(jqXHR, textStatus) {
900
				console.log('Annuaire COMPLETE : ' + textStatus);
903
				console.log('Annuaire COMPLETE : ' + textStatus);
901
				$('#zone-prenom-nom').removeClass('hidden');
904
				$('#zone-prenom-nom').removeClass('hidden');
902
				$('#zone-courriel-confirmation').removeClass('hidden');
905
				$('#zone-courriel-confirmation').removeClass('hidden');
903
			}
906
			}
904
		});
907
		});
905
	}
908
	}
906
	
909
	
907
	event.preventDefault();
910
	event.preventDefault();
908
	event.stopPropagation();
911
	event.stopPropagation();
909
}
912
}
910
 
913
 
911
function validerCourriel(email) { 
914
function validerCourriel(email) { 
912
    var regex = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i),
915
    var regex = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i),
913
		flag = regex.test(email);
916
		flag = regex.test(email);
914
    
917
    
915
    console.log('Valid email ? (', email, ') : ', flag);
918
    console.log('Valid email ? (', email, ') : ', flag);
916
    return flag;
919
    return flag;
917
} 
920
} 
918
 
921
 
919
function miseAJourCourriel() {
922
function miseAJourCourriel() {
920
	if ($('#courriel-memoire').is(':checked')) {
923
	if ($('#courriel-memoire').is(':checked')) {
921
		bdd.setItem('utilisateur.courriel',  $("#courriel").val());
924
		bdd.setItem('utilisateur.courriel',  $("#courriel").val());
922
	}
925
	}
923
}
926
}
924
 
927
 
925
function surErreurCompletionCourriel() {
928
function surErreurCompletionCourriel() {
926
	$('#id-utilisateur').val('');
929
	$('#id-utilisateur').val('');
927
	$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').removeAttr('disabled');
930
	$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').removeAttr('disabled');
928
}
931
}