Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2706 Rev 2707
Line 19... Line 19...
19
	this.separationTagObs = null;
19
	this.separationTagObs = null;
20
	this.obsId = null;
20
	this.obsId = null;
21
	this.serviceSaisieUrl = null;
21
	this.serviceSaisieUrl = null;
22
	this.serviceObsUrl = null;
22
	this.serviceObsUrl = null;
23
	this.nomSciReferentiel = null;
23
	this.nomSciReferentiel = null;
24
	this.especeImposee = null;
24
	this.especeImposee = false;
25
	this.infosEspeceImposee = null;
25
	this.infosEspeceImposee = null;
26
	this.autocompletionElementsNbre = null;
26
	this.autocompletionElementsNbre = null;
27
	this.referentielImpose = null;
27
	this.referentielImpose = null;
28
	this.serviceAutocompletionNomSciUrl = null;
28
	this.serviceAutocompletionNomSciUrl = null;
29
	this.serviceAutocompletionNomSciUrlTpl = null;
29
	this.serviceAutocompletionNomSciUrlTpl = null;
Line 44... Line 44...
44
 */
44
 */
45
WidgetSaisie.prototype.init = function() {
45
WidgetSaisie.prototype.init = function() {
46
	this.initCarto();
46
	this.initCarto();
47
	this.initForm();
47
	this.initForm();
48
	this.initEvts();
48
	this.initEvts();
-
 
49
	this.requeterIdentite();
49
};
50
};
Line 50... Line 51...
50
 
51
 
51
/**
52
/**
52
 * Initialise la cartographie
53
 * Initialise la cartographie
53
 */
54
 */
54
WidgetSaisie.prototype.initCarto = function() {
55
WidgetSaisie.prototype.initCarto = function() {
55
	this.initialiserGoogleMap();
56
	this.initialiserGoogleMap();
-
 
57
	this.initialiserAutocompleteCommune();
-
 
58
 
-
 
59
	$("#carte-recherche").autocomplete({
-
 
60
		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
-
 
61
		source: function(request, response) {
-
 
62
			geocoderOptions.address = request.term + addressSuffix;
-
 
63
			console.log('Geocoder options', geocoderOptions);
-
 
64
			lthis.geocoder.geocode( geocoderOptions, function(results, status) {
-
 
65
				if (status == google.maps.GeocoderStatus.OK) {
-
 
66
					response($.map(results, function(item) {
-
 
67
						var retour = {
-
 
68
							label: item.formatted_address,
-
 
69
							value: item.formatted_address,
-
 
70
							latitude: item.geometry.location.lat(),
-
 
71
							longitude: item.geometry.location.lng()
-
 
72
						};
-
 
73
						return retour;
-
 
74
					}));
-
 
75
				} else {
-
 
76
					lthis.afficherErreurGoogleMap(status);
-
 
77
				}
-
 
78
			});
-
 
79
		},
-
 
80
		// Cette partie est executee a la selection d'une adresse
-
 
81
		select: function(event, ui) {
-
 
82
			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
-
 
83
			lthis.deplacerMarker(latLng);
-
 
84
		}
56
	this.initialiserAutocompleteCommune();
85
	});
Line 57... Line 86...
57
}
86
}
58
 
87
 
59
/**
88
/**
60
 * Initialise le formulaire, les validateurs, les listes de complétion...
89
 * Initialise le formulaire, les validateurs, les listes de complétion...
61
 */
90
 */
-
 
91
WidgetSaisie.prototype.initForm = function() {
62
WidgetSaisie.prototype.initForm = function() {
92
	if (this.obsId != '') {
63
	if (this.obsId != '') {
93
		console.log('obsId: (' + typeof obsId + ') : ' + obsId);
Line 64... Line 94...
64
		this.chargerInfoObs();
94
		this.chargerInfoObs();
65
	}
95
	}
66
 
96
 
67
	this.configurerDatePicker();
97
	this.configurerDatePicker('#date');
Line 68... Line 98...
68
	this.ajouterAutocompletionNoms();
98
	this.ajouterAutocompletionNoms();
Line 115... Line 145...
115
	});
145
	});
116
	// identité
146
	// identité
117
	$("#courriel").on('blur', this.requeterIdentite.bind(this));
147
	$("#courriel").on('blur', this.requeterIdentite.bind(this));
118
	$("#courriel").on('keypress', this.testerLancementRequeteIdentite.bind(this));
148
	$("#courriel").on('keypress', this.testerLancementRequeteIdentite.bind(this));
119
	$(".alert .close").on('click', this.fermerPanneauAlert);
149
	$(".alert .close").on('click', this.fermerPanneauAlert);
