Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3276 Rev 3280
1
/**
1
/**
2
 * Constructeur WidgetSaisie par défaut
2
 * Constructeur WidgetSaisie par défaut
3
 */
3
 */
4
function WidgetSaisie() {
4
function WidgetSaisie() {
5
	this.langue = 'fr';
5
	this.langue = 'fr';
6
	this.obsNbre = 0;
6
	this.obsNbre = 0;
7
	this.nbObsEnCours = 1;
7
	this.nbObsEnCours = 1;
8
	this.totalObsATransmettre = 0;
8
	this.totalObsATransmettre = 0;
9
	this.nbObsTransmises = 0;
9
	this.nbObsTransmises = 0;
10
	this.debug = null;
10
	this.debug = null;
11
	this.html5 = null;
11
	this.html5 = null;
12
	this.tagProjet = null;
12
	this.tagProjet = null;
13
	this.tagImg = null;
13
	this.tagImg = null;
14
	this.tagObs = null;
14
	this.tagObs = null;
15
	this.separationTagImg = null;
15
	this.separationTagImg = null;
16
	this.separationTagObs = null;
16
	this.separationTagObs = null;
17
	this.obsId = null;
17
	this.obsId = null;
18
	this.serviceSaisieUrl = null;
18
	this.serviceSaisieUrl = null;
19
	this.serviceObsUrl = null;
19
	this.serviceObsUrl = null;
20
	this.nomSciReferentiel = null;
20
	this.nomSciReferentiel = null;
21
	this.especeImposee = false;
21
	this.especeImposee = false;
22
	this.infosEspeceImposee = null;
22
	this.infosEspeceImposee = null;
23
	this.isTaxonListe = false;
23
	this.isTaxonListe = false;
24
	this.autocompletionElementsNbre = null;
24
	this.autocompletionElementsNbre = null;
25
	this.referentielImpose = null;
25
	this.referentielImpose = null;
26
	this.serviceAutocompletionNomSciUrl = null;
26
	this.serviceAutocompletionNomSciUrl = null;
27
	this.serviceAutocompletionNomSciUrlTpl = null;
27
	this.serviceAutocompletionNomSciUrlTpl = null;
28
	this.obsMaxNbre = null;
28
	this.obsMaxNbre = null;
29
	this.dureeMessage = null;
29
	this.dureeMessage = null;
30
	this.serviceAnnuaireIdUrl = null;
30
	this.serviceAnnuaireIdUrl = null;
31
	this.serviceNomCommuneUrl = null;
31
	this.serviceNomCommuneUrl = null;
32
	this.serviceNomCommuneUrlAlt = null;
32
	this.serviceNomCommuneUrlAlt = null;
33
	this.chargementIconeUrl = null;
33
	this.chargementIconeUrl = null;
34
	this.chargementImageIconeUrl = null;
34
	this.chargementImageIconeUrl = null;
35
	this.calendrierIconeUrl = null;
35
	this.calendrierIconeUrl = null;
36
	this.pasDePhotoIconeUrl = null;
36
	this.pasDePhotoIconeUrl = null;
37
	this.observer = null;
37
	this.observer = null;
38
 
38
 
39
	// système de traduction minimaliste
39
	// système de traduction minimaliste
40
	this.msgs = {
40
	this.msgs = {
41
		fr: {
41
		fr: {
42
			'format-non-supporte': 'Le format de fichier n\'est pas supporté, les formats acceptés sont',
42
			'format-non-supporte': 'Le format de fichier n\'est pas supporté, les formats acceptés sont',
43
			'date-incomplete': 'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.',
43
			'date-incomplete': 'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.',
44
			'observations-transmises': 'observations transmises',
44
			'observations-transmises': 'observations transmises',
45
			'taxon-ou-image' : 'Veuillez transmettre au moins, soit une image, soit une espèce',
45
			'taxon-ou-image' : 'Veuillez transmettre au moins, soit une image, soit une espèce',
46
			'supprimer-observation-liste': 'Supprimer cette observation de la liste à transmettre',
46
			'supprimer-observation-liste': 'Supprimer cette observation de la liste à transmettre',
47
			'milieu': 'Milieu',
47
			'milieu': 'Milieu',
48
			'commentaires': 'Commentaires',
48
			'commentaires': 'Commentaires',
49
			'erreur-inconnue': 'Erreur inconnue',
49
			'erreur-inconnue': 'Erreur inconnue',
50
			'non-lie-au-ref': 'non lié au référentiel',
50
			'non-lie-au-ref': 'non lié au référentiel',
51
			'obs-le': 'le',
51
			'obs-le': 'le',
52
			'quitter-page' : 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.',
52
			'quitter-page' : 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.',
53
			'courriel-connu' : 'Un compte existe pour ce courriel, connectez-vous pour saisir votre observation',
53
			'courriel-connu' : 'Un compte existe pour ce courriel, connectez-vous pour saisir votre observation',
54
			'obs-numero' : 'Observation n°',
54
			'obs-numero' : 'Observation n°',
55
			'erreur-ajax' : 'Erreur Ajax',
55
			'erreur-ajax' : 'Erreur Ajax',
56
			'erreur' : 'Erreur',
56
			'erreur' : 'Erreur',
57
			'erreur-chargement' : 'Erreur lors du chargement de l\'observation',
57
			'erreur-chargement' : 'Erreur lors du chargement de l\'observation',
58
			'lieu-obs' : 'observé à',
58
			'lieu-obs' : 'observé à',
59
			'lieu-dit' : 'Lieu-dit',
59
			'lieu-dit' : 'Lieu-dit',
60
			'station' : 'Station'
60
			'station' : 'Station'
61
		},
61
		},
62
		en: {
62
		en: {
63
			'format-non-supporte': 'The file format is not supported, the accepted formats are',
63
			'format-non-supporte': 'The file format is not supported, the accepted formats are',
64
			'date-incomplete': 'Format: dd / mm / yyyy. Incomplete date, use 0, example: 00/12/2011.',
64
			'date-incomplete': 'Format: dd / mm / yyyy. Incomplete date, use 0, example: 00/12/2011.',
65
			'observations-transmises': 'observations transmitted',
65
			'observations-transmises': 'observations transmitted',
66
			'taxon-ou-image' : 'Please transmit at least one image or one species',
66
			'taxon-ou-image' : 'Please transmit at least one image or one species',
67
			'supprimer-observation-liste': 'Delete this observation from the list to be transmitted',
67
			'supprimer-observation-liste': 'Delete this observation from the list to be transmitted',
68
			'milieu': 'Environment',
68
			'milieu': 'Environment',
69
			'commentaires': 'Comments',
69
			'commentaires': 'Comments',
70
			'erreur-inconnue': 'Unknown error',
70
			'erreur-inconnue': 'Unknown error',
71
			'non-lie-au-ref': 'unrelated to the referencial ',
71
			'non-lie-au-ref': 'unrelated to the referencial ',
72
			'obs-le': 'the',
72
			'obs-le': 'the',
73
			'quitter-page' : 'Are you sure you want to leave the page?\nThe observations entered but not transmitted will be lost.',
73
			'quitter-page' : 'Are you sure you want to leave the page?\nThe observations entered but not transmitted will be lost.',
74
			'courriel-connu' : 'An account exists for this email, log in to enter your observation',
74
			'courriel-connu' : 'An account exists for this email, log in to enter your observation',
75
			'obs-numero' : 'Observation number ',
75
			'obs-numero' : 'Observation number ',
76
			'erreur-ajax' : 'Ajax Error',
76
			'erreur-ajax' : 'Ajax Error',
77
			'erreur' : 'Error',
77
			'erreur' : 'Error',
78
			'erreur-chargement' : 'Error loading the observation',
78
			'erreur-chargement' : 'Error loading the observation',
79
			'lieu-obs' : 'observed at',
79
			'lieu-obs' : 'observed at',
80
			'lieu-dit' : 'Locality',
80
			'lieu-dit' : 'Locality',
81
			'station' : 'Place'
81
			'station' : 'Place'
82
		}
82
		}
83
	};
83
	};
84
}
84
}
85
 
85
 
86
/**
86
/**
87
 * Initialisation du widget
87
 * Initialisation du widget
88
 */
88
 */
89
WidgetSaisie.prototype.init = function() {
89
WidgetSaisie.prototype.init = function() {
90
	this.initForm();
90
	this.initForm();
91
	this.initEvts();
91
	this.initEvts();
92
	// Auth.js s'en occuppe
92
	// Auth.js s'en occuppe
93
	if ( '' === $( '#nom-complet').text() && valeurOk ( $( '#courriel' ).val() ) ) {
93
	if ( '' === $( '#nom-complet').text() && valeurOk ( $( '#courriel' ).val() ) ) {
94
		this.requeterIdentite();
94
		this.requeterIdentite();
95
	}
95
	}
96
};
96
};
97
 
97
 
98
/**
98
/**
99
 * Initialise le formulaire, les validateurs, les listes de complétion...
99
 * Initialise le formulaire, les validateurs, les listes de complétion...
100
 */
100
 */
101
WidgetSaisie.prototype.initForm = function() {
101
WidgetSaisie.prototype.initForm = function() {
102
 
102
 
103
	var lthis = this;
103
	var lthis = this;
104
	if ( valeurOk( this.obsId ) ) {
104
	if ( valeurOk( this.obsId ) ) {
105
		this.chargerInfoObs();
105
		this.chargerInfoObs();
106
	}
106
	}
107
 
107
 
108
	if( this.isTaxonListe ) {
108
	if( this.isTaxonListe ) {
109
		this.surChangementTaxonListe();
109
		this.surChangementTaxonListe();
110
		$( '#taxon-liste' ).on( 'change', lthis.surChangementTaxonListe );
110
		$( '#taxon-liste' ).on( 'change', lthis.surChangementTaxonListe );
111
		$( '#taxon-liste' ).on( 'change', lthis.surChangementValeurTaxon.bind( lthis ) );
111
		$( '#taxon-liste' ).on( 'change', lthis.surChangementValeurTaxon.bind( lthis ) );
112
		if ( this.debug ) {
112
		if ( this.debug ) {
113
			console.log( 'Selected taxon:' + $( '#taxon-liste option:selected' ).val());
113
			console.log( 'Selected taxon:' + $( '#taxon-liste option:selected' ).val());
114
		}
114
		}
115
	} else {
115
	} else {
116
		this.ajouterAutocompletionNoms();
116
		this.ajouterAutocompletionNoms();
117
	}
117
	}
118
	// au rafraichissement de la page,
118
	// au rafraichissement de la page,
119
	// les input date semblent conserver la valeur entrée précedemment
119
	// les input date semblent conserver la valeur entrée précedemment
120
	// c'est voulu après la création d'un obs mais pas quand la page est actualisée
120
	// c'est voulu après la création d'un obs mais pas quand la page est actualisée
121
	// Déjà tenté: onbeforeunload avec un location.reload(true) n'a pas permis de le faire
121
	// Déjà tenté: onbeforeunload avec un location.reload(true) n'a pas permis de le faire
122
	$( 'input[type=date]' ).each( function () {
122
	$( 'input[type=date]' ).each( function () {
123
		( valeurOk( $( this ).data( 'default' ) ) ) ? $( this ).val( $( this ).data( 'default' ) ) : $( this ).val( '' );
123
		( valeurOk( $( this ).data( 'default' ) ) ) ? $( this ).val( $( this ).data( 'default' ) ) : $( this ).val( '' );
124
	});
124
	});
125
	this.configurerFormValidator();
125
	this.configurerFormValidator();
126
	this.definirReglesFormValidator();
126
	this.definirReglesFormValidator();
127
 
127
 
128
	if( this.especeImposee ) {
128
	if( this.especeImposee ) {
129
	  $( '#taxon' ).attr( 'disabled', 'disabled' );
129
	  $( '#taxon' ).attr( 'disabled', 'disabled' );
130
	  $( '#taxon-input-groupe' ).attr( 'title', '' );
130
	  $( '#taxon-input-groupe' ).attr( 'title', '' );
131
	  // Bricolage cracra pour avoir le nom retenu avec auteur (nom_retenu.libelle ne le mentionne pas)
131
	  // Bricolage cracra pour avoir le nom retenu avec auteur (nom_retenu.libelle ne le mentionne pas)
132
	  var infosEspeceImposee = $.parseJSON( this.infosEspeceImposee );
132
	  var infosEspeceImposee = $.parseJSON( this.infosEspeceImposee );
133
	  var nomRetenuComplet = infosEspeceImposee.nom_retenu_complet,
133
	  var nomRetenuComplet = infosEspeceImposee.nom_retenu_complet,
134
	    debutAnneRefBiblio = nomRetenuComplet.indexOf( ' [' );
134
	    debutAnneRefBiblio = nomRetenuComplet.indexOf( ' [' );
135
	  if ( -1 !== debutAnneRefBiblio ) {
135
	  if ( -1 !== debutAnneRefBiblio ) {
136
	    nomRetenuComplet = nomRetenuComplet.substr( 0, debutAnneRefBiblio );
136
	    nomRetenuComplet = nomRetenuComplet.substr( 0, debutAnneRefBiblio );
137
	  }
137
	  }
138
	  // fin bricolage cracra
138
	  // fin bricolage cracra
139
	  var infosAssociee = {
139
	  var infosAssociee = {
140
	    label : infosEspeceImposee.nom_sci_complet,
140
	    label : infosEspeceImposee.nom_sci_complet,
141
	    value : infosEspeceImposee.nom_sci_complet,
141
	    value : infosEspeceImposee.nom_sci_complet,
142
	    nt : infosEspeceImposee.num_taxonomique,
142
	    nt : infosEspeceImposee.num_taxonomique,
143
	    nomSel : infosEspeceImposee.nom_sci,
143
	    nomSel : infosEspeceImposee.nom_sci,
144
	    nomSelComplet : infosEspeceImposee.nom_sci_complet,
144
	    nomSelComplet : infosEspeceImposee.nom_sci_complet,
145
	    numNomSel : infosEspeceImposee.id,
145
	    numNomSel : infosEspeceImposee.id,
146
	    nomRet : nomRetenuComplet,
146
	    nomRet : nomRetenuComplet,
147
	    numNomRet : infosEspeceImposee['nom_retenu.id'],
147
	    numNomRet : infosEspeceImposee['nom_retenu.id'],
148
	    famille : infosEspeceImposee.famille,
148
	    famille : infosEspeceImposee.famille,
149
	    retenu : ( 'false' === infosEspeceImposee.retenu ) ? false : true
149
	    retenu : ( 'false' === infosEspeceImposee.retenu ) ? false : true
150
	  };
150
	  };
151
	  $( '#taxon' ).data( infosAssociee );
151
	  $( '#taxon' ).data( infosAssociee );
152
	}
152
	}
153
};
153
};
154
 
154
 
155
/**
155
/**
156
 * Initialise les écouteurs d'événements
156
 * Initialise les écouteurs d'événements
157
 */
157
 */
