Subversion Repositories eFlore/Applications.cel

Rev

Rev 3837 | Rev 3946 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3631 idir 1
function WidgetPhotoPopup( proprietes ) {
2
	if( this.valOk( proprietes ) ) {
3823 idir 3
		this.urlWidget                    = proprietes.urlWidget;
4
		this.urls                         = proprietes.urls;
3837 idir 5
		this.infosImages                  = proprietes.infosImages;
6
		this.urlImage                     = proprietes.urlImage;
7
		this.indexPremiereImage           = proprietes.indexPremiereImage;
3833 idir 8
		this.indexImage                   = this.indexPremiereImage;
3823 idir 9
		this.tailleMax                    = proprietes.tailleMax;
10
		this.popupUrl                     = proprietes.popupUrl;
11
		this.urlBaseTelechargement        = proprietes.urlBaseTelechargement;
12
		this.urlServiceRegenererMiniature = proprietes.urlServiceRegenererMiniature;
3631 idir 13
	}
3823 idir 14
 
15
	this.mettreAJourInfosImage();
3631 idir 16
}
17
 
3825 idir 18
WidgetPhotoPopup.prototype = new WidgetPhotoCommun();
3631 idir 19
 
20
WidgetPhotoPopup.prototype.initTpl = function() {
21
	this.redimensionnerGalerie();
3837 idir 22
	$( '#info-img-galerie' ).find( '.active' ).removeClass( 'active' );
23
	$( '#img-cadre-' + this.indexImage + ',#indicateur-img-' + this.indexImage ).addClass( 'active' );
3823 idir 24
 
3837 idir 25
	this.mettreAJourPopup();
3823 idir 26
 
3631 idir 27
	this.redimentionnerModaleCarousel();
28
};
29
 
30
WidgetPhotoPopup.prototype.initEvts = function() {
31
	const lthis = this;
32
 
33
	this.initEvtsDefilerImage();
34
	this.initEvtsContact();
35
	$( window ).on( 'resize', lthis.redimentionnerModaleCarousel.bind( lthis ) );
3823 idir 36
	this.initEvtsFonctionsPhoto();
3631 idir 37
	this.initEvtsRetourGalerieResponsive();
38
	this.initEvtsTagsPF();
39
};
40
 
3823 idir 41
WidgetPhotoPopup.prototype.mettreAJourPopup = function() {
42
	this.mettreAJourInfosImage();
43
	this.afficherTitreImage();
44
	this.traiterMetas();
45
	this.regenererMiniature();
46
	this.fournirLienIdentiplante();
47
};
48
 
49
WidgetPhotoPopup.prototype.mettreAJourInfosImage = function() {
3837 idir 50
	this.item          = this.infosImages[this.urls[this.indexImage]];
3826 idir 51
	this.titreImage    = this.item['titre'];
3825 idir 52
	this.urlLienEflore = this.item['lien'];
3826 idir 53
	this.idImage       = this.item['id_photo'];
54
	this.urlThisImage  = this.item['url_photo']+'.jpg';
55
	this.obs           = this.item['obs'];
56
	this.nn            = '[nn' + this.obs['nom_sel_nn']+']';
57
	this.urlIP         = this.obs['url_ip'];
58
	this.tagsImage     = this.tagsToArray( this.item['tags_photo'] );
59
	this.tagsObs       = this.tagsToArray( this.obs['tags_obs'] );
60
	this.auteur        = this.item['utilisateur']['nom_utilisateur'];
61
	this.date          = this.item['date'];
3823 idir 62
};
63
 
3825 idir 64
WidgetPhotoPopup.prototype.tagsToArray = function( tags ) {
3832 idir 65
	if(!this.valOk(tags)) {
66
		return [];
67
	}
3825 idir 68
	tags = tags.replace( new RegExp('\\.'), '' ).split( ',' );
69
 
70
	let cleanTags       = [],
71
		nbTags          = tags.length,
72
		tag             = '',
73
		tagsSansEspaces = '',
74
		cleanTagIndex   = 0;
75
 
76
	for(let i = 0; i < nbTags; i++) {
77
		tag = tags[i];
78
		tagsSansEspaces = tag.replace( ' ', '');
79
		if( '' !== tagsSansEspaces ) {
80
			cleanTags.push( tag.trim() );
81
		}
82
	}
83
 
84
	return cleanTags;
85
};
86
 
