Subversion Repositories eFlore/Applications.cel

Rev

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

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