Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1826 Rev 1829
Line 16... Line 16...
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 decodeURIComponent(results[1]) || 0;
21
	return (results == null) ? 0 : decodeURIComponent(results[1]);
22
}
22
}
23
function recupererParametresUrl() {
23
function recupererParametresUrl() {
24
	$('#referentiel').val($.urlParam('ref'));
24
	$('#referentiel').val(($.urlParam('ref') == 0) ? NOM_SCI_REFERENTIEL : $.urlParam('ref'));
25
	$('#nom').html($.urlParam('nom_sci'));
25
	$('#nom').html(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));
26
	$('#nom-sci-select').val($.urlParam('nom_sci'));
26
	$('#nom-sci-select').val(($.urlParam('nom_sci') == 0) ? '' : $.urlParam('nom_sci'));
27
	$('#num-nom-select').val($.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);
Line 31... Line 31...
31
	
31
	
Line 122... Line 122...
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('not supported');
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';
Line 134... Line 134...
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.transaction) {
147
db.transaction(function(tx) {
148
	db.transaction(function(tx) {
148
   //tx.executeSql('DROP TABLE IMG');
149
		//tx.executeSql('DROP TABLE IMG');
149
   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)');
150
});
151
	});
-
 
152
}
Line 151... Line 153...
151
 
153
 
152
console.log(bdd);
154
console.log(bdd);
153
function ajouterObs(event) {
155
function ajouterObs(event) {
154
	if ($('#nom').html() != '') {
156
	if ($('#nom').html() != '') {
Line 184... Line 186...
184
		sauvegarderObs(cle, obs);
186
		sauvegarderObs(cle, obs);
185
		bdd.setItem('index_obs', index_obs);
187
		bdd.setItem('index_obs', index_obs);
186
		effacerFormulaire();
188
		effacerFormulaire();
187
		changerPage('#liste', event);
189
		changerPage('#liste', event);
188
	} else {
190
	} else {
-
 
191
		var txt = 'Aucune espèce saisie !';
-
 
192
		$('#obs-saisie-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>')
-
 
193
			.fadeIn(0)
-
 
194
			.delay(1600)
-
 
195
			.fadeOut('slow');
189
		changerPage('#saisie', event);
196
		changerPage('#saisie', event);
190
	}
197
	}
191
}
198
}
Line 192... Line 199...
192
 
199
 
Line 234... Line 241...
234
function supprimerObs(data) {
241
function supprimerObs(data) {
235
	var cle_obs = data.getAttribute('data-obs-num'),
242
	var cle_obs = data.getAttribute('data-obs-num'),
236
		obs = JSON.parse(bdd.getItem(cle_obs)),
243
		obs = JSON.parse(bdd.getItem(cle_obs)),
237
		nbre = bdd.length,
244
		nbre = bdd.length,
238
		a_supprimer = new Array();
245
		a_supprimer = new Array();
239
		
246
	
-
 
247
	if (db.transaction) {
240
	db.transaction(function(tx) {
248
		db.transaction(function(tx) {
241
		tx.executeSql('DELETE FROM IMG WHERE parent LIKE ?', [cle_obs]);
249
			tx.executeSql('DELETE FROM IMG WHERE parent LIKE ?', [cle_obs]);
242
	});
250
		});
-
 
251
	}
243
	bdd.removeItem(cle_obs);
252
	bdd.removeItem(cle_obs);
Line 244... Line 253...
244
	
253
	
245
	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.';
246
	$('#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>')
Line 250... Line 259...
250
	
259
	
251
	chargerListeObs();
260
	chargerListeObs();
Line 252... Line 261...
252
}
261
}
-
 
262
 
253
 
263
function detailsObs(data) {
254
function detailsObs(data) {
264
	if (db.transaction) {
255
	var num_obs = data.getAttribute('data-obs-num');
265
		var num_obs = data.getAttribute('data-obs-num');
256
	var obs = JSON.parse(bdd.getItem(num_obs));
266
		var obs = JSON.parse(bdd.getItem(num_obs));
257
	$('#id-obs').html(obs.num);
267
		$('#id-obs').html(obs.num);
258
	
268
		
259
	var texte = '<strong>' + obs.nom + '</strong> vue le ' + obs.date;
269
		var texte = '<strong>' + obs.nom + '</strong> vue le ' + obs.date;
260
	texte += (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') ? '' :  ' à ' + obs.commune;
270
		texte += (obs.commune == TEXTE_HORS_LIGNE ||  obs.commune == '') ? '' :  ' à ' + obs.commune;
261
	$('#details-obs').html(texte);
271
		$('#details-obs').html(texte);
-
 
272
		$.mobile.changePage('#observation');
-
 
273
		afficherPhotos(obs.num);
-
 
274
	} else {
-
 
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>')
-
 
277
			.fadeIn(0)
-
 
278
			.delay(1600)
262
	$.mobile.changePage('#observation');
279
			.fadeOut('slow');
Line 263... Line 280...
263
	afficherPhotos(obs.num);
280
	}
264
}
281
}
265
 
282
 
Line 731... Line 748...
731
	});
748
	});
732
}
749
}
Line 733... Line 750...
733
 
750
 
734
 
751
 
735
function envoyerObsAuCel(observations) {
-
 
736
	console.log(observations);
752
function envoyerObsAuCel(observations) {
737
/*
753
	//console.log(observations);
738
	var erreurMsg = "";
754
	var erreurMsg = "";
739
	$.ajax({
755
	$.ajax({
740
		url : SERVICE_SAISIE_URL,
756
		url : SERVICE_SAISIE_URL,
Line 768... Line 784...
768
		complete : function(jqXHR, textStatus) {
784
		complete : function(jqXHR, textStatus) {
769
			console.log('complete');
785
			console.log('complete');
770
			console.log(jqXHR);
786
			console.log(jqXHR);
771
		}
787
		}
772
	});
788
	});
773
//*/
-
 
774
}
789
}
Line 775... Line 790...
775
 
790
 
776
//+---------------------------------------------------------------------------------------------------------+
791
//+---------------------------------------------------------------------------------------------------------+
777
//IDENTITÉ
792
//IDENTITÉ