3631 idir 87
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
88
	const lthis = this;
89
 
90
	$( '#precedent, #suivant' ).on( 'click', function() {
91
		lthis.defilerImage( this.id );
92
	});
3823 idir 93
 
3631 idir 94
	$( '#print_content:not(saisir-tag)' ).on( 'keydown', function( event ) {
95
 
3823 idir 96
		const determinerSens = function( enventKey, left, right ) {
97
			switch ( enventKey ) {
98
				case left:
99
					return 'suivant';
100
				case right:
3825 idir 101
					return 'precedent';
3823 idir 102
				default:
103
					break;
3631 idir 104
			}
3823 idir 105
 
106
			return;
3631 idir 107
		}
3823 idir 108
 
109
		event = (event || window.event);
110
		// event.keyCode déprécié, on tente d'abord event.key
111
		let sens = ( 'key' in event ) ? determinerSens( event.key, 'ArrowLeft', 'ArrowRight' ) : determinerSens( event.keyCode, 37, 39 );;
112
 
3631 idir 113
		if ( lthis.valOk( sens ) ) {
114
			lthis.defilerImage( sens );
115
		}
116
	});
117
};
118
 
119
WidgetPhotoPopup.prototype.initEvtsContact = function() {
120
	const lthis = this;
121
 
122
	$( '#bloc-infos-img' ).on( 'click', '.lien_contact', function( event ) {
123
		event.preventDefault();
124
		lthis.chargerContenuModale( this.href );
125
	});
126
};
127
 
3823 idir 128
WidgetPhotoPopup.prototype.initEvtsFonctionsPhoto = function() {
3631 idir 129
	const lthis = this;
130
 
131
	$( '#boutons-footer #bloc-fct a, #retour-metas' ).on( 'click', function( event ){
132
		event.preventDefault();
133
		var voletAOuvrir = $( this ).data( 'volet' ),
134
			voletAFermer = $( '.bloc-volet:not(.hidden)' ).data( 'volet' );
135
 
136
		lthis.ouvrirVoletFct( voletAOuvrir, voletAFermer );
137
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
138
			$( '#info-img-galerie' ).addClass( 'hidden' );
139
			$( '#volet, #retour-galerie' ).removeClass( 'hidden' );
140
		}
141
	});
142
};
143
 
144
WidgetPhotoPopup.prototype.initEvtsRetourGalerieResponsive = function() {
145
	$( '#retour-galerie' ).on( 'click', function( event ) {
146
		event.preventDefault();
147
		$( '#info-img-galerie' ).removeClass( 'hidden' );
148
		$( this ).addClass( 'hidden' );
149
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
150
			$( '#volet' ).addClass( 'hidden' );
151
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
152
		}
153
	});
154
};
155
 
156
WidgetPhotoPopup.prototype.initEvtsTagsPF = function() {
157
	//recupérer tags en ajax (voir pictoflora, peut-être dans le php?)
158
	//	_OPTIONS
159
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
160
	//	_GET
161
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
162
	this.tagsPfCustom();
163
	$( '#bloc-tags' ).on( 'click', '.tag', function( event ) {
164
		event.preventDefault();
165
		$( this ).toggleClass( 'actif' );
166
	});
167
	$( '#bloc-tags' ).on( 'click', '.custom-tag.actif .fermer', function( event ) {
168
		event.preventDefault();
169
		//			Supprimer un custom-tag
170
		//	_OPTIONS
171
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
172
		// 	_paramètres
173
		// L'id du tag à la fin de l'url
174
		//	_DELETE
175
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
176
		// 	_réponse:
177
		// ""
178
		// 			Mettre à jour les mots cles
179
		//	_OPTIONS
180
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
181
		//	_GET
182
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
183
		$( this ).parent( '.custom-tag' ).remove();
184
	});
185
 
186
	$( '#bloc-tags' ).on( 'keyup', '.custom-tag.actif', function( event ) {
3823 idir 187
		let supprimerTag = false;
3631 idir 188
 
3823 idir 189
		event = ( event || window.event );
3631 idir 190
		// event.keyCode déprécié, on tente d'abord event.key
191
		if ( 'key' in event ) {
192
			supprimerTag = ( 'Delete' === event.key || 'Backspace' === event.key );
193
		} else {
194
			supprimerTag = ( 46 === event.keyCode || 8 === event.keyCode );
195
		}
196
		if ( supprimerTag ) {
3823 idir 197
			//			Supprimer un custom-tag
198
			//	_OPTIONS
199
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
200
			// 	_paramètres
201
			// L'id du tag à la fin de l'url
202
			//	_DELETE
203
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
204
			// 	_réponse:
205
			// ""
206
			// 			Mettre à jour les mots cles
207
			//	_OPTIONS
208
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
209
			//	_GET
210
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
3631 idir 211
			$( this ).parent( '.custom-tag' ).remove();
212
		}
213
	});
214
};
215
 
