Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2697 Rev 2700
Line 8... Line 8...
8
	this.nbObsTransmises = 0;
8
	this.nbObsTransmises = 0;
9
	this.map = null;
9
	this.map = null;
10
	this.marker = null;
10
	this.marker = null;
11
	this.latLng = null;
11
	this.latLng = null;
12
	this.geocoder = null;
12
	this.geocoder = null;
-
 
13
	this.debug = null;
-
 
14
	this.html5 = null;
-
 
15
	this.tagProjet = null;
-
 
16
	this.tagImg = null;
-
 
17
	this.tagObs = null;
-
 
18
	this.separationTagImg = null;
-
 
19
	this.separationTagObs = null;
-
 
20
	this.obsId = null;
-
 
21
	this.serviceSaisieUrl = null;
-
 
22
	this.serviceObsUrl = null;
-
 
23
	this.nomSciReferentiel = null;
-
 
24
	this.especeImposee = null;
-
 
25
	this.infosEspeceImposee = null;
-
 
26
	this.autocompletionElementsNbre = null;
-
 
27
	this.referentielImpose = null;
-
 
28
	this.serviceAutocompletionNomSciUrl = null;
-
 
29
	this.serviceAutocompletionNomSciUrlTpl = null;
-
 
30
	this.obsMaxNbre = null;
-
 
31
	this.dureeMessage = null;
-
 
32
	this.serviceAnnuaireIdUrl = null;
-
 
33
	this.serviceNomCommuneUrl = null;
-
 
34
	this.serviceNomCommuneUrlAlt = null;
-
 
35
	this.googleMapMarqueurUrl = null;
-
 
36
	this.chargementIconeUrl = null;
-
 
37
	this.chargementImageIconeUrl = null;
-
 
38
	this.calendrierIconeUrl = null;
-
 
39
	this.pasDePhotoIconeUrl = null;
13
}
40
}
Line 14... Line 41...
14
 
41
 
15
/**
42
/**
16
 * Initialisation du widget
43
 * Initialisation du widget
Line 31... Line 58...
31
 
58
 
32
/**
59
/**
33
 * Initialise le formulaire, les validateurs, les listes de complétion...
60
 * Initialise le formulaire, les validateurs, les listes de complétion...
34
 */
61
 */
35
WidgetSaisie.prototype.initForm = function() {
62
WidgetSaisie.prototype.initForm = function() {
36
	if (OBS_ID != '') {
63
	if (this.obsId != '') {
37
		this.chargerInfoObs();
64
		this.chargerInfoObs();
Line 38... Line 65...
38
	}
65
	}
39
 
66
 
40
	this.configurerDatePicker();
67
	this.configurerDatePicker();
41
	this.ajouterAutocompletionNoms();
68
	this.ajouterAutocompletionNoms();
Line 42... Line 69...
42
	this.configurerFormValidator();
69
	this.configurerFormValidator();
43
	this.definirReglesFormValidator();
70
	this.definirReglesFormValidator();
44
 
71
 
45
	if(ESPECE_IMPOSEE) {
72
	if(this.especeImposee) {
46
		$("#taxon").attr("disabled", "disabled");
73
		$("#taxon").attr("disabled", "disabled");
47
		$("#taxon-input-groupe").attr("title","");
74
		$("#taxon-input-groupe").attr("title","");
48
		var infosAssociee = {
75
		var infosAssociee = {
49
			label : INFOS_ESPECE_IMPOSEE.nom_sci_complet,
76
			label : this.infosEspeceImposee.nom_sci_complet,
50
			value : INFOS_ESPECE_IMPOSEE.nom_sci_complet,
77
			value : this.infosEspeceImposee.nom_sci_complet,
51
			nt : INFOS_ESPECE_IMPOSEE.num_taxonomique,
78
			nt : this.infosEspeceImposee.num_taxonomique,
52
			nomSel : INFOS_ESPECE_IMPOSEE.nom_sci,
79
			nomSel : this.infosEspeceImposee.nom_sci,
53
			nomSelComplet : INFOS_ESPECE_IMPOSEE.nom_sci_complet,
80
			nomSelComplet : this.infosEspeceImposee.nom_sci_complet,
54
			numNomSel : INFOS_ESPECE_IMPOSEE.id,
81
			numNomSel : this.infosEspeceImposee.id,
55
			nomRet : INFOS_ESPECE_IMPOSEE["nom_retenu.libelle"],
82
			nomRet : this.infosEspeceImposee["nom_retenu.libelle"],
56
			numNomRet : INFOS_ESPECE_IMPOSEE["nom_retenu.id"],
83
			numNomRet : this.infosEspeceImposee["nom_retenu.id"],
57
			famille : INFOS_ESPECE_IMPOSEE.famille,
84
			famille : this.infosEspeceImposee.famille,
58
			retenu : (INFOS_ESPECE_IMPOSEE.retenu == 'false') ? false : true
85
			retenu : (this.infosEspeceImposee.retenu == 'false') ? false : true
59
		};
86
		};
Line 74... Line 101...
74
		var options = {
101
		var options = {
75
			success: lthis.afficherMiniature.bind(lthis), // post-submit callback
102
			success: lthis.afficherMiniature.bind(lthis), // post-submit callback
76
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
103
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
77
			resetForm: true // reset the form after successful submit
104
			resetForm: true // reset the form after successful submit
78
		};
105
		};
79
		$("#miniature").append('<img id="miniature-chargement" class="miniature" alt="chargement" src="'+CHARGEMENT_IMAGE_URL+'"/>');
106
		$("#miniature").append('<img id="miniature-chargement" class="miniature" alt="chargement" src="'+this.chargementImageIconeUrl+'"/>');
80
		$("#ajouter-obs").attr('disabled', 'disabled');
107
		$("#ajouter-obs").attr('disabled', 'disabled');
81
		if(lthis.verifierFormat($("#fichier").val())) {
108
		if(lthis.verifierFormat($("#fichier").val())) {
82
			$("#form-upload").ajaxSubmit(options);
109
			$("#form-upload").ajaxSubmit(options);
83
		} else {
110
		} else {
84
			$('#form-upload')[0].reset();
111
			$('#form-upload')[0].reset();
Line 114... Line 141...
114
	});
141
	});
115
	$("body").on('click', ".defilement-miniatures-droite", function(event) {
142
	$("body").on('click', ".defilement-miniatures-droite", function(event) {
116
		event.preventDefault();
143
		event.preventDefault();
117
		lthis.defilerMiniatures($(this));
144
		lthis.defilerMiniatures($(this));
118
	});
145
	});
-
 
146
 
-
 
147
	// fermeture fenêtre
-
 
148
	if (this.debug == false) {
-
 
149
		$(window).on('beforeunload', function(event) {
-
 
150
			return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.';
-
 
151
		});
-
 
152
	}
119
}
153
}
Line 120... Line 154...
120
 