120
	$("[rel=tooltip]").tooltip('enable');
150
	$(".has-tooltip").tooltip('enable');
121
	$("#btn-aide").on('click', this.basculerAffichageAide);
151
	$("#btn-aide").on('click', this.basculerAffichageAide);
122
	$("#prenom").on("change", this.formaterPrenom.bind(this));
152
	$("#prenom").on("change", this.formaterPrenom.bind(this));
123
	$("#nom").on("change", this.formaterNom.bind(this));
153
	$("#nom").on("change", this.formaterNom.bind(this));
Line 124... Line 154...
124
 
154
 
Line 148... Line 178...
148
	if (this.debug == false) {
178
	if (this.debug == false) {
149
		$(window).on('beforeunload', function(event) {
179
		$(window).on('beforeunload', function(event) {
150
			return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.';
180
			return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.';
151
		});
181
		});
152
	}
182
	}
-
 
183
 
-
 
184
	// Autocompletion du champ adresse
-
 
185
	$("#carte-recherche").on('focus', function() {
-
 
186
		$(this).select();
-
 
187
	});
-
 
188
	$("#carte-recherche").on('mouseup', function(event) {// Pour Safari...
-
 
189
		event.preventDefault();
-
 
190
	});
-
 
191
	$("#carte-recherche").keypress(function(e) {
-
 
192
		if (e.which == 13) {
-
 
193
			e.preventDefault();
-
 
194
		}
-
 
195
	});
153
}
196
}
Line 154... Line 197...
154
 
197
 
155
/**
198
/**
156
 * Retourne true si l'extension de l'image "nom" est .jpg ou .jpeg
199
 * Retourne true si l'extension de l'image "nom" est .jpg ou .jpeg
Line 191... Line 234...
191
		'</div>'
234
		'</div>'
192
	return html;
235
	return html;
193
};
236
};
Line 194... Line 237...
194
 
237
 
-
 
238
/**
-
 
239
 * Efface une miniature (formulaire)
-
 
240
 */
-
 
241
WidgetSaisie.prototype.supprimerMiniature = function(miniature) {
-
 
242
	miniature.parents('.miniature').remove();
-
 
243
}
-
 
244
 
195
/**
245
/**
196
 * Efface toutes les miniatures (formulaire)
246
 * Efface toutes les miniatures (formulaire)
197
 */
247
 */
198
WidgetSaisie.prototype.supprimerMiniatures = function() {
248
WidgetSaisie.prototype.supprimerMiniatures = function() {
199
	$("#miniatures").empty();
249
	$("#miniatures").empty();
Line 227... Line 277...
227
		case 'bdtfx':
277
		case 'bdtfx':
228
		case 'bdtxa':
278
		case 'bdtxa':
229
			geocoderOptions.region = 'fr';
279
			geocoderOptions.region = 'fr';
230
			addressSuffix = ', France';
280
			addressSuffix = ', France';
231
	}
281
	}
232
 
-
 
233
	$("#carte-recherche").autocomplete({
-
 
234
		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
-
 
235
		source: function(request, response) {
-
 
236
			geocoderOptions.address = request.term + addressSuffix;
-
 
237
			console.log('Geocoder options', geocoderOptions);
-
 
238
			lthis.geocoder.geocode( geocoderOptions, function(results, status) {
-
 
239
				if (status == google.maps.GeocoderStatus.OK) {
-
 
240
					response($.map(results, function(item) {
-
 
241
						var retour = {
-
 
242
							label: item.formatted_address,
-
 
243
							value: item.formatted_address,
-
 
244
							latitude: item.geometry.location.lat(),
-
 
245
							longitude: item.geometry.location.lng()
-
 
246
						};
-
 
247
						return retour;
-
 
248
					}));
-
 
249
				} else {
-
 
250
					lthis.afficherErreurGoogleMap(status);
-
 
251
				}
-
 
252
			});
-
 
253
		},
-
 
254
		// Cette partie est executee a la selection d'une adresse
-
 
255
		select: function(event, ui) {
-
 
256
			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
-
 
257
			lthis.deplacerMarker(latLng);
-
 
258
		}
-
 
259
	});
-
 
260
 
-
 
261
	// Autocompletion du champ adresse
-
 
262
	$("#carte-recherche").on('focus', function() {
-
 
263
		$(this).select();
-
 
264
	});
-
 
265
	$("#carte-recherche").on('mouseup', function(event) {// Pour Safari...
-
 
266
		event.preventDefault();
-
 
267
	});
-
 
268
	$("#carte-recherche").keypress(function(e) {
-
 
269
		if (e.which == 13) {
-
 
270
			e.preventDefault();
-
 
271
		}
-
 
272
	});