216
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
3823 idir 217
	if ( 'suivant' === sens ) {
3631 idir 218
		this.indexImage++ ;
3837 idir 219
		if( this.indexImage >= this.urls.length ) {
3631 idir 220
			this.indexImage = 0;
221
		}
3823 idir 222
	} else if ( 'precedent' === sens ) {
3631 idir 223
		this.indexImage--;
224
		if( this.indexImage <= 0 ) {
3837 idir 225
			this.indexImage = this.urls.length -1;
3631 idir 226
		}
227
	}
3823 idir 228
	// @TODO: Modifier l'attr content de 'meta[property=og:image]' et y mettre l'url de l'image
229
	this.mettreAJourPopup();
3631 idir 230
};
231
 
232
WidgetPhotoPopup.prototype.afficherTitreImage = function() {
3823 idir 233
	let lienContact  =
234
			this.urlWidget +'?mode=contact&nn=' + this.nn +
235
			'&nom_sci=' + this.obs['nom_sel'] +
236
			'&date=' + this.date +
237
			'&localisation=' + this.obs['localisation'] +
238
			'&id_image=' + this.idImage +
239
			'&auteur=' + this.auteur;
3631 idir 240
 
3823 idir 241
	if ( this.valOk( this.popupUrl ) ) {
242
		if (! this.popupUrl.match( new RegExp( 'img:' + this.idImage ) ) ) {
243
			this.popupUrl = this.actualiserPopupUrl( this.popupUrl, this.urlThisImage );
3631 idir 244
		}
3823 idir 245
		lienContact += '&popup_url=' + encodeURIComponent( this.popupUrl );
3631 idir 246
	}
247
 
3823 idir 248
	$( '#bloc-infos-img' ).html(
3825 idir 249
		this.afficherLien( this.urlLienEflore, this.obs['nom_sel'] )+
3823 idir 250
		' par '+
251
		'<a class="lien_contact" href="' + lienContact + '">' + this.auteur + '</a> '+
252
		' le ' + this.date + ' - ' + this.obs['localisation']
253
	);
3631 idir 254
};
255
 
256
WidgetPhotoPopup.prototype.actualiserPopupUrl = function( queryString, remplacement ) {
3823 idir 257
	let queryStringParsee = queryString.substring(1).split('&');
3631 idir 258
 
259
	$.each( queryStringParsee,  function( i, param ) {
260
		if( /url_image/.test( param ) ) {
261
			queryString = queryString.replace( param, 'url_image=' + remplacement );
262
			return false;
263
		}
264
	});
265
	return queryString;
266
};
267
 
268
WidgetPhotoPopup.prototype.redimentionnerModaleCarousel = function() {
269
	this.redimensionnerGalerie();
270
	if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
271
		$( '#volet, #retour-galerie' ).addClass( 'hidden' );
272
		$( '#info-img-galerie' ).removeClass( 'hidden' );
273
		$( '.bouton-fct.actif' ).removeClass( 'actif' );
274
		$( '.nettoyage-volet.haut' ).text( $( '#bloc-infos-img' ).text() );
275
		$( '#boutons-footer, #info-img-galerie' ).removeClass( 'col-lg-8' );
276
		$( '#bloc-infos-img, #volet' ).removeClass( 'col-lg-4' );
277
	} else {
278
		$( '#volet, #info-img-galerie' ).removeClass( 'hidden' );
279
		if ( this.valOk( $( '.bloc-volet:not(.hidden)' ) ) ) {
280
			$( '.bouton-fct.' + $( '.bloc-volet:not(.hidden)' ).data( 'volet' ) ).addClass( 'actif' );
281
		}
282
		$( '.nettoyage-volet.bas' ).text( $( '#bloc-infos-img' ).text() );
283
		$( '#boutons-footer, #info-img-galerie' ).addClass( 'col-lg-8' );
284
		$( '#bloc-infos-img, #volet' ).addClass( 'col-lg-4' );
285
		$( '#retour-galerie' ).addClass( 'hidden' );
286
	}