154
 
121
/**
155
/**
122
 * Retourne true si l'extension de l'image "nom" est .jpg ou .jpeg
156
 * Retourne true si l'extension de l'image "nom" est .jpg ou .jpeg
Line 129... Line 163...
129
 
163
 
130
/**
164
/**
131
 * Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
165
 * Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
132
 */
166
 */
133
WidgetSaisie.prototype.afficherMiniature = function(reponse) {
167
WidgetSaisie.prototype.afficherMiniature = function(reponse) {
134
	if (DEBUG) {
168
	if (this.debug) {
135
		var debogage = $("debogage", reponse).text();
169
		var debogage = $("debogage", reponse).text();
136
		//console.log("Débogage upload : "+debogage);
170
		//console.log("Débogage upload : "+debogage);
137
	}
171
	}
138
	var message = $("message", reponse).text();
172
	var message = $("message", reponse).text();
Line 173... Line 207...
173
	var geocoderOptions = {
207
	var geocoderOptions = {
174
	},
208
	},
175
	addressSuffix = '',
209
	addressSuffix = '',
176
	lthis = this;
210
	lthis = this;
Line 177... Line 211...
177
 
211
 
178
	switch(NOM_SCI_REFERENTIEL) {
212
	switch(this.nomSciReferentiel) {
179
		case 'isfan':
213
		case 'isfan':
180
			// Si des résultats se trouvent dans ce rectangle, ils apparaîtront en premier.
214
			// Si des résultats se trouvent dans ce rectangle, ils apparaîtront en premier.
181
			// Ça marche moyen...
215
			// Ça marche moyen...
182
			geocoderOptions.bounds = new google.maps.LatLngBounds(
216
			geocoderOptions.bounds = new google.maps.LatLngBounds(
Line 237... Line 271...
237
		}
271
		}
238
	});
272
	});
239
};
273
};
Line 240... Line 274...
240
 
274
 
241
WidgetSaisie.prototype.afficherErreurGoogleMap = function(status) {
275
WidgetSaisie.prototype.afficherErreurGoogleMap = function(status) {
242
	if (DEBUG) {
276
	if (this.debug) {
243
		$('#dialogue-google-map .contenu').empty().append(
277
		$('#dialogue-google-map .contenu').empty().append(
244
			'<pre class="msg-erreur">'+
278
			'<pre class="msg-erreur">'+
245
			"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
279
			"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
246
			'</pre>');
280
			'</pre>');
247
		afficherPanneau('#dialogue-google-map');
281
		this.afficherPanneau('#dialogue-google-map');
248
	}
282
	}
Line 249... Line 283...
249
};
283
};
250
 
