Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
2710 mathias 1
// Héritage
2
function WidgetSaisieMissionsFlore() {
3
	this.serviceAltitudeUrl = null;
3018 delphine 4
	this.taxons = {};
2406 jpm 5
}
2710 mathias 6
WidgetSaisieMissionsFlore.prototype = new WidgetSaisie();
2406 jpm 7
 
8
 
2710 mathias 9
WidgetSaisieMissionsFlore.prototype.initForm = function() {
10
	// super()
11
	WidgetSaisie.prototype.initForm.call(this);
2406 jpm 12
 
2710 mathias 13
	this.surChangementAbondance();// Vérif lors du chargement de la page
14
	$('#abondance').on('change', this.surChangementAbondance.bind(this));
15
};
2410 jpm 16
 
2710 mathias 17
WidgetSaisieMissionsFlore.prototype.initEvts = function() {
18
	// super()
19
	WidgetSaisie.prototype.initEvts.call(this);
2406 jpm 20
 
2710 mathias 21
	var lthis = this;
22
	$('body').on('click', '.fermer', function(event) {
23
			event.preventDefault();
24
			lthis.basculerOuvertureFermetureCadre($(this).find('.icone'));
2406 jpm 25
	});
2710 mathias 26
	$('.btn-coord ').on('click', this.basculerAffichageCoord);
2406 jpm 27
 
2710 mathias 28
	this.surChangementNbreObs();
29
};
2410 jpm 30
 
2710 mathias 31
WidgetSaisieMissionsFlore.prototype.mettreAJourMarkerPosition = function(latLng) {
32
	this.trouverCommune(latLng);
33
	this.trouverAltitude(latLng);
2410 jpm 34
 
35
	var lat = latLng.lat().toFixed(5),
36
		lng = latLng.lng().toFixed(5);
2710 mathias 37
	this.remplirChampLatitude(lat);
38
	this.remplirChampLongitude(lng);
39
	this.remplirChampsLambert93(lat, lng);
40
};
2406 jpm 41
 
2410 jpm 42
proj4.defs([
43
	['EPSG:4326', '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'],
44
	['EPSG:2154', '+title=RGF93 / Lambert-93 +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs']
45
]);
2710 mathias 46
WidgetSaisieMissionsFlore.prototype.remplirChampsLambert93 = function(lat, lng) {
2410 jpm 47
	// Prendre en compte l'initialisation des projections
48
	var coordinate = {x: lng,y: lat};
49
	proj4(proj4.defs('EPSG:4326'), proj4.defs('EPSG:2154')).forward(coordinate);
50
	$('#l93-x').val(coordinate.x.toFixed(0));
51
	$('#l93-y').val(coordinate.y.toFixed(0));
2710 mathias 52
};
2410 jpm 53
 
2710 mathias 54
WidgetSaisieMissionsFlore.prototype.trouverAltitude = function(pos) {
55
	var lthis = this;
56
	var url_service = this.serviceAltitudeUrl,
57
		urlAltFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
58
	$.ajax({
59
		url: urlAltFormatee,
60
		type: 'GET',
61
		dataType: 'jsonp',
62
		beforeSend : function() {
63
			$('#altitude').empty();
64
			$('#dialogue-erreur .alert-txt').empty();
65
		},
66
		success : function(data, textStatus, jqXHR) {
67
			$('#altitude').empty().append(data.altitude);
68
			$('#marqueur-altitude').data('altitude', data.altitude);
69
		},
70
		statusCode : {
71
		    500 : function(jqXHR, textStatus, errorThrown) {
72
				if (lthis.debug) {
73
					$('#dialogue-erreur .alert-txt').append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissant l\'altitude.</p>');
2410 jpm 74
					reponse = jQuery.parseJSON(jqXHR.responseText);
75
					var erreurMsg = '';
76
					if (reponse != null) {
77
						$.each(reponse, function (cle, valeur) {
78
							erreurMsg += valeur + '<br />';
79
						});
80
					}
2406 jpm 81
 
2710 mathias 82
					$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
2410 jpm 83
				}
2710 mathias 84
		    }
85
		},
86
		error : function(jqXHR, textStatus, errorThrown) {
87
			if (lthis.debug) {
88
				$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de l\'appel au service fournissant l\'altitude.</p>');
89
				reponse = jQuery.parseJSON(jqXHR.responseText);
90
				var erreurMsg = '';
91
				if (reponse != null) {
92
					$.each(reponse, function (cle, valeur) {
93
						erreurMsg += valeur + '<br />';
94
					});
2410 jpm 95
				}
96
 
2710 mathias 97
				$('#dialogue-erreur .alert-txt').append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
2406 jpm 98
			}
99
		},
2710 mathias 100
		complete : function(jqXHR, textStatus) {
101
			var debugMsg = extraireEnteteDebug(jqXHR);
102
			if (debugMsg != '') {
103
				if (lthis.debug) {
104
					$('#dialogue-erreur .alert-txt').append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
105
				}
2410 jpm 106
			}
2710 mathias 107
			if ($('#dialogue-erreur .msg').length > 0) {
108
				$('#dialogue-erreur').show();
2406 jpm 109
			}
110
		}
111
	});