287
};
288
 
289
WidgetPhotoPopup.prototype.redimensionnerGalerie = function() {
290
	var maxSize = ( $( window ).width() / $( window ).height() ) < 1 ? $( window ).width() : $( window ).height();
291
 
292
	maxSize -= 30;
293
	$( '.carousel-item img' ).each( function( index, image ) {
294
		var proportion  = image.dataset.width / image.dataset.height,
295
			cssResize   = {};
296
 
297
		if ( proportion >= 1 ) {
298
			cssResize['width'] = maxSize;
299
		}
300
		if ( proportion <= 1) {
301
			cssResize['height'] = maxSize;
302
		}
303
		$( image ).css( cssResize );
304
	});
305
};
306
 
307
WidgetPhotoPopup.prototype.ouvrirVoletFct = function( voletAOuvrir, voletAFermer ) {
308
	if( voletAOuvrir !== voletAFermer ) {
309
		$( '#boutons-footer  .' + voletAFermer ).removeClass( 'actif' );
310
		$( '#boutons-footer  .' + voletAOuvrir ).addClass( 'actif' );
311
		$( '#bloc-' + voletAFermer ).addClass( 'hidden' );
312
		$( '#bloc-' + voletAOuvrir ).removeClass( 'hidden' );
313
		$( '#volet' ).scrollTop(0);
3823 idir 314
		$( '#retour-metas' ).removeClass( 'hidden', 'meta' === voletAOuvrir );
3631 idir 315
	}
316
};
317
 
318
WidgetPhotoPopup.prototype.tagsPfCustom = function() {
319
	const lthis = this;
320
 
321
	$( '#saisir-tag' ).on( 'blur keyup', function( event ) {
3823 idir 322
		event = ( event || window.event );
3631 idir 323
 
324
		var ajouterTag = ( 'blur' === event.type );
325
 
326
		// event.keyCode déprécié, on tente d'abord event.key
327
		if ( 'key' in event  ) {
328
			if ( 'Enter' === event.key ) {
329
				ajouterTag = true;
330
			}
331
		} else if ( 13 === event.keyCode ) {
332
			ajouterTag = true;
333
		}
334
		if	( ajouterTag ) {
335
			var nouveauTag     = $( this ).val(),
336
				nouveauTagAttr = lthis.chaineValableAttributsHtml( nouveauTag.toLowerCase() );
337
 
338
			if( lthis.valOk( nouveauTagAttr ) && !lthis.valOk( $( '#' + nouveauTagAttr + '.tag' ) ) ) {
339
				// 			Envoyer tags en ajax :
340
				// 	_OPTIONS
341
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
342
				//  _paramètres :
343
				//rien
344
				// 	_PUT
345
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
346
				// 	_paramètres :
347
				// image=197938&mot_cle=motcleperso&auteur.id=44084
348
				// 			Mettre à jour les mots cles
349
				//	_OPTIONS
350
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
351
				//	_GET
352
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
353
				$( '#tags-pf-supp' ).append(
3823 idir 354
					'<a id="' + nouveauTagAttr + '" class="btn tag custom-tag actif">' +
3631 idir 355
						nouveauTag + '&nbsp;<i class="fas fa-times-circle fermer"></i>' +
356
					'</a>'
357
				);
358
				$( '#form-tags-auteur' )[0].reset();
359
				$( this ).val( '' );
360
			}
361
		}
362
	});
363
};
3823 idir 364
 
