Subversion Repositories eFlore/Applications.cel

Rev

Rev 3018 | 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},
238
			determinationSource: {isbn: true}
2406 jpm 239
		}
240
	});
2710 mathias 241
};
2406 jpm 242
 
2710 mathias 243
WidgetSaisieMissionsFlore.prototype.basculerOuvertureFermetureCadre = function(element) {
2410 jpm 244
	if (element.hasClass('glyphicon-plus-sign')) {
245
		element.removeClass('glyphicon-plus-sign').addClass('glyphicon-minus-sign');
2406 jpm 246
	} else {
2410 jpm 247
		element.removeClass('glyphicon-minus-sign').addClass('glyphicon-plus-sign');
2406 jpm 248
	}
2710 mathias 249
};
2406 jpm 250
 
2841 mathias 251
 
252
 
2710 mathias 253
WidgetSaisieMissionsFlore.prototype.basculerAffichageCoord = function() {
2841 mathias 254
	var textActuel = $(this).text();
2410 jpm 255
	var textActuel = $(this).text(),
2710 mathias 256
		textARemplacer = $(this).data('toggle-text');
2410 jpm 257
	$(this).text(textARemplacer).data('toggle-text', textActuel);
258
 
2841 mathias 259
 
260
 
2410 jpm 261
	if ($(this).hasClass('cacher-coord')) {
262
		$(this).removeClass('cacher-coord').addClass('afficher-coord');
263
		$('#coordonnees-geo').addClass('hidden');
264
	} else {
265
		$(this).removeClass('afficher-coord').addClass('cacher-coord');
266
		$('#coordonnees-geo').removeClass('hidden');
267
	}
268
 
2406 jpm 269
	return false;
2710 mathias 270
};
2406 jpm 271
 
2710 mathias 272
WidgetSaisieMissionsFlore.prototype.afficherObs = function() {
2410 jpm 273
	var date = $('#date').val(),
274
		commune = $('#commune-nom').text(),
275
		codeInsee = $('#commune-code-insee').text(),
276
		lat = $('input[name="latitude"]').val(),
277
		lng = $('input[name="longitude"]').val(),
278
		lieudit = $('#lieudit').val(),
279
		station = $('#station').val(),
280
 
281
		milieux = $('#milieu').val(),
2710 mathias 282
		exposition = this.getTextOptionSelectionne('station-exposition'),
283
		pente = this.getTextOptionSelectionne('station-pente'),
2410 jpm 284
 
3017 delphine 285
		certitude = this.getTextOptionSelectionne('certitude'),
2710 mathias 286
		phenologie = this.getTextOptionSelectionne('phenologie'),
287
		abondance = this.getTextOptionSelectionne('abondance'),
2410 jpm 288
		individus = (($('#individus-nbre').val() === undefined || $('#individus-nbre').val() === '') ? '' : ' (' + $('#individus-nbre').val() + ')'),
2710 mathias 289
		typeReleve = this.getTextOptionSelectionne('releve-type'),
2410 jpm 290
		sourceDet = $('#determination-source').val(),
291
 
3018 delphine 292
		notes = $('#notes').val(),
293
 
294
		referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
2410 jpm 295
 
3018 delphine 296
	if (this.especeImposee == 1) {
297
		var numNomSel = $('#taxon').data('numNomSel'),
298
			nomSel = $('#taxon').val();
299
	} else {
300
		var numNomSel = $('#taxon').val();
301
		var nomSel = taxons[numNomSel]['nom_sel'];
302
	}
303
 
2410 jpm 304
	$('#liste-obs').prepend(
2710 mathias 305
		'<div id="obs'+this.obsNbre+'" class="obs obs'+this.obsNbre+'">'+
2406 jpm 306
				'<div class="well">'+
307
					'<div class="obs-action pull-right has-tooltip" data-placement="bottom" '+
308
						'title="Supprimer cette observation de la liste à transmettre">'+
2710 mathias 309
						'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
2410 jpm 310
							'<span class="glyphicon glyphicon-trash icon-white"></i>'+
2406 jpm 311
						'</button>'+
312
					'</div> '+
2410 jpm 313
					'<div class="row">'+
314
						'<div class="col-md-2 obs-miniatures">'+
2710 mathias 315
							this.ajouterImgMiniatureAuTransfert()+
2406 jpm 316
						'</div>'+
2410 jpm 317
						'<div class="col-md-8">'+
318
							'<ul class="list-unstyled obs-entete">'+
3018 delphine 319
								'<li>'+	'<span class="nom-sci">' + nomSel + '</span> ' +
320
								'<span class="nn">[nn'+numNomSel+']</span>'+
321
								'<span class="referentiel-obs">' + referentiel +' ('+certitude+') </span>' +
322
									'observé à ' +
2410 jpm 323
									'<span class="commune">' + commune + '</span> ' +
324
									'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
325
									' le ' +
326
									'<span class="date">' + date + '</span>' +
327
								'</li>' +
328
							'</ul>'+
329
							'<ul class="list-unstyled obs-details">'+
330
								'<li>' +
331
									'<span>Lieu-dit :</span> ' + lieudit + ' ; ' +
332
									'<span>Station :</span> ' + station + ' ; ' +
333
								'</li>' +
334
								'<li>' +
335
									'<span>Milieu :</span> ' + milieux + ' ; ' +
336
									'<span>Exposition :</span> ' + exposition + ' ; ' +
337
									'<span>Pente :</span> ' + pente + ' ; ' +
338
								'</li>' +
339
								'<li>' +
340
									'<span>Phénologie :</span> ' + phenologie + ' ; ' +
341
									'<span>Abondance :</span> ' + abondance + individus + ' ; ' +
342
									'<span>Relevé :</span> ' + typeReleve + ' ; ' +
343
									'<span>Source :</span> ' + sourceDet + ' ; ' +
344
								'</li>' +
345
								'<li>' +
3018 delphine 346
									'<span>Certitude :</span> ' + certitude +' ; '+
2410 jpm 347
									'<span>Commentaires :</span> ' + notes +
2406 jpm 348
								'</li>'+
349
							'</ul>'+
350
						'</div>'+
351
					'</div>'+
352
				'</div>'+
353
		'</div>');
2710 mathias 354
	$('#zone-liste-obs').removeClass("hidden").show();
2406 jpm 355
}
356
 
