Subversion Repositories eFlore/Applications.cel

Rev

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

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