Subversion Repositories eFlore/Applications.cel

Rev

Rev 2860 | Rev 2862 | Go to most recent revision | 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
		}
44
		$('#barre-progression-upload').attr('aria-valuemax', this.obsNbre);
45
		$('#barre-progression-upload .sr-only').text('0/'+this.obsNbre+" observations transmises");
46
	} else {
47
		this.afficherPanneau('#dialogue-form-invalide');
48
	}
49
};
50
 
2857 aurel 51
// surcharge fonction definirReglesFormValidator()
52
WidgetSaisieMessicoles.prototype.definirReglesFormValidator = function() {
53
	// WidgetSaisie.definirReglesFormValidator();
54
	$("#form-observateur").validate({
55
		rules: {
56
			courriel : {
57
				required : true,
58
				email : true},
59
			courriel_confirmation : {
60
				required : true,
61
				equalTo: "#courriel"}
62
		}
63
	});
64
	$("#form-station").validate({
2860 mathias 65
		ignore: ':hidden:not("#latitude, #longitude")', // validation des champs cachés...
66
		errorPlacement: function(error, element) { // ...mais erreur visible
67
			error.insertBefore("#coordonnees-geo");
68
		},
69
		groups: {
70
			latLon: "latitude longitude"
71
		},
2857 aurel 72
		rules: {
73
			latitude : {
2860 mathias 74
				required: true,
75
				range: [-90, 90]
76
			},
2857 aurel 77
			longitude : {
2860 mathias 78
				required: true,
79
				range: [-180, 180]
80
			}
2861 mathias 81
		},
82
		messages: {
83
			// astuce pour simuler un message personnalisé pour le groupe "latLon"
84
			latitude: "Veuillez géolocaliser votre observation en déplaçant le curseur sur la carte",
85
			longitude: "Veuillez géolocaliser votre observation en déplaçant le curseur sur la carte"
2857 aurel 86
		}
87
	});
88
	$("#form-obs").validate({
89
		rules: {
90
			"taxon-liste" : "required",
91
			taxon : "required",
92
			"abondance-liste" : "required",
93
			"zone-champ[]" : {
94
            	required : true,
95
            	minlength : 1
96
            }
2860 mathias 97
		},
98
		errorPlacement: function(error, element) { // pas top mais mieux que rien
99
			error.insertBefore(element.parent());
2857 aurel 100
		}
101
	});
102
	$("#form-date").validate({
103
		rules: {
104
			date : {
105
				required : true,
106
				date : date
107
			}
108
		}
109
	});
110
};
111
 
112
// surcharge fonction validerFormulaire()
113
WidgetSaisieMessicoles.prototype.validerFormulaire = function() {
114
	observateur = $("#form-observateur").valid();
115
	station = $("#form-station").valid();
116
	obs = $("#form-obs").valid();
117
	date = $("#form-date").valid();
118
	return (observateur && station && obs && date);
119
};
120
 
