Subversion Repositories eFlore/Applications.cel

Rev

Rev 1720 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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