Subversion Repositories eFlore/Applications.cel

Rev

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

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