Subversion Repositories eFlore/Applications.cel

Rev

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

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