158
WidgetSaisie.prototype.initEvts = function() {
158
WidgetSaisie.prototype.initEvts = function() {
159
	var lthis = this;
159
	var lthis = this;
-
 
160
 
-
 
161
	$( '#tb-geolocation' ).on( 'submit blur click focus mousedown mouseleave mouseup touchend touchstart change', '*', function( event ) {
-
 
162
		event.preventDefault();
-
 
163
		return false;
160
 
164
	});
161
	// identité
165
	// identité
162
	$( '#bouton-anonyme' ).on( 'click', function( event ) {
166
	$( '#bouton-anonyme' ).on( 'click', function( event ) {
163
		arreter( event );
167
		arreter( event );
164
		$( this ).css({
168
		$( this ).css({
165
			'background-color': 'rgba(0, 159, 184, 0.7)',
169
			'background-color': 'rgba(0, 159, 184, 0.7)',
166
			'color': '#fff'
170
			'color': '#fff'
167
		});
171
		});
168
		$( '#anonyme' ).removeClass( 'hidden' );
172
		$( '#anonyme' ).removeClass( 'hidden' );
169
		$( '#courriel' ).focus();
173
		$( '#courriel' ).focus();
170
	});
174
	});
171
	if ( '' === $( '#nom-complet').text() ) {
175
	if ( '' === $( '#nom-complet').text() ) {
172
		$( '#courriel' ).on( 'blur', this.requeterIdentite.bind( this ) );
176
		$( '#courriel' ).on( 'blur', this.requeterIdentite.bind( this ) );
173
		$( '#courriel' ).on( 'keypress', this.testerLancementRequeteIdentite.bind( this ) );
177
		$( '#courriel' ).on( 'keypress', this.testerLancementRequeteIdentite.bind( this ) );
174
	}
178
	}
175
	$( '#prenom' ).on( 'change', this.formaterPrenom );
179
	$( '#prenom' ).on( 'change', this.formaterPrenom );
176
	$( '#nom' ).on( 'change', this.formaterNom );
180
	$( '#nom' ).on( 'change', this.formaterNom );
177
	$( '#courriel_confirmation' ).on( 'paste', this.bloquerCopierCollerCourriel.bind( this ) );
181
	$( '#courriel_confirmation' ).on( 'paste', this.bloquerCopierCollerCourriel.bind( this ) );
178
 
182
 
179
	// Sur téléchargement image
183
	// Sur téléchargement image
180
	$( '#fichier' ).on( 'change', function ( e ) {
184
	$( '#fichier' ).on( 'change', function ( e ) {
181
		arreter( e );
185
		arreter( e );
182
		var options = {
186
		var options = {
183
			success: lthis.afficherMiniature.bind( lthis ), // post-submit callback
187
			success: lthis.afficherMiniature.bind( lthis ), // post-submit callback
184
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
188
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
185
			resetForm: true // reset the form after successful submit
189
			resetForm: true // reset the form after successful submit
186
		};
190
		};
187
		$( '#miniature' ).append( '<img id="miniature-chargement" class="miniature" alt="chargement" src="' + this.chargementImageIconeUrl + '"/>' );
191
		$( '#miniature' ).append( '<img id="miniature-chargement" class="miniature" alt="chargement" src="' + this.chargementImageIconeUrl + '"/>' );
188
		$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
192
		$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
189
		if( lthis.verifierFormat( $( '#fichier' ).val() ) ) {
193
		if( lthis.verifierFormat( $( '#fichier' ).val() ) ) {
190
			$( '#form-upload' ).ajaxSubmit( options );
194
			$( '#form-upload' ).ajaxSubmit( options );
191
		} else {
195
		} else {
192
			$( '#form-upload' )[0].reset();
196
			$( '#form-upload' )[0].reset();
193
			window.alert( lthis.msgTraduction( 'format-non-supporte' ) + ' ' + $( '#fichier' ).attr( 'accept' ) );
197
			window.alert( lthis.msgTraduction( 'format-non-supporte' ) + ' ' + $( '#fichier' ).attr( 'accept' ) );
194
		}
198
		}
195
		return false;
199
		return false;
196
	});
200
	});
197
 
201
 
198
	$( 'body' ).on( 'click', '.effacer-miniature', function() {
202
	$( 'body' ).on( 'click', '.effacer-miniature', function() {
199
		$( this ).parent().remove();
203
		$( this ).parent().remove();
200
	});
204
	});
201
 
205
 
202
	$( '#referentiel' ).on( 'change', this.surChangementReferentiel.bind( this ) );
206
	$( '#referentiel' ).on( 'change', this.surChangementReferentiel.bind( this ) );
203
 
207
 
204
	$( '#ajouter-obs' ).on( 'click', this.ajouterObs.bind( this ) );
208
	$( '#ajouter-obs' ).on( 'click', this.ajouterObs.bind( this ) );
205
	$( '.obs-nbre' ).on( 'changement', this.surChangementNbreObs.bind( this ) );
209
	$( '.obs-nbre' ).on( 'changement', this.surChangementNbreObs.bind( this ) );
206
 
210
 
207
	$( 'body' ).on( 'click', '.defilement-miniatures-gauche', function( event ) {
211
	$( 'body' ).on( 'click', '.defilement-miniatures-gauche', function( event ) {
208
		event.preventDefault();
212
		event.preventDefault();
209
		lthis.defilerMiniatures( $( this ) );
213
		lthis.defilerMiniatures( $( this ) );
210
	});
214
	});
211
	$( 'body' ).on( 'click', '.defilement-miniatures-droite', function( event ) {
215
	$( 'body' ).on( 'click', '.defilement-miniatures-droite', function( event ) {
212
		event.preventDefault();
216
		event.preventDefault();
213
		lthis.defilerMiniatures( $( this ) );
217
		lthis.defilerMiniatures( $( this ) );
214
	});
218
	});
215
	$( 'body' ).on( 'click', '.supprimer-obs', function() {
219
	$( 'body' ).on( 'click', '.supprimer-obs', function() {
216
	 var that = this,
220
	 var that = this,
217
			suppObs = lthis.supprimerObs.bind( lthis );
221
			suppObs = lthis.supprimerObs.bind( lthis );
218
	 // bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
222
	 // bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
219
	 suppObs( that );
223
	 suppObs( that );
220
	});
224
	});
221
 
225
 
222
	$( '#transmettre-obs' ).on( 'click', this.transmettreObs.bind( this ) );
226
	$( '#transmettre-obs' ).on( 'click', this.transmettreObs.bind( this ) );
223
 
227
 
224
	// Alertes et tooltips
228
	// Alertes et tooltips
225
	$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
229
	$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
226
	$( '#btn-aide' ).on( 'click', this.basculerAffichageAide );
230
	$( '#btn-aide' ).on( 'click', this.basculerAffichageAide );
227
	$( '.has-tooltip' ).tooltip( 'enable' );
231
	$( '.has-tooltip' ).tooltip( 'enable' );
228
};
232
};
229
 
233
 
230
// Identité Observateur *******************************************************/
234
// Identité Observateur *******************************************************/
231
WidgetSaisie.prototype.requeterIdentite = function() {
235
WidgetSaisie.prototype.requeterIdentite = function() {
232
	var lthis = this;
236
	var lthis = this;
233
	var courriel = $( '#courriel' ).val();
237
	var courriel = $( '#courriel' ).val();
234
	var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;
238
	var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;
235
	if ( valeurOk( courriel ) ) {
239
	if ( valeurOk( courriel ) ) {
236
		$.ajax({
240
		$.ajax({
237
			url : urlAnnuaire,
241
			url : urlAnnuaire,
238
			type : 'GET',
242
			type : 'GET',
239
			success : function( data, textStatus, jqXHR ) {
243
			success : function( data, textStatus, jqXHR ) {
240
				if ( lthis.debug ) {
244
				if ( lthis.debug ) {
241
					console.log( 'SUCCESS: ' + textStatus );
245
					console.log( 'SUCCESS: ' + textStatus );
242
				}
246
				}
243
				if ( valeurOk( data ) && valeurOk( data[courriel] ) ) {
247
				if ( valeurOk( data ) && valeurOk( data[courriel] ) ) {
244
					var infos = data[courriel];
248
					var infos = data[courriel];
245
					lthis.surSuccesCompletionCourriel( infos, courriel );
249
					lthis.surSuccesCompletionCourriel( infos, courriel );
246
				} else {
250
				} else {
247
					lthis.surErreurCompletionCourriel();
251
					lthis.surErreurCompletionCourriel();
248
				}
252
				}
249
			},
253
			},
250
			error : function( jqXHR, textStatus, errorThrown ) {
254
			error : function( jqXHR, textStatus, errorThrown ) {
251
				if ( lthis.debug ) {
255
				if ( lthis.debug ) {
252
					console.log( 'ERREUR: '+ textStatus );
256
					console.log( 'ERREUR: '+ textStatus );
253
				}
257
				}
254
				lthis.surErreurCompletionCourriel();
258
				lthis.surErreurCompletionCourriel();
255
			},
259
			},
256
			complete : function( jqXHR, textStatus ) {
260
			complete : function( jqXHR, textStatus ) {
257
				if ( lthis.debug ) {
261
				if ( lthis.debug ) {
258
					console.log( 'COMPLETE: '+ textStatus );
262
					console.log( 'COMPLETE: '+ textStatus );
259
				}
263
				}
260
			}
264
			}
261
		});
265
		});
262
	}
266
	}
263
};
267
};
264
 
268
 
265
// se déclanche quand on choisit "Observation sans inscription" mais que le mail entré est incrit à Tela
269
// se déclanche quand on choisit "Observation sans inscription" mais que le mail entré est incrit à Tela
266
WidgetSaisie.prototype.surSuccesCompletionCourriel = function( infos, courriel ) {
270
WidgetSaisie.prototype.surSuccesCompletionCourriel = function( infos, courriel ) {
267
	if ( $( '#utilisateur-connecte' ).hasClass( 'hidden' ) ) {// si quelque chose a foiré après actualisation
271
	if ( $( '#utilisateur-connecte' ).hasClass( 'hidden' ) ) {// si quelque chose a foiré après actualisation
268
		if ( !valeurOk( $( '#warning-identite' ) ) ) {
272
		if ( !valeurOk( $( '#warning-identite' ) ) ) {
269
			$( '#zone-courriel' ).before( '<p id="warning-identite" class="warning"><i class="fas fa-exclamation-triangle"></i> ' + this.msgTraduction( 'courriel-connu' ) + '</p>' );
273
			$( '#zone-courriel' ).before( '<p id="warning-identite" class="warning"><i class="fas fa-exclamation-triangle"></i> ' + this.msgTraduction( 'courriel-connu' ) + '</p>' );
270
		}
274
		}
271
		$( '#bouton-inscription, #zone-prenom-nom, #zone-courriel-confirmation' ).addClass( 'hidden' );
275
		$( '#bouton-inscription, #zone-prenom-nom, #zone-courriel-confirmation' ).addClass( 'hidden' );
272
		$( '#prenom, #nom, #courriel_confirmation' ).attr( 'disabled', 'disabled' );
276
		$( '#prenom, #nom, #courriel_confirmation' ).attr( 'disabled', 'disabled' );
273
		$( '.nav.control-group' ).addClass( 'error' );
277
		$( '.nav.control-group' ).addClass( 'error' );
274
	}
278
	}
275
};
279
};
276
 
280
 
277
// se déclanche quand on choisit "Observation sans inscription" et qu'effectivement le mail n'est pas connu de Tela
281
// se déclanche quand on choisit "Observation sans inscription" et qu'effectivement le mail n'est pas connu de Tela
278
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
282
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
279
	$( '#creation-compte, #zone-prenom-nom, #zone-courriel-confirmation' ).removeClass( 'hidden' );
283
	$( '#creation-compte, #zone-prenom-nom, #zone-courriel-confirmation' ).removeClass( 'hidden' );
280
	$( '#warning-identite' ).remove();
284
	$( '#warning-identite' ).remove();
281
	$( '.nav.control-group' ).removeClass( 'error' );
285
	$( '.nav.control-group' ).removeClass( 'error' );
282
 
286
 
283
	$( '#prenom, #nom, #courriel_confirmation' ).val( '' );
287
	$( '#prenom, #nom, #courriel_confirmation' ).val( '' );
284
	$( '#prenom, #nom, #courriel_confirmation' ).removeAttr( 'disabled' );
288
	$( '#prenom, #nom, #courriel_confirmation' ).removeAttr( 'disabled' );
285
};
289
};
286
 
290
 
287
WidgetSaisie.prototype.testerLancementRequeteIdentite = function( event ) {
291
WidgetSaisie.prototype.testerLancementRequeteIdentite = function( event ) {
288
	if ( valeurOk( event.which, true, 13 ) ) {
292
	if ( valeurOk( event.which, true, 13 ) ) {
289
		this.requeterIdentite();
293
		this.requeterIdentite();
290
		event.preventDefault();
294
		event.preventDefault();
291
		event.stopPropagation();
295
		event.stopPropagation();
292
	}
296
	}
293
};
297
};
294
 
298
 
295
WidgetSaisie.prototype.formaterNom = function() {
299
WidgetSaisie.prototype.formaterNom = function() {
296
	$( this ).val( $( this ).val().toUpperCase() );
300
	$( this ).val( $( this ).val().toUpperCase() );
297
};
301
};
298
 
302
 
299
WidgetSaisie.prototype.formaterPrenom = function() {
303
WidgetSaisie.prototype.formaterPrenom = function() {
300
	var prenom = new Array(),
304
	var prenom = new Array(),
301
			mots = $( this ).val().split( ' ' ),
305
			mots = $( this ).val().split( ' ' ),
302
			motsLength = mots.length;
306
			motsLength = mots.length;
303
 
307
 
304
	for ( var i = 0; i < motsLength; i++ ) {
308
	for ( var i = 0; i < motsLength; i++ ) {
305
		var mot = mots[i];
309
		var mot = mots[i];
306
		if ( 0 <= mot.indexOf( '-' ) ) {
310
		if ( 0 <= mot.indexOf( '-' ) ) {
307
			var prenomCompose = new Array(),
311
			var prenomCompose = new Array(),
308
					motsComposes = mot.split( '-' )
312
					motsComposes = mot.split( '-' )
309
					motsComposesLength = motsComposes.length;
313
					motsComposesLength = motsComposes.length;
310
			for ( var j = 0; j < motsComposesLength; j++ ) {
314
			for ( var j = 0; j < motsComposesLength; j++ ) {
311
				var motSimple = motsComposes[j],
315
				var motSimple = motsComposes[j],
312
						motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
316
						motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
313
 
317
 
314
				prenomCompose.push( motMajuscule );
318
				prenomCompose.push( motMajuscule );
315
			}
319
			}
316
			prenom.push( prenomCompose.join( '-' ) );
320
			prenom.push( prenomCompose.join( '-' ) );
317
		} else {
321
		} else {
318
			var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
322
			var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
319
			prenom.push( motMajuscule );
323
			prenom.push( motMajuscule );
320
		}
324
		}
321
	}
325
	}
322
	$( this ).val( prenom.join( ' ' ) );
326
	$( this ).val( prenom.join( ' ' ) );
323
};
327
};
324
 
328
 
325
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
329
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
326
	this.afficherPanneau( '#dialogue-bloquer-copier-coller' );
330
	this.afficherPanneau( '#dialogue-bloquer-copier-coller' );
327
	return false;
331
	return false;
328
};
332
};
329
 
333
 
330
// Préchargement des infos-obs ************************************************/
334
// Préchargement des infos-obs ************************************************/
331
WidgetSaisie.prototype.chargerInfoObs = function() {
335
WidgetSaisie.prototype.chargerInfoObs = function() {
332
	var urlObs = this.serviceObsUrl + '/' + this.obsId;
336
	var urlObs = this.serviceObsUrl + '/' + this.obsId;
333
	var lthis = this;
337
	var lthis = this;
334
	$.ajax({
338
	$.ajax({
335
		url: urlObs,
339
		url: urlObs,
336
		type: 'GET',
340
		type: 'GET',
337
		success: function( data, textStatus, jqXHR ) {
341
		success: function( data, textStatus, jqXHR ) {
338
			if ( valeurOk( data ) ) {
342
			if ( valeurOk( data ) ) {
339
				lthis.prechargerForm( data );
343
				lthis.prechargerForm( data );
340
			} else {
344
			} else {
341
				lthis.surErreurChargementInfosObs.bind( lthis );
345
				lthis.surErreurChargementInfosObs.bind( lthis );
342
			}
346
			}
343
		},
347
		},
344
		error: function( jqXHR, textStatus, errorThrown ) {
348
		error: function( jqXHR, textStatus, errorThrown ) {
345
			lthis.surErreurChargementInfosObs();
349
			lthis.surErreurChargementInfosObs();
346
		}
350
		}
347
	});
351
	});
348
};
352
};
349
 
353
 
350
// @TODO faire mieux que ça !
354
// @TODO faire mieux que ça !
351
WidgetSaisie.prototype.surErreurChargementInfosObs = function() {
355
WidgetSaisie.prototype.surErreurChargementInfosObs = function() {
352
	alert( this.msgTraduction( 'erreur-chargement' ) );
356
	alert( this.msgTraduction( 'erreur-chargement' ) );
353
};
357
};
354
 
358
 
355
WidgetSaisie.prototype.prechargerForm = function( data ) {
359
WidgetSaisie.prototype.prechargerForm = function( data ) {
356
 
360
 
357
	$( '#milieu' ).val( data.milieu );
361
	$( '#milieu' ).val( data.milieu );
358
 
362
 
359
	// $( '#carte-recherche' ).val( data.zoneGeo );
363
	// $( '#carte-recherche' ).val( data.zoneGeo );
360
	// $( '#commune-nom' ).text( data.zoneGeo );
364
	// $( '#commune-nom' ).text( data.zoneGeo );
361
 
365
 
362
	// if( data.hasOwnProperty( 'codeZoneGeo' ) ) {
366
	// if( data.hasOwnProperty( 'codeZoneGeo' ) ) {
363
	//   // TODO: trouver un moyen qui fonctionne lorsqu'on aura d'autres référentiels que INSEE
367
	//   // TODO: trouver un moyen qui fonctionne lorsqu'on aura d'autres référentiels que INSEE
364
	//   $( '#commune-code-insee' ).text( data.codeZoneGeo.replace( 'INSEE-C:', '' ) );
368
	//   $( '#commune-code-insee' ).text( data.codeZoneGeo.replace( 'INSEE-C:', '' ) );
365
	// }
369
	// }
366
 
370
 
367
	// if( data.hasOwnProperty( 'latitude' ) && data.hasOwnProperty( 'longitude' ) ) {
371
	// if( data.hasOwnProperty( 'latitude' ) && data.hasOwnProperty( 'longitude' ) ) {
368
	//   var latLng = new google.maps.LatLng( data.latitude, data.longitude );
372
	//   var latLng = new google.maps.LatLng( data.latitude, data.longitude );
369
	//   this.mettreAJourMarkerPosition( latLng );
373
	//   this.mettreAJourMarkerPosition( latLng );
370
	//   this.marker.setPosition( latLng );
374
	//   this.marker.setPosition( latLng );
371
	//   this.map.setCenter( latLng );
375
	//   this.map.setCenter( latLng );
372
	//   this.map.setZoom( 16 );
376
	//   this.map.setZoom( 16 );
373
	// }
377
	// }
374
};
378
};
375
 
379
 
376
// uniquement utilisé si taxon-liste ******************************************/
380
// uniquement utilisé si taxon-liste ******************************************/
377
// Affiche/Cache le champ taxon
381
// Affiche/Cache le champ taxon
378
WidgetSaisie.prototype.surChangementTaxonListe = function() {
382
WidgetSaisie.prototype.surChangementTaxonListe = function() {
379
	if ( valeurOk( $( '#taxon-liste' ).val() ) ) {
383
	if ( valeurOk( $( '#taxon-liste' ).val() ) ) {
380
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
384
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
381
			$( '#taxon-input-groupe' )
385
			$( '#taxon-input-groupe' )
382
				.hide( 200, function () {
386
				.hide( 200, function () {
383
					$( this ).addClass( 'hidden' ).show();
387
					$( this ).addClass( 'hidden' ).show();
384
				})
388
				})
385
				.find( '#taxon-autre' ).val( '' );
389
				.find( '#taxon-autre' ).val( '' );
386
		} else {
390
		} else {
387
			$( '#taxon-input-groupe' )
391
			$( '#taxon-input-groupe' )
388
				.hide()
392
				.hide()
389
				.removeClass( 'hidden' )
393
				.removeClass( 'hidden' )
390
				.show(200)
394
				.show(200)
391
				.find( '#taxon-autre' )
395
				.find( '#taxon-autre' )
392
					.on( 'change', function() {
396
					.on( 'change', function() {
393
						if( !valeurOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
397
						if( !valeurOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
394
							$( '#taxon' ).val( $( '#taxon-autre' ).val() );
398
							$( '#taxon' ).val( $( '#taxon-autre' ).val() );
395
							$( '#taxon' ).data( 'numNomSel', '' )
399
							$( '#taxon' ).data( 'numNomSel', '' )
396
								.data( 'nomRet','' )
400
								.data( 'nomRet','' )
397
								.data( 'numNomRet', '' )
401
								.data( 'numNomRet', '' )
398
								.data( 'nt', '' )
402
								.data( 'nt', '' )
399
								.data( 'famille', '' );
403
								.data( 'famille', '' );
400
						}
404
						}
401
						$( '#taxon' ).trigger( 'change' );
405
						$( '#taxon' ).trigger( 'change' );
402
					});
406
					});
403
		}
407
		}
404
	}
408
	}