365
WidgetPhotoPopup.prototype.traiterMetas = function() {
366
	this.afficherMetas();
367
	this.afficherPopupLocalisation();
368
	this.afficherMetasPlus();
369
	this.fournirLienTelechargement();
370
};
371
 
372
WidgetPhotoPopup.prototype.afficherMetas = function() {
373
	const lthis         = this;
374
	const META_CONTENUS = {
3825 idir 375
		'nom' : this.afficherLien( this.urlLienEflore, this.obs['nom_sel'] ),
3823 idir 376
		'localisation' : this.obs['localisation'],
377
		'auteur' : this.auteur,
378
		'date-obs' : this.date,
379
		'commentaire' : this.obs['commentaire'],
380
		'certitude' : this.obs['certitude'],
381
		'fiabilite' : this.obs['fiabilite'],
382
		'num-photo' : this.idImage,
383
		'titre-original' : this.item['nom_original'],
384
		'date-photo' : this.formaterDate( this.item['date_photo'] ),
385
		'attribution-copy' : this.item['attribution'],
386
		'url-copy' : this.urlThisImage
387
	};
388
 
389
	$.each( META_CONTENUS, function( attrId, contenu ) {
390
		let $metaContainer = $( '#bloc-meta #'+attrId );
391
 
392
		if ( lthis.valOk( contenu ) ) {
393
			switch( attrId ) {
394
				case 'attribution-copy' :
395
				case 'url-copy' :
396
					$metaContainer.val( contenu );
397
					lthis.copieAutoChamp( $metaContainer );
398
					break;
399
				case 'nom' :
400
					$( '.contenu', $metaContainer ).html( contenu );
3825 idir 401
					$( '.bouton', $metaContainer ).attr( 'href', lthis.urlLienEflore );
3823 idir 402
					break;
403
				case 'auteur' :
3827 idir 404
					$( '.bouton', $metaContainer ).attr( 'href', lthis.item['urlProfil'] );
3823 idir 405
				default:
406
					$( '.contenu', $metaContainer ).text( contenu );
407
					break;
408
			}
409
		}
410
	});
411
};
412
 
3824 idir 413
WidgetPhotoPopup.prototype.copieAutoChamp = function( $champACopier ) {
3838 idir 414
	$champACopier.off( 'click' ).on( 'click', function() {
415
		$( '#attribution-copy, #url-copy' ).removeClass( 'hidden' )
416
			.find( '.copy-message' ).remove();
3823 idir 417
 
418
		$( this ).select();
419
		document.execCommand( 'copy' );
420
 
421
		$( this ).after(
422
			'<p class="copy-message alert-success" style="width: 100%; height:' + $( this ).outerHeight() + 'px; margin: 0; display:flex;">'+
423
				'<span style="margin:auto; font-size:1rem;">Copié dans le presse papier</span>'+
424
			'</p>'
425
		).addClass( 'hidden' );
426
 
427
		setTimeout( function() {
428
			$( '.copy-message' ).remove();
429
			$champACopier.removeClass( 'hidden' );
430
		}, 1000 );
431
	});
432
};
433
 