-
 
273
};
282
};
Line 274... Line 283...
274
 
283
 
275
WidgetSaisie.prototype.afficherErreurGoogleMap = function(status) {
284
WidgetSaisie.prototype.afficherErreurGoogleMap = function(status) {
276
	if (this.debug) {
285
	if (this.debug) {
Line 450... Line 459...
450
					}
459
					}
451
			    }
460
			    }
452
			},
461
			},
453
			error : function(jqXHR, textStatus, errorThrown) {
462
			error : function(jqXHR, textStatus, errorThrown) {
454
				if (this.debug) {
463
				if (this.debug) {
455
					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
464
					$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la recherche de la commune.</p>');
456
					reponse = jQuery.parseJSON(jqXHR.responseText);
465
					reponse = jQuery.parseJSON(jqXHR.responseText);
457
					var erreurMsg = "";
466
					var erreurMsg = "";
458
					if (reponse != null) {
467
					if (reponse != null) {
459
						$.each(reponse, function (cle, valeur) {
468
						$.each(reponse, function (cle, valeur) {
460
							erreurMsg += valeur + "<br />";
469
							erreurMsg += valeur + "<br />";
Line 501... Line 510...
501
				$("#id_utilisateur").val(infos.id);
510
				$("#id_utilisateur").val(infos.id);
502
				$("#prenom").val(infos.prenom);
511
				$("#prenom").val(infos.prenom);
503
				$("#nom").val(infos.nom);
512
				$("#nom").val(infos.nom);
504
				$("#courriel_confirmation").val(courriel);
513
				$("#courriel_confirmation").val(courriel);
505
				$("#prenom, #nom, #courriel_confirmation").attr('disabled', 'disabled');
514
				$("#prenom, #nom, #courriel_confirmation").attr('disabled', 'disabled');
506
				$("#date").focus();
515
				lthis.focusChampFormulaire();
507
				lthis.masquerPanneau("#dialogue-courriel-introuvable");
516
				lthis.masquerPanneau("#dialogue-courriel-introuvable");
508
			} else {
517
			} else {
509
				lthis.surErreurCompletionCourriel();
518
				lthis.surErreurCompletionCourriel();
510
			}
519
			}
511
		},
520
		},
Line 521... Line 530...
521
			
530
			
522
		}
531
		}
523
	});
532
	});
Line -... Line 533...
-
 
533
};
-
 
534
 
-
 
535
WidgetSaisie.prototype.focusChampFormulaire = function() {
-
 
536
	$("#date").focus();
524
};
537
}
525
 
538
 
526
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
539
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
527
	$("#prenom, #nom, #courriel_confirmation").val('');
540
	$("#prenom, #nom, #courriel_confirmation").val('');
528
	$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
541
	$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
529
	this.afficherPanneau("#dialogue-courriel-introuvable");
-
 
530
};
-
 
Line 531... Line 542...
531
//+---------------------------------------------------------------------------------------------------------+
542
	this.afficherPanneau("#dialogue-courriel-introuvable");
532
//FORMULAIRE
543
};
-
 
544
 
533
 
545
WidgetSaisie.prototype.chargerInfoObs = function() {
534
WidgetSaisie.prototype.chargerInfoObs = function() {
546
	var urlObs = this.serviceObsUrl + '/' + this.obsId;
535
	var urlObs = this.serviceObsUrl + '/' + this.obsId;
547
	var lthis = this;
536
	$.ajax({
548
	$.ajax({
537
		url: urlObs,
549
		url: urlObs,
538
		type: 'GET',
550
		type: 'GET',
-
 
551
		success: function(data, textStatus, jqXHR) {
-
 
552
			if (data != undefined && data != "") {
539
		success: function(data, textStatus, jqXHR) {
553
				this.prechargerForm(data);
540
			if (data != undefined && data != "") {
-
 
541
				this.prechargerForm(data);
-
 
542
			}
554
			} else {
543
			// TODO: voir s'il est pertinent d'indiquer quelque chose en cas d'erreur ou d'obs
555
				lthis.surErreurChargementInfosObs();
544
			// inexistante
556
			}
545
		},
557
		},
546
		error: function(jqXHR, textStatus, errorThrown) {
558
		error: function(jqXHR, textStatus, errorThrown) {
547
			// TODO: cf TODO ci-dessus
559
			lthis.surErreurChargementInfosObs();
Line -... Line 560...
-
 
560
		}
-
 
561
	});
-
 
562
};
-
 
563
 
-
 
564
// @TODO faire mieux que ça !
548
		}
565
WidgetSaisie.prototype.surErreurChargementInfosObs = function() {
Line 549... Line 566...
549
	});
566
	alert("Erreur lors du chargement de l'observation");
Line 550... Line 567...
550
};
567
}
Line 639... Line 656...
639
			taxon : "required"