2410 jpm 112
};
113
 
2710 mathias 114
WidgetSaisieMissionsFlore.prototype.surChangementAbondance = function() {
115
	if (this.afficherIndividusNbreGroupe()) {
2410 jpm 116
		$('#individus-nbre-groupe').removeClass('hidden');
117
		$('#individus-nbre').valid();
118
	} else {
119
		$('#individus-nbre-groupe').addClass('hidden');
120
	}
2710 mathias 121
};
2410 jpm 122
 
2710 mathias 123
WidgetSaisieMissionsFlore.prototype.afficherIndividusNbreGroupe = function() {
2410 jpm 124
	var abondance = $('#abondance').val();
2412 jpm 125
	if (abondance === '1-4 individus' || abondance === '5-9 individus' || abondance === '10-49 individus') {
2410 jpm 126
		return true;
127
	} else {
128
		return false;
129
	}
2710 mathias 130
};
2410 jpm 131
 
2710 mathias 132
WidgetSaisieMissionsFlore.prototype.configurerFormValidator = function() {
133
	var lthis = this;
2406 jpm 134
	$.validator.addMethod(
2410 jpm 135
		'dateCel',
2406 jpm 136
		function (value, element) {
2412 jpm 137
			return value === '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value));
2406 jpm 138
		},
2410 jpm 139
		'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
2406 jpm 140
 
2410 jpm 141
	$.validator.addMethod(
142
		'individusNbre',
143
		function (value, element) {
144
			var ok = true;
2710 mathias 145
			if (lthis.afficherIndividusNbreGroupe()) {
2412 jpm 146
				var abondance = $('#abondance').val();
147
				if (abondance === '1-4 individus') {
148
					ok = value === '' || (value !== '' && /^[0-9]+$/.test(value) && value >= 1 && value < 5);
149
				} else if (abondance == '5-9 individus') {
150
					ok = value === '' || (value !== '' && /^[0-9]+$/.test(value) && value >= 5 && value < 10);
151
				} else if (abondance === '10-49 individus') {
152
					ok = value === '' || (value !== '' && /^[0-9]+$/.test(value) && value >= 10 && value < 50);
153
				}
2410 jpm 154
			}
155
			return ok;
156
		},
2412 jpm 157
		"Veuillez indiquer le nombre d'individus sous forme d'entier positif et compris dans la classe définie par le champ « Abondance » (Ex. : 3, 15 ou 33...).");
2410 jpm 158
 
2412 jpm 159
	$.validator.addMethod(
2410 jpm 160
		'isbn',
161
		function (value, element) {
162
			var isbn = value.trim();
163
			return (value == '' || (/^ISBN(-1(?:(0)|3))?:?( )*[0-9]+[- ][0-9]+[- ][0-9]+[- ][0-9]*[- ]*[xX0-9]$/).test(isbn));
164
		},
165
		'Format : ISBN 10 ou 13 avec chaque partie séparée par un espace ou tiret. <br />'+
166
		'Doit débuter par : "ISBN" ou "ISBN-10" ou "ISBN-13". Suivi par ":" ou ": " ou directement le code ISBN.<br />'+
167
		'(Ex. : ISBN:978-3-642-11746-6, ISBN:978 3 642 11746 6, ISBN: 978 3 642 11746 6, ISBN-10: 3 642 11746 6).');
168
 
169
	// Modification des méthodes par défaut de Jquery Validation pour Boostrap 3
170
	$.validator.setDefaults({
171
		ignore: [],// Forcer Jquery Validate à examiner les éléments en "display:none;"
2406 jpm 172
		highlight: function(element) {
2410 jpm 173
			$(element).closest('.form-group').addClass('has-error');
2406 jpm 174
		},
2410 jpm 175
		unhighlight: function(element) {
176
			$(element).closest('.form-group').removeClass('has-error');
177
		},
2406 jpm 178
		success: function(element) {
2410 jpm 179
			$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
2406 jpm 180
 
2410 jpm 181
			if ($(element).attr('id') == 'taxon' && $('#taxon').val() != '') {
2406 jpm 182
				// Si le taxon n'est pas lié au référentiel, on vide le data associé
183
				if ($('#taxon').data('value') != $('#taxon').val()) {
184
					$('#taxon').data('numNomSel', '');
185
					$('#taxon').data('nomRet', '');
186
					$('#taxon').data('numNomRet', '');
187
					$('#taxon').data('nt', '');
188
					$('#taxon').data('famille', '');
189
				}
190
			}
2410 jpm 191
		},
192
		errorElement: 'span',
193
		errorClass: 'help-block',
194
		errorPlacement: function(error, element) {
195
			//console.log(element.attr('name') +'-'+ element.parent('.input-group').length);
196
			if (element.parent('.input-group').length) {
197
				error.insertAfter(element.parent());
198
			} else {
199
				error.insertAfter(element);
200
			}
2406 jpm 201
		}
202
	});
2710 mathias 203
};
2406 jpm 204
 
2710 mathias 205
WidgetSaisieMissionsFlore.prototype.definirReglesFormValidator = function() {
2406 jpm 206
	$('#form-observateur').validate({
207
		rules: {
208
			courriel : {
209
				required : true,
210
				email : true},
211
			courriel_confirmation : {
212
				required : true,
213
				equalTo: '#courriel'}
214
		}
215
	});
216
	$('#form-station').validate({
217
		rules: {
218
			latitude : {
219
				range: [-90, 90],
220
				required: true},
221
			longitude : {
222
				range: [-180, 180],
223
				required: true},
2410 jpm 224
			'l93-x': 'required',
225
			'l93-y': 'required'
2406 jpm 226
		}
227
	});
2412 jpm 228
	$('#form-obs-date').validate({
2406 jpm 229
		rules: {
230
			date: {
231
				required: true,
2412 jpm 232
				'dateCel' : true}
233
		}
234
	});
235
	$('#form-obs').validate({
236
		rules: {
2410 jpm 237
			individusNombre: {individusNbre: true},
3141 delphine 238
			determinationSource: {isbn: true},
239
			certitude: {required: true}
2406 jpm 240
		}
241
	});
2710 mathias 242
};
2406 jpm 243
 
2710 mathias 244
WidgetSaisieMissionsFlore.prototype.basculerOuvertureFermetureCadre = function(element) {
2410 jpm 245
	if (element.hasClass('glyphicon-plus-sign')) {
246
		element.removeClass('glyphicon-plus-sign').addClass('glyphicon-minus-sign');
2406 jpm 247
	} else {
2410 jpm 248
		element.removeClass('glyphicon-minus-sign').addClass('glyphicon-plus-sign');
2406 jpm 249
	}
2710 mathias 250
};
2406 jpm 251
 
2841 mathias 252
 
253
 
2710 mathias 254
WidgetSaisieMissionsFlore.prototype.basculerAffichageCoord = function() {
2841 mathias 255
	var textActuel = $(this).text();
2410 jpm 256
	var textActuel = $(this).text(),
2710 mathias 257
		textARemplacer = $(this).data('toggle-text');
2410 jpm 258
	$(this).text(textARemplacer).data('toggle-text', textActuel);
259
 
2841 mathias 260
 
261
 
2410 jpm 262
	if ($(this).hasClass('cacher-coord')) {
263
		$(this).removeClass('cacher-coord').addClass('afficher-coord');
264
		$('#coordonnees-geo').addClass('hidden');
265
	} else {
266
		$(this).removeClass('afficher-coord').addClass('cacher-coord');
267
		$('#coordonnees-geo').removeClass('hidden');
268
	}
269
 
2406 jpm 270
	return false;
2710 mathias 271
};
2406 jpm 272
 
2710 mathias 273
WidgetSaisieMissionsFlore.prototype.afficherObs = function() {
2410 jpm 274
	var date = $('#date').val(),
275
		commune = $('#commune-nom').text(),
276
		codeInsee = $('#commune-code-insee').text(),
277
		lat = $('input[name="latitude"]').val(),
278
		lng = $('input[name="longitude"]').val(),
279
		lieudit = $('#lieudit').val(),
280
		station = $('#station').val(),
281
 
282
		milieux = $('#milieu').val(),
2710 mathias 283
		exposition = this.getTextOptionSelectionne('station-exposition'),
284
		pente = this.getTextOptionSelectionne('station-pente'),
2410 jpm 285
 
3017 delphine 286
		certitude = this.getTextOptionSelectionne('certitude'),
2710 mathias 287
		phenologie = this.getTextOptionSelectionne('phenologie'),
288
		abondance = this.getTextOptionSelectionne('abondance'),
2410 jpm 289
		individus = (($('#individus-nbre').val() === undefined || $('#individus-nbre').val() === '') ? '' : ' (' + $('#individus-nbre').val() + ')'),
2710 mathias 290
		typeReleve = this.getTextOptionSelectionne('releve-type'),
2410 jpm 291
		sourceDet = $('#determination-source').val(),
292
 
3018 delphine 293
		notes = $('#notes').val(),
294
 
295
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
2410 jpm 296
 
3018 delphine 297
	if (this.especeImposee == 1) {
298
		var numNomSel = $('#taxon').data('numNomSel'),
299
			nomSel = $('#taxon').val();
300
	} else {
301
		var numNomSel = $('#taxon').val();
302
		var nomSel = taxons[numNomSel]['nom_sel'];
303
	}
304
 
2410 jpm 305
	$('#liste-obs').prepend(
2710 mathias 306
		'<div id="obs'+this.obsNbre+'" class="obs obs'+this.obsNbre+'">'+
2406 jpm 307
				'<div class="well">'+
308
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
309
						'title="Supprimer cette observation de la liste à transmettre">'+
2710 mathias 310
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
2410 jpm 311
							'<span class="glyphicon glyphicon-trash icon-white"></i>'+
2406 jpm 312
						'</button>'+
313
					'</div> '+
2410 jpm 314
					'<div class="row">'+
315
						'<div class="col-md-2 obs-miniatures">'+
2710 mathias 316
							this.ajouterImgMiniatureAuTransfert()+
2406 jpm 317
						'</div>'+
2410 jpm 318
						'<div class="col-md-8">'+
319
							'<ul class="list-unstyled obs-entete">'+
3018 delphine 320
								'<li>'+	'<span class="nom-sci">' + nomSel + '</span> ' +
321
								'<span class="nn">[nn'+numNomSel+']</span>'+
322
								'<span class="referentiel-obs">' + referentiel +' ('+certitude+') </span>' +
323
									'observé à ' +
2410 jpm 324
									'<span class="commune">' + commune + '</span> ' +
325
									'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
326
									' le ' +
327
									'<span class="date">' + date + '</span>' +
328
								'</li>' +
329
							'</ul>'+
330
							'<ul class="list-unstyled obs-details">'+
331
								'<li>' +
332
									'<span>Lieu-dit :</span> ' + lieudit + ' ; ' +
333
									'<span>Station :</span> ' + station + ' ; ' +
334
								'</li>' +
335
								'<li>' +
336
									'<span>Milieu :</span> ' + milieux + ' ; ' +
337
									'<span>Exposition :</span> ' + exposition + ' ; ' +
338
									'<span>Pente :</span> ' + pente + ' ; ' +
339
								'</li>' +
340
								'<li>' +
341
									'<span>Phénologie :</span> ' + phenologie + ' ; ' +
342
									'<span>Abondance :</span> ' + abondance + individus + ' ; ' +
343
									'<span>Relevé :</span> ' + typeReleve + ' ; ' +
344
									'<span>Source :</span> ' + sourceDet + ' ; ' +
345
								'</li>' +
346
								'<li>' +
3018 delphine 347
									'<span>Certitude :</span> ' + certitude +' ; '+
2410 jpm 348
									'<span>Commentaires :</span> ' + notes +
2406 jpm 349
								'</li>'+
350
							'</ul>'+
351
						'</div>'+
352
					'</div>'+
353
				'</div>'+
354
		'</div>');
2710 mathias 355
	$('#zone-liste-obs').removeClass("hidden").show();
2406 jpm 356
}
357
 
2710 mathias 358
WidgetSaisieMissionsFlore.prototype.getTextOptionSelectionne = function(id) {
2410 jpm 359
	var optionVal = $('#' + id).val(),
360
		optionText = $('#' + id + ' option:selected').text();
361
	return ((optionVal === undefined || optionVal === '') ? '' : optionText);
2710 mathias 362
};
2410 jpm 363
 
2710 mathias 364
WidgetSaisieMissionsFlore.prototype.stockerObsData = function() {
3018 delphine 365
	if (this.especeImposee == 1) {
366
		var numNomSel = $('#taxon').data('numNomSel'),
367
			nomSel = $('#taxon').val(),
368
			nomRet = $('#taxon').data('nomRet'),
369
			numNomRet = $('#taxon').data('numNomRet'),
370
			numTaxon = $('#taxon').data('nt'),
371
			famille = $('#taxon').data('famille'),
372
			referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
373
	} else {
374
		var numNomSel = $('#taxon').val();
375
		var nomSel = taxons[numNomSel]['nom_sel'],
376
			nomRet = taxons[numNomSel]['nom_ret'],
377
			numNomRet = taxons[numNomSel]['num_nom_ret'],
378
			numTaxon = taxons[numNomSel]['num_taxon'],
379
			famille = taxons[numNomSel]['famille'],
380
			referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
381
	}
2406 jpm 382
 
2710 mathias 383
	$('#liste-obs').data('obsId'+this.obsNbre, {
2410 jpm 384
		'date' : $('#date').val(),
385
		'notes' : $('#notes').val().trim(),
2406 jpm 386
 
2410 jpm 387
		'nom_sel': nomSel,
388
		'num_nom_sel': numNomSel,
389
		'nom_ret': nomRet,
390
		'num_nom_ret': numNomRet,
391
		'num_taxon': numTaxon,
392
		'famille': famille,
393
		'referentiel': referentiel,
3018 delphine 394
		'certitude': $('#certitude').val(),
2406 jpm 395
 
2410 jpm 396
		'latitude' : $('#latitude').val(),
397
		'longitude' : $('#longitude').val(),
398
		'commune_nom' : $('#commune-nom').text(),
399
		'commune_code_insee' : $('#commune-code-insee').text(),
400
		'altitude': $('#altitude').text(),
401
		'lieudit': $('#lieudit').val().trim(),
402
		'station': $('#station').val().trim(),
403
		'milieu': $('#milieu').val().trim(),
404
		'abondance': $('#abondance').val(),
405
		'phenologie': $('#phenologie').val(),
406
 
2406 jpm 407
		//Ajout des champs images
2710 mathias 408
		'image_nom' : this.getNomsImgsOriginales(),
2406 jpm 409
 
410
		// Ajout des champs étendus de l'obs
2710 mathias 411
		'obs_etendue': this.getObsChpEtendus()
2406 jpm 412
	});
2710 mathias 413
};
2406 jpm 414
 
2710 mathias 415
WidgetSaisieMissionsFlore.prototype.validerFormulaire = function() {
2412 jpm 416
	var observateur = $('#form-observateur').valid(),
417
		station = $('#form-station').valid(),
418
		obsDate = $('#form-obs-date').valid(),
419
		obs = $('#form-obs').valid();
420
	return (observateur == true && station == true && obs == true && obsDate == true) ? true : false;
2710 mathias 421
};