434
WidgetPhotoPopup.prototype.afficherMetasPlus = function() {
435
	const lthis         = this;
436
	const META_LABELS  = {
437
		'id_obs' : 'observation n°',
438
		'projet' : 'projet',
3825 idir 439
		'nom_referentiel' : 'réferentiel',
3823 idir 440
		'date_obs' : 'date d´observation',
441
		'nom_sel': 'nom scientifique',
442
		'nom_sel_nn' : 'nom scientifique n°',
443
		'nom_ret' : 'nom retenu',
444
		'nom_ret_nn' : 'nom retenu n°',
445
		'famille' : 'famille',
446
		'tags_obs' : 'tags de l´observation',
447
		'lieudit' : 'lieu dit',
448
		'station' : 'station',
449
		'milieu' : 'milieu',
450
		'latitude' : 'latitude',
451
		'longitude' : 'longitude',
452
		'altitude' : 'altitude',
453
		'localisation_precision': 'précision de la localisation',
454
		'code_insee' : 'code insee de la commune',
455
		'dept' : 'département',
456
		'pays' : 'pays',
457
		'est_ip_valide' : 'validée sur identiplante',
458
		'score_ip' : 'score identiplante',
459
		'url_ip' : 'url identiplante',
460
		'abondance' : 'abondance',
461
		'phenologie' : 'phénologie',
462
		'spontaneite' : 'spontaneite',
463
		'type_donnees' : 'type de donnees',
464
		'biblio' : 'bibliographie',
465
		'source' : 'source',
466
		'herbier' : 'herbier',
467
		'observateur' : 'observateur',
468
		'observateur_structure' : 'structure'
469
	};
3825 idir 470
 
3823 idir 471
	const $contenuPlusMeta  = $( '#contenu-meta-plus' );
3825 idir 472
	let degres = $contenuPlusMeta.is( ':visible' ) ? '180' : '0';
3823 idir 473
 
474
	this.rotationFleche( degres );
3825 idir 475
	$contenuPlusMeta.empty();
3823 idir 476
 
477
	$.each( META_LABELS, function( cle, label ) {
478
		let idAttr = cle.replace( '_', '-' ),
479
			contenu = lthis.obs[cle];
480
 
3825 idir 481
		switch( cle ) {
482
			case 'nom_sel':
483
				contenu = lthis.afficherLien( lthis.urlLienEflore, contenu );
484
				break;
485
 
486
			case 'nom_ret':
487
				let urlEfloreNomRetenu = lthis.urlLienEflore.replace( lthis.obs['nom_sel_nn'], lthis.obs['nom_ret_nn'] );
488
 
489
				contenu = lthis.afficherLien( urlEfloreNomRetenu, contenu );
490
				break;
491
 
492
			case 'url_ip':
493
				contenu = lthis.afficherLien( contenu, contenu );
494
				break;
495
 
496
			case 'est_ip_valide':
497
			case 'herbier':
498
				if( '0' === contenu ) {
499
					contenu = 'non';
500
				}
501
				break;
502
 
503
			case 'date_obs':
504
				contenu = lthis.formaterDate( contenu );
505
				break;
506
 
507
			case 'tags_obs':
508
				let tagsObsLength = lthis.tagsObs.length;
509
				contenu = lthis.tagsObs.join( '<br>' );
510
				break;
511
 
512
			default:
513
				break;
3823 idir 514
		}
515
 
516
		if ( lthis.valOk( contenu ) ) {
517
			$contenuPlusMeta.append(
518
				'<li id="' + idAttr + '-meta-plus" class="row">'+
519
					'<div class="col-5 label">' + label.charAt( 0 ).toUpperCase() + label.slice( 1 ) + '</div>'+
3829 idir 520
					'<div class="col-7 contenu">' + contenu + '</div>'+
3823 idir 521
				'</li>'
522
			);
523
		}
524
	});
525
 
3825 idir 526
	if( !$contenuPlusMeta.hasClass( 'actif' ) ) {
527
		$contenuPlusMeta.hide();
528
	}
529
 
530
	let estVisible = false;
531
 
3823 idir 532
	$( '#plus-meta' ).off( 'click' ).on( 'click', function( event ) {
533
		event.preventDefault();
534
		$contenuPlusMeta.toggle( 200, function() {
3825 idir 535
			estVisible = $contenuPlusMeta.is( ':visible' );
536
			degres     = estVisible ? '180' : '0';
537
			$( this ).toggleClass( 'actif', estVisible );
3823 idir 538
			lthis.rotationFleche( degres );
539
		});
540
	});
541
};
542
 
543
WidgetPhotoPopup.prototype.rotationFleche = function( degres ) {
544
	$( '#plus-meta i' ).css({
545
		'-webkit-transform' : 'rotate('+ degres +'deg)',
546
		'-moz-transform' : 'rotate('+ degres +'deg)',
547
		'-ms-transform' : 'rotate('+ degres +'deg)',
548
		'transform' : 'rotate('+ degres +'deg)'
549
	});
550
};
551
 
552
WidgetPhotoPopup.prototype.fournirLienTelechargement = function() {
553
	const lthis = this;
554
 
555
	$( '#formats' ).on( 'change', function() {
556
		let format             = ( $( this ).val() || 'O' ),
557
			lienTelechargement = lthis.urlBaseTelechargement + lthis.idImage + '?methode=telecharger&format=' + format;
558
 
559
		$( '#telecharger' ).attr( 'href', lienTelechargement );
560
	});
561
 
562
	$( '#formats' ).trigger( 'change' );
563
};
564
 