405
};
409
};
406
 
410
 
407
 
411
 
408
WidgetSaisie.prototype.surChangementValeurTaxon = function() {
412
WidgetSaisie.prototype.surChangementValeurTaxon = function() {
409
	var numNomSel = 0;
413
	var numNomSel = 0;
410
 
414
 
411
	if( valeurOk( $( '#taxon-liste' ).val() ) ) {
415
	if( valeurOk( $( '#taxon-liste' ).val() ) ) {
412
		if( 'autre' === $( '#taxon-liste' ).val() ) {
416
		if( 'autre' === $( '#taxon-liste' ).val() ) {
413
			this.ajouterAutocompletionNoms();
417
			this.ajouterAutocompletionNoms();
414
		} else {
418
		} else {
415
			var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
419
			var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
416
			// $( '#taxon' ).val( $( '#taxon-liste' ).val() );
420
			// $( '#taxon' ).val( $( '#taxon-liste' ).val() );
417
			$( '#taxon' ).val( $( '#taxon-liste' ).val() )
421
			$( '#taxon' ).val( $( '#taxon-liste' ).val() )
418
				.data( 'value', $( '#taxon-liste' ).val() )
422
				.data( 'value', $( '#taxon-liste' ).val() )
419
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
423
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
420
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
424
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
421
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
425
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
422
				.data( 'nt', optionRetenue.data( 'nt' ) )
426
				.data( 'nt', optionRetenue.data( 'nt' ) )
423
				.data( 'famille', optionRetenue.data( 'famille' ) );
427
				.data( 'famille', optionRetenue.data( 'famille' ) );
424
			$( '#taxon' ).trigger( 'change' );
428
			$( '#taxon' ).trigger( 'change' );
425
 
429
 
426
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
430
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
427
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
431
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
428
			if( !valeurOk( numNomSel ) ) {
432
			if( !valeurOk( numNomSel ) ) {
429
				$( '#certitude' ).find( 'option' ).each( function() {
433
				$( '#certitude' ).find( 'option' ).each( function() {
430
					if ( $( this ).hasClass( 'aDeterminer' ) ) {
434
					if ( $( this ).hasClass( 'aDeterminer' ) ) {
431
						$( this ).attr( 'selected', true );
435
						$( this ).attr( 'selected', true );
432
					} else {
436
					} else {
433
						$( this ).attr( 'selected', false );
437
						$( this ).attr( 'selected', false );
434
					}
438
					}
435
				});
439
				});
436
			}
440
			}
437
		}
441
		}
438
	}
442
	}
439
};
443
};
440
 
444
 
441
// Autocompletion taxons ******************************************************/
445
// Autocompletion taxons ******************************************************/
442
WidgetSaisie.prototype.ajouterAutocompletionNoms = function() {
446
WidgetSaisie.prototype.ajouterAutocompletionNoms = function() {
443
	var lthis = this;
447
	var lthis = this;
444
 
448
 
445
	var taxonSelecteur = '#taxon';
449
	var taxonSelecteur = '#taxon';
446
	if ( valeurOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
450
	if ( valeurOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
447
		taxonSelecteur += '-autre';
451
		taxonSelecteur += '-autre';
448
	}
452
	}
449
	$( taxonSelecteur ).autocomplete({
453
	$( taxonSelecteur ).autocomplete({
450
		source: function( requete, add ) {
454
		source: function( requete, add ) {
451
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
455
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
452
			requete = '';
456
			requete = '';
453
			if( valeurOk( $( '#referentiel' ).val(), false, 'autre' ) ) {
457
			if( valeurOk( $( '#referentiel' ).val(), false, 'autre' ) ) {
454
				var url = lthis.getUrlAutocompletionNomsSci();
458
				var url = lthis.getUrlAutocompletionNomsSci();
455
				$.getJSON( url, requete, function( data ) {
459
				$.getJSON( url, requete, function( data ) {
456
					var suggestions = lthis.traiterRetourNomsSci( data );
460
					var suggestions = lthis.traiterRetourNomsSci( data );
457
					add( suggestions );
461
					add( suggestions );
458
				})
462
				})
459
				.fail( function() {
463
				.fail( function() {
460
				    $( '#certitude' ).find( 'option' ).each( function() {
464
				    $( '#certitude' ).find( 'option' ).each( function() {
461
						if ( $( this ).hasClass( 'aDeterminer' ) ) {
465
						if ( $( this ).hasClass( 'aDeterminer' ) ) {
462
							$( this ).attr( 'selected', true );
466
							$( this ).attr( 'selected', true );
463
						} else {
467
						} else {
464
							$( this ).attr( 'selected', false );
468
							$( this ).attr( 'selected', false );
465
						}
469
						}
466
					});
470
					});
467
				});
471
				});
468
			}
472
			}
469
		},
473
		},
470
		html: true
474
		html: true
471
	});
475
	});
472
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
476
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
473
};
477
};
474
 
478
 
475
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
479
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
476
	var taxonSelecteur = '#taxon';
480
	var taxonSelecteur = '#taxon';
477
	if ( valeurOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
481
	if ( valeurOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
478
		taxonSelecteur += '-autre';
482
		taxonSelecteur += '-autre';
479
	}
483
	}
480
	var mots = $( taxonSelecteur ).val();
484
	var mots = $( taxonSelecteur ).val();
481
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
485
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
482
	url = url.replace( '{masque}', mots );
486
	url = url.replace( '{masque}', mots );
483
	return url;
487
	return url;
484
};
488
};
485
 
489
 
486
WidgetSaisie.prototype.traiterRetourNomsSci = function( data ) {
490
WidgetSaisie.prototype.traiterRetourNomsSci = function( data ) {
487
 
491
 
488
	var taxonSelecteur = '#taxon';
492
	var taxonSelecteur = '#taxon';
489
	if ( valeurOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
493
	if ( valeurOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
490
		taxonSelecteur += '-autre';
494
		taxonSelecteur += '-autre';
491
	}
495
	}
492
	var suggestions = [];
496
	var suggestions = [];
493
	if ( undefined != data.resultat ) {
497
	if ( undefined != data.resultat ) {
494
		$.each( data.resultat, function( i, val ) {
498
		$.each( data.resultat, function( i, val ) {
495
			val.nn = i;
499
			val.nn = i;
496
			var nom = {
500
			var nom = {
497
				label : '',
501
				label : '',
498
				value : '',
502
				value : '',
499
				nt : 0,
503
				nt : 0,
500
				nomSel : '',
504
				nomSel : '',
501
				nomSelComplet : '',
505
				nomSelComplet : '',
502
				numNomSel : 0,
506
				numNomSel : 0,
503
				nomRet : '',
507
				nomRet : '',
504
				numNomRet : 0,
508
				numNomRet : 0,
505
				famille : '',
509
				famille : '',
506
				retenu : false
510
				retenu : false
507
			};
511
			};
508
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
512
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
509
				nom.label = '...';
513
				nom.label = '...';
510
				nom.value = $( taxonSelecteur ).val();
514
				nom.value = $( taxonSelecteur ).val();
511
				suggestions.push( nom );
515
				suggestions.push( nom );
512
				return false;
516
				return false;
513
			} else {
517
			} else {
514
				nom.label = val.nom_sci_complet;
518
				nom.label = val.nom_sci_complet;
515
				nom.value = val.nom_sci_complet;
519
				nom.value = val.nom_sci_complet;
516
				nom.nt = val.num_taxonomique;
520
				nom.nt = val.num_taxonomique;
517
				nom.nomSel = val.nom_sci;
521
				nom.nomSel = val.nom_sci;
518
				nom.nomSelComplet = val.nom_sci_complet;
522
				nom.nomSelComplet = val.nom_sci_complet;
519
				nom.numNomSel = val.nn;
523
				nom.numNomSel = val.nn;
520
				nom.nomRet = val.nom_retenu_complet;
524
				nom.nomRet = val.nom_retenu_complet;
521
				nom.numNomRet = val['nom_retenu.id'];
525
				nom.numNomRet = val['nom_retenu.id'];
522
				nom.famille = val.famille;
526
				nom.famille = val.famille;
523
				// Tester dans ce sens, permet de considérer 'absent' comme 'false' => est-ce opportun ?
527
				// Tester dans ce sens, permet de considérer 'absent' comme 'false' => est-ce opportun ?
524
				// en tout cas c'est harmonisé avec le CeL
528
				// en tout cas c'est harmonisé avec le CeL
525
				nom.retenu = ( 'true' == val.retenu );
529
				nom.retenu = ( 'true' == val.retenu );
526
 
530
 
527
				suggestions.push( nom );
531
				suggestions.push( nom );
528
			}
532
			}
529
		});
533
		});
530
	}
534
	}
531
	return suggestions;
535
	return suggestions;
532
};
536
};
533
 
537
 
534
WidgetSaisie.prototype.surAutocompletionTaxon = function( event, ui ) {
538
WidgetSaisie.prototype.surAutocompletionTaxon = function( event, ui ) {
535
	if ( valeurOk( ui ) ) {
539
	if ( valeurOk( ui ) ) {
536
		$( '#taxon' ).val( ui.item.value );
540
		$( '#taxon' ).val( ui.item.value );
537
		$( '#taxon' ).data( 'value', ui.item.value )
541
		$( '#taxon' ).data( 'value', ui.item.value )
538
			.data( 'numNomSel', ui.item.numNomSel )
542
			.data( 'numNomSel', ui.item.numNomSel )
539
			.data( 'nomRet', ui.item.nomRet )
543
			.data( 'nomRet', ui.item.nomRet )
540
			.data( 'numNomRet', ui.item.numNomRet )
544
			.data( 'numNomRet', ui.item.numNomRet )
541
			.data( 'nt', ui.item.nt )
545
			.data( 'nt', ui.item.nt )
542
			.data( 'famille', ui.item.famille );
546
			.data( 'famille', ui.item.famille );
543
		if ( ui.item.retenu ) {
547
		if ( ui.item.retenu ) {
544
			$( '#taxon' ).addClass( 'ns-retenu' );
548
			$( '#taxon' ).addClass( 'ns-retenu' );
545
		} else {
549
		} else {
546
			$( '#taxon' ).removeClass( 'ns-retenu' );
550
			$( '#taxon' ).removeClass( 'ns-retenu' );
547
		}
551
		}
548
 
552
 
549
		// Si l'espèce est mal déterminée la certitude est "à déterminer"
553
		// Si l'espèce est mal déterminée la certitude est "à déterminer"
550
		if( !valeurOk( $( '#taxon' ).data( 'numNomSel' ) ) ) {
554
		if( !valeurOk( $( '#taxon' ).data( 'numNomSel' ) ) ) {
551
			$( '#certitude' ).find( 'option' ).each( function() {
555
			$( '#certitude' ).find( 'option' ).each( function() {
552
				if ( $( this ).hasClass( 'aDeterminer' ) ) {
556
				if ( $( this ).hasClass( 'aDeterminer' ) ) {
553
					$( this ).attr( 'selected', true );
557
					$( this ).attr( 'selected', true );
554
				} else {
558
				} else {
555
					$( this ).attr( 'selected', false );
559
					$( this ).attr( 'selected', false );
556
				}
560
				}
557
			});
561
			});
558
		}
562
		}
559
	}
563
	}
560
	$( '#taxon' ).trigger( 'change' );
564
	$( '#taxon' ).trigger( 'change' );
561
};
565
};
562
 
566
 
563
// Form Validator *************************************************************/
567
// Form Validator *************************************************************/
564
WidgetSaisie.prototype.configurerFormValidator = function() {
568
WidgetSaisie.prototype.configurerFormValidator = function() {
565
	var lthis = this;
569
	var lthis = this;
566
 
570
 
567
	$.validator.addMethod(
571
	$.validator.addMethod(
568
		'dateCel',
572
		'dateCel',
569
		function ( value, element ) {
573
		function ( value, element ) {
570
			return ( valeurOk( value ) && ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) ) );
574
			return ( valeurOk( value ) && ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) ) );
571
		},
575
		},
572
		lthis.msgTraduction( 'date-incomplete' )
576
		lthis.msgTraduction( 'date-incomplete' )
573
	);
577
	);
574
 
578
 
575
	$.validator.addMethod(
579
	$.validator.addMethod(
576
		'userEmailOk',
580
		'userEmailOk',
577
		function ( value, element ) {
581
		function ( value, element ) {
578
			return ( valeurOk( value ) );
582
			return ( valeurOk( value ) );
579
		},
583
		},
580
		''
584
		''
581
	);
585
	);
582
 
586
 
583
	$.validator.addMethod(
587
	$.validator.addMethod(
584
		'minMaxOk',
588
		'minMaxOk',
585
		function ( value, element, param ) {
589
		function ( value, element, param ) {
586
			$.validator.messages.minMaxOk = lthis.validerMinMax( element ).message;
590
			$.validator.messages.minMaxOk = lthis.validerMinMax( element ).message;
587
			return lthis.validerMinMax( element ).cond;
591
			return lthis.validerMinMax( element ).cond;
588
		},
592
		},
589
		$.validator.messages.minMaxOk
593
		$.validator.messages.minMaxOk
590
	);
594
	);
591
 
595
 
592
	$.validator.addMethod(
596
	$.validator.addMethod(
593
		'listFields',
597
		'listFields',
594
		function ( value, element ) {
598
		function ( value, element ) {
595
			return ( valeurOk( value ) );
599
			return ( valeurOk( value ) );
596
		},
600
		},
597
		''
601
		''
598
	);
602
	);
599
 
603
 
600
	$.extend( $.validator.defaults, {
604
	$.extend( $.validator.defaults, {
601
		errorElement: 'span',
605
		errorElement: 'span',
602
		onfocusout: function( element ) {
606
		onfocusout: function( element ) {
603
			if( valeurOk( element.id, false, 'taxon' ) ) {
607
			if( valeurOk( element.id, false, 'taxon' ) ) {
604
				if ( $( element ).valid() ) {
608
				if ( $( element ).valid() ) {
605
					$( element ).closest( '.control-group' ).removeClass( 'error' );
609
					$( element ).closest( '.control-group' ).removeClass( 'error' );
606
				} else {
610
				} else {
607
					$( element ).closest( '.control-group' ).addClass( 'error' );
611
					$( element ).closest( '.control-group' ).addClass( 'error' );
608
				}
612
				}
609
			}
613
			}
610
		},
614
		},
611
		onkeyup : function( element ) {
615
		onkeyup : function( element ) {
612
			if( valeurOk( element.id, false, 'taxon' ) ) {
616
			if( valeurOk( element.id, false, 'taxon' ) ) {
613
				if ( $( element ).valid() ) {
617
				if ( $( element ).valid() ) {
614
					$( element ).closest( '.control-group' ).removeClass( 'error' );
618
					$( element ).closest( '.control-group' ).removeClass( 'error' );
615
				} else {
619
				} else {
616
					$( element ).closest( '.control-group' ).addClass( 'error' );
620
					$( element ).closest( '.control-group' ).addClass( 'error' );
617
				}
621
				}
618
			}
622
			}
619
		},
623
		},
620
		unhighlight: function( element ) {
624
		unhighlight: function( element ) {
621
			if( valeurOk( element.id, false, 'taxon' ) ) {
625
			if( valeurOk( element.id, false, 'taxon' ) ) {
622
				$( element ).closest( '.control-group' ).removeClass( 'error' );
626
				$( element ).closest( '.control-group' ).removeClass( 'error' );
623
			}
627
			}
624
		},
628
		},
625
		highlight: function( element ) {
629
		highlight: function( element ) {
626
			$( element ).closest( '.control-group' ).addClass( 'error' );
630
			$( element ).closest( '.control-group' ).addClass( 'error' );
627
		}
631
		}
628
	});
632
	});
629
};
633
};
630
 
634
 