284
 
Line 269... Line 303...
269
 
303
 
270
WidgetSaisie.prototype.initialiserGoogleMap = function() {
304
WidgetSaisie.prototype.initialiserGoogleMap = function() {
271
	var latLng,
305
	var latLng,
272
		zoomDefaut;
306
		zoomDefaut;
273
	// Carte @TODO mettre ça dans la config
307
	// Carte @TODO mettre ça dans la config
274
	if(NOM_SCI_REFERENTIEL == 'bdtre') {
308
	if(this.nomSciReferentiel == 'bdtre') {
275
		latLng = new google.maps.LatLng(-21.10, 55.30);// Réunion
309
		latLng = new google.maps.LatLng(-21.10, 55.30);// Réunion
276
		zoomDefaut = 7;
310
		zoomDefaut = 7;
277
	} else if(NOM_SCI_REFERENTIEL == 'lbf') {
311
	} else if(this.nomSciReferentiel == 'lbf') {
278
		latLng = new google.maps.LatLng(33.72211, 35.8603);// Liban
312
		latLng = new google.maps.LatLng(33.72211, 35.8603);// Liban
279
		zoomDefaut = 7;
313
		zoomDefaut = 7;
280
	} else if(NOM_SCI_REFERENTIEL == 'bdtxa') {
314
	} else if(this.nomSciReferentiel == 'bdtxa') {
281
		latLng = new google.maps.LatLng(14.6, -61.08334);// Fort-De-France
315
		latLng = new google.maps.LatLng(14.6, -61.08334);// Fort-De-France
282
		zoomDefaut = 8;
316
		zoomDefaut = 8;
283
	} else if(NOM_SCI_REFERENTIEL == 'isfan') {
317
	} else if(this.nomSciReferentiel == 'isfan') {
284
		latLng = new google.maps.LatLng(29.28358, 10.21884);// Afrique du Nord
318
		latLng = new google.maps.LatLng(29.28358, 10.21884);// Afrique du Nord
285
		zoomDefaut = 4;
319
		zoomDefaut = 4;
286
	} else if(NOM_SCI_REFERENTIEL == 'apd') {
320
	} else if(this.nomSciReferentiel == 'apd') {
287
		latLng = new google.maps.LatLng(8.75624, 1.80176);// Afrique de l'Ouest et du Centre
321
		latLng = new google.maps.LatLng(8.75624, 1.80176);// Afrique de l'Ouest et du Centre
288
		zoomDefaut = 4;
322
		zoomDefaut = 4;
289
	} else {
323
	} else {
290
		latLng = new google.maps.LatLng(46.30871, 2.54395);// Centre de la France
324
		latLng = new google.maps.LatLng(46.30871, 2.54395);// Centre de la France
Line 322... Line 356...
322
	// Marqueur google draggable
356
	// Marqueur google draggable
323
	this.marker = new google.maps.Marker({
357
	this.marker = new google.maps.Marker({
324
		map: this.map,
358
		map: this.map,
325
		draggable: true,
359
		draggable: true,
326
		title: 'Ma station',
360
		title: 'Ma station',
327
		icon: GOOGLE_MAP_MARQUEUR_URL,
361
		icon: this.googleMapMarqueurUrl,
328
		position: latLng
362
		position: latLng
329
	});
363
	});
Line 330... Line 364...
330
 
364
 
Line 378... Line 412...
378
	var lng = Math.round(lngDecimale * 100000) / 100000;
412
	var lng = Math.round(lngDecimale * 100000) / 100000;
379
	$('#longitude').val(lng);
413
	$('#longitude').val(lng);
380
};
414
};
Line 381... Line 415...
381
 
415
 
-
 
416
WidgetSaisie.prototype.trouverCommune = function(pos) {
382
WidgetSaisie.prototype.trouverCommune = function(pos) {
417
	var lthis = this;
Line 383... Line 418...
383
	$(function() {
418
	$(function() {
Line 384... Line 419...
384
 
419
 
385
		var url_service = SERVICE_NOM_COMMUNE_URL;
420
		var url_service = lthis.serviceNomCommuneUrl;
386
 
421
 
387
		var urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
422
		var urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
Line 399... Line 434...
399
				$("#commune-code-insee").append(data.codeINSEE);
434
				$("#commune-code-insee").append(data.codeINSEE);
400
				$("#marqueur-commune").data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
435
				$("#marqueur-commune").data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
401
			},
436
			},
402
			statusCode : {
437
			statusCode : {
403
			    500 : function(jqXHR, textStatus, errorThrown) {
438
			    500 : function(jqXHR, textStatus, errorThrown) {
404
					if (DEBUG) {
439
					if (this.debug) {
405
						$("#dialogue-erreur .alert-txt").append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissante le nom des communes.</p>');
440
						$("#dialogue-erreur .alert-txt").append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissante le nom des communes.</p>');
406
						reponse = jQuery.parseJSON(jqXHR.responseText);
441
						reponse = jQuery.parseJSON(jqXHR.responseText);
407
						var erreurMsg = "";
442
						var erreurMsg = "";
408
						if (reponse != null) {
443
						if (reponse != null) {
409
							$.each(reponse, function (cle, valeur) {
444
							$.each(reponse, function (cle, valeur) {
Line 414... Line 449...
414
						$("#dialogue-erreur .alert-txt").append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
449
						$("#dialogue-erreur .alert-txt").append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
415
					}
450
					}
416
			    }
451
			    }
417
			},
452
			},
418
			error : function(jqXHR, textStatus, errorThrown) {
453
			error : function(jqXHR, textStatus, errorThrown) {
419
				if (DEBUG) {
454
				if (this.debug) {
420
					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
455
					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
421
					reponse = jQuery.parseJSON(jqXHR.responseText);
456
					reponse = jQuery.parseJSON(jqXHR.responseText);
422
					var erreurMsg = "";
457
					var erreurMsg = "";
423
					if (reponse != null) {
458
					if (reponse != null) {
424
						$.each(reponse, function (cle, valeur) {
459
						$.each(reponse, function (cle, valeur) {
Line 430... Line 465...
430
				}
465
				}
431
			},
466
			},
432
			complete : function(jqXHR, textStatus) {
467
			complete : function(jqXHR, textStatus) {
433
				var debugMsg = extraireEnteteDebug(jqXHR);
468
				var debugMsg = extraireEnteteDebug(jqXHR);
434
				if (debugMsg != '') {
469
				if (debugMsg != '') {
435
					if (DEBUG) {
470
					if (this.debug) {
436
						$("#dialogue-erreur .alert-txt").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
471
						$("#dialogue-erreur .alert-txt").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
437
					}
472
					}
438
				}
473
				}
439
				if ($("#dialogue-erreur .msg").length > 0) {
474
				if ($("#dialogue-erreur .msg").length > 0) {
440
					$("#dialogue-erreur").show();
475
					$("#dialogue-erreur").show();
Line 454... Line 489...
454
 
489
 
455
WidgetSaisie.prototype.requeterIdentite = function() {
490
WidgetSaisie.prototype.requeterIdentite = function() {
456
	var lthis = this;
491
	var lthis = this;
457
	var courriel = $("#courriel").val();
492
	var courriel = $("#courriel").val();
458
	//TODO: mettre ceci en paramètre de config
493
	//TODO: mettre ceci en paramètre de config
459
	var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL+courriel;//http://localhost/applications/annuaire/jrest/
494
	var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;//http://localhost/applications/annuaire/jrest/
460
	$.ajax({
495
	$.ajax({
461
		url : urlAnnuaire,
496
		url : urlAnnuaire,
462
		type : "GET",
497
		type : "GET",
463
		success : function(data, textStatus, jqXHR) {
498
		success : function(data, textStatus, jqXHR) {
Line 488... Line 523...
488
};
523
};
Line 489... Line 524...
489
 
524
 
490
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
525
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
491
	$("#prenom, #nom, #courriel_confirmation").val('');
526
	$("#prenom, #nom, #courriel_confirmation").val('');
492
	$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
527
	$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
493
	afficherPanneau("#dialogue-courriel-introuvable");
528
	this.afficherPanneau("#dialogue-courriel-introuvable");
494
};
529
};
495
//+---------------------------------------------------------------------------------------------------------+
530
//+---------------------------------------------------------------------------------------------------------+
Line 496... Line 531...
496
//FORMULAIRE
531
//FORMULAIRE
497
 
532
 
498
WidgetSaisie.prototype.chargerInfoObs = function() {
533
WidgetSaisie.prototype.chargerInfoObs = function() {
499
	var urlObs = SERVICE_OBS_URL + '/' + OBS_ID;
534
	var urlObs = this.serviceObsUrl + '/' + this.obsId;
500
	$.ajax({
535
	$.ajax({
501
		url: urlObs,
536
		url: urlObs,
502
		type: 'GET',
537
		type: 'GET',
Line 610... Line 645...
610
	$("#date").datepicker({
645
	$("#date").datepicker({
611
		dateFormat: "dd/mm/yy",
646
		dateFormat: "dd/mm/yy",
612
		maxDate: new Date,
647
		maxDate: new Date,
613
		showOn: "button",
648
		showOn: "button",
614
		buttonImageOnly: true,
649
		buttonImageOnly: true,
615
		buttonImage: CALENDRIER_ICONE_URL,
650
		buttonImage: this.calendrierIconeUrl,
616
		buttonText: "Afficher le calendrier pour saisir la date.",
651
		buttonText: "Afficher le calendrier pour saisir la date.",
617
		showButtonPanel: true
652
		showButtonPanel: true
618
	});
653
	});
619
	$("img.ui-datepicker-trigger").appendTo("#date-icone");
654
	$("img.ui-datepicker-trigger").appendTo("#date-icone");
620
};
655
};
Line 660... Line 695...
660
		$('#btn-aide-txt', this).text("Activer l'aide");
695
		$('#btn-aide-txt', this).text("Activer l'aide");
661
	}
696
	}
662
};
697
};
Line 663... Line 698...
663
 
698
 
664
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
699
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
665
	afficherPanneau("#dialogue-bloquer-copier-coller");
700
	this.afficherPanneau("#dialogue-bloquer-copier-coller");
666
	return false;
701
	return false;
Line 667... Line 702...
667
};
702
};
668
 
703
 
Line 682... Line 717...
682
		$(".obs-nbre").text(this.obsNbre);
717
		$(".obs-nbre").text(this.obsNbre);
683
		$(".obs-nbre").triggerHandler('changement');
718
		$(".obs-nbre").triggerHandler('changement');
684
		this.afficherObs();
719
		this.afficherObs();
685
		this.stockerObsData();
720
		this.stockerObsData();
686
		this.supprimerMiniatures();
721
		this.supprimerMiniatures();
687
		if(!ESPECE_IMPOSEE) {
722
		if(! this.especeImposee) {
688
			$("#taxon").val("");
723
			$("#taxon").val("");
689
			$("#taxon").data("numNomSel",undefined);
724
			$("#taxon").data("numNomSel",undefined);
690
		}
725
		}
691
		$('#barre-progression-upload').attr('aria-valuemax', this.obsNbre);
726
		$('#barre-progression-upload').attr('aria-valuemax', this.obsNbre);
692
		$('#barre-progression-upload .sr-only').text('0/'+this.obsNbre+" observations transmises");
727
		$('#barre-progression-upload .sr-only').text('0/'+this.obsNbre+" observations transmises");
693
	} else {
728
	} else {
694
		afficherPanneau('#dialogue-form-invalide');
729
		this.afficherPanneau('#dialogue-form-invalide');
695
	}
730
	}
696
};
731
};
Line 697... Line 732...
697
 
732
 
698
/**
733
/**
Line 716... Line 751...
716
						'<div class="span9">'+
751
						'<div class="span9">'+
717
							'<ul class="unstyled">'+
752
							'<ul class="unstyled">'+
718
								'<li>'+
753
								'<li>'+
719
									'<span class="nom-sci">'+$("#taxon").val()+'</span> '+
754
									'<span class="nom-sci">'+$("#taxon").val()+'</span> '+
720
									this.ajouterNumNomSel()+'<span class="referentiel-obs">'+
755
									this.ajouterNumNomSel()+'<span class="referentiel-obs">'+
721
									($("#taxon").data("numNomSel") == undefined ? '' : '['+NOM_SCI_REFERENTIEL+']')+'</span>'+
756
									($("#taxon").data("numNomSel") == undefined ? '' : '['+ this.nomSciReferentiel +']')+'</span>'+
722
									' observé à '+
757
									' observé à '+
723
									'<span class="commune">'+$('#commune-nom').text()+'</span> '+
758
									'<span class="commune">'+$('#commune-nom').text()+'</span> '+
724
									'('+$('#commune-code-insee').text()+') ['+$("#latitude").val()+' / '+$("#longitude").val()+']'+
759
									'('+$('#commune-code-insee').text()+') ['+$("#latitude").val()+' / '+$("#longitude").val()+']'+
725
									' le '+
760
									' le '+
726
									'<span class="date">'+$("#date").val()+'</span>'+
761
									'<span class="date">'+$("#date").val()+'</span>'+
Line 751... Line 786...
751
		'num_nom_sel' : $("#taxon").data("numNomSel"),
786
		'num_nom_sel' : $("#taxon").data("numNomSel"),
752
		'nom_ret' : $("#taxon").data("nomRet"),
787
		'nom_ret' : $("#taxon").data("nomRet"),
753
		'num_nom_ret' : $("#taxon").data("numNomRet"),
788
		'num_nom_ret' : $("#taxon").data("numNomRet"),
754
		'num_taxon' : $("#taxon").data("nt"),
789
		'num_taxon' : $("#taxon").data("nt"),
755
		'famille' : $("#taxon").data("famille"),
790
		'famille' : $("#taxon").data("famille"),
756
		'referentiel' : ($("#taxon").data("numNomSel") == undefined ? '' : NOM_SCI_REFERENTIEL),
791
		'referentiel' : ($("#taxon").data("numNomSel") == undefined ? '' : lthis.nomSciReferentiel),
Line 757... Line 792...
757
 
792
 
758
		'latitude' : $("#latitude").val(),
793
		'latitude' : $("#latitude").val(),
759
		'longitude' : $("#longitude").val(),
794
		'longitude' : $("#longitude").val(),
760
		'commune_nom' : $("#commune-nom").text(),
795
		'commune_nom' : $("#commune-nom").text(),
Line 768... Line 803...
768
		'image_b64' : lthis.getB64ImgsOriginales()
803
		'image_b64' : lthis.getB64ImgsOriginales()
769
	});
804
	});
770
};
805
};
Line 771... Line 806...
771
 
806
 
772
WidgetSaisie.prototype.surChangementReferentiel = function() {
807
WidgetSaisie.prototype.surChangementReferentiel = function() {
773
	NOM_SCI_REFERENTIEL = $('#referentiel').val();
808
	this.nomSciReferentiel = $('#referentiel').val();
774
	$('#taxon').val('');
809
	$('#taxon').val('');
775
	this.initialiserAutocompleteCommune();
810
	this.initialiserAutocompleteCommune();
776
	this.initialiserGoogleMap();
811
	this.initialiserGoogleMap();
Line 777... Line 812...
777
};
812
};
778
 
813
 
779
WidgetSaisie.prototype.surChangementNbreObs = function() {
814
WidgetSaisie.prototype.surChangementNbreObs = function() {
780
	if (this.obsNbre == 0) {
815
	if (this.obsNbre == 0) {
781
		$("#transmettre-obs").attr('disabled', 'disabled');
816
		$("#transmettre-obs").attr('disabled', 'disabled');
782
		$("#ajouter-obs").removeAttr('disabled');
817
		$("#ajouter-obs").removeAttr('disabled');
783
	} else if (this.obsNbre > 0 && this.obsNbre < OBS_MAX_NBRE) {
818
	} else if (this.obsNbre > 0 && this.obsNbre < this.obsMaxNbre) {
784
		$("#transmettre-obs").removeAttr('disabled');
819
		$("#transmettre-obs").removeAttr('disabled');
785
		$("#ajouter-obs").removeAttr('disabled');
820
		$("#ajouter-obs").removeAttr('disabled');
786
	} else if (this.obsNbre >= OBS_MAX_NBRE) {
821
	} else if (this.obsNbre >= this.obsMaxNbre) {
787
		$("#ajouter-obs").attr('disabled', 'disabled');
822
		$("#ajouter-obs").attr('disabled', 'disabled');
788
		afficherPanneau("#dialogue-bloquer-creer-obs");
823
		this.afficherPanneau("#dialogue-bloquer-creer-obs");
Line 789... Line 824...
789
	}
824
	}
790
};
825
};
791
 
826
 
792
WidgetSaisie.prototype.transmettreObs = function() {
827
WidgetSaisie.prototype.transmettreObs = function() {
793
	var observations = $("#liste-obs").data();
828
	var observations = $("#liste-obs").data();
794
	if (observations == undefined || jQuery.isEmptyObject(observations)) {
829
	if (observations == undefined || jQuery.isEmptyObject(observations)) {
795
		afficherPanneau("#dialogue-zero-obs");
830
		this.afficherPanneau("#dialogue-zero-obs");
796
	} else {
831
	} else {
797
		this.nbObsEnCours = 1;
832
		this.nbObsEnCours = 1;
Line 809... Line 844...
809
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
844
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
810
	// TODO: utiliser var.keys quand ça sera plus répandu
845
	// TODO: utiliser var.keys quand ça sera plus répandu
811
	// ou bien utiliser un vrai tableau et pas un objet
846
	// ou bien utiliser un vrai tableau et pas un objet
812
	for (var obsNum in observations) {
847
	for (var obsNum in observations) {
813
		var obsATransmettre = {
848
		var obsATransmettre = {
814
			'projet' : TAG_PROJET,
849
			'projet' : this.tagProjet,
815
			'tag-obs' : TAG_OBS,
850
			'tag-obs' : this.tagObs,
816
			'tag-img' : TAG_IMG
851
			'tag-img' : this.tagImg
817
		};
852
		};
818
		var utilisateur = {
853
		var utilisateur = {
819
			id_utilisateur : $("#id_utilisateur").val(),
854
			id_utilisateur : $("#id_utilisateur").val(),
820
			prenom : $("#prenom").val(),
855
			prenom : $("#prenom").val(),
821
			nom : $("#nom").val(),
856
			nom : $("#nom").val(),
Line 828... Line 863...
828
			this.envoyerObsAuCel(idObsNumerique, obsATransmettre);
863
			this.envoyerObsAuCel(idObsNumerique, obsATransmettre);
829
		}
864
		}
Line 830... Line 865...
830
 
865
 
831
		break;
866
		break;
-
 
867
	}
832
	}
868
	$('#zone-liste-obs').addClass("hidden");
Line 833... Line 869...
833
};
869
};
834
 
870
 
835
WidgetSaisie.prototype.mettreAJourProgression = function() {
871
WidgetSaisie.prototype.mettreAJourProgression = function() {
Line 847... Line 883...
847
 
883
 
848
WidgetSaisie.prototype.envoyerObsAuCel = function(idObs, observation) {
884
WidgetSaisie.prototype.envoyerObsAuCel = function(idObs, observation) {
849
	var lthis = this;
885
	var lthis = this;
850
	var erreurMsg = "";
886
	var erreurMsg = "";
851
	$.ajax({
887
	$.ajax({
852
		url : SERVICE_SAISIE_URL,
888
		url : lthis.serviceSaisieUrl,
853
		type : "POST",
889
		type : "POST",
854
		data : observation,
890
		data : observation,
855
		dataType : "json",
891
		dataType : "json",
856
		beforeSend : function() {
892
		beforeSend : function() {
Line 861... Line 897...
861
		},
897
		},
862
		success : function(data, textStatus, jqXHR) {
898
		success : function(data, textStatus, jqXHR) {
863
			// mise à jour du nombre d'obs à transmettre
899
			// mise à jour du nombre d'obs à transmettre
864
			// et suppression de l'obs
900
			// et suppression de l'obs
865
			lthis.supprimerObsParId(idObs);
901
			lthis.supprimerObsParId(idObs);
866
			this.nbObsEnCours++;
902
			lthis.nbObsEnCours++;
867
			// mise à jour du statut
903
			// mise à jour du statut
868
			lthis.mettreAJourProgression();
904
			lthis.mettreAJourProgression();
869
			if(this.obsNbre > 0) {
905
			if(lthis.obsNbre > 0) {
870
				// dépilement de la suivante
906
				// dépilement de la suivante
871
				lthis.depilerObsPourEnvoi();
907
				lthis.depilerObsPourEnvoi();
872
			}
908
			}
873
		},
909
		},
874
		statusCode : {
910
		statusCode : {
Line 884... Line 920...
884
					$.each(reponse, function (cle, valeur) {
920
					$.each(reponse, function (cle, valeur) {
885
						erreurMsg += valeur + "\n";
921
						erreurMsg += valeur + "\n";
886
					});
922
					});
887
				}
923
				}
888
			} catch(e) {
924
			} catch(e) {
889
				erreurMsg += "L'erreur n'était pas en JSON.";
925
				erreurMsg += "Erreur inconnue: " + jqXHR.responseText;
890
			}
926
			}
891
		},
927
		},
892
		complete : function(jqXHR, textStatus) {
928
		complete : function(jqXHR, textStatus) {
893
			var debugMsg = extraireEnteteDebug(jqXHR);
929
			var debugMsg = extraireEnteteDebug(jqXHR);
Line 894... Line 930...
894
 
930
 
895
			if (erreurMsg != '') {
931
			if (erreurMsg != '') {
896
				if (DEBUG) {
932
				if (this.debug) {
897
					$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
933
					$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
898
					$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
934
					$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
899
				}
935
				}
900
				var hrefCourriel = "mailto:cel_remarques@tela-botanica.org?"+
936
				var hrefCourriel = "mailto:cel_remarques@tela-botanica.org?"+
901
					"subject=Dysfonctionnement du widget de saisie "+TAG_PROJET+
937
					"subject=Dysfonctionnement du widget de saisie "+ this.tagProjet +
Line 902... Line 938...
902
					"&body="+erreurMsg+"%0D%0ADébogage :%0D%0A"+debugMsg;
938
					"&body="+erreurMsg+"%0D%0ADébogage :%0D%0A"+debugMsg;
903
 
939
 
904
				// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
940
				// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
Line 912... Line 948...
912
					.html());
948
					.html());
913
				$("#dialogue-obs-transaction-ko").show();
949
				$("#dialogue-obs-transaction-ko").show();
914
				$("#chargement").hide();
950
				$("#chargement").hide();
915
				lthis.initialiserBarreProgression();
951
				lthis.initialiserBarreProgression();
916
			} else {
952
			} else {
917
				if (DEBUG) {
953
				if (lthis.debug) {
918
					$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
954
					$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
919
				}
955
				}
920
				if(this.obsNbre == 0) {
956
				if(lthis.obsNbre == 0) {
921
					setTimeout(function() {
957
					setTimeout(function() {
922
						$("#chargement").hide();
958
						$("#chargement").hide();
923
						$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
959
						$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
924
						$("#dialogue-obs-transaction-ok").show();
960
						$("#dialogue-obs-transaction-ok").show();
925
						window.location.hash = "dialogue-obs-transaction-ok";
961
						window.location.hash = "dialogue-obs-transaction-ok";
Line 1023... Line 1059...
1023
				'<a href="#" class="defilement-miniatures-gauche '+visible+'">&#60;</a>'+
1059
				'<a href="#" class="defilement-miniatures-gauche '+visible+'">&#60;</a>'+
1024
				miniatures+
1060
				miniatures+
1025
				'<a href="#" class="defilement-miniatures-droite '+visible+'">&#62;</a>'+
1061
				'<a href="#" class="defilement-miniatures-droite '+visible+'">&#62;</a>'+
1026
			'</div>';
1062
			'</div>';
1027
	} else {
1063
	} else {
1028
		html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
1064
		html = '<img class="miniature" alt="Aucune photo"src="'+ this.pasDePhotoIconeUrl +'" />';
1029
	}
1065
	}
1030
	return html;
1066
	return html;
1031
};
1067
};
Line 1032... Line 1068...
1032
 
1068
 
Line 1092... Line 1128...
1092
	});
1128
	});
1093
};
1129
};
Line 1094... Line 1130...
1094
 
1130
 
1095
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
1131
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
1096
	var mots = $('#taxon').val();
1132
	var mots = $('#taxon').val();
1097
	var url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_REFERENTIEL);
1133
	var url = this.serviceAutocompletionNomSciUrlTpl.replace('{referentiel}', this.nomSciReferentiel);
1098
	url = url.replace('{masque}', mots);
1134
	url = url.replace('{masque}', mots);
1099
	return url;
1135
	return url;
Line 1100... Line 1136...
1100
};
1136
};
Line 1105... Line 1141...
1105
		$.each(data.resultat, function(i, val) {
1141
		$.each(data.resultat, function(i, val) {
1106
			val.nn = i;
1142
			val.nn = i;
1107
			var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '',
1143
			var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '',
1108
				nomRet : '', numNomRet : '', famille : '', retenu : false
1144
				nomRet : '', numNomRet : '', famille : '', retenu : false
1109
			};
1145
			};
1110
			if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
1146
			if (suggestions.length >= this.autocompletionElementsNbre) {
1111
				nom.label = "...";
1147
				nom.label = "...";
1112
				nom.value = $('#taxon').val();
1148
				nom.value = $('#taxon').val();
1113
				suggestions.push(nom);
1149
				suggestions.push(nom);
1114
				return false;
1150
				return false;
1115
			} else {
1151
			} else {
Line 1132... Line 1168...
1132
	}
1168
	}
Line 1133... Line 1169...
1133
 
1169
 
1134
	return suggestions;
1170
	return suggestions;
Line -... Line 1171...
-
 
1171
};
-
 
1172
 
-
 
1173
WidgetSaisie.prototype.afficherPanneau = function(selecteur) {
-
 
1174
	$(selecteur).fadeIn("slow").delay(this.dureeMessage).fadeOut("slow");
1135
};
1175
}
Line 1136... Line 1176...
1136
 
1176
 
1137
// lib hors objet --
1177
// lib hors objet --
1138
 
1178
 
Line 1166... Line 1206...
1166
		}
1206
		}
1167
	}
1207
	}
1168
	return msgDebug;
1208
	return msgDebug;
1169
}
1209
}
Line 1170... Line -...
1170
 
-
 
1171
function afficherPanneau(selecteur) {
-
 
1172
	$(selecteur).fadeIn("slow").delay(DUREE_MESSAGE).fadeOut("slow");
-
 
1173
}
-
 
1174
 
1210
 
1175
/*
1211
/*
1176
 * jQuery UI Autocomplete HTML Extension
1212
 * jQuery UI Autocomplete HTML Extension
1177
 *
1213
 *
1178
 * Copyright 2010, Scott González (http://scottgonzalez.com)
1214
 * Copyright 2010, Scott González (http://scottgonzalez.com)