2710 mathias 357
WidgetSaisieMissionsFlore.prototype.getTextOptionSelectionne = function(id) {
2410 jpm 358
	var optionVal = $('#' + id).val(),
359
		optionText = $('#' + id + ' option:selected').text();
360
	return ((optionVal === undefined || optionVal === '') ? '' : optionText);
2710 mathias 361
};
2410 jpm 362
 
2710 mathias 363
WidgetSaisieMissionsFlore.prototype.stockerObsData = function() {
3018 delphine 364
	if (this.especeImposee == 1) {
365
		var numNomSel = $('#taxon').data('numNomSel'),
366
			nomSel = $('#taxon').val(),
367
			nomRet = $('#taxon').data('nomRet'),
368
			numNomRet = $('#taxon').data('numNomRet'),
369
			numTaxon = $('#taxon').data('nt'),
370
			famille = $('#taxon').data('famille'),
371
			referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
372
	} else {
373
		var numNomSel = $('#taxon').val();
374
		var nomSel = taxons[numNomSel]['nom_sel'],
375
			nomRet = taxons[numNomSel]['nom_ret'],
376
			numNomRet = taxons[numNomSel]['num_nom_ret'],
377
			numTaxon = taxons[numNomSel]['num_taxon'],
378
			famille = taxons[numNomSel]['famille'],
379
			referentiel = (numNomSel == undefined) ? '' : this.nomSciReferentiel;
380
	}
2406 jpm 381
 
2710 mathias 382
	$('#liste-obs').data('obsId'+this.obsNbre, {
2410 jpm 383
		'date' : $('#date').val(),
384
		'notes' : $('#notes').val().trim(),
2406 jpm 385
 
2410 jpm 386
		'nom_sel': nomSel,
387
		'num_nom_sel': numNomSel,
388
		'nom_ret': nomRet,
389
		'num_nom_ret': numNomRet,
390
		'num_taxon': numTaxon,
391
		'famille': famille,
392
		'referentiel': referentiel,
3018 delphine 393
		'certitude': $('#certitude').val(),
2406 jpm 394
 
2410 jpm 395
		'latitude' : $('#latitude').val(),
396
		'longitude' : $('#longitude').val(),
397
		'commune_nom' : $('#commune-nom').text(),
398
		'commune_code_insee' : $('#commune-code-insee').text(),
399
		'altitude': $('#altitude').text(),
400
		'lieudit': $('#lieudit').val().trim(),
401
		'station': $('#station').val().trim(),
402
		'milieu': $('#milieu').val().trim(),
403
		'abondance': $('#abondance').val(),
404
		'phenologie': $('#phenologie').val(),
405
 
2406 jpm 406
		//Ajout des champs images
2710 mathias 407
		'image_nom' : this.getNomsImgsOriginales(),
2406 jpm 408
 
409
		// Ajout des champs étendus de l'obs
2710 mathias 410
		'obs_etendue': this.getObsChpEtendus()
2406 jpm 411
	});
2710 mathias 412
};
2406 jpm 413
 
2710 mathias 414
WidgetSaisieMissionsFlore.prototype.validerFormulaire = function() {
2412 jpm 415
	var observateur = $('#form-observateur').valid(),
416
		station = $('#form-station').valid(),
417
		obsDate = $('#form-obs-date').valid(),
418
		obs = $('#form-obs').valid();
419
	return (observateur == true && station == true && obs == true && obsDate == true) ? true : false;
2710 mathias 420
};