631
WidgetSaisie.prototype.chpEtendusValidation = function() {
635
WidgetSaisie.prototype.chpEtendusValidation = function() {
632
	var lthis = this;
636
	var lthis = this;
633
	var $thisForm = $( '#form-supp' ),
637
	var $thisForm = $( '#form-supp' ),
634
			elements  =
638
			elements  =
635
				'.checkbox,'+
639
				'.checkbox,'+
636
				'.radio,'+
640
				'.radio,'+
637
				'.checkboxes,'+
641
				'.checkboxes,'+
638
				'.select,'+
642
				'.select,'+
639
				'textarea,'+
643
				'textarea,'+
640
				'input[type=text]:not(.collect-other),'+
644
				'input[type=text]:not(.collect-other),'+
641
				'input[type=email],'+
645
				'input[type=email],'+
642
				'input[type=number],'+
646
				'input[type=number],'+
643
				'input[type=range],'+
647
				'input[type=range],'+
644
				'input[type=date]',
648
				'input[type=date]',
645
			speFields = ['checkbox','radio','checkboxes','select'],
649
			speFields = ['checkbox','radio','checkboxes','select'],
646
			spefieldsCount = speFields.length,
650
			spefieldsCount = speFields.length,
647
			chpSuppValidation = {
651
			chpSuppValidation = {
648
				rules : {},
652
				rules : {},
649
				messages : {},
653
				messages : {},
650
				minmax : []
654
				minmax : []
651
			},
655
			},
652
			errors = {},
656
			errors = {},
653
			namesListFields = [],
657
			namesListFields = [],
654
			picked = '';
658
			picked = '';
655
 
659
 
656
	$( elements, $thisForm ).each( function() {
660
	$( elements, $thisForm ).each( function() {
657
		for( var fieldsClass = 0; spefieldsCount > fieldsClass; fieldsClass++ ) {
661
		for( var fieldsClass = 0; spefieldsCount > fieldsClass; fieldsClass++ ) {
658
			if ( valeurOk( $( this ).attr( 'required' ) ) && $( this ).hasClass( speFields[fieldsClass] ) && !valeurOk( chpSuppValidation.rules[ dataName ] ) ) {
662
			if ( valeurOk( $( this ).attr( 'required' ) ) && $( this ).hasClass( speFields[fieldsClass] ) && !valeurOk( chpSuppValidation.rules[ dataName ] ) ) {
659
				var dataName = $( this ).data( 'name' );
663
				var dataName = $( this ).data( 'name' );
660
 
664
 
661
				namesListFields.push( dataName );
665
				namesListFields.push( dataName );
662
				chpSuppValidation.rules[ dataName ] = { required : true };
666
				chpSuppValidation.rules[ dataName ] = { required : true };
663
 
667
 
664
				if ( valeurOk( $( '.other', $( this ) ) ) ) {
668
				if ( valeurOk( $( '.other', $( this ) ) ) ) {
665
					picked = ( 'select' === speFields[fieldsClass] ) ? ':selected' : ':checked';
669
					picked = ( 'select' === speFields[fieldsClass] ) ? ':selected' : ':checked';
666
					chpSuppValidation.rules[ 'collect-other-' + dataName.replace( '[]', '' ) ] = {
670
					chpSuppValidation.rules[ 'collect-other-' + dataName.replace( '[]', '' ) ] = {
667
						required : '#other-' + dataName.replace( '[]', '' ) + picked,
671
						required : '#other-' + dataName.replace( '[]', '' ) + picked,
668
						minlength: 1
672
						minlength: 1
669
					};
673
					};
670
					chpSuppValidation.messages[ 'collect-other-' + dataName.replace( '[]', '' ) ] = false;
674
					chpSuppValidation.messages[ 'collect-other-' + dataName.replace( '[]', '' ) ] = false;
671
				}
675
				}
672
				chpSuppValidation.rules[ dataName ]['listFields'] = true;
676
				chpSuppValidation.rules[ dataName ]['listFields'] = true;
673
				chpSuppValidation.messages[ dataName ] = 'Ce champ est requis :\nVeuillez choisir une option, ou entrer une valeur autre valide.';
677
				chpSuppValidation.messages[ dataName ] = 'Ce champ est requis :\nVeuillez choisir une option, ou entrer une valeur autre valide.';
674
				errors[dataName] = '.' + speFields[fieldsClass];
678
				errors[dataName] = '.' + speFields[fieldsClass];
675
			}
679
			}
676
		}
680
		}
677
		if ( valeurOk( $( this ).attr( 'name' ) ) && valeurOk ( $( this ).attr( 'required' ) ) && 0 > $.inArray( $( this ).attr( 'name' ) , namesListFields ) ) {
681
		if ( valeurOk( $( this ).attr( 'name' ) ) && valeurOk ( $( this ).attr( 'required' ) ) && 0 > $.inArray( $( this ).attr( 'name' ) , namesListFields ) ) {
678
			chpSuppValidation.rules[ $( this ).attr( 'name' ) ] = { required : true, minlength: 1 };
682
			chpSuppValidation.rules[ $( this ).attr( 'name' ) ] = { required : true, minlength: 1 };
679
			if(
683
			if(
680
					( valeurOk( $( this ).attr( 'type' ), true, 'number' ) || valeurOk( $( this ).attr( 'type' ), true, 'range' ) ) &&
684
					( valeurOk( $( this ).attr( 'type' ), true, 'number' ) || valeurOk( $( this ).attr( 'type' ), true, 'range' ) ) &&
681
					( valeurOk( $( this )[0].min ) || valeurOk( $( this )[0].max ) )
685
					( valeurOk( $( this )[0].min ) || valeurOk( $( this )[0].max ) )
682
				) {
686
				) {
683
				chpSuppValidation.rules[ $( this ).attr('name') ]['minMaxOk'] = true;
687
				chpSuppValidation.rules[ $( this ).attr('name') ]['minMaxOk'] = true;
684
				chpSuppValidation.messages[ $( this ).attr('name') ] = lthis.validerMinMax( $( this )[0] ).message;
688
				chpSuppValidation.messages[ $( this ).attr('name') ] = lthis.validerMinMax( $( this )[0] ).message;
685
			}
689
			}
686
		}
690
		}
687
	});
691
	});
688
	if ( valeurOk( chpSuppValidation.rules ) ) {
692
	if ( valeurOk( chpSuppValidation.rules ) ) {
689
		$.each( chpSuppValidation.rules, function( key ) {
693
		$.each( chpSuppValidation.rules, function( key ) {
690
			if ( !valeurOk( chpSuppValidation.messages[key] ) ) {
694
			if ( !valeurOk( chpSuppValidation.messages[key] ) ) {
691
				chpSuppValidation.messages[key] = 'Ce champ est requis :\nVeuillez entrer une valeur valide.';
695
				chpSuppValidation.messages[key] = 'Ce champ est requis :\nVeuillez entrer une valeur valide.';
692
			}
696
			}
693
		});
697
		});
694
		if ( 0 < Object.keys( errors ).length ) {
698
		if ( 0 < Object.keys( errors ).length ) {
695
			chpSuppValidation['errors'] = errors;
699
			chpSuppValidation['errors'] = errors;
696
		}
700
		}
697
	}
701
	}
698
	return chpSuppValidation;
702
	return chpSuppValidation;
699
};
703
};
700
 
704
 
701
WidgetSaisie.prototype.validerMinMax = function( element ) {
705
WidgetSaisie.prototype.validerMinMax = function( element ) {
702
 
706
 
703
	var mMCond      = new Boolean(),
707
	var mMCond      = new Boolean(),
704
			minCond     = parseFloat( element.value ) >= parseFloat( element.min ),
708
			minCond     = parseFloat( element.value ) >= parseFloat( element.min ),
705
			maxCond     = parseFloat( element.value ) <= parseFloat( element.max ),
709
			maxCond     = parseFloat( element.value ) <= parseFloat( element.max ),
706
			messageMnMx = 'La valeur entrée doit être',
710
			messageMnMx = 'La valeur entrée doit être',
707
			returnMnMx  = { cond : true , message : '' };
711
			returnMnMx  = { cond : true , message : '' };
708
 
712
 
709
	if(
713
	if(
710
			( valeurOk( element.type, true, 'number' ) || valeurOk( element.type, true, 'range' ) ) &&
714
			( valeurOk( element.type, true, 'number' ) || valeurOk( element.type, true, 'range' ) ) &&
711
			( valeurOk( element.min ) || valeurOk( element.max ) )
715
			( valeurOk( element.min ) || valeurOk( element.max ) )
712
		) {
716
		) {
713
		if ( element.min && element.max ) {
717
		if ( element.min && element.max ) {
714
			messageMnMx += ' comprise entre ' + element.min + ' et ' + element.max;
718
			messageMnMx += ' comprise entre ' + element.min + ' et ' + element.max;
715
			mnMxCond     = ( minCond && maxCond );
719
			mnMxCond     = ( minCond && maxCond );
716
		} else if ( element.min ) {
720
		} else if ( element.min ) {
717
			messageMnMx += ' supérieure à ' + element.min;
721
			messageMnMx += ' supérieure à ' + element.min;
718
			mnMxCond     = minCond;
722
			mnMxCond     = minCond;
719
		} else {
723
		} else {
720
			messageMnMx += ' inférieure à ' + element.max;
724
			messageMnMx += ' inférieure à ' + element.max;
721
			mnMxCond     = maxCond;
725
			mnMxCond     = maxCond;
722
		}
726
		}
723
		returnMnMx.cond    = mnMxCond;
727
		returnMnMx.cond    = mnMxCond;
724
		returnMnMx.message = messageMnMx;
728
		returnMnMx.message = messageMnMx;
725
	}
729
	}
726
	return returnMnMx;
730
	return returnMnMx;
727
 
731
 
728
};
732
};
729
 
733
 
730
 
734
 
731
WidgetSaisie.prototype.definirReglesFormValidator = function() {
735
WidgetSaisie.prototype.definirReglesFormValidator = function() {
732
	var formSuppValidation = this.chpEtendusValidation(),
736
	var formSuppValidation = this.chpEtendusValidation(),
733
		lthis = this;
737
		lthis = this;
734
 
738
 
735
	$( '#form-supp' ).validate({
739
	$( '#form-supp' ).validate({
736
		onclick : function( element ) {
740
		onclick : function( element ) {
737
			if (
741
			if (
738
				(
742
				(
739
					valeurOk( element.type, true, 'checkbox' ) ||
743
					valeurOk( element.type, true, 'checkbox' ) ||
740
					valeurOk( element.type, true, 'radio' )
744
					valeurOk( element.type, true, 'radio' )
741
				) &&
745
				) &&
742
				(
746
				(
743
					!valeurOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':checked' ) ) ||
747
					!valeurOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':checked' ) ) ||
744
					valeurOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':not(.other):checked' ) ) ||
748
					valeurOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':not(.other):checked' ) ) ||
745
					!valeurOk( $( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ) ) ||
749
					!valeurOk( $( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ) ) ||
746
					$( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ).is( ':checked' ) ||
750
					$( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ).is( ':checked' ) ||
747
					(
751
					(
748
						$( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ).is( ':checked' ) &&
752
						$( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ).is( ':checked' ) &&
749
						$( element ).closest( '.control-group' ).hasClass('error')
753
						$( element ).closest( '.control-group' ).hasClass('error')
750
					)
754
					)
751
				)
755
				)
752
			) {
756
			) {
753
				$( element ).valid();
757
				$( element ).valid();
754
				if ( $( element ).valid() ) {
758
				if ( $( element ).valid() ) {
755
					$( element ).closest( '.control-group' ).removeClass( 'error' );
759
					$( element ).closest( '.control-group' ).removeClass( 'error' );
756
					$( element ).next( $( 'span.error' ) ).remove();
760
					$( element ).next( $( 'span.error' ) ).remove();
757
				} else {
761
				} else {
758
					$( element ).closest( '.control-group' ).addClass( 'error' );
762
					$( element ).closest( '.control-group' ).addClass( 'error' );
759
				}
763
				}
760
			}
764
			}
761
			return false;
765
			return false;
762
		},
766
		},
763
		rules : formSuppValidation.rules,
767
		rules : formSuppValidation.rules,
764
		messages : formSuppValidation.messages,
768
		messages : formSuppValidation.messages,
765
		errorPlacement : function( error , element ) {
769
		errorPlacement : function( error , element ) {
766
			if ( 0 < Object.keys( formSuppValidation.errors ).length ) {
770
			if ( 0 < Object.keys( formSuppValidation.errors ).length ) {
767
				var errorsKeys = Object.keys( formSuppValidation.errors ),
771
				var errorsKeys = Object.keys( formSuppValidation.errors ),
768
						thisKey = '',
772
						thisKey = '',
769
						errorsFlag = true;
773
						errorsFlag = true;
770
				for ( i = 0 ; i < errorsKeys.length ; i++ ) {
774
				for ( i = 0 ; i < errorsKeys.length ; i++ ) {
771
					thisKey = errorsKeys[i];
775
					thisKey = errorsKeys[i];
772
					if( $( element ).attr( 'name' ) === thisKey ) {
776
					if( $( element ).attr( 'name' ) === thisKey ) {
773
						$( formSuppValidation.errors[thisKey] ).append( error );
777
						$( formSuppValidation.errors[thisKey] ).append( error );
774
						errorsFlag = false;
778
						errorsFlag = false;
775
					}
779
					}
776
				}
780
				}
777
				if ( errorsFlag ) {
781
				if ( errorsFlag ) {
778
					error.insertAfter( element );
782
					error.insertAfter( element );
779
				}
783
				}
780
			} else {
784
			} else {
781
				error.insertAfter( element );
785
				error.insertAfter( element );
782
			}
786
			}
783
		}
787
		}
784
	});
788
	});
785
 
789
 
786
	$( '#form-supp .select' ).change( function() {
790
	$( '#form-supp .select' ).change( function() {
787
		$( this ).valid();
791
		$( this ).valid();
788
	});
792
	});
789
 
793
 
790
	$( 'input[type=date]' ).on( 'input', function() {
794
	$( 'input[type=date]' ).on( 'input', function() {
791
		$( this ).valid();
795
		$( this ).valid();
792
	});
796
	});
793
 
797
 
794
	// Validation Taxon si pas de miniature
798
	// Validation Taxon si pas de miniature
795
	$( '#taxon' ).on( 'change', function() {
799
	$( '#taxon' ).on( 'change', function() {
796
		var images = valeurOk( $( '#miniatures .miniature' ) );
800
		var images = valeurOk( $( '#miniatures .miniature' ) );
797
		lthis.validerTaxonImage( valeurOk( $( this ).val() ), images );
801
		lthis.validerTaxonImage( valeurOk( $( this ).val() ), images );
798
	});
802
	});
799
 
803
 
800
	// Validation miniatures avec MutationObserver
804
	// Validation miniatures avec MutationObserver
801
	this.surPresenceAbsenceMiniature();
805
	this.surPresenceAbsenceMiniature();
802
 
806
 
803
	$( '#form-observation' ).validate({
807
	$( '#form-observation' ).validate({
804
		rules : {
808
		rules : {
805
			date_releve : {
809
			date_releve : {
806
				required : true,
810
				required : true,
807
				'dateCel' : true
811
				'dateCel' : true
808
			},
812
			},
809
			latitude : {
813
			latitude : {
810
				required : true,
814
				required : true,
811
				minlength : 1,
815
				minlength : 1,
812
				range : [-90, 90]
816
				range : [-90, 90]
813
			},
817
			},
814
			longitude : {
818
			longitude : {
815
				required : true,
819
				required : true,
816
				minlength : 1,
820
				minlength : 1,
817
				range : [-180, 180]
821
				range : [-180, 180]
818
			}
822
			}
819
		}
823
		}
820
	});
824
	});
821
 
825
 
822
	$( '#form-observateur' ).validate({
826
	$( '#form-observateur' ).validate({
823
		rules : {
827
		rules : {
824
			courriel : {
828
			courriel : {
825
				required : true,
829
				required : true,
826
				email : true,
830
				email : true,
827
				'userEmailOk' : true
831
				'userEmailOk' : true
828
			},
832
			},
829
			courriel_confirmation : {
833
			courriel_confirmation : {
830
				required : true,
834
				required : true,
831
				equalTo : '#courriel'
835
				equalTo : '#courriel'
832
			}
836
			}
833
		}
837
		}
834
	});
838
	});
835
 
839
 
836
	$( '#connexion,#bouton-inscription,#bouton-anonyme' ).click( function( event ) {
840
	$( '#connexion,#bouton-inscription,#bouton-anonyme' ).click( function( event ) {
837
		$( '.nav.control-group' ).removeClass( 'error' );
841
		$( '.nav.control-group' ).removeClass( 'error' );
838
	});
842
	});
839
};
843
};
840
 
844
 
841
WidgetSaisie.prototype.validerTaxonImage = function( taxon = false, images = false ) {
845
WidgetSaisie.prototype.validerTaxonImage = function( taxon = false, images = false ) {
842
	var taxonOuImage = ( images || taxon );
846
	var taxonOuImage = ( images || taxon );
843
	if ( images || taxon ) {
847
	if ( images || taxon ) {
844
		this.masquerPanneau( '#dialogue-taxon-or-image' );
848
		this.masquerPanneau( '#dialogue-taxon-or-image' );
845
		$( '#bloc-taxon' ).removeClass( 'error' )
849
		$( '#bloc-taxon' ).removeClass( 'error' )
846
			.find( 'span.error' ).hide();
850
			.find( 'span.error' ).hide();
847
		$( '#fichier' ).parent( 'label.label-file' ).removeClass( 'error' );
851
		$( '#fichier' ).parent( 'label.label-file' ).removeClass( 'error' );
848
		$( '#photos-conteneur').removeClass( 'error' ).find( 'span.error' ).hide();
852
		$( '#photos-conteneur').removeClass( 'error' ).find( 'span.error' ).hide();
849
	} else {
853
	} else {
850
		this.afficherPanneau( '#dialogue-taxon-or-image' );
854
		this.afficherPanneau( '#dialogue-taxon-or-image' );
851
		$( '#bloc-taxon' ).addClass( 'error' )
855
		$( '#bloc-taxon' ).addClass( 'error' )
852
			.find( 'span.error' ).show();
856
			.find( 'span.error' ).show();
853
		$( '#fichier' ).parent( 'label.label-file' ).addClass( 'error' );
857
		$( '#fichier' ).parent( 'label.label-file' ).addClass( 'error' );
854
		$( '#photos-conteneur').addClass( 'error' ).find( 'span.error' ).show();
858
		$( '#photos-conteneur').addClass( 'error' ).find( 'span.error' ).show();
855
	}
859
	}
856
	return ( images || taxon );
860
	return ( images || taxon );
857
};
861
};
858
 
862
 
859
WidgetSaisie.prototype.surPresenceAbsenceMiniature = function() {
863
WidgetSaisie.prototype.surPresenceAbsenceMiniature = function() {
860
	var lthis = this;
864
	var lthis = this;
861
 
865
 
862
	// voir : https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/disconnect
866
	// voir : https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/disconnect
863
	// Selectionne le noeud dont les mutations seront observées
867
	// Selectionne le noeud dont les mutations seront observées
864
	var targetNode = document.getElementById( 'miniatures' );
868
	var targetNode = document.getElementById( 'miniatures' );
865
	// Fonction callback à éxécuter quand une mutation est observée
869
	// Fonction callback à éxécuter quand une mutation est observée
866
	var callback = function( mutationsList ) {
870
	var callback = function( mutationsList ) {
867
	    for( var mutation of mutationsList ) {
871
	    for( var mutation of mutationsList ) {
868
	    	var taxon = valeurOk( $( '#taxon' ).val() );
872
	    	var taxon = valeurOk( $( '#taxon' ).val() );
869
	        images = ( 0 < mutation.target.childElementCount );
873
	        images = ( 0 < mutation.target.childElementCount );
870
		 	lthis.validerTaxonImage( taxon, images );
874
		 	lthis.validerTaxonImage( taxon, images );
871
	    }
875
	    }
872
	};
876
	};
873
	// Créé une instance de l'observateur lié à la fonction de callback
877
	// Créé une instance de l'observateur lié à la fonction de callback
874
	this.observer = new MutationObserver( callback );
878
	this.observer = new MutationObserver( callback );
875
	// Commence à observer le noeud cible pour les mutations précédemment configurées
879
	// Commence à observer le noeud cible pour les mutations précédemment configurées
876
	this.observer.observe( targetNode, { childList: true } );
880
	this.observer.observe( targetNode, { childList: true } );
877
};
881
};
878
 
