Subversion Repositories eFlore/Applications.cel

Rev

Rev 2910 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2850 aurel 1
/* Héritage */
2
function WidgetSaisieMessicoles()
3
{
2857 aurel 4
	this.taxons = {};
2850 aurel 5
}
2857 aurel 6
 
2850 aurel 7
WidgetSaisieMessicoles.prototype = new WidgetSaisie();
8
 
9
/* Surcharge des fonctions */
2854 mathias 10
 
2857 aurel 11
// Surcharge ajouterObs
12
WidgetSaisieMessicoles.prototype.ajouterObs = function() {
2852 mathias 13
	// Fermeture automatique des dialogue de transmission de données
14
	// @WARNING TEST
15
	$('#dialogue-obs-transaction-ko').hide();
16
	$('#dialogue-obs-transaction-ok').hide();
2850 aurel 17
 
2852 mathias 18
	// vérification : si la détermination est incertaine, obligation
19
	// de fournir au moins une image
2857 aurel 20
	var certitude = $('#identification-liste').val(),
21
		nbImages = $('#miniatures img').length,
2852 mathias 22
		imagesOK = true;
23
	if (certitude != "certaine" && nbImages == 0) {
24
		imagesOK = false;
2857 aurel 25
		$('#image-obligatoire').show();
2852 mathias 26
	} else {
2857 aurel 27
		$('#image-obligatoire').hide();
2852 mathias 28
	}
29
 
30
	if ((this.validerFormulaire() == true) && imagesOK) {
31
		this.masquerPanneau('#dialogue-form-invalide');
2857 aurel 32
		//return false;
2852 mathias 33
		// suite des opérations
34
		this.obsNbre = this.obsNbre + 1;
35
		$(".obs-nbre").text(this.obsNbre);
36
		$(".obs-nbre").triggerHandler('changement');
37
		this.afficherObs();
38
		this.stockerObsData();
39
		this.supprimerMiniatures();
40
		if(! this.especeImposee) {
41
			$("#taxon").val("");
42
			$("#taxon").data("numNomSel",undefined);
43
		}
2881 aurel 44
		$('#form-obs').each(function(){
45
			this.reset();
46
		});
2852 mathias 47
		$('#barre-progression-upload').attr('aria-valuemax', this.obsNbre);
48
		$('#barre-progression-upload .sr-only').text('0/'+this.obsNbre+" observations transmises");
49
	} else {
50
		this.afficherPanneau('#dialogue-form-invalide');
51
	}
52
};
53
 
2857 aurel 54
// surcharge fonction definirReglesFormValidator()
55
WidgetSaisieMessicoles.prototype.definirReglesFormValidator = function() {
56
	// WidgetSaisie.definirReglesFormValidator();
57
	$("#form-observateur").validate({
58
		rules: {
59
			courriel : {
60
				required : true,
61
				email : true},
62
			courriel_confirmation : {
63
				required : true,
64
				equalTo: "#courriel"}
65
		}
66
	});
2883 aurel 67
	$("#form-releve").validate({
68
		rules: {
69
			date : {
70
				required : true,
3013 killian 71
				'dateCel' : true
2883 aurel 72
			},
73
			"type-culture" : "required"
74
		},
75
		errorPlacement: function(error, element) {
76
			error.insertBefore(element.parent());
77
		}
78
	});
2857 aurel 79
	$("#form-station").validate({
2860 mathias 80
		ignore: ':hidden:not("#latitude, #longitude")', // validation des champs cachés...
81
		errorPlacement: function(error, element) { // ...mais erreur visible
82
			error.insertBefore("#coordonnees-geo");
83
		},
84
		groups: {
85
			latLon: "latitude longitude"
86
		},
2857 aurel 87
		rules: {
88
			latitude : {
2860 mathias 89
				required: true,
90
				range: [-90, 90]
91
			},
2857 aurel 92
			longitude : {
2860 mathias 93
				required: true,
94
				range: [-180, 180]
95
			}
2861 mathias 96
		},
97
		messages: {
98
			// astuce pour simuler un message personnalisé pour le groupe "latLon"
99
			latitude: "Veuillez géolocaliser votre observation en déplaçant le curseur sur la carte",
100
			longitude: "Veuillez géolocaliser votre observation en déplaçant le curseur sur la carte"
2857 aurel 101
		}
102
	});
103
	$("#form-obs").validate({
104
		rules: {
105
			"taxon-liste" : "required",
106
			"abondance-liste" : "required",
107
			"zone-champ[]" : {
108
            	required : true,
109
            	minlength : 1
110
            }
2860 mathias 111
		},
2881 aurel 112
		errorPlacement: function(error, element) {
2860 mathias 113
			error.insertBefore(element.parent());
2857 aurel 114
		}
115
	});
116
};
117
 
