Subversion Repositories eFlore/Applications.cel

Rev

Rev 3249 | Rev 3263 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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