882
 
879
WidgetSaisie.prototype.validerFormulaire = function() {
883
WidgetSaisie.prototype.validerFormulaire = function() {
880
	var observateur  = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() && $( '#courriel_confirmation' ).valid() )
884
	var observateur  = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() && $( '#courriel_confirmation' ).valid() )
881
	var obs          = $( '#form-observation' ).valid();
885
	var obs          = $( '#form-observation' ).valid();
882
	var geoloc       = ( valeurOk( $( '#latitude' ).val() ) && valeurOk( $( '#longitude' ).val() ) ) ;
886
	var geoloc       = ( valeurOk( $( '#latitude' ).val() ) && valeurOk( $( '#longitude' ).val() ) ) ;
883
	var images       = valeurOk( $( '#miniatures .miniature' ) );
887
	var images       = valeurOk( $( '#miniatures .miniature' ) );
884
	var taxon        = valeurOk( $( '#taxon' ).val() );
888
	var taxon        = valeurOk( $( '#taxon' ).val() );
885
	// validation et panneau taxon/images
889
	// validation et panneau taxon/images
886
 	var taxonOuImage = this.validerTaxonImage( taxon, images );
890
 	var taxonOuImage = this.validerTaxonImage( taxon, images );
887
 	// console.log(taxonOuImage);
891
 	// console.log(taxonOuImage);
888
	var chpsSupp     = new Boolean();
892
	var chpsSupp     = new Boolean();
889
	if ( valeurOk( $( '#form-supp' ) ) ) {
893
	if ( valeurOk( $( '#form-supp' ) ) ) {
890
		chpsSupp = ( function () {
894
		chpsSupp = ( function () {
891
			var otherFlag = $( '#form-supp' ).valid();
895
			var otherFlag = $( '#form-supp' ).valid();
892
			if( valeurOk( $( '.other', $( '#form-supp' ) ) ) ) {
896
			if( valeurOk( $( '.other', $( '#form-supp' ) ) ) ) {
893
				$( '.other', $( '#form-supp' ) ).each( function() {
897
				$( '.other', $( '#form-supp' ) ).each( function() {
894
					var picked = ( $( this ).data( 'element' ) !== 'select' ) ? ':checked' : ':selected';
898
					var picked = ( $( this ).data( 'element' ) !== 'select' ) ? ':checked' : ':selected';
895
						if ( $( this ).is( picked ) && valeurOk( $( this ).val(), true, 'other' ) ) {
899
						if ( $( this ).is( picked ) && valeurOk( $( this ).val(), true, 'other' ) ) {
896
							otherFlag = false;
900
							otherFlag = false;
897
						}
901
						}
898
				});
902
				});
899
			}
903
			}
900
			return otherFlag;
904
			return otherFlag;
901
		})();
905
		})();
902
	} else {
906
	} else {
903
		chpsSupp = true;
907
		chpsSupp = true;
904
	}
908
	}
905
	// panneau geoloc
909
	// panneau geoloc
906
	if ( geoloc ) {
910
	if ( geoloc ) {
907
		this.masquerPanneau( '#dialogue-geoloc-ko' );
911
		this.masquerPanneau( '#dialogue-geoloc-ko' );
908
		$( '#geoloc-datas' ).closest( '.control-group' ).removeClass( 'error' );
912
		$( '#geoloc-datas' ).closest( '.control-group' ).removeClass( 'error' );
909
	} else{
913
	} else{
910
		this.afficherPanneau( '#dialogue-geoloc-ko' );
914
		this.afficherPanneau( '#dialogue-geoloc-ko' );
911
		$( '#geoloc-datas' ).closest( '.control-group' ).addClass( 'error' );
915
		$( '#geoloc-datas' ).closest( '.control-group' ).addClass( 'error' );
912
	}
916
	}
913
	// panneau observateur
917
	// panneau observateur
914
	if ( observateur ) {
918
	if ( observateur ) {
915
		this.masquerPanneau( '#dialogue-utilisateur-non-identifie' );
919
		this.masquerPanneau( '#dialogue-utilisateur-non-identifie' );
916
		$( '.nav.control-group' ).removeClass( 'error' );
920
		$( '.nav.control-group' ).removeClass( 'error' );
917
	} else {
921
	} else {
918
		this.afficherPanneau( '#dialogue-utilisateur-non-identifie' );
922
		this.afficherPanneau( '#dialogue-utilisateur-non-identifie' );
919
		$( '.nav.control-group' ).addClass( 'error' );
923
		$( '.nav.control-group' ).addClass( 'error' );
920
	}
924
	}
921
 
925
 
922
	return ( observateur && obs && geoloc && taxonOuImage && chpsSupp );
926
	return ( observateur && obs && geoloc && taxonOuImage && chpsSupp );
923
};
927
};
924
 
928
 
925
// Fichier Images *************************************************************/
929
// Fichier Images *************************************************************/
926
/**
930
/**
927
 * Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
931
 * Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
928
 */
932
 */
929
WidgetSaisie.prototype.afficherMiniature = function( reponse ) {
933
WidgetSaisie.prototype.afficherMiniature = function( reponse ) {
930
	if ( this.debug ) {
934
	if ( this.debug ) {
931
		var debogage = $( 'debogage', reponse ).text();
935
		var debogage = $( 'debogage', reponse ).text();
932
		//console.log( 'Débogage upload : '+debogage);
936
		//console.log( 'Débogage upload : '+debogage);
933
	}
937
	}
934
	var message = $( 'message', reponse ).text();
938
	var message = $( 'message', reponse ).text();
935
	if ( valeurOk( message ) ) {
939
	if ( valeurOk( message ) ) {
936
		$( '#miniature-msg' ).append( message );
940
		$( '#miniature-msg' ).append( message );
937
	} else {
941
	} else {
938
		$( '#miniatures' ).append( this.creerWidgetMiniature( reponse ) );
942
		$( '#miniatures' ).append( this.creerWidgetMiniature( reponse ) );
939
	}
943
	}
940
	$( '#ajouter-obs' ).removeAttr( 'disabled' );
944
	$( '#ajouter-obs' ).removeAttr( 'disabled' );
941
};
945
};
942
 
946
 
943
/**
947
/**
944
 * Crée la miniature d'une image temporaire (formulaire), avec le bouton pour l'effacer
948
 * Crée la miniature d'une image temporaire (formulaire), avec le bouton pour l'effacer
945
 */
949
 */
946
WidgetSaisie.prototype.creerWidgetMiniature = function( reponse ) {
950
WidgetSaisie.prototype.creerWidgetMiniature = function( reponse ) {
947
	var miniatureUrl = $( 'miniature-url', reponse ).text();
951
	var miniatureUrl = $( 'miniature-url', reponse ).text();
948
	var imgNom = $( 'image-nom', reponse ).text();
952
	var imgNom = $( 'image-nom', reponse ).text();
949
	var html =
953
	var html =
950
		'<div class="miniature mb-3 mr-3">'+
954
		'<div class="miniature mb-3 mr-3">'+
951
			'<img class="miniature-img" class="miniature img-rounded" alt="' + imgNom + '" src="' + miniatureUrl + '"/>'+
955
			'<img class="miniature-img" class="miniature img-rounded" alt="' + imgNom + '" src="' + miniatureUrl + '"/>'+
952
			'<a class="effacer-miniature"><i class="far fa-trash-alt"></i></a>'+
956
			'<a class="effacer-miniature"><i class="far fa-trash-alt"></i></a>'+
953
		'</div>';
957
		'</div>';
954
	return html;
958
	return html;
955
};
959
};
956
 
960
 
957
/**
961
/**
958
 * Retourne true si l'extension de l'image 'nom' est .jpg ou .jpeg
962
 * Retourne true si l'extension de l'image 'nom' est .jpg ou .jpeg
959
 */
963
 */
960
WidgetSaisie.prototype.verifierFormat = function( nom ) {
964
WidgetSaisie.prototype.verifierFormat = function( nom ) {
961
	var parts = nom.split( '.' );
965
	var parts = nom.split( '.' );
962
	extension = parts[ parts.length - 1 ];
966
	extension = parts[ parts.length - 1 ];
963
	return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() );
967
	return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() );
964
};
968
};
965
 
969
 
966
/**
970
/**
967
 * Efface une miniature (formulaire)
971
 * Efface une miniature (formulaire)
968
 */
972
 */
969
WidgetSaisie.prototype.supprimerMiniature = function( miniature ) {
973
WidgetSaisie.prototype.supprimerMiniature = function( miniature ) {
970
	miniature.parents( '.miniature' ).remove();
974
	miniature.parents( '.miniature' ).remove();
971
};
975
};
972
 
976
 
973
// Referentiel ****************************************************************/
977
// Referentiel ****************************************************************/
974
// N'est pas utilisé en cas de taxon-liste
978
// N'est pas utilisé en cas de taxon-liste
975
WidgetSaisie.prototype.surChangementReferentiel = function() {
979
WidgetSaisie.prototype.surChangementReferentiel = function() {
976
	this.nomSciReferentiel = $( '#referentiel' ).val();
980
	this.nomSciReferentiel = $( '#referentiel' ).val();
977
	//réinitialise taxon.val
981
	//réinitialise taxon.val
978
	$( '#taxon' ).val( '' );
982
	$( '#taxon' ).val( '' );
979
	$( '#taxon' ).data( 'numNomSel', '' );
983
	$( '#taxon' ).data( 'numNomSel', '' );
980
	// this.initialiserAutocompleteCommune();
984
	// this.initialiserAutocompleteCommune();
981
	// this.initialiserGoogleMap( false );
985
	// this.initialiserGoogleMap( false );
982
};
986
};
983
 
987
 
984
// Ajouter Obs ****************************************************************/
988
// Ajouter Obs ****************************************************************/
985
/**
989
/**
986
 * Ajoute une observation saisie dans le formulaire à la liste des observations à transmettre
990
 * Ajoute une observation saisie dans le formulaire à la liste des observations à transmettre
987
 */
991
 */
988
WidgetSaisie.prototype.ajouterObs = function() {
992
WidgetSaisie.prototype.ajouterObs = function() {
989
	// Fermeture automatique des dialogue de transmission de données
993
	// Fermeture automatique des dialogue de transmission de données
990
	// @WARNING TEST
994
	// @WARNING TEST
991
	$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
995
	$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
992
	$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
996
	$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
993
 
997
 
994
	if ( this.validerFormulaire() ) {
998
	if ( this.validerFormulaire() ) {
995
		this.masquerPanneau( '#dialogue-form-invalide' );
999
		this.masquerPanneau( '#dialogue-form-invalide' );
996
		this.obsNbre = this.obsNbre + 1;
1000
		this.obsNbre = this.obsNbre + 1;
997
		$( '.obs-nbre' ).text( this.obsNbre );
1001
		$( '.obs-nbre' ).text( this.obsNbre );
998
		$( '.obs-nbre' ).triggerHandler( 'changement' );
1002
		$( '.obs-nbre' ).triggerHandler( 'changement' );
999
		this.afficherObs();
1003
		this.afficherObs();
1000
		this.stockerObsData();
1004
		this.stockerObsData();
1001
		this.supprimerMiniatures();
1005
		this.supprimerMiniatures();
1002
		if( !this.especeImposee ) {
1006
		if( !this.especeImposee ) {
1003
			$( '#taxon' ).val( '' );
1007
			$( '#taxon' ).val( '' );
1004
			$( '#taxon' ).data( 'numNomSel', '' )
1008
			$( '#taxon' ).data( 'numNomSel', '' )
1005
				.data( 'nomRet','' )
1009
				.data( 'nomRet','' )
1006
				.data( 'numNomRet', '' )
1010
				.data( 'numNomRet', '' )
1007
				.data( 'nt', '' )
1011
				.data( 'nt', '' )
1008
				.data( 'famille', '' );
1012
				.data( 'famille', '' );
1009
			if( this.isTaxonListe ) {
1013
			if( this.isTaxonListe ) {
1010
				$( '#taxon-liste' ).find( 'option' ).each( function() {
1014
				$( '#taxon-liste' ).find( 'option' ).each( function() {
1011
					if ( $( this ).hasClass( 'choisir' ) ) {
1015
					if ( $( this ).hasClass( 'choisir' ) ) {
1012
						$( this ).attr( 'selected', true );
1016
						$( this ).attr( 'selected', true );
1013
					} else {
1017
					} else {
1014
						$( this ).attr( 'selected', false );
1018
						$( this ).attr( 'selected', false );
1015
					}
1019
					}
1016
				});
1020
				});
1017
				$( '#taxon-input-groupe' ).addClass( 'hidden' );
1021
				$( '#taxon-input-groupe' ).addClass( 'hidden' );
1018
				$('#taxon-autre').val('');
1022
				$('#taxon-autre').val('');
1019
			}
1023
			}
1020
		}
1024
		}
1021
		if ( valeurOk( $( '#form-supp' ) ) ) {
1025
		if ( valeurOk( $( '#form-supp' ) ) ) {
1022
			$( '#form-supp' ).validate().resetForm();
1026
			$( '#form-supp' ).validate().resetForm();
1023
			// if ( valeurOk( $( '#form-supp' ) ) ) {
1027
			// if ( valeurOk( $( '#form-supp' ) ) ) {
1024
		}
1028
		}
1025
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
1029
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
1026
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.msgTraduction( 'observations-transmises' ) );
1030
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.msgTraduction( 'observations-transmises' ) );
1027
	} else {
1031
	} else {
1028
		this.afficherPanneau( '#dialogue-form-invalide' );
1032
		this.afficherPanneau( '#dialogue-form-invalide' );
1029
	}
1033
	}
1030
};
1034
};
1031
 
1035
 
1032
/**
1036
/**
1033
 * Affiche une observation dans la liste des observations à transmettre
1037
 * Affiche une observation dans la liste des observations à transmettre
1034
 */
1038
 */
