Subversion Repositories eFlore/Applications.cel

Rev

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