Subversion Repositories eFlore/Applications.cel

Rev

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

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