1035
WidgetSaisie.prototype.afficherObs = function() {
1039
WidgetSaisie.prototype.afficherObs = function() {
1036
 
1040
 
1037
	var numNomSel = $( '#taxon' ).data( 'numNomSel' ),
1041
	var numNomSel = $( '#taxon' ).data( 'numNomSel' ),
1038
			taxon = $( '#taxon' ).val(),
1042
			taxon = $( '#taxon' ).val(),
1039
			referentiel = '',
1043
			referentiel = '',
1040
			commune = '',
1044
			commune = '',
1041
			inseeLatitudeLongitude = '',
1045
			inseeLatitudeLongitude = '',
1042
			lieudit = '',
1046
			lieudit = '',
1043
			station = '',
1047
			station = '',
1044
			milieu = '',
1048
			milieu = '',
1045
			commentaires = '';
1049
			commentaires = '';
1046
 
1050
 
1047
	if ( valeurOk( numNomSel ) ) {
1051
	if ( valeurOk( numNomSel ) ) {
1048
		referentiel = '<span class="referentiel-obs">' + '[' + this.nomSciReferentiel + ']' + '</span>';
1052
		referentiel = '<span class="referentiel-obs">' + '[' + this.nomSciReferentiel + ']' + '</span>';
1049
	}
1053
	}
1050
	if ( valeurOk( $( '#commune-nom' ).val() ) ) {
1054
	if ( valeurOk( $( '#commune-nom' ).val() ) ) {
1051
		commune = ' '  + this.msgTraduction( 'lieu-obs' ) + ' <span class="commune">' + $( '#commune-nom' ).val() + '</span> ';
1055
		commune = ' '  + this.msgTraduction( 'lieu-obs' ) + ' <span class="commune">' + $( '#commune-nom' ).val() + '</span> ';
1052
	}
1056
	}
1053
	if ( valeurOk( $( '#commune-insee' ).val() ) &&  valeurOk( $( '#latitude' ).val() ) && valeurOk( $( '#longitude' ).val() ) ) {
1057
	if ( valeurOk( $( '#commune-insee' ).val() ) &&  valeurOk( $( '#latitude' ).val() ) && valeurOk( $( '#longitude' ).val() ) ) {
1054
		inseeLatitudeLongitude = '(INSEE Commune:' + $('#commune-insee').val() + ') [' + $( '#latitude' ).val() + ' / ' + $( '#longitude' ).val() + ']';
1058
		inseeLatitudeLongitude = '(INSEE Commune:' + $('#commune-insee').val() + ') [' + $( '#latitude' ).val() + ' / ' + $( '#longitude' ).val() + ']';
1055
	}
1059
	}
1056
	if ( valeurOk( $( '#lieudit' ).val() ) ) {
1060
	if ( valeurOk( $( '#lieudit' ).val() ) ) {
1057
		lieudit = '<span>' + this.msgTraduction( 'lieu-dit' ) + ' :</span> ' + $( '#lieudit' ).val() + ' ';
1061
		lieudit = '<span>' + this.msgTraduction( 'lieu-dit' ) + ' :</span> ' + $( '#lieudit' ).val() + ' ';
1058
	}
1062
	}
1059
	if ( valeurOk( $( '#station' ).val() ) ) {
1063
	if ( valeurOk( $( '#station' ).val() ) ) {
1060
		station = '<span>' + this.msgTraduction( 'station' ) + ' :</span> ' + $( '#station' ).val() + ' ';
1064
		station = '<span>' + this.msgTraduction( 'station' ) + ' :</span> ' + $( '#station' ).val() + ' ';
1061
	}
1065
	}
1062
	if ( valeurOk( $( '#milieu' ).val() ) ) {
1066
	if ( valeurOk( $( '#milieu' ).val() ) ) {
1063
		milieu = '<span>' + this.msgTraduction( 'milieu' ) + ' :</span> ' + $( '#milieu' ).val() + ' ';
1067
		milieu = '<span>' + this.msgTraduction( 'milieu' ) + ' :</span> ' + $( '#milieu' ).val() + ' ';
1064
	}
1068
	}
1065
	if ( valeurOk( $( '#notes' ).val() ) ) {
1069
	if ( valeurOk( $( '#notes' ).val() ) ) {
1066
		commentaires = this.msgTraduction( 'commentaires' ) + ' : <span class="discretion">' + $( '#notes' ).val() + '</span>' + ' ';
1070
		commentaires = this.msgTraduction( 'commentaires' ) + ' : <span class="discretion">' + $( '#notes' ).val() + '</span>' + ' ';
1067
	}
1071
	}
1068
 
1072
 
1069
	var responsivDiff1 = '',
1073
	var responsivDiff1 = '',
1070
			responsivDiff2 = '',
1074
			responsivDiff2 = '',
1071
			responsivDiff3 = '',
1075
			responsivDiff3 = '',
1072
			responsivDiff4 = '',
1076
			responsivDiff4 = '',
1073
			responsivDiff5 = '',
1077
			responsivDiff5 = '',
1074
			responsivDiff6 = '';
1078
			responsivDiff6 = '';
1075
	if ( window.matchMedia( '(min-width: 576px)' ).matches ) {
1079
	if ( window.matchMedia( '(min-width: 576px)' ).matches ) {
1076
		/* La largeur minimum de l'affichage est 600 px inclus */
1080
		/* La largeur minimum de l'affichage est 600 px inclus */
1077
		responsivDiff1 = ' droite';
1081
		responsivDiff1 = ' droite';
1078
		responsivDiff2 = '<div></div>';
1082
		responsivDiff2 = '<div></div>';
1079
		responsivDiff3 = '<div class="row">';
1083
		responsivDiff3 = '<div class="row">';
1080
		responsivDiff4 = ' col-md-2 col-sm-4';
1084
		responsivDiff4 = ' col-md-2 col-sm-4';
1081
		responsivDiff5 = ' class="col-md-9 col-sm-7"';
1085
		responsivDiff5 = ' class="col-md-9 col-sm-7"';
1082
		responsivDiff6 = '</div>';
1086
		responsivDiff6 = '</div>';
1083
	}
1087
	}
1084
 
1088
 
1085
 
1089
 
1086
		$( '#liste-obs' ).prepend(
1090
		$( '#liste-obs' ).prepend(
1087
			'<div id="obs' + this.obsNbre + '" class="obs obs' + this.obsNbre + ' mb-2">'+
1091
			'<div id="obs' + this.obsNbre + '" class="obs obs' + this.obsNbre + ' mb-2">'+
1088
 
1092
 
1089
				'<div '+
1093
				'<div '+
1090
					'class="obs-action" '+
1094
					'class="obs-action" '+
1091
					'title="' + this.msgTraduction( 'supprimer-observation-liste' ) + '"'+
1095
					'title="' + this.msgTraduction( 'supprimer-observation-liste' ) + '"'+
1092
				'>'+
1096
				'>'+
1093
					'<button class="btn btn-danger supprimer-obs' + responsivDiff1 + '" value="'+ this.obsNbre + '" title="' + this.msgTraduction( 'obs-numero' ) + this.obsNbre + '">'+
1097
					'<button class="btn btn-danger supprimer-obs' + responsivDiff1 + '" value="'+ this.obsNbre + '" title="' + this.msgTraduction( 'obs-numero' ) + this.obsNbre + '">'+
1094
					'<i class="far fa-trash-alt"></i>'+
1098
					'<i class="far fa-trash-alt"></i>'+
1095
					'</button>'+
1099
					'</button>'+
1096
					responsivDiff2 +
1100
					responsivDiff2 +
1097
				'</div> '+
1101
				'</div> '+
1098
 
1102
 
1099
				responsivDiff3 +
1103
				responsivDiff3 +
1100
					'<div class="thumbnail' + responsivDiff4 + '">'+
1104
					'<div class="thumbnail' + responsivDiff4 + '">'+
1101
						this.ajouterImgMiniatureAuTransfert()+
1105
						this.ajouterImgMiniatureAuTransfert()+
1102
					'</div>'+
1106
					'</div>'+
1103
					'<div' + responsivDiff5 + '>'+
1107
					'<div' + responsivDiff5 + '>'+
1104
						'<ul class="unstyled">'+
1108
						'<ul class="unstyled">'+
1105
							'<li>'+
1109
							'<li>'+
1106
								'<span class="nom-sci">' + taxon + '</span> '+
1110
								'<span class="nom-sci">' + taxon + '</span> '+
1107
								this.ajouterNumNomSel( numNomSel ) +
1111
								this.ajouterNumNomSel( numNomSel ) +
1108
								referentiel +
1112
								referentiel +
1109
								commune +
1113
								commune +
1110
								inseeLatitudeLongitude +
1114
								inseeLatitudeLongitude +
1111
								' ' + this.msgTraduction( 'obs-le' ) + ' ' +
1115
								' ' + this.msgTraduction( 'obs-le' ) + ' ' +
1112
								'<span class="date">' + this.fournirDate( $( '#date_releve' ).val() ) + '</span>'+
1116
								'<span class="date">' + this.fournirDate( $( '#date_releve' ).val() ) + '</span>'+
1113
							'</li>'+
1117
							'</li>'+
1114
							'<li>'+
1118
							'<li>'+
1115
								lieudit +
1119
								lieudit +
1116
								station +
1120
								station +
1117
								milieu +
1121
								milieu +
1118
							'</li>'+
1122
							'</li>'+
1119
							'<li>'+
1123
							'<li>'+
1120
								commentaires +
1124
								commentaires +
1121
							'</li>'+
1125
							'</li>'+
1122
						'</ul>'+
1126
						'</ul>'+
1123
					'</div>'+
1127
					'</div>'+
1124
				responsivDiff6+
1128
				responsivDiff6+
1125
			'</div>'
1129
			'</div>'
1126
		);
1130
		);
1127
 
1131
 
1128
	$( '#zone-liste-obs' ).removeClass( 'hidden' );
1132
	$( '#zone-liste-obs' ).removeClass( 'hidden' );
1129
};
1133
};
1130
 
1134
 
1131
/**
1135
/**
1132
 * Ajoute une boîte de miniatures avec défilement des images,
1136
 * Ajoute une boîte de miniatures avec défilement des images,
1133
 * pour une obs de la liste des obs à transmettre
1137
 * pour une obs de la liste des obs à transmettre
1134
 */
1138
 */
1135
WidgetSaisie.prototype.ajouterImgMiniatureAuTransfert = function() {
1139
WidgetSaisie.prototype.ajouterImgMiniatureAuTransfert = function() {
1136
	var html        =
1140
	var html        =
1137
				'<div class="defilement-miniatures">'+
1141
				'<div class="defilement-miniatures">'+
1138
					'<figure class="centre">'+
1142
					'<figure class="centre">'+
1139
						'<img class="miniature align-middle" alt="Aucune photo" src="' + this.pasDePhotoIconeUrl + '" width="80%" />'+
1143
						'<img class="miniature align-middle" alt="Aucune photo" src="' + this.pasDePhotoIconeUrl + '" width="80%" />'+
1140
					'</figure>'+
1144
					'</figure>'+
1141
				'</div>',
1145
				'</div>',
1142
			miniatures   = '',
1146
			miniatures   = '',
1143
			premiere     = true,
1147
			premiere     = true,
1144
			centre       = '';
1148
			centre       = '';
1145
			defilVisible = '';
1149
			defilVisible = '';
1146
 
1150
 
1147
	if ( valeurOk( $( '#miniatures img' ) ) ) {
1151
	if ( valeurOk( $( '#miniatures img' ) ) ) {
1148
		$( '#miniatures img' ).each( function() {
1152
		$( '#miniatures img' ).each( function() {
1149
			var imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
1153
			var imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
1150
			premiere = false;
1154
			premiere = false;
1151
 
1155
 
1152
			var css        = ( $( this ).hasClass( 'b64' ) ) ? 'miniature b64' : 'miniature',
1156
			var css        = ( $( this ).hasClass( 'b64' ) ) ? 'miniature b64' : 'miniature',
1153
					src        = $( this ).attr( 'src' ),
1157
					src        = $( this ).attr( 'src' ),
1154
					alt        = $( this ).attr( 'alt' ),
1158
					alt        = $( this ).attr( 'alt' ),
1155
					miniature  = '<img class="' + css + ' ' + imgVisible + ' align-middle"  alt="' + alt + '"src="' + src + '" width="80%" />';
1159
					miniature  = '<img class="' + css + ' ' + imgVisible + ' align-middle"  alt="' + alt + '"src="' + src + '" width="80%" />';
1156
 
1160
 
1157
			miniatures += miniature;
1161
			miniatures += miniature;
1158
		});
1162
		});
1159
		if ( 1 === $( '#miniatures img' ).length ) {
1163
		if ( 1 === $( '#miniatures img' ).length ) {
1160
			centre       = 'centre';
1164
			centre       = 'centre';
1161
			defilVisible = ' defilement-miniatures-cache';
1165
			defilVisible = ' defilement-miniatures-cache';
1162
		}
1166
		}
1163
		html             =
1167
		html             =
1164
			'<div class="defilement-miniatures">'+
1168
			'<div class="defilement-miniatures">'+
1165
				'<a href="#" class="defilement-miniatures-gauche mr-1' + defilVisible + '"><i class="fas fa-chevron-circle-left"></i></a>'+
1169
				'<a href="#" class="defilement-miniatures-gauche mr-1' + defilVisible + '"><i class="fas fa-chevron-circle-left"></i></a>'+
1166
				'<figure class="' + centre + '">'+
1170
				'<figure class="' + centre + '">'+
1167
					miniatures+
1171
					miniatures+
1168
				'</figure>'+
1172
				'</figure>'+
1169
				'<a href="#" class="defilement-miniatures-droite ml-1' + defilVisible + '"><i class="fas fa-chevron-circle-right"></i></a>'+
1173
				'<a href="#" class="defilement-miniatures-droite ml-1' + defilVisible + '"><i class="fas fa-chevron-circle-right"></i></a>'+
1170
			'</div>';
1174
			'</div>';
1171
	}
1175
	}
1172
	return html;
1176
	return html;
1173
};
1177
};
1174
 
1178
 
1175
WidgetSaisie.prototype.fournirDate = function( dateObs ) {
1179
WidgetSaisie.prototype.fournirDate = function( dateObs ) {
1176
	if ( /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/.test( dateObs ) ) {
1180
	if ( /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/.test( dateObs ) ) {
1177
		return dateObs;
1181
		return dateObs;
1178
	} else if ( /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test( dateObs ) ) {
1182
	} else if ( /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test( dateObs ) ) {
1179
		var dateArray = dateObs.split( '-' );
1183
		var dateArray = dateObs.split( '-' );
1180
		return dateArray[2] + '/' + dateArray[1] + '/' + dateArray[0]
1184
		return dateArray[2] + '/' + dateArray[1] + '/' + dateArray[0]
1181
	} else {
1185
	} else {
1182
		console.log( 'erreur date : ' + dateObs )
1186
		console.log( 'erreur date : ' + dateObs )
1183
	}
1187
	}
1184
}
1188
}
1185
 
1189
 
1186
WidgetSaisie.prototype.ajouterNumNomSel = function( numNomSel ) {
1190
WidgetSaisie.prototype.ajouterNumNomSel = function( numNomSel ) {
1187
	var nn = '<span class="nn">[nn' + numNomSel + ']</span>';
1191
	var nn = '<span class="nn">[nn' + numNomSel + ']</span>';
1188
	if ( !valeurOk( numNomSel ) ) {
1192
	if ( !valeurOk( numNomSel ) ) {
1189
		nn = '<span class="alert-error">[' + this.msgTraduction( 'non-lie-au-ref' ) + ']</span>';
1193
		nn = '<span class="alert-error">[' + this.msgTraduction( 'non-lie-au-ref' ) + ']</span>';
1190
	}
1194
	}
1191
	return nn;
1195
	return nn;
1192
};
1196
};
1193
 
1197
 
1194
 
1198
 
1195
WidgetSaisie.prototype.stockerObsData = function() {
1199
WidgetSaisie.prototype.stockerObsData = function() {
1196
	var lthis = this;
1200
	var lthis = this;
1197
 
1201
 
1198
	var numNomSel   = $( '#taxon' ).data( 'numNomSel' ),
1202
	var numNomSel   = $( '#taxon' ).data( 'numNomSel' ),
1199
			nomSel      = $( '#taxon' ).val(),
1203
			nomSel      = $( '#taxon' ).val(),
1200
			nomRet      = $( '#taxon' ).data( 'nomRet' ),
1204
			nomRet      = $( '#taxon' ).data( 'nomRet' ),
1201
			numNomRet   = $( '#taxon' ).data( 'numNomRet' ),
1205
			numNomRet   = $( '#taxon' ).data( 'numNomRet' ),
1202
			numTaxon    = $( '#taxon' ).data( 'nt' ),
1206
			numTaxon    = $( '#taxon' ).data( 'nt' ),
1203
			famille     = $( '#taxon' ).data( 'famille' ),
1207
			famille     = $( '#taxon' ).data( 'famille' ),
1204
			referentiel = ( !valeurOk( numNomSel ) ) ? 'autre' : this.nomSciReferentiel;
1208
			referentiel = ( !valeurOk( numNomSel ) ) ? 'autre' : this.nomSciReferentiel;
1205
 
1209
 
1206
	$( '#liste-obs' ).data( 'obsId' + this.obsNbre, {
1210
	$( '#liste-obs' ).data( 'obsId' + this.obsNbre, {
1207
		'num_nom_sel'        : numNomSel,
1211
		'num_nom_sel'        : numNomSel,
1208
		'nom_sel'            : nomSel,
1212
		'nom_sel'            : nomSel,
1209
		'nom_ret'            : nomRet,
1213
		'nom_ret'            : nomRet,
1210
		'num_nom_ret'        : numNomRet,
1214
		'num_nom_ret'        : numNomRet,
1211
		'num_taxon'          : numTaxon,
1215
		'num_taxon'          : numTaxon,
1212
		'famille'            : famille,
1216
		'famille'            : famille,
1213
		'referentiel'        : referentiel,
1217
		'referentiel'        : referentiel,
1214
		'certitude'          : $( '#certitude' ).val(),
1218
		'certitude'          : $( '#certitude' ).val(),
1215
		'date'               : lthis.fournirDate( $( '#date_releve' ).val() ),
1219
		'date'               : lthis.fournirDate( $( '#date_releve' ).val() ),
1216
		'notes'              : $( '#notes' ).val().trim(),
1220
		'notes'              : $( '#notes' ).val().trim(),
1217
		'pays'               : $( '#pays' ).val(),
1221
		'pays'               : $( '#pays' ).val(),
1218
		'commune_nom'        : $( '#commune-nom' ).val(),
1222
		'commune_nom'        : $( '#commune-nom' ).val(),
1219
		'commune_code_insee' : $( '#commune-insee' ).val(),
1223
		'commune_code_insee' : $( '#commune-insee' ).val(),
1220
		'latitude'           : $( '#latitude' ).val(),
1224
		'latitude'           : $( '#latitude' ).val(),
1221
		'longitude'          : $( '#longitude' ).val(),
1225
		'longitude'          : $( '#longitude' ).val(),
1222
		'altitude'           : $( '#altitude' ).val(),
1226
		'altitude'           : $( '#altitude' ).val(),
1223
// début valeurs pour test:
1227
// début valeurs pour test:
1224
		// 'commune_nom'        : 'Montpellier',
1228
		// 'commune_nom'        : 'Montpellier',
1225
		// 'commune_code_insee' : '34172',
1229
		// 'commune_code_insee' : '34172',
1226
		// 'latitude'           : '43.608320',
1230
		// 'latitude'           : '43.608320',
1227
		// 'longitude'          : '3.880196',
1231
		// 'longitude'          : '3.880196',
1228
		// 'altitude'           : '0',
1232
		// 'altitude'           : '0',
1229
//fin valeurs pour test
1233
//fin valeurs pour test
1230
		'lieudit'            : $( '#lieudit' ).val(),
1234
		'lieudit'            : $( '#lieudit' ).val(),
1231
		'station'            : $( '#station' ).val(),
1235
		'station'            : $( '#station' ).val(),
1232
		'milieu'             : $( '#milieu' ).val(),
1236
		'milieu'             : $( '#milieu' ).val(),
1233
		//Ajout des champs images
1237
		//Ajout des champs images
1234
		'image_nom'          : lthis.getNomsImgsOriginales(),
1238
		'image_nom'          : lthis.getNomsImgsOriginales(),
1235
		'image_b64'          : lthis.getB64ImgsOriginales(),
1239
		'image_b64'          : lthis.getB64ImgsOriginales(),
1236
		// Ajout des champs étendus de l'obs
1240
		// Ajout des champs étendus de l'obs
1237
		'obs_etendue'        : lthis.getObsChpEtendus()
1241
		'obs_etendue'        : lthis.getObsChpEtendus()
1238
	});
1242
	});
1239
};
1243
};
1240
 
1244
 
1241
WidgetSaisie.prototype.getNomsImgsOriginales = function() {
1245
WidgetSaisie.prototype.getNomsImgsOriginales = function() {
1242
	var noms = new Array();
1246
	var noms = new Array();
1243
	$( '.miniature-img' ).each( function() {
1247
	$( '.miniature-img' ).each( function() {
1244
		noms.push( $( this ).attr( 'alt' ) );
1248
		noms.push( $( this ).attr( 'alt' ) );
1245
	});
1249
	});
1246
	return noms;
1250
	return noms;
1247
};
1251
};
1248
 
1252
 
1249
WidgetSaisie.prototype.getB64ImgsOriginales = function() {
1253
WidgetSaisie.prototype.getB64ImgsOriginales = function() {
1250
	var b64 = new Array();
1254
	var b64 = new Array();
1251
	$( '.miniature-img' ).each( function() {
1255
	$( '.miniature-img' ).each( function() {
1252
		if ( $( this ).hasClass( 'b64' ) ) {
1256
		if ( $( this ).hasClass( 'b64' ) ) {
1253
			b64.push( $( this ).attr( 'src' ) );
1257
			b64.push( $( this ).attr( 'src' ) );
1254
		} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
1258
		} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
1255
			b64.push( $( this ).data( 'b64' ) );
1259
			b64.push( $( this ).data( 'b64' ) );
1256
		}
1260
		}
1257
	});
1261
	});
1258
	return b64;
1262
	return b64;
1259
};
1263
};
1260
 
1264
 
1261
/**
1265
/**
1262
 * Retourne un Array contenant les valeurs des champs étendus
1266
 * Retourne un Array contenant les valeurs des champs étendus
1263
 */
1267
 */