656
			taxon : "required"
640
		}
657
		}
641
	});
658
	});
642
};
659
};
Line 643... Line 660...
643
 
660
 
644
WidgetSaisie.prototype.configurerDatePicker = function() {
661
WidgetSaisie.prototype.configurerDatePicker = function(selector) {
645
	$.datepicker.setDefaults($.datepicker.regional["fr"]);
662
	$.datepicker.setDefaults($.datepicker.regional["fr"]);
646
	$("#date").datepicker({
663
	$(selector).datepicker({
647
		dateFormat: "dd/mm/yy",
664
		dateFormat: "dd/mm/yy",
648
		maxDate: new Date,
665
		maxDate: new Date,
649
		showOn: "button",
666
		showOn: "button",
650
		buttonImageOnly: true,
667
		buttonImageOnly: true,
651
		buttonImage: this.calendrierIconeUrl,
668
		buttonImage: this.calendrierIconeUrl,
652
		buttonText: "Afficher le calendrier pour saisir la date.",
669
		buttonText: "Afficher le calendrier pour saisir la date.",
-
 
670
		showButtonPanel: true,
-
 
671
		onSelect: function(date) {
-
 
672
			$(this).valid();
653
		showButtonPanel: true
673
		}
654
	});
674
	});
655
	$("img.ui-datepicker-trigger").appendTo("#date-icone");
675
	$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
Line 656... Line 676...
656
};
676
};
657
 
677
 
658
WidgetSaisie.prototype.fermerPanneauAlert = function() {
678
WidgetSaisie.prototype.fermerPanneauAlert = function() {
Line 685... Line 705...
685
	$(this).val(prenom.join(' '));
705
	$(this).val(prenom.join(' '));
686
};
706
};
Line 687... Line 707...
687
 
707
 
688
WidgetSaisie.prototype.basculerAffichageAide = function()  {
708
WidgetSaisie.prototype.basculerAffichageAide = function()  {
689
	if ($(this).hasClass('btn-warning')) {
709
	if ($(this).hasClass('btn-warning')) {
690
		$("[rel=tooltip]").tooltip('enable');
710
		$(".has-tooltip").tooltip('enable');
691
		$(this).removeClass('btn-warning').addClass('btn-success');
711
		$(this).removeClass('btn-warning').addClass('btn-success');
692
		$('#btn-aide-txt', this).text("Désactiver l'aide");
712
		$('#btn-aide-txt', this).text("Désactiver l'aide");
693
	} else {
713
	} else {
694
		$("[rel=tooltip]").tooltip('disable');
714
		$(".has-tooltip").tooltip('disable');
695
		$(this).removeClass('btn-success').addClass('btn-warning');
715
		$(this).removeClass('btn-success').addClass('btn-warning');
696
		$('#btn-aide-txt', this).text("Activer l'aide");
716
		$('#btn-aide-txt', this).text("Activer l'aide");
697
	}
717
	}
Line 737... Line 757...
737
WidgetSaisie.prototype.afficherObs = function() {
757
WidgetSaisie.prototype.afficherObs = function() {
738
	$("#liste-obs").prepend(
758
	$("#liste-obs").prepend(
739
		'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">'+
759
		'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">'+
740
			'<div class="span12">'+
760
			'<div class="span12">'+
741
				'<div class="well">'+
761
				'<div class="well">'+
742
					'<div class="obs-action pull-right" rel="tooltip" data-placement="bottom" '+
762
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
743
						'title="Supprimer cette observation de la liste à transmettre">'+
763
						'title="Supprimer cette observation de la liste à transmettre">'+
744
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
764
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
745
							'<i class="icon-trash icon-white"></i>'+
765
							'<i class="icon-trash icon-white"></i>'+
746
						'</button>'+
766
						'</button>'+
747
					'</div> '+
767
					'</div> '+
Line 773... Line 793...
773
						'</div>'+
793
						'</div>'+
774
					'</div>'+
794
					'</div>'+
775
				'</div>'+
795
				'</div>'+
776
			'</div>'+
796
			'</div>'+
777
		'</div>');
797
		'</div>');
-
 
798
	$('#zone-liste-obs').removeClass("hidden").show();
778
};
799
};
Line 779... Line 800...
779
 
800
 
780
WidgetSaisie.prototype.stockerObsData = function() {
801
WidgetSaisie.prototype.stockerObsData = function() {
781
	var lthis = this;
802
	var lthis = this;