118
// surcharge fonction validerFormulaire()
119
WidgetSaisieMessicoles.prototype.validerFormulaire = function() {
120
	observateur = $("#form-observateur").valid();
2883 aurel 121
	releve = $("#form-releve").valid();
2857 aurel 122
	station = $("#form-station").valid();
123
	obs = $("#form-obs").valid();
2890 aurel 124
	return (observateur && station && obs && releve);
2857 aurel 125
};
126
 
127
// surcharge fonction stockerObsData()
128
WidgetSaisieMessicoles.prototype.stockerObsData = function() {
129
	var lthis = this;
130
	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
131
		numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val();
132
	var nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
133
		nomRet = nomHorsListe ? $('#taxon').data('nomRet') : this.taxons[numNomSel]['nom_ret'],
134
		numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : this.taxons[numNomSel]['num_nom_ret'],
135
		numTaxon = nomHorsListe ? $('#taxon').data('nt') : this.taxons[numNomSel]['num_taxon'],
136
		famille = nomHorsListe ? $('#taxon').data('famille') : this.taxons[numNomSel]['famille'],
137
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel,
2862 mathias 138
		notes = $('#notes').val();
139
	// champs spécifques aux messicoles
140
	var abondance = $('#abondance-liste').val(),
141
		certitude = $('#identification-liste').val();
2880 aurel 142
 
2862 mathias 143
 
2857 aurel 144
	$('#liste-obs').data('obsId'+this.obsNbre, {
145
		'date': $('#date').val(),
146
		'notes': notes,
147
 
148
		'latitude': $('#latitude').val(),
149
		'longitude': $('#longitude').val(),
150
		'commune_nom': $('#commune-nom').text(),
151
		'commune_code_insee': $('#commune-code-insee').text(),
2862 mathias 152
		'lieudit' : $("#lieudit").val(),
153
		'station' : $("#station").val(),
154
		'milieu' : $("#milieu").val(),
2857 aurel 155
 
156
		'nom_sel': nomSel,
157
		'num_nom_sel': numNomSel,
158
		'nom_ret': nomRet,
159
		'num_nom_ret': numNomRet,
160
		'num_taxon': numTaxon,
161
		'famille': famille,
162
		'referentiel': referentiel,
2862 mathias 163
 
2857 aurel 164
		'certitude': certitude,
165
		'abondance': abondance,
166
 
167
		// Ajout des champs images
2862 mathias 168
		'image_nom' : lthis.getNomsImgsOriginales(),
169
		'image_b64' : lthis.getB64ImgsOriginales(),
2857 aurel 170
 
171
		// Ajout des champs étendus de l'obs
2862 mathias 172
		'obs_etendue': lthis.getObsChpEtendus()
2857 aurel 173
	});
174
	if (this.debug) {
175
		console.log($('#liste-obs').data('obsId'+this.obsNbre));
176
	}
177
};
178
 
179
/**
180
 * Affiche une observation dans la liste des observations à transmettre
181
 */