1264
WidgetSaisie.prototype.getObsChpEtendus = function() {
1268
WidgetSaisie.prototype.getObsChpEtendus = function() {
1265
	var champs    = new Array(),
1269
	var champs    = new Array(),
1266
			$thisForm = $( '#form-supp' ),
1270
			$thisForm = $( '#form-supp' ),
1267
			elements  =
1271
			elements  =
1268
				'input[type=text]:not(.collect-other),'+
1272
				'input[type=text]:not(.collect-other),'+
1269
				'input[type=checkbox]:checked,'+
1273
				'input[type=checkbox]:checked,'+
1270
				'input[type=radio]:checked,'+
1274
				'input[type=radio]:checked,'+
1271
				'input[type=email],'+
1275
				'input[type=email],'+
1272
				'input[type=number],'+
1276
				'input[type=number],'+
1273
				'input[type=range],'+
1277
				'input[type=range],'+
1274
				'input[type=date],'+
1278
				'input[type=date],'+
1275
				'textarea,'+
1279
				'textarea,'+
1276
				'.select',
1280
				'.select',
1277
			retour    = new Array();
1281
			retour    = new Array();
1278
 
1282
 
1279
	$( elements, $thisForm ).each( function() {
1283
	$( elements, $thisForm ).each( function() {
1280
		if ( valeurOk( $( this ).val() ) && ( valeurOk( $( this ).attr( 'name' ) ) || valeurOk( $( this ).data( 'name' ) ) ) ) {
1284
		if ( valeurOk( $( this ).val() ) && ( valeurOk( $( this ).attr( 'name' ) ) || valeurOk( $( this ).data( 'name' ) ) ) ) {
1281
			var valeur = $( this ).val(),
1285
			var valeur = $( this ).val(),
1282
					cle    = ( valeurOk( $( this ).attr( 'name' ) ) ) ? $( this ).attr( 'name' ) : $( this ).data( 'name' );
1286
					cle    = ( valeurOk( $( this ).attr( 'name' ) ) ) ? $( this ).attr( 'name' ) : $( this ).data( 'name' );
1283
			if ( cle in champs ) {
1287
			if ( cle in champs ) {
1284
				champs[cle] += ';' + valeur;
1288
				champs[cle] += ';' + valeur;
1285
			} else {
1289
			} else {
1286
				champs[cle] = valeur;
1290
				champs[cle] = valeur;
1287
			}
1291
			}
1288
		}
1292
		}
1289
	});
1293
	});
1290
	for( var key in champs ) {
1294
	for( var key in champs ) {
1291
		retour.push({ 'cle' : key , 'valeur' : champs[key] });
1295
		retour.push({ 'cle' : key , 'valeur' : champs[key] });
1292
	};
1296
	};
1293
	return retour;
1297
	return retour;
1294
};
1298
};
1295
 
1299
 
1296
/**
1300
/**
1297
 * Efface toutes les miniatures (formulaire)
1301
 * Efface toutes les miniatures (formulaire)
1298
 */
1302
 */
1299
WidgetSaisie.prototype.supprimerMiniatures = function() {
1303
WidgetSaisie.prototype.supprimerMiniatures = function() {
1300
	// Déconnection MutationObserver miniatures
1304
	// Déconnection MutationObserver miniatures
1301
	// Sinon on a une erreur avant la création d'une nouvelle obs
1305
	// Sinon on a une erreur avant la création d'une nouvelle obs
1302
	this.observer.disconnect();
1306
	this.observer.disconnect();
1303
	$( '#miniatures' ).empty();
1307
	$( '#miniatures' ).empty();
1304
	// Validation miniatures reprend à 0 pour une nouvelle obs
1308
	// Validation miniatures reprend à 0 pour une nouvelle obs
1305
	this.surPresenceAbsenceMiniature();
1309
	this.surPresenceAbsenceMiniature();
1306
	$( '#miniature-msg' ).empty();
1310
	$( '#miniature-msg' ).empty();
1307
};
1311
};
1308
 
1312
 
1309
WidgetSaisie.prototype.surChangementNbreObs = function() {
1313
WidgetSaisie.prototype.surChangementNbreObs = function() {
1310
	if ( 0 === this.obsNbre ) {
1314
	if ( 0 === this.obsNbre ) {
1311
		$( '#transmettre-obs' ).attr( 'disabled', 'disabled' );
1315
		$( '#transmettre-obs' ).attr( 'disabled', 'disabled' );
1312
	} else if ( 0 < this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
1316
	} else if ( 0 < this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
1313
		$( '#transmettre-obs' ).removeAttr( 'disabled' );
1317
		$( '#transmettre-obs' ).removeAttr( 'disabled' );
1314
		$( '#ajouter-obs' ).removeAttr( 'disabled' );
1318
		$( '#ajouter-obs' ).removeAttr( 'disabled' );
1315
	} else if ( this.obsNbre >= this.obsMaxNbre ) {
1319
	} else if ( this.obsNbre >= this.obsMaxNbre ) {
1316
		$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
1320
		$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
1317
		this.afficherPanneau( '#dialogue-bloquer-creer-obs' );
1321
		this.afficherPanneau( '#dialogue-bloquer-creer-obs' );
1318
	}
1322
	}
1319
};
1323
};
1320
 
1324
 
1321
WidgetSaisie.prototype.defilerMiniatures = function( element ) {
1325
WidgetSaisie.prototype.defilerMiniatures = function( element ) {
1322
 
1326
 
1323
	var miniatureSelectionne = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
1327
	var miniatureSelectionne = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
1324
	miniatureSelectionne.removeClass( 'miniature-selectionnee' );
1328
	miniatureSelectionne.removeClass( 'miniature-selectionnee' );
1325
	miniatureSelectionne.addClass( 'miniature-cachee' );
1329
	miniatureSelectionne.addClass( 'miniature-cachee' );
1326
 
1330
 
1327
	var miniatureAffichee    = miniatureSelectionne;
1331
	var miniatureAffichee    = miniatureSelectionne;
1328
 
1332
 
1329
	if( element.hasClass( 'defilement-miniatures-gauche' ) ) {
1333
	if( element.hasClass( 'defilement-miniatures-gauche' ) ) {
1330
		if( 0 !== miniatureSelectionne.prev( '.miniature' ).length ) {
1334
		if( 0 !== miniatureSelectionne.prev( '.miniature' ).length ) {
1331
			miniatureAffichee = miniatureSelectionne.prev( '.miniature' );
1335
			miniatureAffichee = miniatureSelectionne.prev( '.miniature' );
1332
		} else {
1336
		} else {
1333
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).last();
1337
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).last();
1334
		}
1338
		}
1335
	} else {
1339
	} else {
1336
		if( 0 !== miniatureSelectionne.next('.miniature').length ) {
1340
		if( 0 !== miniatureSelectionne.next('.miniature').length ) {
1337
			miniatureAffichee = miniatureSelectionne.next( '.miniature' );
1341
			miniatureAffichee = miniatureSelectionne.next( '.miniature' );
1338
		} else {
1342
		} else {
1339
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).first();
1343
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).first();
1340
		}
1344
		}
1341
	}
1345
	}
1342
	miniatureAffichee.addClass( 'miniature-selectionnee' );
1346
	miniatureAffichee.addClass( 'miniature-selectionnee' );
1343
	miniatureAffichee.removeClass( 'miniature-cachee' );
1347
	miniatureAffichee.removeClass( 'miniature-cachee' );
1344
};
1348
};
1345
 
1349
 
1346
WidgetSaisie.prototype.supprimerObs = function( selector ) {
1350
WidgetSaisie.prototype.supprimerObs = function( selector ) {
1347
	var obsId = $( selector ).val();
1351
	var obsId = $( selector ).val();
1348
	// Problème avec IE 6 et 7
1352
	// Problème avec IE 6 et 7
1349
	if ( 'Supprimer' === obsId ) {
1353
	if ( 'Supprimer' === obsId ) {
1350
		obsId = $( selector ).attr( 'title' );
1354
		obsId = $( selector ).attr( 'title' );
1351
	}
1355
	}
1352
	this.supprimerObsParId( obsId );
1356
	this.supprimerObsParId( obsId );
1353
};
1357
};
1354
 
1358
 
1355
WidgetSaisie.prototype.supprimerObsParId = function( obsId ) {
1359
WidgetSaisie.prototype.supprimerObsParId = function( obsId ) {
1356
	this.obsNbre = this.obsNbre - 1;
1360
	this.obsNbre = this.obsNbre - 1;
1357
	$( '.obs-nbre' ).text( this.obsNbre );
1361
	$( '.obs-nbre' ).text( this.obsNbre );
1358
	$( '.obs-nbre' ).triggerHandler( 'changement' );
1362
	$( '.obs-nbre' ).triggerHandler( 'changement' );
1359
	$( '.obs' + obsId ).remove();
1363
	$( '.obs' + obsId ).remove();
1360
	$( '#liste-obs' ).removeData( 'obsId' + obsId );
1364
	$( '#liste-obs' ).removeData( 'obsId' + obsId );
1361
};
1365
};
1362
 
1366
 
1363
WidgetSaisie.prototype.transmettreObs = function() {
1367
WidgetSaisie.prototype.transmettreObs = function() {
1364
	var observations = $( '#liste-obs' ).data();
1368
	var observations = $( '#liste-obs' ).data();
1365
	if ( this.debug ) {
1369
	if ( this.debug ) {
1366
		console.log( observations );
1370
		console.log( observations );
1367
	}
1371
	}
1368
	if ( !valeurOk( typeof observations, true, 'object' ) ) {
1372
	if ( !valeurOk( typeof observations, true, 'object' ) ) {
1369
		this.afficherPanneau( '#dialogue-zero-obs' );
1373
		this.afficherPanneau( '#dialogue-zero-obs' );
1370
	} else {
1374
	} else {
1371
		this.nbObsEnCours = 1;
1375
		this.nbObsEnCours = 1;
1372
		this.nbObsTransmises = 0;
1376
		this.nbObsTransmises = 0;
1373
		this.totalObsATransmettre = $.map( observations, function( n, i ) {
1377
		this.totalObsATransmettre = $.map( observations, function( n, i ) {
1374
			return i;
1378
			return i;
1375
		}).length;
1379
		}).length;
1376
		this.depilerObsPourEnvoi();
1380
		this.depilerObsPourEnvoi();
1377
	}
1381
	}
1378
	return false;
1382
	return false;
1379
};
1383
};
1380
 
1384
 
1381
WidgetSaisie.prototype.depilerObsPourEnvoi = function() {
1385
WidgetSaisie.prototype.depilerObsPourEnvoi = function() {
1382
	var observations = $( '#liste-obs' ).data();
1386
	var observations = $( '#liste-obs' ).data();
1383
	// la boucle est factice car on utilise un tableau
1387
	// la boucle est factice car on utilise un tableau
1384
	// dont on a besoin de n'extraire que le premier élément
1388
	// dont on a besoin de n'extraire que le premier élément
1385
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
1389
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
1386
	// TODO: utiliser var.keys quand ça sera plus répandu
1390
	// TODO: utiliser var.keys quand ça sera plus répandu
1387
	// ou bien utiliser un vrai tableau et pas un objet
1391
	// ou bien utiliser un vrai tableau et pas un objet
1388
	for ( var obsNum in observations ) {
1392
	for ( var obsNum in observations ) {
1389
		var obsATransmettre = {
1393
		var obsATransmettre = {
1390
			'projet'  : this.tagProjet,
1394
			'projet'  : this.tagProjet,
1391
			'tag-obs' : this.tagObs,
1395
			'tag-obs' : this.tagObs,
1392
			'tag-img' : this.tagImg
1396
			'tag-img' : this.tagImg
1393
		};
1397
		};
1394
		var utilisateur = {
1398
		var utilisateur = {
1395
			id_utilisateur : $( '#id_utilisateur' ).val(),
1399
			id_utilisateur : $( '#id_utilisateur' ).val(),
1396
			prenom         : $( '#prenom' ).val(),
1400
			prenom         : $( '#prenom' ).val(),
1397
			nom            : $( '#nom' ).val(),
1401
			nom            : $( '#nom' ).val(),
1398
			courriel       : $( '#courriel' ).val()
1402
			courriel       : $( '#courriel' ).val()
1399
		};
1403
		};
1400
		obsATransmettre['utilisateur'] = utilisateur;
1404
		obsATransmettre['utilisateur'] = utilisateur;
1401
		obsATransmettre[obsNum] = observations[obsNum];
1405
		obsATransmettre[obsNum] = observations[obsNum];
1402
		var idObsNumerique = obsNum.replace( 'obsId', '' );
1406
		var idObsNumerique = obsNum.replace( 'obsId', '' );
1403
		if( '' !== idObsNumerique ) {
1407
		if( '' !== idObsNumerique ) {
1404
			this.envoyerObsAuCel( idObsNumerique, obsATransmettre );
1408
			this.envoyerObsAuCel( idObsNumerique, obsATransmettre );
1405
		}
1409
		}
1406
		break;
1410
		break;
1407
	}
1411
	}
1408
};
1412
};
1409
 
1413
 