565
 
566
WidgetPhotoPopup.prototype.afficherPopupLocalisation = function() {
567
	const lthis = this;
568
 
569
	$( '#localisation a.bouton' ).on( 'click', function( event ){
570
		event.preventDefault();
571
 
572
		$( this ).after(
573
			'<div id="localisation-map-container">'+
574
				'<button id="map-close" type="button" class="bouton btn btn-sm btn-outline-secondary" aria-label="Close">'+
575
					'<span aria-hidden="true">×</span>'+
576
				'</button>'+
577
				'<div id="localisation-map"></div>'+
578
			'</div>'
579
		);
580
 
581
		let lat = lthis.obs['latitude'],
582
			lng = lthis.obs['longitude'],
583
			map = L.map( 'localisation-map', {
584
				zoomControl: true,
585
				dragging: false,
586
				scrollWheelZoom: 'center'
587
			} ).setView( [lat, lng], 12 );
588
 
589
		map.markers = [];
590
 
591
		L.tileLayer(
592
			'https://osm.tela-botanica.org/tuiles/osmfr/{z}/{x}/{y}.png',
593
			{
594
				attribution: 'Data © <a href="http://osm.org/copyright">OpenStreetMap</a>',
595
				maxZoom: 18
596
			}
597
		).addTo( map );
598
 
599
		map.addLayer( new L.FeatureGroup() );
600
 
601
		let marker = new L.Marker(
602
			{
603
				'lat': lat,
604
				'lng': lng
605
			},
606
			{
607
				draggable: false,
608
			}
609
		);
610
 
611
 
612
		map.addLayer( marker );
613
		map.markers.push( marker );
614
 
615
		$( '#map-close' ).on( 'click', function( event ){
616
			$( '#localisation-map-container' ).remove();
617
		});
618
	});
619
 
620
	$( '#fenetre-modal' ).on( 'click', function( event ) {
621
		if(
622
			!$( event.target ).closest( '#localisation-map-container' ).length
623
			&& !$( event.target ).closest( '#obs-localisation' ).length
624
		) {
625
			$( '#localisation-map-container' ).remove();
626
		}
627
	});
628
};
629
 
630
 
631
WidgetPhotoPopup.prototype.regenererMiniature = function() {
632
	const lthis = this;
633
	$( '#regenerer-miniature' ).off( 'click' ).on( 'click', function( event ) {
634
		event.preventDefault();
635
 
636
		let url = lthis.urlServiceRegenererMiniature + lthis.idImage;
637
 
3829 idir 638
		$.get( url, function( data ) {
639
				console.log( data );
640
			}
641
		).fail( function() {
642
			console.log( 'La régénérétion d´image ne s´est pas faite' );
3823 idir 643
		});
644
	});
645
};
646
 
647
WidgetPhotoPopup.prototype.formaterDate = function( sqlDate ) {
648
	dateFormatee = sqlDate
649
		.substring( 0, 10 )
650
		.split( '-' )
651
		.reverse()
652
		.join('/');
653
 
654
	return dateFormatee;
655
};
656
 
3825 idir 657
WidgetPhotoPopup.prototype.afficherLien = function( url, nom ) {
658
	if( !/https?:\/\//.test( url ) ) {
659
		url = 'https://' + url;
660
	}
661
	return '<a href="' + url + '" target="_blank">' + nom + '</a> ';
662
};
663
 
3823 idir 664
WidgetPhotoPopup.prototype.fournirLienIdentiplante = function() {
665
	const lthis = this;
666
	$( '.signaler-erreur-obs' ).each( function() {
667
		$( this ).attr( 'href', lthis.urlIP );
668
	});
669
};
670
 
671
// WidgetPhotoPopup.prototype.afficherTags = function() {
672
// 	const lthis = this;
673
// 	const TAGS_BASE = [
674
// 		'port',
675
// 		'fleur',
676
// 		'fruit',
677
// 		'feuille',
678
// 		'ecorce',
679
// 		'rameau',
680
// 		'planche',
681
// 		'insecte'
682
// 	];
683
 
684
 
685
// };