182
WidgetSaisieMessicoles.prototype.afficherObs = function() {
2863 mathias 183
	console.log(this.taxons);
2862 mathias 184
	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false,
185
		numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val();
186
	var nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
2863 mathias 187
		//famille = nomHorsListe ? $('#taxon').data('famille') : this.taxons[numNomSel]['famille'],
2862 mathias 188
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
189
 
2857 aurel 190
	var commune = $("#commune-nom").text();
191
	commune = commune.trim() != "" ? commune : $("#carte-recherche").val();
192
	var code_insee = $('#commune-code-insee').text();
193
	code_insee = code_insee.trim() != "" ? "("+code_insee+")" : "";
194
	var latitude = $("#latitude").val();
195
	var longitude = $("#longitude").val();
2881 aurel 196
	var lieudit = ($('#lieudit').val() != "" ? $('#lieudit').val() : "aucun lieu-dit saisi");
197
	var station = ($('#station').val() != "" ? $('#station').val() : "aucune station saisie");
198
	var milieu = ($('#milieu').val() != "" ? $('#milieu').val() : "aucun milieu saisi");
199
	var notes = ($('#notes').val() != "" ? $('#notes').val() : "<b>aucunes notes saisies</b>");
2862 mathias 200
	var date = $("#date").val();
201
	// champs spécifques aux messicoles
2881 aurel 202
 
203
 
204
	var culture = ($('input[name=type-culture]').is(':checked') ? $('input[name=type-culture]:checked').data('titre') : "?");
205
	var cultureDetails = ($('input[name=type-culture]').is(':checked') ? $('input[name=type-culture]:checked').parent().find('input[type=text]').val() : '?');
206
 
207
 
208
 
2857 aurel 209
	var identification = $('#identification-liste option:selected').data('titre');
210
	var abondance = $('#abondance-liste option:selected').data('titre');
211
	var zoneChamp = [];
212
	// récupération des cases à cocher multiples dans un tableau pour l'abondance
213
	$('input[name="zone-champ[]"]:checked').each(function() {
214
		zoneChamp.push(' '+$(this).data('titre'));
215
	});
216
 
217
	// affichage des données de l'observation à transmettre
218
	$("#liste-obs").prepend(
219
		'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">'+
220
			'<div class="span12">'+
221
				'<div class="well">'+
222
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
223
						'title="Supprimer cette observation de la liste à transmettre">'+
224
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
225
							'<i class="icon-trash icon-white"></i>'+
226
						'</button>'+
227
					'</div> '+
228
					'<div class="row-fluid">'+
229
						'<div class="thumbnail span2">'+
230
						this.ajouterImgMiniatureAuTransfert()+
231
						'</div>'+
232
						'<div class="span9">'+
233
							'<ul class="unstyled">'+
234
								'<li>'+
2866 aurel 235
									'<span class="nom-sci gras">'+nomSel+'</span> '+
2862 mathias 236
									this.ajouterNumNomSel(numNomSel, referentiel)+
2857 aurel 237
									' observé à <span class="gras">'+commune+' '+code_insee+'</span> ['+latitude+' / '+longitude+']'+' le <span class="gras">'+' '+date+'</span>'+
238
								'</li>'+
239
								'<li>'+
240
									'<div class="row-fluid">'+
241
										'<span class="span4">Lieu-dit : <span class="gras">'+lieudit+'</span></span>'+
242
										'<span class="span4">Station : <span class="gras">'+station+'</span></span>'+
243
										'<span class="span4">Milieu : <span class="gras">'+milieu+'</span></span>'+
244
									'</div>'+
245
								'</li>'+
246
								'<li>'+
247
									'<div class="row-fluid">'+
2881 aurel 248
										'<span class="span4">Culture de <span class="gras">'+cultureDetails+'</span> de type <span class="gras">'+culture+'</span></span>'+
2857 aurel 249
										'<span class="span4">Identification <span class="gras">'+identification+'</span></span>'+
250
										'<span class="span4">Abondance de <span class="gras">'+abondance+'</span></span>'+
251
									'</div>'+
252
								'</li>'+
253
								'<li>'+
254
									'Espèce située en <span class="gras">'+zoneChamp+'</span> du champ'+
255
								'</li>'+
256
								'<li>'+
257
									'Notes : <span class="discretion">'+notes+'</span>'+
258
								'</li>'+
259
							'</ul>'+
260
						'</div>'+
261
					'</div>'+
262
				'</div>'+
263
			'</div>'+
264
		'</div>');
265
	$('#zone-liste-obs').removeClass("hidden").show();
266
};
267
 
2863 mathias 268
WidgetSaisieMessicoles.prototype.surAutocompletionTaxon = function(event, ui) {
269
	$("#taxon").data(ui.item);
270
	if (ui.item.retenu == true) {
271
		$("#taxon").addClass('ns-retenu');
272
	} else {
273
		$("#taxon").removeClass('ns-retenu');
274
	}
275
	// détection de si c'est un(e?) messicole ou pas
276
	var panneauAvertissementNonMessicole = $('#avertissement-non-messicole');
277
	panneauAvertissementNonMessicole.hide();
278
	if (nnr_messicoles.indexOf(parseInt(ui.item.numNomRet)) == -1) {
279
		panneauAvertissementNonMessicole.show();
280
	}
281
};
282
 
2862 mathias 283
WidgetSaisieMessicoles.prototype.ajouterNumNomSel = function(numNom, referentiel) {
284
	var nn = '';
285
	if (numNom == '' || numNom == undefined) {
286
		nn = '<span class="alert-error">[non lié au référentiel]</span>';
287
	} else {
288
		nn = '<span class="nn">[nn'+numNom+']</span>'
289
		+ '<span class="referentiel-obs"> '
290
		+ referentiel+'</span>';
291
	}
292
	return nn;
293
};
2857 aurel 294
 
