Subversion Repositories eFlore/Applications.cel

Rev

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