121
// surcharge fonction stockerObsData()
122
WidgetSaisieMessicoles.prototype.stockerObsData = function() {
123
	var lthis = this;
124
	var nomHorsListe = $('#taxon-liste').val() == '?' ? true : false;
125
		nomSpecial = $('#taxon-liste option:selected').hasClass('nom-special'),
126
		numNomSel = nomHorsListe ? $('#taxon').data('numNomSel') : $('#taxon-liste').val();
127
	var nomSel = nomHorsListe ? $('#taxon').val() : $('#taxon-liste option:selected').data('nom-a-sauver'),
128
		nomRet = nomHorsListe ? $('#taxon').data('nomRet') : this.taxons[numNomSel]['nom_ret'],
129
		numNomRet = nomHorsListe ? $('#taxon').data('numNomRet') : this.taxons[numNomSel]['num_nom_ret'],
130
		numTaxon = nomHorsListe ? $('#taxon').data('nt') : this.taxons[numNomSel]['num_taxon'],
131
		famille = nomHorsListe ? $('#taxon').data('famille') : this.taxons[numNomSel]['famille'],
132
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel,
133
		notes = (nomSpecial ? this.taxons[numNomSel]['nom_fr'] + '. ' : '') + $('#notes').val(),
134
		zoneChamp = [],
135
		abondance = $('#abondance-liste option:selected').val(),
136
		typeCulture = $('input[name=type-culture]:checked').val(),
137
		certitude = $('input[name=certitude]:checked').val(),
138
		certitude = (certitude == undefined) ? '' : certitude;
139
 
140
 
141
	$('#liste-obs').data('obsId'+this.obsNbre, {
142
		'date': $('#date').val(),
143
		'notes': notes,
144
 
145
		'station': $('#station').val(),
146
		'latitude': $('#latitude').val(),
147
		'longitude': $('#longitude').val(),
148
		'commune_nom': $('#commune-nom').text(),
149
		'commune_code_insee': $('#commune-code-insee').text(),
150
 
151
		'nom_sel': nomSel,
152
		'num_nom_sel': numNomSel,
153
		'nom_ret': nomRet,
154
		'num_nom_ret': numNomRet,
155
		'num_taxon': numTaxon,
156
		'famille': famille,
157
		'referentiel': referentiel,
158
		'certitude': certitude,
159
		'milieu': milieu,
160
		'zone_champ': zoneChamp,
161
		'abondance': abondance,
162
		'type_culture': typeCulture,
163
 
164
		// Ajout des champs images
165
		//'image_nom': lthis.getNomsImgsOriginales(),
166
 
167
		// Ajout des champs étendus de l'obs
168
		//'obs_etendue': lthis.getObsChpEtendus()
169
	});
170
	if (this.debug) {
171
		console.log($('#liste-obs').data('obsId'+this.obsNbre));
172
	}
173
};
174
 
175
/**
176
 * Affiche une observation dans la liste des observations à transmettre
177
 */
178
WidgetSaisieMessicoles.prototype.afficherObs = function() {
179
 
180
	var commune = $("#commune-nom").text();
181
	commune = commune.trim() != "" ? commune : $("#carte-recherche").val();
182
 
183
	var code_insee = $('#commune-code-insee').text();
184
	code_insee = code_insee.trim() != "" ? "("+code_insee+")" : "";
185
 
186
	var taxonListe = $("#taxon-liste option:selected").data('nom-a-sauver');
187
	var taxon = $("#taxon").val();
188
	var numNomSel = $("#taxon").data("numNomSel");
189
	var latitude = $("#latitude").val();
190
	var longitude = $("#longitude").val();
191
	var date = $("#date").val();
192
	var lieudit = ($('#lieudit').val() != "" ? $('#lieudit').val() : "pas de lieu-dit saisi");
193
	var station = ($('#station').val() != "" ? $('#station').val() : "pas de station saisie");
194
	var milieu = ($('#milieu').val() != "" ? $('#milieu').val() : "pas de milieu saisi");
195
	var culture = ($('#culture-autres-radio').is(':checked') ? $('#culture-autres-input').val() : $('input[name=type-culture]:checked').data('titre'));
196
	var identification = $('#identification-liste option:selected').data('titre');
197
	var abondance = $('#abondance-liste option:selected').data('titre');
198
	var zoneChamp = [];
199
	// récupération des cases à cocher multiples dans un tableau pour l'abondance
200
	$('input[name="zone-champ[]"]:checked').each(function() {
201
		zoneChamp.push(' '+$(this).data('titre'));
202
	});
203
	var notes = $("#notes").val();
204
 
205
	if (this.debug) {
206
		console.log(commune+'  -  '+code_insee);
207
	}
2860 mathias 208
 
2857 aurel 209
	// affichage des données de l'observation à transmettre
210
	$("#liste-obs").prepend(
211
		'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">'+
212
			'<div class="span12">'+
213
				'<div class="well">'+
214
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
215
						'title="Supprimer cette observation de la liste à transmettre">'+
216
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
217
							'<i class="icon-trash icon-white"></i>'+
218
						'</button>'+
219
					'</div> '+
220
					'<div class="row-fluid">'+
221
						'<div class="thumbnail span2">'+
222
						this.ajouterImgMiniatureAuTransfert()+
223
						'</div>'+
224
						'<div class="span9">'+
225
							'<ul class="unstyled">'+
226
								'<li>'+
227
									'<span class="nom-sci">'+taxonListe+taxon+'</span> '+
228
									this.ajouterNumNomSel()+'<span class="referentiel-obs">'+
229
									(numNomSel == undefined ? '' : '['+ this.nomSciReferentiel +']')+'</span>'+
230
									' observé à <span class="gras">'+commune+' '+code_insee+'</span> ['+latitude+' / '+longitude+']'+' le <span class="gras">'+' '+date+'</span>'+
231
								'</li>'+
232
								'<li>'+
233
									'<div class="row-fluid">'+
234
										'<span class="span4">Lieu-dit : <span class="gras">'+lieudit+'</span></span>'+
235
										'<span class="span4">Station : <span class="gras">'+station+'</span></span>'+
236
										'<span class="span4">Milieu : <span class="gras">'+milieu+'</span></span>'+
237
									'</div>'+
238
								'</li>'+
239
								'<li>'+
240
									'<div class="row-fluid">'+
241
										'<span class="span4">Culture de type <span class="gras">'+culture+'</span></span>'+
242
										'<span class="span4">Identification <span class="gras">'+identification+'</span></span>'+
243
										'<span class="span4">Abondance de <span class="gras">'+abondance+'</span></span>'+
244
									'</div>'+
245
								'</li>'+
246
								'<li>'+
247
									'Espèce située en <span class="gras">'+zoneChamp+'</span> du champ'+
248
								'</li>'+
249
								'<li>'+
250
									'Notes : <span class="discretion">'+notes+'</span>'+
251
								'</li>'+
252
							'</ul>'+
253
						'</div>'+
254
					'</div>'+
255
				'</div>'+
256
			'</div>'+
257
		'</div>');
258
	$('#zone-liste-obs').removeClass("hidden").show();
259
};
260
 