1410
WidgetSaisie.prototype.envoyerObsAuCel = function( idObs, observation ) {
1414
WidgetSaisie.prototype.envoyerObsAuCel = function( idObs, observation ) {
1411
	var lthis = this;
1415
	var lthis = this;
1412
 
1416
 
1413
	var erreurMsg = '';
1417
	var erreurMsg = '';
1414
	$.ajax({
1418
	$.ajax({
1415
		url        : lthis.serviceSaisieUrl,
1419
		url        : lthis.serviceSaisieUrl,
1416
		type       : 'POST',
1420
		type       : 'POST',
1417
		data       : observation,
1421
		data       : observation,
1418
		dataType   : 'json',
1422
		dataType   : 'json',
1419
		beforeSend : function() {
1423
		beforeSend : function() {
1420
			$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
1424
			$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
1421
			$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
1425
			$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
1422
			$( '.alert-txt' ).empty();
1426
			$( '.alert-txt' ).empty();
1423
			$( '.alert-txt .msg-erreur' ).remove();
1427
			$( '.alert-txt .msg-erreur' ).remove();
1424
			$( '.alert-txt .msg-debug' ).remove();
1428
			$( '.alert-txt .msg-debug' ).remove();
1425
			$( '#chargement' ).removeClass( 'hidden' );
1429
			$( '#chargement' ).removeClass( 'hidden' );
1426
		},
1430
		},
1427
		success    : function( data, textStatus, jqXHR ) {
1431
		success    : function( data, textStatus, jqXHR ) {
1428
			// mise à jour du nombre d'obs à transmettre
1432
			// mise à jour du nombre d'obs à transmettre
1429
			// et suppression de l'obs
1433
			// et suppression de l'obs
1430
			lthis.supprimerObsParId( idObs );
1434
			lthis.supprimerObsParId( idObs );
1431
			lthis.nbObsEnCours++;
1435
			lthis.nbObsEnCours++;
1432
			// mise à jour du statut
1436
			// mise à jour du statut
1433
			lthis.mettreAJourProgression();
1437
			lthis.mettreAJourProgression();
1434
			if( 0 < lthis.obsNbre ) {
1438
			if( 0 < lthis.obsNbre ) {
1435
				// dépilement de la suivante
1439
				// dépilement de la suivante
1436
				lthis.depilerObsPourEnvoi();
1440
				lthis.depilerObsPourEnvoi();
1437
			}
1441
			}
1438
		},
1442
		},
1439
		statusCode  : {
1443
		statusCode  : {
1440
			500 : function( jqXHR, textStatus, errorThrown ) {
1444
			500 : function( jqXHR, textStatus, errorThrown ) {
1441
				erreurMsg += lthis.msgTraduction( 'erreur' ) + ' 500 :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1445
				erreurMsg += lthis.msgTraduction( 'erreur' ) + ' 500 :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1442
				}
1446
				}
1443
		},
1447
		},
1444
		error        : function( jqXHR, textStatus, errorThrown ) {
1448
		error        : function( jqXHR, textStatus, errorThrown ) {
1445
			erreurMsg += lthis.msgTraduction( 'erreur-ajax' ) + ' :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1449
			erreurMsg += lthis.msgTraduction( 'erreur-ajax' ) + ' :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1446
			try {
1450
			try {
1447
				reponse = jQuery.parseJSON( jqXHR.responseText );
1451
				reponse = jQuery.parseJSON( jqXHR.responseText );
1448
				if ( null !== reponse ) {
1452
				if ( null !== reponse ) {
1449
					$.each( reponse, function( cle, valeur ) {
1453
					$.each( reponse, function( cle, valeur ) {
1450
						erreurMsg += valeur + '\n';
1454
						erreurMsg += valeur + '\n';
1451
					});
1455
					});
1452
				}
1456
				}
1453
			} catch( e ) {
1457
			} catch( e ) {
1454
				erreurMsg += lthis.msgTraduction( 'erreur-inconnue' ) + ' : ' + jqXHR.responseText;
1458
				erreurMsg += lthis.msgTraduction( 'erreur-inconnue' ) + ' : ' + jqXHR.responseText;
1455
			}
1459
			}
1456
		},
1460
		},
1457
		complete      : function( jqXHR, textStatus ) {
1461
		complete      : function( jqXHR, textStatus ) {
1458
			var debugMsg = extraireEnteteDebug( jqXHR );
1462
			var debugMsg = extraireEnteteDebug( jqXHR );
1459
 
1463
 
1460
			if ( '' !== erreurMsg ) {
1464
			if ( '' !== erreurMsg ) {
1461
				if ( lthis.debug ) {
1465
				if ( lthis.debug ) {
1462
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-erreur">' + erreurMsg + '</pre>' );
1466
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-erreur">' + erreurMsg + '</pre>' );
1463
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1467
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1464
				}
1468
				}
1465
				var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
1469
				var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
1466
					'subject=Dysfonctionnement du widget de saisie ' + lthis.tagProjet+
1470
					'subject=Dysfonctionnement du widget de saisie ' + lthis.tagProjet+
1467
					'&body=' + erreurMsg + '%0D%0ADébogage :%0D%0A' + debugMsg;
1471
					'&body=' + erreurMsg + '%0D%0ADébogage :%0D%0A' + debugMsg;
1468
 
1472
 
1469
				// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
1473
				// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
1470
				$( '#obs' + idObs + ' div div' ).addClass( 'obs-erreur' );
1474
				$( '#obs' + idObs + ' div div' ).addClass( 'obs-erreur' );
1471
				window.location.hash = 'obs' + idObs;
1475
				window.location.hash = 'obs' + idObs;
1472
 
1476
 
1473
				$( '#dialogue-obs-transaction-ko .alert-txt' ).append(
1477
				$( '#dialogue-obs-transaction-ko .alert-txt' ).append(
1474
					$( '#tpl-transmission-ko' ).clone()
1478
					$( '#tpl-transmission-ko' ).clone()
1475
						.find( '.courriel-erreur' )
1479
						.find( '.courriel-erreur' )
1476
						.attr( 'href', hrefCourriel )
1480
						.attr( 'href', hrefCourriel )
1477
						.end()
1481
						.end()
1478
						.html()
1482
						.html()
1479
				);
1483
				);
1480
				$( '#dialogue-obs-transaction-ko' ).removeClass( 'hidden' );
1484
				$( '#dialogue-obs-transaction-ko' ).removeClass( 'hidden' );
1481
				$( '#chargement' ).addClass( 'hidden' );
1485
				$( '#chargement' ).addClass( 'hidden' );
1482
				lthis.initialiserBarreProgression;
1486
				lthis.initialiserBarreProgression;
1483
			} else {
1487
			} else {
1484
				if ( lthis.debug ) {
1488
				if ( lthis.debug ) {
1485
					$( '#dialogue-obs-transaction-ok .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1489
					$( '#dialogue-obs-transaction-ok .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1486
				}
1490
				}
1487
				if( 0 === lthis.obsNbre ) {
1491
				if( 0 === lthis.obsNbre ) {
1488
					setTimeout( function() {
1492
					setTimeout( function() {
1489
						$( '#chargement' ).addClass( 'hidden' );
1493
						$( '#chargement' ).addClass( 'hidden' );
1490
						$( '#dialogue-obs-transaction-ok .alert-txt' ).append( $( '#tpl-transmission-ok' ).clone().html() );
1494
						$( '#dialogue-obs-transaction-ok .alert-txt' ).append( $( '#tpl-transmission-ok' ).clone().html() );
1491
						$( '#dialogue-obs-transaction-ok' ).removeClass( 'hidden' );
1495
						$( '#dialogue-obs-transaction-ok' ).removeClass( 'hidden' );
1492
						window.location.hash = 'dialogue-obs-transaction-ok';
1496
						window.location.hash = 'dialogue-obs-transaction-ok';
1493
						lthis.initialiserObs.bind( lthis );
1497
						lthis.initialiserObs.bind( lthis );
1494
					}, 1500 );
1498
					}, 1500 );
1495
				}
1499
				}
1496
			}
1500
			}
1497
		}
1501
		}
1498
	});
1502
	});
1499
};
1503
};
1500
 
1504
 
1501
WidgetSaisie.prototype.mettreAJourProgression = function() {
1505
WidgetSaisie.prototype.mettreAJourProgression = function() {
1502
	this.nbObsTransmises++;
1506
	this.nbObsTransmises++;
1503
 
1507
 
1504
	var pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
1508
	var pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
1505
 
1509
 
1506
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', this.nbObsTransmises );
1510
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', this.nbObsTransmises );
1507
	$( '#barre-progression-upload' ).css( 'width', pct + '%' );
1511
	$( '#barre-progression-upload' ).css( 'width', pct + '%' );
1508
	$( '#barre-progression-upload .sr-only' ).text( this.nbObsTransmises + '/' + this.totalObsATransmettre + ' ' + this.msgTraduction( 'observations-transmises' ) );
1512
	$( '#barre-progression-upload .sr-only' ).text( this.nbObsTransmises + '/' + this.totalObsATransmettre + ' ' + this.msgTraduction( 'observations-transmises' ) );
1509
	if( 0 === this.obsNbre ) {
1513
	if( 0 === this.obsNbre ) {
1510
		$( '.progress' ).removeClass( 'active' );
1514
		$( '.progress' ).removeClass( 'active' );
1511
		$( '.progress' ).removeClass( 'progress-bar-striped' );
1515
		$( '.progress' ).removeClass( 'progress-bar-striped' );
1512
	}
1516
	}
1513
};
1517
};
1514
 
1518
 
1515
WidgetSaisie.prototype.initialiserBarreProgression = function() {
1519
WidgetSaisie.prototype.initialiserBarreProgression = function() {
1516
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', 0 );
1520
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', 0 );
1517
	$( '#barre-progression-upload' ).css( 'width', '0%' );
1521
	$( '#barre-progression-upload' ).css( 'width', '0%' );
1518
	$( '#barre-progression-upload .sr-only' ).text( '0/0 ' + this.msgTraduction( 'observations-transmises' ) );
1522
	$( '#barre-progression-upload .sr-only' ).text( '0/0 ' + this.msgTraduction( 'observations-transmises' ) );
1519
	$( '.progress' ).addClass( 'active' );
1523
	$( '.progress' ).addClass( 'active' );
1520
	$( '.progress' ).addClass( 'progress-bar-striped' );
1524
	$( '.progress' ).addClass( 'progress-bar-striped' );
1521
};
1525
};
1522
 
1526
 
1523
WidgetSaisie.prototype.initialiserObs = function() {
1527
WidgetSaisie.prototype.initialiserObs = function() {
1524
	this.obsNbre = 0;
1528
	this.obsNbre = 0;
1525
	this.nbObsTransmises = 0;
1529
	this.nbObsTransmises = 0;
1526
	this.nbObsEnCours = 0;
1530
	this.nbObsEnCours = 0;
1527
	this.totalObsATransmettre = 0;
1531
	this.totalObsATransmettre = 0;
1528
	this.initialiserBarreProgression();
1532
	this.initialiserBarreProgression();
1529
	$( '.obs-nbre' ).text( this.obsNbre );
1533
	$( '.obs-nbre' ).text( this.obsNbre );
1530
	$( '.obs-nbre' ).triggerHandler( 'changement' );
1534
	$( '.obs-nbre' ).triggerHandler( 'changement' );
1531
	$( '#liste-obs' ).removeData();
1535
	$( '#liste-obs' ).removeData();
1532
	$( '.obs' ).remove();
1536
	$( '.obs' ).remove();
1533
	$( '#dialogue-bloquer-creer-obs' ).addClass( 'hidden' );
1537
	$( '#dialogue-bloquer-creer-obs' ).addClass( 'hidden' );
1534
};
1538
};
1535
 
1539
 
1536
WidgetSaisie.prototype.afficherPanneau = function( selecteur ) {
1540
WidgetSaisie.prototype.afficherPanneau = function( selecteur ) {
1537
	$( selecteur )
1541
	$( selecteur )
1538
		.removeClass( 'hidden')
1542
		.removeClass( 'hidden')
1539
		.hide()
1543
		.hide()
1540
		.show( 600 )
1544
		.show( 600 )
1541
		.delay( this.dureeMessage )
1545
		.delay( this.dureeMessage )
1542
		.hide( 600 );
1546
		.hide( 600 );
1543
};
1547
};
1544
 
1548
 
1545
WidgetSaisie.prototype.masquerPanneau = function( selecteur ) {
1549
WidgetSaisie.prototype.masquerPanneau = function( selecteur ) {
1546
	$( selecteur ).addClass( 'hidden' );
1550
	$( selecteur ).addClass( 'hidden' );
1547
};
1551
};
1548
 
1552
 
1549
WidgetSaisie.prototype.fermerPanneauAlert = function() {
1553
WidgetSaisie.prototype.fermerPanneauAlert = function() {
1550
	$( this ).parentsUntil( '.zone-alerte', '.alert' ).addClass( 'hidden' );
1554
	$( this ).parentsUntil( '.zone-alerte', '.alert' ).addClass( 'hidden' );
1551
};
1555
};
1552
 
1556
 
1553
/**
1557
/**
1554
 * Si la langue est définie dans this.langue, et si des messages sont définis
1558
 * Si la langue est définie dans this.langue, et si des messages sont définis
1555
 * dans this.msgs, tente de trouver le message dont la clé est [cle] dans la
1559
 * dans this.msgs, tente de trouver le message dont la clé est [cle] dans la
1556
 * langue en cours. S'il n'est pas trouvé, retourne la version française (par
1560
 * langue en cours. S'il n'est pas trouvé, retourne la version française (par
1557
 * défaut); si celle-ci n'exite pas, retourne "N/A".
1561
 * défaut); si celle-ci n'exite pas, retourne "N/A".
1558
 */
1562
 */
1559
WidgetSaisie.prototype.msgTraduction = function( cle ) {
1563
WidgetSaisie.prototype.msgTraduction = function( cle ) {
1560
	var msg = 'N/A';
1564
	var msg = 'N/A';
1561
	if ( this.msgs ) {
1565
	if ( this.msgs ) {
1562
		if ( this.langue in this.msgs && cle in this.msgs[this.langue] ) {
1566
		if ( this.langue in this.msgs && cle in this.msgs[this.langue] ) {
1563
			msg = this.msgs[this.langue][cle];
1567
			msg = this.msgs[this.langue][cle];
1564
		} else if ( cle in this.msgs['fr'] ) {
1568
		} else if ( cle in this.msgs['fr'] ) {
1565
			msg = this.msgs['fr'][cle];
1569
			msg = this.msgs['fr'][cle];
1566
		}
1570
		}
1567
	}
1571
	}
1568
	return msg;
1572
	return msg;
1569
};
1573
};
1570
 
1574
 
1571
// lib hors objet --
1575
// lib hors objet --
1572
 
1576
 
1573
/**
1577
/**
1574
* Permet à la fois de vérifier qu'une valeur ou objet existe et n'est pas vide
1578
* Permet à la fois de vérifier qu'une valeur ou objet existe et n'est pas vide
1575
* et de comparer à une autre valeur :
1579
* et de comparer à une autre valeur :
1576
* Vérifie qu'une variable ou objet n'est pas : vide, null, undefined, NaN
1580
* Vérifie qu'une variable ou objet n'est pas : vide, null, undefined, NaN
1577
* Si comparer est défini on le compare à valeur en fonction de sensComparaison
1581
* Si comparer est défini on le compare à valeur en fonction de sensComparaison
1578
* Un booléen est une variable valide : on retourne true
1582
* Un booléen est une variable valide : on retourne true
1579
* @param { string || number || object || undefined } valeur
1583
* @param { string || number || object || undefined } valeur
1580
* @param { boolean } sensComparaison : true = rechercher, false = refuser
1584
* @param { boolean } sensComparaison : true = rechercher, false = refuser
1581
* @param { string || number || object || undefined || boolean } comparer :valeur à comparer
1585
* @param { string || number || object || undefined || boolean } comparer :valeur à comparer
1582
* @returns {boolean}
1586
* @returns {boolean}
1583
*/
1587
*/
1584
function valeurOk( valeur, sensComparaison = true, comparer = undefined ) {
1588
function valeurOk( valeur, sensComparaison = true, comparer = undefined ) {
1585
 
1589
 
1586
	if ( 'boolean' !== typeof valeur ) {
1590
	if ( 'boolean' !== typeof valeur ) {
1587
		switch( typeof valeur ) {
1591
		switch( typeof valeur ) {
1588
			case 'string' :
1592
			case 'string' :
1589
				retour = ( '' !== valeur );
1593
				retour = ( '' !== valeur );
1590
			 break;
1594
			 break;
1591
			case 'number' :
1595
			case 'number' :
1592
					retour = ( NaN !== valeur );
1596
					retour = ( NaN !== valeur );
1593
				break;
1597
				break;
1594
			case 'object' :
1598
			case 'object' :
1595
					retour = ( null !== valeur && undefined !== valeur && !$.isEmptyObject( valeur ) );
1599
					retour = ( null !== valeur && undefined !== valeur && !$.isEmptyObject( valeur ) );
1596
					if ( undefined !== valeur.length ) {
1600
					if ( undefined !== valeur.length ) {
1597
						retour = ( retour  && 0 < valeur.length );
1601
						retour = ( retour  && 0 < valeur.length );
1598
					}
1602
					}
1599
				break;
1603
				break;
1600
			case 'undefined' :
1604
			case 'undefined' :
1601
			default :
1605
			default :
1602
				retour = false;
1606
				retour = false;
1603
		}
1607
		}
1604
		if ( retour && comparer !== undefined ) {
1608
		if ( retour && comparer !== undefined ) {
1605
			var resultComparaison = ( comparer === valeur );
1609
			var resultComparaison = ( comparer === valeur );
1606
			retour = ( sensComparaison ) ? resultComparaison : !resultComparaison ;
1610
			retour = ( sensComparaison ) ? resultComparaison : !resultComparaison ;
1607
		}
1611
		}
1608
		return retour;
1612
		return retour;
1609
	} else {
1613
	} else {
1610
		// Un booléen est une valeur valable
1614
		// Un booléen est une valeur valable
1611
		return true;
1615
		return true;
1612
	}
1616
	}
1613
}
1617
}
1614
 
1618
 
1615
/**
1619
/**
1616
* Stope l'évènement courant quand on clique sur un lien.
1620
* Stope l'évènement courant quand on clique sur un lien.
1617
* Utile pour Chrome, Safari...
1621
* Utile pour Chrome, Safari...
1618
*/
1622
*/
1619
function arreter( evenement ) {
1623
function arreter( evenement ) {
1620
	if ( evenement.stopPropagation ) {
1624
	if ( evenement.stopPropagation ) {
1621
		evenement.stopPropagation();
1625
		evenement.stopPropagation();
1622
	}
1626
	}
1623
	if ( evenement.preventDefault ) {
1627
	if ( evenement.preventDefault ) {
1624
		evenement.preventDefault();
1628
		evenement.preventDefault();
1625
	}
1629
	}
1626
	return false;
1630
	return false;
1627
}
1631
}
1628
 
1632
 
1629
/**
1633
/**
1630
 * Extrait les données de désinsectisation d'une requête AJAX de jQuery
1634
 * Extrait les données de désinsectisation d'une requête AJAX de jQuery
1631
 * @param jqXHR
1635
 * @param jqXHR
1632
 * @returns {String}
1636
 * @returns {String}
1633
 */
1637
 */
1634
function extraireEnteteDebug( jqXHR ) {
1638
function extraireEnteteDebug( jqXHR ) {
1635
	var msgDebug = '';
1639
	var msgDebug = '';
1636
	if ( '' !== jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) ) {
1640
	if ( '' !== jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) ) {
1637
		var debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
1641
		var debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
1638
		if ( null !== debugInfos ) {
1642
		if ( null !== debugInfos ) {
1639
			$.each( debugInfos, function( cle, valeur ) {
1643
			$.each( debugInfos, function( cle, valeur ) {
1640
				msgDebug += valeur + '\n';
1644
				msgDebug += valeur + '\n';
1641
			});
1645
			});
1642
		}
1646
		}
1643
	}
1647
	}
1644
	return msgDebug;
1648
	return msgDebug;
1645
}
1649
}
1646
 
1650
 
1647
/*
1651
/*
1648
 * jQuery UI Autocomplete HTML Extension
1652
 * jQuery UI Autocomplete HTML Extension
1649
 *
1653
 *
1650
 * Copyright 2010, Scott González (http://scottgonzalez.com)
1654
 * Copyright 2010, Scott González (http://scottgonzalez.com)
1651
 * Dual licensed under the MIT or GPL Version 2 licenses.
1655
 * Dual licensed under the MIT or GPL Version 2 licenses.
1652
 *
1656
 *
1653
 * http://github.com/scottgonzalez/jquery-ui-extensions
1657
 * http://github.com/scottgonzalez/jquery-ui-extensions
1654
 *
1658
 *
1655
 * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
1659
 * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
1656
 */
1660
 */
1657
	( function( $ ) {
1661
	( function( $ ) {
1658
		var proto = $.ui.autocomplete.prototype,
1662
		var proto = $.ui.autocomplete.prototype,
1659
			initSource = proto._initSource;
1663
			initSource = proto._initSource;
1660
 
1664
 
1661
		WidgetSaisie.prototype.filter = function( array, term ) {
1665
		WidgetSaisie.prototype.filter = function( array, term ) {
1662
			var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
1666
			var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
1663
			return $.grep( array, function( value ) {
1667
			return $.grep( array, function( value ) {
1664
				return matcher.test( $( '<div>' ).html( value.label || value.value || value ).text() );
1668
				return matcher.test( $( '<div>' ).html( value.label || value.value || value ).text() );
1665
			});
1669
			});
1666
		}
1670
		}
1667
		$.extend( proto, {
1671
		$.extend( proto, {
1668
			_initSource: function() {
1672
			_initSource: function() {
1669
				if ( this.options.html && $.isArray( this.options.source ) ) {
1673
				if ( this.options.html && $.isArray( this.options.source ) ) {
1670
					this.source = function( request, response ) {
1674
					this.source = function( request, response ) {
1671
						response( filter( this.options.source, request.term ) );
1675
						response( filter( this.options.source, request.term ) );
1672
					};
1676
					};
1673
				} else {
1677
				} else {
1674
					initSource.call( this );
1678
					initSource.call( this );
1675
				}
1679
				}
1676
			},
1680
			},
1677
			_renderItem: function( ul, item) {
1681
			_renderItem: function( ul, item) {
1678
				if ( item.retenu ) {
1682
				if ( item.retenu ) {
1679
					item.label = '<strong>' + item.label + '</strong>';
1683
					item.label = '<strong>' + item.label + '</strong>';
1680
				}
1684
				}
1681
 
1685
 
1682
				return $( '<li></li>' )
1686
				return $( '<li></li>' )
1683
					.data( 'item.autocomplete', item )
1687
					.data( 'item.autocomplete', item )
1684
					.append( $( '<a></a>' )[ ( this.options.html ) ? 'html' : 'text' ]( item.label ) )
1688
					.append( $( '<a></a>' )[ ( this.options.html ) ? 'html' : 'text' ]( item.label ) )
1685
					.appendTo( ul );
1689
					.appendTo( ul );
1686
			}
1690
			}
1687
		});
1691
		});
1688
	})( jQuery );
1692
	})( jQuery );