Subversion Repositories eFlore/Applications.cel

Rev

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

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