261
 
262
 
263
 
2851 mathias 264
/* jQuery en vrac */
265
$(document).ready(function() {
266
	// super popover qui va chercher son contenu dans un div à côté (pour les
267
	// boutons d'aide des types de champs, etc.)
268
	$('[data-toggle="popover"]').popover({
269
        html : true,
270
        content: function() {
271
			var parentFor = $(this).parent().attr("for");
272
			var popoverHtmlContentDiv = $('.popover-html-content[data-for="' + parentFor + '"]');
273
			return popoverHtmlContentDiv.html();
274
        }
275
    });
2860 mathias 276
 
2857 aurel 277
    // Activation de la saisie si on clique sur 'Autres' (type de champ)
278
    $('.culture').change(function() {
279
    	var input = $('#culture-autres-input');
2860 mathias 280
   		($('#culture-autres-radio').is(':checked')) ? input.show() && input.focus() : input.hide();
2857 aurel 281
    });
2860 mathias 282
 
283
    // Affichage de l'espèce liée au référentiel sélectionné lors de la sélection 'Autres' (espèce)
2857 aurel 284
    $('#taxon-liste').change(function() {
285
    	var option = $('#taxon-liste').val();
286
    	var taxonCompletion = $('#taxon-input-groupe');
287
    	if (option == '?') {
288
    		taxonCompletion.show();
289
    		$('#taxon').focus();
2856 aurel 290
    	}
291
    	else {
2857 aurel 292
    		taxonCompletion.hide();
2856 aurel 293
    	}
294
    });
2860 mathias 295
 
2857 aurel 296
    // On masque l'option par défaut pour l'abondance puisque le choix est obligatoire
297
    $('#abondance-liste').click(masquerTitreListe('abondance'));
298
    function masquerTitreListe(element) {
299
		$('#' + element + '-liste .a-masquer').hide();
300
	}
2850 aurel 301
});