2862 mathias 295
// surcharge, abadon du mécanisme générique et bidouillage en dur (plus facile
296
// car champs radio / checkboxes)
297
WidgetSaisieMessicoles.prototype.getObsChpEtendus = function() {
298
	var champs = [];
2857 aurel 299
 
2862 mathias 300
	var zoneChamp = [];
301
	$('input[name="zone-champ[]"]:checked').each(function() {
302
		zoneChamp.push($(this).val());
303
	});
304
	//console.log("zc:", zoneChamp);
305
	// obligatoire donc jamais vide (on croise les doigts)
306
	champs.push({
307
		cle: "zoneDuChamp",
308
		label: "Zone du champ",
309
		valeur: zoneChamp.join()
310
	});
2881 aurel 311
 
312
	var typeCulture = $('input[name=type-culture]:checked').data('titre');
2862 mathias 313
	//console.log("tc:", typeCulture);
314
	if (typeCulture != '') {
315
		champs.push({
316
			cle: "typeDeCulture",
317
			label: "Type de culture",
2882 aurel 318
			valeur: (typeCulture == undefined ? "" : typeCulture)
2862 mathias 319
		});
320
	}
2881 aurel 321
 
322
	var typeCultureDetails = $('input[name=type-culture]:checked').parent().find('input[type=text]').val();
323
 
324
	//console.log("tcd:", typeCultureDetails);
325
	if (typeCultureDetails != '') {
2880 aurel 326
		champs.push({
2881 aurel 327
			cle: "typeDeCultureDetails",
328
			label: "Details de la culture",
329
			valeur: typeCultureDetails
2880 aurel 330
		});
331
	}
2862 mathias 332
 
333
	return champs;
334
}
335
 
336
 
337
 
338
 
2851 mathias 339
/* jQuery en vrac */
340
$(document).ready(function() {
2881 aurel 341
 
2851 mathias 342
	// super popover qui va chercher son contenu dans un div à côté (pour les
343
	// boutons d'aide des types de champs, etc.)
344
	$('[data-toggle="popover"]').popover({
345
        html : true,
346
        content: function() {
347
			var parentFor = $(this).parent().attr("for");
348
			var popoverHtmlContentDiv = $('.popover-html-content[data-for="' + parentFor + '"]');
349
			return popoverHtmlContentDiv.html();
350
        }
351
    });
2860 mathias 352
 
2880 aurel 353
    // Activation de la saisie si on clique sur un type de champ
2881 aurel 354
    function gererAffichageChampCulture(){
355
    	$('.culture input[type=text]').hide();
356
    	var radio = $('.culture input[type=radio]:checked');
357
    	var input = radio.parent().find('input[type=text]');
2880 aurel 358
   		(radio.is(':checked')) ? input.show() && input.focus() : input.hide();
2881 aurel 359
   	}
360
   	$('.culture').change(gererAffichageChampCulture);
361
   	// ... et aussi au chargement du widget, si la sélection est restée sur un champ
362
	gererAffichageChampCulture();
363
 
364
 
365
 
366
 
2860 mathias 367
 
368
    // Affichage de l'espèce liée au référentiel sélectionné lors de la sélection 'Autres' (espèce)
2862 mathias 369
	function gererAffichageChampAutreEspece() {
2857 aurel 370
    	var option = $('#taxon-liste').val();
371
    	var taxonCompletion = $('#taxon-input-groupe');
372
    	if (option == '?') {
373
    		taxonCompletion.show();
374
    		$('#taxon').focus();
2856 aurel 375
    	}
376
    	else {
2857 aurel 377
    		taxonCompletion.hide();
2856 aurel 378
    	}
2862 mathias 379
    }
380
    $('#taxon-liste').change(gererAffichageChampAutreEspece);
381
	// ... et aussi au chargement du widget, si la sélection est restée sur "Autre espèce"
382
	gererAffichageChampAutreEspece();
2860 mathias 383
 
2857 aurel 384
    // On masque l'option par défaut pour l'abondance puisque le choix est obligatoire
385
    $('#abondance-liste').click(masquerTitreListe('abondance'));
386
    function masquerTitreListe(element) {
387
		$('#' + element + '-liste .a-masquer').hide();
388
	}
2850 aurel 389
});