Subversion Repositories eFlore/Applications.cel

Rev

Rev 3980 | Rev 3984 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3980 Rev 3983
1
function WidgetPhotoPopup( proprietes ) {
1
function WidgetPhotoPopup( proprietes ) {
2
	if( this.valOk( proprietes ) ) {
2
	if( this.valOk( proprietes ) ) {
3
		this.urlWidget                    = proprietes.urlWidget;
3
		this.urlWidget                    = proprietes.urlWidget;
4
		this.urls                         = proprietes.urls;
4
		this.urls                         = proprietes.urls;
5
		this.infosImages                  = proprietes.infosImages;
5
		this.infosImages                  = proprietes.infosImages;
6
		this.urlImage                     = proprietes.urlImage;
6
		this.urlImage                     = proprietes.urlImage;
7
		this.indexPremiereImage           = proprietes.indexPremiereImage;
7
		this.indexPremiereImage           = proprietes.indexPremiereImage;
8
		this.indexImage                   = this.indexPremiereImage;
8
		this.indexImage                   = this.indexPremiereImage;
9
		this.tailleMax                    = proprietes.tailleMax;
9
		this.tailleMax                    = proprietes.tailleMax;
10
		this.popupUrl                     = proprietes.popupUrl;
10
		this.popupUrl                     = proprietes.popupUrl;
11
		this.urlBaseTelechargement        = proprietes.urlBaseTelechargement;
11
		this.urlBaseTelechargement        = proprietes.urlBaseTelechargement;
12
		this.urlServiceRegenererMiniature = proprietes.urlServiceRegenererMiniature;
12
		this.urlServiceRegenererMiniature = proprietes.urlServiceRegenererMiniature;
13
		this.userId       				  = proprietes.userId;
13
		this.userId       				  = proprietes.userId;
14
		this.token						  = proprietes.token;
14
		this.token						  = proprietes.token;
15
		this.protocoles					  = proprietes.protocoles;
15
		this.protocoles					  = proprietes.protocoles;
-
 
16
		this.urlServiceDel				  = proprietes.urlServiceDel;
16
	}
17
	}
17
	this.protocole = null;
18
	this.protocole = null;
18
	this.voteId = null;
19
	this.voteId = null;
19
	this.votes = null;
20
	this.votes = null;
20
	this.mettreAJourInfosImage();
21
	this.mettreAJourInfosImage();
21
}
22
}
22
 
23
 
23
WidgetPhotoPopup.prototype = new WidgetPhotoCommun();
24
WidgetPhotoPopup.prototype = new WidgetPhotoCommun();
24
 
25
 
25
WidgetPhotoPopup.prototype.initTpl = function() {
26
WidgetPhotoPopup.prototype.initTpl = function() {
26
	this.redimensionnerGalerie();
27
	this.redimensionnerGalerie();
27
	$( '#info-img-galerie' ).find( '.active' ).removeClass( 'active' );
28
	$( '#info-img-galerie' ).find( '.active' ).removeClass( 'active' );
28
	$( '#img-cadre-' + this.indexImage + ',#indicateur-img-' + this.indexImage ).addClass( 'active' );
29
	$( '#img-cadre-' + this.indexImage + ',#indicateur-img-' + this.indexImage ).addClass( 'active' );
29
 
30
 
30
	this.mettreAJourPopup();
31
	this.mettreAJourPopup();
31
 
32
 
32
	this.redimentionnerModaleCarousel();
33
	this.redimentionnerModaleCarousel();
33
};
34
};
34
 
35
 
35
WidgetPhotoPopup.prototype.initEvts = function() {
36
WidgetPhotoPopup.prototype.initEvts = function() {
36
	const lthis = this;
37
	const lthis = this;
37
 
38
 
38
	this.initEvtsDefilerImage();
39
	this.initEvtsDefilerImage();
39
	// this.initEvtsContact();
40
	// this.initEvtsContact();
40
	$( window ).on( 'resize', lthis.redimentionnerModaleCarousel.bind( lthis ) );
41
	$( window ).on( 'resize', lthis.redimentionnerModaleCarousel.bind( lthis ) );
41
	this.initEvtsFonctionsPhoto();
42
	this.initEvtsFonctionsPhoto();
42
	this.initEvtsRetourGalerieResponsive();
43
	this.initEvtsRetourGalerieResponsive();
43
	this.initEvtsTagsPF();
-
 
44
};
44
};
45
 
45
 
46
WidgetPhotoPopup.prototype.mettreAJourPopup = function() {
46
WidgetPhotoPopup.prototype.mettreAJourPopup = function() {
47
	this.mettreAJourInfosImage();
47
	this.mettreAJourInfosImage();
48
	this.afficherTitreImage();
48
	this.afficherTitreImage();
49
	this.traiterMetas();
49
	this.traiterMetas();
50
	this.regenererMiniature();
50
	this.regenererMiniature();
51
	this.fournirLienIdentiplante();
51
	this.fournirLienIdentiplante();
52
	this.pivoterImage();
52
	this.pivoterImage();
53
	this.initEvtsProtocole();
53
	this.initEvtsProtocole();
-
 
54
	this.initEvtsTagsPF();
-
 
55
	this.initEvtsTagsCel();
54
};
56
};
55
 
57
 
56
WidgetPhotoPopup.prototype.mettreAJourInfosImage = function() {
58
WidgetPhotoPopup.prototype.mettreAJourInfosImage = function() {
57
	this.item          = this.infosImages[this.urls[this.indexImage]];
59
	this.item          = this.infosImages[this.urls[this.indexImage]];
58
	this.titreImage    = this.item['titre'];
60
	this.titreImage    = this.item['titre'];
59
	this.urlLienEflore = this.item['lien'];
61
	this.urlLienEflore = this.item['lien'];
60
	this.idImage       = this.item['id_photo'];
62
	this.idImage       = this.item['id_photo'];
61
 
63
 
62
	// If last caract of the url is a ',' we remove it
64
	// If last caract of the url is a ',' we remove it
63
	const lastCaractUrlImage = this.item['url_photo'].slice(-1);
65
	const lastCaractUrlImage = this.item['url_photo'].slice(-1);
64
	if (lastCaractUrlImage === ','){
66
	if (lastCaractUrlImage === ','){
65
		this.item['url_photo'] = this.item['url_photo'].replace(/.$/,'');
67
		this.item['url_photo'] = this.item['url_photo'].replace(/.$/,'');
66
	}
68
	}
67
 
69
 
68
	this.urlThisImage  = this.item['url_photo']+'.jpg';
70
	this.urlThisImage  = this.item['url_photo']+'.jpg';
69
	this.obs           = this.item['obs'];
71
	this.obs           = this.item['obs'];
70
	this.nn            = '[nn' + this.obs['nom_sel_nn']+']';
72
	this.nn            = '[nn' + this.obs['nom_sel_nn']+']';
71
	this.urlIP         = this.obs['url_ip'];
73
	this.urlIP         = this.obs['url_ip'];
72
	this.tagsImage     = this.tagsToArray( this.item['tags_photo'] );
74
	this.tagsImage     = this.tagsToArray( this.item['tags_photo'] );
73
	this.tagsObs       = this.tagsToArray( this.obs['tags_obs'] );
75
	this.tagsObs       = this.tagsToArray( this.obs['tags_obs'] );
74
	let auteurMail = this.item['utilisateur']['mail_utilisateur'].split("@")[0];
76
	let auteurMail = this.item['utilisateur']['mail_utilisateur'].split("@")[0];
75
	this.auteur        = this.item["utilisateur"]["nom_utilisateur"] ? this.item["utilisateur"]["nom_utilisateur"] : auteurMail;
77
	this.auteur        = this.item["utilisateur"]["nom_utilisateur"] ? this.item["utilisateur"]["nom_utilisateur"] : auteurMail;
76
	this.date          = this.item['date'];
78
	this.date          = this.item['date'];
77
};
79
};
78
 
80
 
79
WidgetPhotoPopup.prototype.tagsToArray = function( tags ) {
81
WidgetPhotoPopup.prototype.tagsToArray = function( tags ) {
80
	if(!this.valOk(tags)) {
82
	if(!this.valOk(tags)) {
81
		return [];
83
		return [];
82
	}
84
	}
83
	tags = tags.replace( new RegExp('\\.'), '' ).split( ',' );
85
	tags = tags.replace( new RegExp('\\.'), '' ).split( ',' );
84
 
86
 
85
	let cleanTags       = [],
87
	let cleanTags       = [],
86
		nbTags          = tags.length,
88
		nbTags          = tags.length,
87
		tag             = '',
89
		tag             = '',
88
		tagsSansEspaces = '',
90
		tagsSansEspaces = '',
89
		cleanTagIndex   = 0;
91
		cleanTagIndex   = 0;
90
 
92
 
91
	for(let i = 0; i < nbTags; i++) {
93
	for(let i = 0; i < nbTags; i++) {
92
		tag = tags[i];
94
		tag = tags[i];
93
		tagsSansEspaces = tag.replace( ' ', '');
95
		tagsSansEspaces = tag.replace( ' ', '');
94
		if( '' !== tagsSansEspaces ) {
96
		if( '' !== tagsSansEspaces ) {
95
			cleanTags.push( tag.trim() );
97
			cleanTags.push( tag.trim() );
96
		}
98
		}
97
	}
99
	}
98
 
100
 
99
	return cleanTags;
101
	return cleanTags;
100
};
102
};
101
 
103
 
102
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
104
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
103
	const lthis = this;
105
	const lthis = this;
-
 
106
 
-
 
107
	$( '#precedent, #suivant' ).off('click');
104
 
108
 
105
	$( '#precedent, #suivant' ).on( 'click', function() {
109
	$( '#precedent, #suivant' ).on( 'click', function() {
-
 
110
		lthis.defilerImage( this.id );
106
		lthis.defilerImage( this.id );
111
		lthis.initEvtsTagsPF();
107
	});
112
	});
108
 
113
 
109
	$( '#print_content:not(saisir-tag)' ).on( 'keydown', function( event ) {
114
	$( '#print_content:not(saisir-tag)' ).on( 'keydown', function( event ) {
110
 
115
 
111
		const determinerSens = function( enventKey, left, right ) {
116
		const determinerSens = function( enventKey, left, right ) {
112
			switch ( enventKey ) {
117
			switch ( enventKey ) {
113
				case left:
118
				case left:
114
					return 'suivant';
119
					return 'suivant';
115
				case right:
120
				case right:
116
					return 'precedent';
121
					return 'precedent';
117
				default:
122
				default:
118
					break;
123
					break;
119
			}
124
			}
120
 
125
 
121
			return;
126
			return;
122
		}
127
		}
123
 
128
 
124
		event = (event || window.event);
129
		event = (event || window.event);
125
		// event.keyCode déprécié, on tente d'abord event.key
130
		// event.keyCode déprécié, on tente d'abord event.key
126
		let sens = ( 'key' in event ) ? determinerSens( event.key, 'ArrowLeft', 'ArrowRight' ) : determinerSens( event.keyCode, 37, 39 );;
131
		let sens = ( 'key' in event ) ? determinerSens( event.key, 'ArrowLeft', 'ArrowRight' ) : determinerSens( event.keyCode, 37, 39 );;
127
 
132
 
128
		if ( lthis.valOk( sens ) ) {
133
		if ( lthis.valOk( sens ) ) {
129
			lthis.defilerImage( sens );
134
			lthis.defilerImage( sens );
130
		}
135
		}
131
	});
136
	});
132
};
137
};
133
 
138
 
134
// WidgetPhotoPopup.prototype.initEvtsContact = function() {
139
// WidgetPhotoPopup.prototype.initEvtsContact = function() {
135
// 	const lthis = this;
140
// 	const lthis = this;
136
//
141
//
137
// 	$( '#bloc-infos-img' ).on( 'click', '.lien_contact', function( event ) {
142
// 	$( '#bloc-infos-img' ).on( 'click', '.lien_contact', function( event ) {
138
// 		event.preventDefault();
143
// 		event.preventDefault();
139
// 		lthis.chargerContenuModale( this.href );
144
// 		lthis.chargerContenuModale( this.href );
140
// 	});
145
// 	});
141
// };
146
// };
142
 
147
 
143
WidgetPhotoPopup.prototype.initEvtsFonctionsPhoto = function() {
148
WidgetPhotoPopup.prototype.initEvtsFonctionsPhoto = function() {
144
	const lthis = this;
149
	const lthis = this;
145
 
150
 
146
	$( '#boutons-footer #bloc-fct a, #retour-metas' ).on( 'click', function( event ){
151
	$( '#boutons-footer #bloc-fct a, #retour-metas' ).on( 'click', function( event ){
147
		event.preventDefault();
152
		event.preventDefault();
148
		var voletAOuvrir = $( this ).data( 'volet' ),
153
		var voletAOuvrir = $( this ).data( 'volet' ),
149
			voletAFermer = $( '.bloc-volet:not(.hidden)' ).data( 'volet' );
154
			voletAFermer = $( '.bloc-volet:not(.hidden)' ).data( 'volet' );
150
 
155
 
151
		lthis.ouvrirVoletFct( voletAOuvrir, voletAFermer );
156
		lthis.ouvrirVoletFct( voletAOuvrir, voletAFermer );
152
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
157
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
153
			$( '#info-img-galerie' ).addClass( 'hidden' );
158
			$( '#info-img-galerie' ).addClass( 'hidden' );
154
			$( '#volet, #retour-galerie' ).removeClass( 'hidden' );
159
			$( '#volet, #retour-galerie' ).removeClass( 'hidden' );
155
		}
160
		}
156
	});
161
	});
157
};
162
};
158
 
163
 
159
WidgetPhotoPopup.prototype.initEvtsRetourGalerieResponsive = function() {
164
WidgetPhotoPopup.prototype.initEvtsRetourGalerieResponsive = function() {
160
	$( '#retour-galerie' ).on( 'click', function( event ) {
165
	$( '#retour-galerie' ).on( 'click', function( event ) {
161
		event.preventDefault();
166
		event.preventDefault();
162
		$( '#info-img-galerie' ).removeClass( 'hidden' );
167
		$( '#info-img-galerie' ).removeClass( 'hidden' );
163
		$( this ).addClass( 'hidden' );
168
		$( this ).addClass( 'hidden' );
164
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
169
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
165
			$( '#volet' ).addClass( 'hidden' );
170
			$( '#volet' ).addClass( 'hidden' );
166
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
171
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
167
		}
172
		}
168
	});
173
	});
169
};
174
};
-
 
175
 
-
 
176
WidgetPhotoPopup.prototype.initEvtsTagsCel = function(){
-
 
177
	const lthis = this;
-
 
178
	$( '#tags-cel' ).html('');
-
 
179
 
-
 
180
	$( '#tags-cel' ).append(
-
 
181
		"<p>"+ lthis.item['tags_photo']+"</p>"
-
 
182
	)
-
 
183
}
170
 
184
 
171
WidgetPhotoPopup.prototype.initEvtsTagsPF = function() {
185
WidgetPhotoPopup.prototype.initEvtsTagsPF = function() {
172
	//recupérer tags en ajax (voir pictoflora, peut-être dans le php?)
186
	const tagsPfDiv = $('#tags-pf');
173
	//	_OPTIONS
187
	tagsPfDiv.html('');
-
 
188
	tagsPfDiv.append('<a id="port" class="btn tag">Port</a>' +
174
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
189
		'<a id="fleur" class="btn tag">Fleur</a>' +
175
	//	_GET
190
		'<a id="fruit" class="btn tag">Fruit</a>' +
-
 
191
		'<a id="feuille" class="btn tag">Feuille</a>' +
-
 
192
		'<a id="ecorce" class="btn tag">Ecorce</a>' +
-
 
193
		'<a id="rameau" class="btn tag">Rameau</a>' +
-
 
194
		'<a id="planche" class="btn tag">Planche</a>' +
-
 
195
		'<a id="rosette" class="btn tag">Rosette</a>' +
-
 
196
		'<a id="pousse" class="btn tag">Pousse</a>');
-
 
197
 
176
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
198
	this.tagsPf();
-
 
199
	this.tagsPfCustom();
-
 
200
 
-
 
201
	$( '#bloc-tags' ).off('click');
177
	this.tagsPfCustom();
202
 
178
	$( '#bloc-tags' ).on( 'click', '.tag', function( event ) {
203
	$( '#bloc-tags' ).on( 'click', '.tag', function( event ) {
179
		event.preventDefault();
204
		event.preventDefault();
180
		$( this ).toggleClass( 'actif' );
205
		$( this ).toggleClass( 'actif' );
-
 
206
 
-
 
207
		var motCleClique = '';
-
 
208
		motCleClique = $(this).attr('id');
-
 
209
 
-
 
210
		// Utiliser la méthode findIndex pour obtenir l'index de l'élément dans le tableau
-
 
211
		var indexElementTrouve = lthis.item['tags_pf'].findIndex(function (tag) {
-
 
212
			return tag['mot_cle'] === motCleClique;
-
 
213
		});
-
 
214
 
-
 
215
		// Vérifier si l'élément a été trouvé
-
 
216
		if (indexElementTrouve !== -1) {
-
 
217
			//supprimer tag dans DEL
-
 
218
			if (lthis.item['tags_pf'][indexElementTrouve].hasOwnProperty('id_mot_cle') && lthis.item['tags_pf'][indexElementTrouve]['id_mot_cle'] != ''){
-
 
219
				let url = lthis.urlServiceDel + 'mots-cles/' + lthis.item['tags_pf'][indexElementTrouve]['id_mot_cle']
-
 
220
 
-
 
221
				lthis.envoyerVersService('DELETE', url)
-
 
222
			}
-
 
223
 
-
 
224
			// Supprimer l'élément de this.item['tags_pf'] à l'index trouvé
-
 
225
			lthis.item['tags_pf'].splice(indexElementTrouve, 1);
-
 
226
		} else {
-
 
227
			//Ajout tag dans le DEL
-
 
228
			let url = lthis.urlServiceDel + 'mots-cles';
-
 
229
			let donnees = {
-
 
230
				"image" : lthis.idImage,
-
 
231
				"mot_cle" : motCleClique,
-
 
232
				"auteur.id" : lthis.item["utilisateur"]["id_utilisateur"]
-
 
233
			}
-
 
234
 
-
 
235
			lthis.envoyerVersService('PUT', url, JSON.stringify(donnees), function (erreur, tagId) {
-
 
236
				if (erreur) {
-
 
237
					console.error("Erreur lors de la requête :", erreur);
-
 
238
				} else {
-
 
239
					console.log('tag : ' + motCleClique + ' ajouté');
-
 
240
					lthis.item['tags_pf'].push({'id_mot_cle' : tagId['id'][0], 'mot_cle' : motCleClique})
-
 
241
				}
-
 
242
			});
-
 
243
		}
-
 
244
		//TODO post vers le del
181
	});
245
	});
-
 
246
	/* //@TODO est-ce qu'on garde cette croix?
182
	$( '#bloc-tags' ).on( 'click', '.custom-tag.actif .fermer', function( event ) {
247
	$( '#bloc-tags' ).on( 'click', '.custom-tag.actif .fermer', function( event ) {
183
		event.preventDefault();
248
		event.preventDefault();
184
		//			Supprimer un custom-tag
249
		//			Supprimer un custom-tag
185
		//	_OPTIONS
250
		//	_OPTIONS
186
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
251
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
187
		// 	_paramètres
252
		// 	_paramètres
188
		// L'id du tag à la fin de l'url
253
		// L'id du tag à la fin de l'url
189
		//	_DELETE
254
		//	_DELETE
190
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
255
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
191
		// 	_réponse:
256
		// 	_réponse:
192
		// ""
257
		// ""
193
		// 			Mettre à jour les mots cles
258
		// 			Mettre à jour les mots cles
194
		//	_OPTIONS
259
		//	_OPTIONS
195
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
260
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
196
		//	_GET
261
		//	_GET
197
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
262
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
198
		$( this ).parent( '.custom-tag' ).remove();
263
		$( this ).parent( '.custom-tag' ).remove();
199
	});
264
	});
-
 
265
	*/
200
 
266
/*
201
	$( '#bloc-tags' ).on( 'keyup', '.custom-tag.actif', function( event ) {
267
	$( '#bloc-tags' ).on( 'keyup', '.custom-tag.actif', function( event ) {
202
		let supprimerTag = false;
268
		let supprimerTag = false;
203
 
269
 
204
		event = ( event || window.event );
270
		event = ( event || window.event );
205
		// event.keyCode déprécié, on tente d'abord event.key
271
		// event.keyCode déprécié, on tente d'abord event.key
206
		if ( 'key' in event ) {
272
		if ( 'key' in event ) {
207
			supprimerTag = ( 'Delete' === event.key || 'Backspace' === event.key );
273
			supprimerTag = ( 'Delete' === event.key || 'Backspace' === event.key );
208
		} else {
274
		} else {
209
			supprimerTag = ( 46 === event.keyCode || 8 === event.keyCode );
275
			supprimerTag = ( 46 === event.keyCode || 8 === event.keyCode );
210
		}
276
		}
211
		if ( supprimerTag ) {
277
		if ( supprimerTag ) {
212
			//			Supprimer un custom-tag
278
			//			Supprimer un custom-tag
213
			//	_OPTIONS
279
			//	_OPTIONS
214
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
280
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
215
			// 	_paramètres
281
			// 	_paramètres
216
			// L'id du tag à la fin de l'url
282
			// L'id du tag à la fin de l'url
217
			//	_DELETE
283
			//	_DELETE
218
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
284
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
219
			// 	_réponse:
285
			// 	_réponse:
220
			// ""
286
			// ""
221
			// 			Mettre à jour les mots cles
287
			// 			Mettre à jour les mots cles
222
			//	_OPTIONS
288
			//	_OPTIONS
223
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
289
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
224
			//	_GET
290
			//	_GET
225
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
291
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
226
			$( this ).parent( '.custom-tag' ).remove();
292
			$( this ).parent( '.custom-tag' ).remove();
227
		}
293
		}
228
	});
294
	});
-
 
295
 */
229
};
296
};
230
 
297
 
231
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
298
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
232
	if ( 'suivant' === sens ) {
299
	if ( 'suivant' === sens ) {
233
		this.indexImage++ ;
300
		this.indexImage++ ;
234
		if( this.indexImage >= this.urls.length ) {
301
		if( this.indexImage >= this.urls.length ) {
235
			this.indexImage = 0;
302
			this.indexImage = 0;
236
		}
303
		}
237
	} else if ( 'precedent' === sens ) {
304
	} else if ( 'precedent' === sens ) {
238
		this.indexImage--;
305
		this.indexImage--;
239
		if( this.indexImage <= 0 ) {
306
		if( this.indexImage <= 0 ) {
240
			this.indexImage = this.urls.length -1;
307
			this.indexImage = this.urls.length -1;
241
		}
308
		}
242
	}
309
	}
243
	// @TODO: Modifier l'attr content de 'meta[property=og:image]' et y mettre l'url de l'image
310
	// @TODO: Modifier l'attr content de 'meta[property=og:image]' et y mettre l'url de l'image
244
	this.mettreAJourPopup();
311
	this.mettreAJourPopup();
245
};
312
};
246
 
313
 
247
WidgetPhotoPopup.prototype.afficherTitreImage = function() {
314
WidgetPhotoPopup.prototype.afficherTitreImage = function() {
248
	let lienContact  =
315
	let lienContact  =
249
			this.urlWidget +'?mode=contact&nn=' + this.nn +
316
			this.urlWidget +'?mode=contact&nn=' + this.nn +
250
			'&nom_sci=' + this.obs['nom_sel'] +
317
			'&nom_sci=' + this.obs['nom_sel'] +
251
			'&date=' + this.date +
318
			'&date=' + this.date +
252
			'&localisation=' + this.obs['localisation'] +
319
			'&localisation=' + this.obs['localisation'] +
253
			'&id_image=' + this.idImage +
320
			'&id_image=' + this.idImage +
254
			'&auteur=' + this.auteur;
321
			'&auteur=' + this.auteur;
255
 
322
 
256
	if ( this.valOk( this.popupUrl ) ) {
323
	if ( this.valOk( this.popupUrl ) ) {
257
		if (! this.popupUrl.match( new RegExp( 'img:' + this.idImage ) ) ) {
324
		if (! this.popupUrl.match( new RegExp( 'img:' + this.idImage ) ) ) {
258
			this.popupUrl = this.actualiserPopupUrl( this.popupUrl, this.urlThisImage );
325
			this.popupUrl = this.actualiserPopupUrl( this.popupUrl, this.urlThisImage );
259
		}
326
		}
260
		lienContact += '&popup_url=' + encodeURIComponent( this.popupUrl );
327
		lienContact += '&popup_url=' + encodeURIComponent( this.popupUrl );
261
	}
328
	}
262
 
329
 
263
	$( '#bloc-infos-img' ).html(
330
	$( '#bloc-infos-img' ).html(
264
		this.afficherLien( this.urlLienEflore, this.obs['nom_sel'] )+
331
		this.afficherLien( this.urlLienEflore, this.obs['nom_sel'] )+
265
		' par '+
332
		' par '+
266
		'<a class="lien_contact" href="' + this.item['urlProfil'] + '" target="_blank" title="Afficher le profil">' + this.auteur + '</a> '+
333
		'<a class="lien_contact" href="' + this.item['urlProfil'] + '" target="_blank" title="Afficher le profil">' + this.auteur + '</a> '+
267
		' le ' + this.date + ' - ' + this.obs['localisation']
334
		' le ' + this.date + ' - ' + this.obs['localisation']
268
	);
335
	);
269
};
336
};
270
 
337
 
271
WidgetPhotoPopup.prototype.actualiserPopupUrl = function( queryString, remplacement ) {
338
WidgetPhotoPopup.prototype.actualiserPopupUrl = function( queryString, remplacement ) {
272
	let queryStringParsee = queryString.substring(1).split('&');
339
	let queryStringParsee = queryString.substring(1).split('&');
273
 
340
 
274
	$.each( queryStringParsee,  function( i, param ) {
341
	$.each( queryStringParsee,  function( i, param ) {
275
		if( /url_image/.test( param ) ) {
342
		if( /url_image/.test( param ) ) {
276
			queryString = queryString.replace( param, 'url_image=' + remplacement );
343
			queryString = queryString.replace( param, 'url_image=' + remplacement );
277
			return false;
344
			return false;
278
		}
345
		}
279
	});
346
	});
280
	return queryString;
347
	return queryString;
281
};
348
};
282
 
349
 
283
WidgetPhotoPopup.prototype.redimentionnerModaleCarousel = function() {
350
WidgetPhotoPopup.prototype.redimentionnerModaleCarousel = function() {
284
	this.redimensionnerGalerie();
351
	this.redimensionnerGalerie();
285
	if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
352
	if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
286
		$( '#volet, #retour-galerie' ).addClass( 'hidden' );
353
		$( '#volet, #retour-galerie' ).addClass( 'hidden' );
287
		$( '#info-img-galerie' ).removeClass( 'hidden' );
354
		$( '#info-img-galerie' ).removeClass( 'hidden' );
288
		$( '.bouton-fct.actif' ).removeClass( 'actif' );
355
		$( '.bouton-fct.actif' ).removeClass( 'actif' );
289
		$( '.nettoyage-volet.haut' ).text( $( '#bloc-infos-img' ).text() );
356
		$( '.nettoyage-volet.haut' ).text( $( '#bloc-infos-img' ).text() );
290
		$( '#boutons-footer, #info-img-galerie' ).removeClass( 'col-lg-8' );
357
		$( '#boutons-footer, #info-img-galerie' ).removeClass( 'col-lg-8' );
291
		$( '#bloc-infos-img, #volet' ).removeClass( 'col-lg-4' );
358
		$( '#bloc-infos-img, #volet' ).removeClass( 'col-lg-4' );
292
	} else {
359
	} else {
293
		$( '#volet, #info-img-galerie' ).removeClass( 'hidden' );
360
		$( '#volet, #info-img-galerie' ).removeClass( 'hidden' );
294
		if ( this.valOk( $( '.bloc-volet:not(.hidden)' ) ) ) {
361
		if ( this.valOk( $( '.bloc-volet:not(.hidden)' ) ) ) {
295
			$( '.bouton-fct.' + $( '.bloc-volet:not(.hidden)' ).data( 'volet' ) ).addClass( 'actif' );
362
			$( '.bouton-fct.' + $( '.bloc-volet:not(.hidden)' ).data( 'volet' ) ).addClass( 'actif' );
296
		}
363
		}
297
		$( '.nettoyage-volet.bas' ).text( $( '#bloc-infos-img' ).text() );
364
		$( '.nettoyage-volet.bas' ).text( $( '#bloc-infos-img' ).text() );
298
		$( '#boutons-footer, #info-img-galerie' ).addClass( 'col-lg-8' );
365
		$( '#boutons-footer, #info-img-galerie' ).addClass( 'col-lg-8' );
299
		$( '#bloc-infos-img, #volet' ).addClass( 'col-lg-4' );
366
		$( '#bloc-infos-img, #volet' ).addClass( 'col-lg-4' );
300
		$( '#retour-galerie' ).addClass( 'hidden' );
367
		$( '#retour-galerie' ).addClass( 'hidden' );
301
	}
368
	}
302
};
369
};
303
 
370
 
304
WidgetPhotoPopup.prototype.redimensionnerGalerie = function() {
371
WidgetPhotoPopup.prototype.redimensionnerGalerie = function() {
305
	var maxSize = ( $( window ).width() / $( window ).height() ) < 1 ? $( window ).width() : $( window ).height();
372
	var maxSize = ( $( window ).width() / $( window ).height() ) < 1 ? $( window ).width() : $( window ).height();
306
 
373
 
307
	maxSize -= 30;
374
	maxSize -= 30;
308
	$( '.carousel-item img' ).each( function( index, image ) {
375
	$( '.carousel-item img' ).each( function( index, image ) {
309
		var proportion  = image.dataset.width / image.dataset.height,
376
		var proportion  = image.dataset.width / image.dataset.height,
310
			cssResize   = {};
377
			cssResize   = {};
311
 
378
 
312
		if ( proportion >= 1 ) {
379
		if ( proportion >= 1 ) {
313
			cssResize['width'] = maxSize;
380
			cssResize['width'] = maxSize;
314
		}
381
		}
315
		if ( proportion <= 1) {
382
		if ( proportion <= 1) {
316
			cssResize['height'] = maxSize;
383
			cssResize['height'] = maxSize;
317
		}
384
		}
318
		$( image ).css( cssResize );
385
		$( image ).css( cssResize );
319
	});
386
	});
320
};
387
};
321
 
388
 
322
WidgetPhotoPopup.prototype.ouvrirVoletFct = function( voletAOuvrir, voletAFermer ) {
389
WidgetPhotoPopup.prototype.ouvrirVoletFct = function( voletAOuvrir, voletAFermer ) {
323
	if( voletAOuvrir !== voletAFermer ) {
390
	if( voletAOuvrir !== voletAFermer ) {
324
		$( '#boutons-footer  .' + voletAFermer ).removeClass( 'actif' );
391
		$( '#boutons-footer  .' + voletAFermer ).removeClass( 'actif' );
325
		$( '#boutons-footer  .' + voletAOuvrir ).addClass( 'actif' );
392
		$( '#boutons-footer  .' + voletAOuvrir ).addClass( 'actif' );
326
		$( '#bloc-' + voletAFermer ).addClass( 'hidden' );
393
		$( '#bloc-' + voletAFermer ).addClass( 'hidden' );
327
		$( '#bloc-' + voletAOuvrir ).removeClass( 'hidden' );
394
		$( '#bloc-' + voletAOuvrir ).removeClass( 'hidden' );
328
		$( '#volet' ).scrollTop(0);
395
		$( '#volet' ).scrollTop(0);
329
		$( '#retour-metas' ).removeClass( 'hidden', 'meta' === voletAOuvrir );
396
		$( '#retour-metas' ).removeClass( 'hidden', 'meta' === voletAOuvrir );
330
	}
397
	}
331
};
398
};
-
 
399
 
-
 
400
WidgetPhotoPopup.prototype.tagsPf = function () {
-
 
401
	const lthis = this;
-
 
402
	$('#tags-pf-supp').html('');
-
 
403
 
-
 
404
	lthis.item['tags_pf'].forEach(tag => {
-
 
405
		const tagElement = document.getElementById(tag['mot_cle']);
-
 
406
 
-
 
407
		// Vérifier si l'élément existe
-
 
408
		if (tagElement) {
-
 
409
			// Ajouter la classe 'active' à l'élément <a>
-
 
410
			tagElement.classList.add('actif');
-
 
411
		} else {
-
 
412
			$('#tags-pf-supp').append('<a id="'+tag['mot_cle']+'" class="btn tag custom-tag actif">' + tag['mot_cle'] + '&nbsp;' +
-
 
413
				// '<i class="fas fa-times-circle fermer"></i>' +
-
 
414
				'</a>')
-
 
415
		}
-
 
416
	});
-
 
417
}
332
 
418
 
333
WidgetPhotoPopup.prototype.tagsPfCustom = function() {
419
WidgetPhotoPopup.prototype.tagsPfCustom = function() {
334
	const lthis = this;
420
	const lthis = this;
335
 
421
 
336
	$( '#saisir-tag' ).on( 'blur keyup', function( event ) {
422
	$( '#saisir-tag' ).on( 'blur keyup', function( event ) {
337
		event = ( event || window.event );
423
		event = ( event || window.event );
338
 
424
 
339
		var ajouterTag = ( 'blur' === event.type );
425
		var ajouterTag = ( 'blur' === event.type );
340
 
426
 
341
		// event.keyCode déprécié, on tente d'abord event.key
427
		// event.keyCode déprécié, on tente d'abord event.key
342
		if ( 'key' in event  ) {
428
		if ( 'key' in event  ) {
343
			if ( 'Enter' === event.key ) {
429
			if ( 'Enter' === event.key ) {
344
				ajouterTag = true;
430
				ajouterTag = true;
345
			}
431
			}
346
		} else if ( 13 === event.keyCode ) {
432
		} else if ( 13 === event.keyCode ) {
347
			ajouterTag = true;
433
			ajouterTag = true;
348
		}
434
		}
349
		if	( ajouterTag ) {
435
		if	( ajouterTag ) {
350
			var nouveauTag     = $( this ).val(),
436
			var nouveauTag     = $( this ).val(),
351
				nouveauTagAttr = lthis.chaineValableAttributsHtml( nouveauTag.toLowerCase() );
437
				nouveauTagAttr = lthis.chaineValableAttributsHtml( nouveauTag.toLowerCase() );
352
 
438
 
353
			if( lthis.valOk( nouveauTagAttr ) && !lthis.valOk( $( '#' + nouveauTagAttr + '.tag' ) ) ) {
439
			if( lthis.valOk( nouveauTagAttr ) && !lthis.valOk( $( '#' + nouveauTagAttr + '.tag' ) ) ) {
354
				// 			Envoyer tags en ajax :
-
 
355
				// 	_OPTIONS
-
 
356
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
-
 
357
				//  _paramètres :
-
 
358
				//rien
-
 
359
				// 	_PUT
-
 
360
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
-
 
361
				// 	_paramètres :
-
 
362
				// image=197938&mot_cle=motcleperso&auteur.id=44084
-
 
363
				// 			Mettre à jour les mots cles
-
 
364
				//	_OPTIONS
-
 
365
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
-
 
366
				//	_GET
-
 
367
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
-
 
368
				$( '#tags-pf-supp' ).append(
440
				$( '#tags-pf-supp' ).append(
369
					'<a id="' + nouveauTagAttr + '" class="btn tag custom-tag actif">' +
441
					'<a id="' + nouveauTagAttr + '" class="btn tag custom-tag actif">' +
-
 
442
						nouveauTag + '&nbsp;' +
370
						nouveauTag + '&nbsp;<i class="fas fa-times-circle fermer"></i>' +
443
					// '<i class="fas fa-times-circle fermer"></i>' +
371
					'</a>'
444
					'</a>'
372
				);
445
				);
-
 
446
 
-
 
447
				let url = lthis.urlServiceDel + 'mots-cles';
-
 
448
				let donnees = {
-
 
449
					"image" : lthis.idImage,
-
 
450
					"mot_cle" : nouveauTagAttr,
-
 
451
					"auteur.id" : lthis.item["utilisateur"]["id_utilisateur"]
-
 
452
				}
-
 
453
 
-
 
454
				// Envoie du nouveau tag dans le DEL
-
 
455
				lthis.envoyerVersService('PUT', url, JSON.stringify(donnees), function (erreur, tagId) {
-
 
456
					if (erreur) {
-
 
457
						console.error("Erreur lors de la requête :", erreur);
-
 
458
					} else {
-
 
459
						console.log('tag : ' + nouveauTagAttr + ' ajouté');
-
 
460
						lthis.item['tags_pf'].push({'id_mot_cle' : tagId['id'][0], 'mot_cle' : nouveauTagAttr})
-
 
461
					}
-
 
462
				});
-
 
463
 
373
				$( '#form-tags-auteur' )[0].reset();
464
				// $( '#form-tags-auteur' )[0].reset();
374
				$( this ).val( '' );
465
				$( this ).val( '' );
375
			}
466
			}
376
		}
467
		}
377
	});
468
	});
378
};
469
};
379
 
470
 
380
WidgetPhotoPopup.prototype.traiterMetas = function() {
471
WidgetPhotoPopup.prototype.traiterMetas = function() {
381
	this.afficherMetas();
472
	this.afficherMetas();
382
	this.afficherPopupLocalisation();
473
	this.afficherPopupLocalisation();
383
	this.afficherMetasPlus();
474
	this.afficherMetasPlus();
384
	this.fournirLienTelechargement();
475
	this.fournirLienTelechargement();
385
};
476
};
386
 
477
 
387
WidgetPhotoPopup.prototype.afficherMetas = function() {
478
WidgetPhotoPopup.prototype.afficherMetas = function() {
388
	const lthis         = this;
479
	const lthis         = this;
389
	const META_CONTENUS = {
480
	const META_CONTENUS = {
390
		'nom' : this.afficherLien( this.urlLienEflore, this.obs['nom_sel'] ),
481
		'nom' : this.afficherLien( this.urlLienEflore, this.obs['nom_sel'] ),
391
		'localisation' : this.obs['localisation'],
482
		'localisation' : this.obs['localisation'],
392
		'auteur' : this.auteur,
483
		'auteur' : this.auteur,
393
		'date-obs' : this.date,
484
		'date-obs' : this.date,
394
		'commentaire' : this.obs['commentaire'],
485
		'commentaire' : this.obs['commentaire'],
395
		'certitude' : this.obs['certitude'],
486
		'certitude' : this.obs['certitude'],
396
		'fiabilite' : this.obs['fiabilite'],
487
		'fiabilite' : this.obs['fiabilite'],
397
		'num-photo' : this.idImage,
488
		'num-photo' : this.idImage,
398
		'titre-original' : this.item['nom_original'],
489
		'titre-original' : this.item['nom_original'],
399
		'date-photo' : this.formaterDate( this.item['date_photo'] ),
490
		'date-photo' : this.formaterDate( this.item['date_photo'] ),
400
		'attribution-copy' : this.item['attribution'],
491
		'attribution-copy' : this.item['attribution'],
401
		'url-copy' : this.urlThisImage
492
		'url-copy' : this.urlThisImage
402
	};
493
	};
403
 
494
 
404
	$.each( META_CONTENUS, function( attrId, contenu ) {
495
	$.each( META_CONTENUS, function( attrId, contenu ) {
405
		let $metaContainer = $( '#bloc-meta #'+attrId );
496
		let $metaContainer = $( '#bloc-meta #'+attrId );
406
 
497
 
407
		if ( lthis.valOk( contenu ) ) {
498
		if ( lthis.valOk( contenu ) ) {
408
			switch( attrId ) {
499
			switch( attrId ) {
409
				case 'attribution-copy' :
500
				case 'attribution-copy' :
410
				case 'url-copy' :
501
				case 'url-copy' :
411
					$metaContainer.val( contenu );
502
					$metaContainer.val( contenu );
412
					lthis.copieAutoChamp( $metaContainer );
503
					lthis.copieAutoChamp( $metaContainer );
413
					break;
504
					break;
414
				case 'nom' :
505
				case 'nom' :
415
					$( '.contenu', $metaContainer ).html( contenu );
506
					$( '.contenu', $metaContainer ).html( contenu );
416
					$( '.bouton', $metaContainer ).attr( 'href', lthis.urlLienEflore );
507
					$( '.bouton', $metaContainer ).attr( 'href', lthis.urlLienEflore );
417
					break;
508
					break;
418
				case 'auteur' :
509
				case 'auteur' :
419
					$( '.bouton', $metaContainer ).attr( 'href', lthis.item['urlProfil'] );
510
					$( '.bouton', $metaContainer ).attr( 'href', lthis.item['urlProfil'] );
420
				default:
511
				default:
421
					$( '.contenu', $metaContainer ).text( contenu );
512
					$( '.contenu', $metaContainer ).text( contenu );
422
					break;
513
					break;
423
			}
514
			}
424
		}
515
		}
425
	});
516
	});
426
};
517
};
427
 
518
 
428
WidgetPhotoPopup.prototype.copieAutoChamp = function( $champACopier ) {
519
WidgetPhotoPopup.prototype.copieAutoChamp = function( $champACopier ) {
429
	$champACopier.off( 'click' ).on( 'click', function() {
520
	$champACopier.off( 'click' ).on( 'click', function() {
430
		$( '#attribution-copy, #url-copy' ).removeClass( 'hidden' )
521
		$( '#attribution-copy, #url-copy' ).removeClass( 'hidden' )
431
			.find( '.copy-message' ).remove();
522
			.find( '.copy-message' ).remove();
432
 
523
 
433
		$( this ).select();
524
		$( this ).select();
434
		document.execCommand( 'copy' );
525
		document.execCommand( 'copy' );
435
 
526
 
436
		$( this ).after(
527
		$( this ).after(
437
			'<p class="copy-message alert-success" style="width: 100%; height:' + $( this ).outerHeight() + 'px; margin: 0; display:flex;">'+
528
			'<p class="copy-message alert-success" style="width: 100%; height:' + $( this ).outerHeight() + 'px; margin: 0; display:flex;">'+
438
				'<span style="margin:auto; font-size:1rem;">Copié dans le presse papier</span>'+
529
				'<span style="margin:auto; font-size:1rem;">Copié dans le presse papier</span>'+
439
			'</p>'
530
			'</p>'
440
		).addClass( 'hidden' );
531
		).addClass( 'hidden' );
441
 
532
 
442
		setTimeout( function() {
533
		setTimeout( function() {
443
			$( '.copy-message' ).remove();
534
			$( '.copy-message' ).remove();
444
			$champACopier.removeClass( 'hidden' );
535
			$champACopier.removeClass( 'hidden' );
445
		}, 1000 );
536
		}, 1000 );
446
	});
537
	});
447
};
538
};
448
 
539
 
449
WidgetPhotoPopup.prototype.afficherMetasPlus = function() {
540
WidgetPhotoPopup.prototype.afficherMetasPlus = function() {
450
	const lthis         = this;
541
	const lthis         = this;
451
	const META_LABELS  = {
542
	const META_LABELS  = {
452
		'id_obs' : 'observation n°',
543
		'id_obs' : 'observation n°',
453
		'projet' : 'projet',
544
		'projet' : 'projet',
454
		'nom_referentiel' : 'réferentiel',
545
		'nom_referentiel' : 'réferentiel',
455
		'date_obs' : 'date d´observation',
546
		'date_obs' : 'date d´observation',
456
		'nom_sel': 'nom scientifique',
547
		'nom_sel': 'nom scientifique',
457
		'nom_sel_nn' : 'nom scientifique n°',
548
		'nom_sel_nn' : 'nom scientifique n°',
458
		'nom_ret' : 'nom retenu',
549
		'nom_ret' : 'nom retenu',
459
		'nom_ret_nn' : 'nom retenu n°',
550
		'nom_ret_nn' : 'nom retenu n°',
460
		'famille' : 'famille',
551
		'famille' : 'famille',
461
		'tags_obs' : 'tags de l´observation',
552
		'tags_obs' : 'tags de l´observation',
462
		'lieudit' : 'lieu dit',
553
		'lieudit' : 'lieu dit',
463
		'station' : 'station',
554
		'station' : 'station',
464
		'milieu' : 'milieu',
555
		'milieu' : 'milieu',
465
		'latitude' : 'latitude',
556
		'latitude' : 'latitude',
466
		'longitude' : 'longitude',
557
		'longitude' : 'longitude',
467
		'altitude' : 'altitude',
558
		'altitude' : 'altitude',
468
		'localisation_precision': 'précision de la localisation',
559
		'localisation_precision': 'précision de la localisation',
469
		'code_insee' : 'code insee de la commune',
560
		'code_insee' : 'code insee de la commune',
470
		'dept' : 'département',
561
		'dept' : 'département',
471
		'pays' : 'pays',
562
		'pays' : 'pays',
472
		'est_ip_valide' : 'validée sur identiplante',
563
		'est_ip_valide' : 'validée sur identiplante',
473
		'score_ip' : 'score identiplante',
564
		'score_ip' : 'score identiplante',
474
		'url_ip' : 'url identiplante',
565
		'url_ip' : 'url identiplante',
475
		'abondance' : 'abondance',
566
		'abondance' : 'abondance',
476
		'phenologie' : 'phénologie',
567
		'phenologie' : 'phénologie',
477
		'spontaneite' : 'spontaneite',
568
		'spontaneite' : 'spontaneite',
478
		'type_donnees' : 'type de donnees',
569
		'type_donnees' : 'type de donnees',
479
		'biblio' : 'bibliographie',
570
		'biblio' : 'bibliographie',
480
		'source' : 'source',
571
		'source' : 'source',
481
		'herbier' : 'herbier',
572
		'herbier' : 'herbier',
482
		'observateur' : 'observateur',
573
		'observateur' : 'observateur',
483
		'observateur_structure' : 'structure'
574
		'observateur_structure' : 'structure'
484
	};
575
	};
485
 
576
 
486
	const $contenuPlusMeta  = $( '#contenu-meta-plus' );
577
	const $contenuPlusMeta  = $( '#contenu-meta-plus' );
487
	let degres = $contenuPlusMeta.is( ':visible' ) ? '180' : '0';
578
	let degres = $contenuPlusMeta.is( ':visible' ) ? '180' : '0';
488
 
579
 
489
	this.rotationFleche( degres );
580
	this.rotationFleche( degres );
490
	$contenuPlusMeta.empty();
581
	$contenuPlusMeta.empty();
491
 
582
 
492
	$.each( META_LABELS, function( cle, label ) {
583
	$.each( META_LABELS, function( cle, label ) {
493
		let idAttr = cle.replace( '_', '-' ),
584
		let idAttr = cle.replace( '_', '-' ),
494
			contenu = lthis.obs[cle];
585
			contenu = lthis.obs[cle];
495
 
586
 
496
		switch( cle ) {
587
		switch( cle ) {
497
			case 'nom_sel':
588
			case 'nom_sel':
498
				contenu = lthis.afficherLien( lthis.urlLienEflore, contenu );
589
				contenu = lthis.afficherLien( lthis.urlLienEflore, contenu );
499
				break;
590
				break;
500
 
591
 
501
			case 'nom_ret':
592
			case 'nom_ret':
502
				let urlEfloreNomRetenu = lthis.urlLienEflore.replace( lthis.obs['nom_sel_nn'], lthis.obs['nom_ret_nn'] );
593
				let urlEfloreNomRetenu = lthis.urlLienEflore.replace( lthis.obs['nom_sel_nn'], lthis.obs['nom_ret_nn'] );
503
 
594
 
504
				contenu = lthis.afficherLien( urlEfloreNomRetenu, contenu );
595
				contenu = lthis.afficherLien( urlEfloreNomRetenu, contenu );
505
				break;
596
				break;
506
 
597
 
507
			case 'url_ip':
598
			case 'url_ip':
508
				contenu = lthis.afficherLien( contenu, contenu );
599
				contenu = lthis.afficherLien( contenu, contenu );
509
				break;
600
				break;
510
 
601
 
511
			case 'est_ip_valide':
602
			case 'est_ip_valide':
512
			case 'herbier':
603
			case 'herbier':
513
				if( '0' === contenu ) {
604
				if( '0' === contenu ) {
514
					contenu = 'non';
605
					contenu = 'non';
515
				}
606
				}
516
				break;
607
				break;
517
 
608
 
518
			case 'date_obs':
609
			case 'date_obs':
519
				contenu = lthis.formaterDate( contenu );
610
				contenu = lthis.formaterDate( contenu );
520
				break;
611
				break;
521
 
612
 
522
			case 'tags_obs':
613
			case 'tags_obs':
523
				let tagsObsLength = lthis.tagsObs.length;
614
				let tagsObsLength = lthis.tagsObs.length;
524
				contenu = lthis.tagsObs.join( '<br>' );
615
				contenu = lthis.tagsObs.join( '<br>' );
525
				break;
616
				break;
526
 
617
 
527
			default:
618
			default:
528
				break;
619
				break;
529
		}
620
		}
530
 
621
 
531
		if ( lthis.valOk( contenu ) ) {
622
		if ( lthis.valOk( contenu ) ) {
532
			$contenuPlusMeta.append(
623
			$contenuPlusMeta.append(
533
				'<li id="' + idAttr + '-meta-plus" class="row">'+
624
				'<li id="' + idAttr + '-meta-plus" class="row">'+
534
					'<div class="col-5 label">' + label.charAt( 0 ).toUpperCase() + label.slice( 1 ) + '</div>'+
625
					'<div class="col-5 label">' + label.charAt( 0 ).toUpperCase() + label.slice( 1 ) + '</div>'+
535
					'<div class="col-7 contenu">' + contenu + '</div>'+
626
					'<div class="col-7 contenu">' + contenu + '</div>'+
536
				'</li>'
627
				'</li>'
537
			);
628
			);
538
		}
629
		}
539
	});
630
	});
540
 
631
 
541
	if( !$contenuPlusMeta.hasClass( 'actif' ) ) {
632
	if( !$contenuPlusMeta.hasClass( 'actif' ) ) {
542
		$contenuPlusMeta.hide();
633
		$contenuPlusMeta.hide();
543
	}
634
	}
544
 
635
 
545
	let estVisible = false;
636
	let estVisible = false;
546
 
637
 
547
	$( '#plus-meta' ).off( 'click' ).on( 'click', function( event ) {
638
	$( '#plus-meta' ).off( 'click' ).on( 'click', function( event ) {
548
		event.preventDefault();
639
		event.preventDefault();
549
		$contenuPlusMeta.toggle( 200, function() {
640
		$contenuPlusMeta.toggle( 200, function() {
550
			estVisible = $contenuPlusMeta.is( ':visible' );
641
			estVisible = $contenuPlusMeta.is( ':visible' );
551
			degres     = estVisible ? '180' : '0';
642
			degres     = estVisible ? '180' : '0';
552
			$( this ).toggleClass( 'actif', estVisible );
643
			$( this ).toggleClass( 'actif', estVisible );
553
			lthis.rotationFleche( degres );
644
			lthis.rotationFleche( degres );
554
		});
645
		});
555
	});
646
	});
556
};
647
};
557
 
648
 
558
WidgetPhotoPopup.prototype.rotationFleche = function( degres ) {
649
WidgetPhotoPopup.prototype.rotationFleche = function( degres ) {
559
	$( '#plus-meta i' ).css({
650
	$( '#plus-meta i' ).css({
560
		'-webkit-transform' : 'rotate('+ degres +'deg)',
651
		'-webkit-transform' : 'rotate('+ degres +'deg)',
561
		'-moz-transform' : 'rotate('+ degres +'deg)',
652
		'-moz-transform' : 'rotate('+ degres +'deg)',
562
		'-ms-transform' : 'rotate('+ degres +'deg)',
653
		'-ms-transform' : 'rotate('+ degres +'deg)',
563
		'transform' : 'rotate('+ degres +'deg)'
654
		'transform' : 'rotate('+ degres +'deg)'
564
	});
655
	});
565
};
656
};
566
 
657
 
567
WidgetPhotoPopup.prototype.fournirLienTelechargement = function() {
658
WidgetPhotoPopup.prototype.fournirLienTelechargement = function() {
568
	const lthis = this;
659
	const lthis = this;
569
 
660
 
570
	$( '#formats' ).on( 'change', function() {
661
	$( '#formats' ).on( 'change', function() {
571
		let format             = ( $( this ).val() || 'O' ),
662
		let format             = ( $( this ).val() || 'O' ),
572
			lienTelechargement = lthis.urlBaseTelechargement + lthis.idImage + '?methode=telecharger&format=' + format;
663
			lienTelechargement = lthis.urlBaseTelechargement + lthis.idImage + '?methode=telecharger&format=' + format;
573
 
664
 
574
		$( '#telecharger' ).attr( 'href', lienTelechargement );
665
		$( '#telecharger' ).attr( 'href', lienTelechargement );
575
	});
666
	});
576
 
667
 
577
	$( '#formats' ).trigger( 'change' );
668
	$( '#formats' ).trigger( 'change' );
578
};
669
};
579
 
670
 
580
 
671
 
581
WidgetPhotoPopup.prototype.afficherPopupLocalisation = function() {
672
WidgetPhotoPopup.prototype.afficherPopupLocalisation = function() {
582
	const lthis = this;
673
	const lthis = this;
583
 
674
 
584
	$( '#localisation a.bouton' ).on( 'click', function( event ){
675
	$( '#localisation a.bouton' ).on( 'click', function( event ){
585
		event.preventDefault();
676
		event.preventDefault();
586
 
677
 
587
		$( this ).after(
678
		$( this ).after(
588
			'<div id="localisation-map-container">'+
679
			'<div id="localisation-map-container">'+
589
				'<button id="map-close" type="button" class="bouton btn btn-sm btn-outline-secondary" aria-label="Close">'+
680
				'<button id="map-close" type="button" class="bouton btn btn-sm btn-outline-secondary" aria-label="Close">'+
590
					'<span aria-hidden="true">×</span>'+
681
					'<span aria-hidden="true">×</span>'+
591
				'</button>'+
682
				'</button>'+
592
				'<div id="localisation-map"></div>'+
683
				'<div id="localisation-map"></div>'+
593
			'</div>'
684
			'</div>'
594
		);
685
		);
595
 
686
 
596
		let lat = lthis.obs['latitude'],
687
		let lat = lthis.obs['latitude'],
597
			lng = lthis.obs['longitude'],
688
			lng = lthis.obs['longitude'],
598
			map = L.map( 'localisation-map', {
689
			map = L.map( 'localisation-map', {
599
				zoomControl: true,
690
				zoomControl: true,
600
				dragging: false,
691
				dragging: false,
601
				scrollWheelZoom: 'center'
692
				scrollWheelZoom: 'center'
602
			} ).setView( [lat, lng], 12 );
693
			} ).setView( [lat, lng], 12 );
603
 
694
 
604
		map.markers = [];
695
		map.markers = [];
605
 
696
 
606
		L.tileLayer(
697
		L.tileLayer(
607
			// 'https://osm.tela-botanica.org/tuiles/osmfr/{z}/{x}/{y}.png',
698
			// 'https://osm.tela-botanica.org/tuiles/osmfr/{z}/{x}/{y}.png',
608
			'https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png',
699
			'https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png',
609
			{
700
			{
610
				attribution: 'Data © <a href="http://osm.org/copyright">OpenStreetMap</a>',
701
				attribution: 'Data © <a href="http://osm.org/copyright">OpenStreetMap</a>',
611
				maxZoom: 18
702
				maxZoom: 18
612
			}
703
			}
613
		).addTo( map );
704
		).addTo( map );
614
 
705
 
615
		map.addLayer( new L.FeatureGroup() );
706
		map.addLayer( new L.FeatureGroup() );
616
 
707
 
617
		let marker = new L.Marker(
708
		let marker = new L.Marker(
618
			{
709
			{
619
				'lat': lat,
710
				'lat': lat,
620
				'lng': lng
711
				'lng': lng
621
			},
712
			},
622
			{
713
			{
623
				draggable: false,
714
				draggable: false,
624
			}
715
			}
625
		);
716
		);
626
 
717
 
627
 
718
 
628
		map.addLayer( marker );
719
		map.addLayer( marker );
629
		map.markers.push( marker );
720
		map.markers.push( marker );
630
 
721
 
631
		$( '#map-close' ).on( 'click', function( event ){
722
		$( '#map-close' ).on( 'click', function( event ){
632
			$( '#localisation-map-container' ).remove();
723
			$( '#localisation-map-container' ).remove();
633
		});
724
		});
634
	});
725
	});
635
 
726
 
636
	$( '#fenetre-modal' ).on( 'click', function( event ) {
727
	$( '#fenetre-modal' ).on( 'click', function( event ) {
637
		if(
728
		if(
638
			!$( event.target ).closest( '#localisation-map-container' ).length
729
			!$( event.target ).closest( '#localisation-map-container' ).length
639
			&& !$( event.target ).closest( '#obs-localisation' ).length
730
			&& !$( event.target ).closest( '#obs-localisation' ).length
640
		) {
731
		) {
641
			$( '#localisation-map-container' ).remove();
732
			$( '#localisation-map-container' ).remove();
642
		}
733
		}
643
	});
734
	});
644
};
735
};
645
 
736
 
646
 
737
 
647
WidgetPhotoPopup.prototype.regenererMiniature = function() {
738
WidgetPhotoPopup.prototype.regenererMiniature = function() {
648
	const lthis = this;
739
	const lthis = this;
649
	$( '#regenerer-miniature' ).off( 'click' ).on( 'click', function( event ) {
740
	$( '#regenerer-miniature' ).off( 'click' ).on( 'click', function( event ) {
650
		event.preventDefault();
741
		event.preventDefault();
651
 
742
 
652
		let url = lthis.urlServiceRegenererMiniature + lthis.idImage;
743
		let url = lthis.urlServiceRegenererMiniature + lthis.idImage;
653
		$.get( url, function( data ) {
744
		$.get( url, function( data ) {
654
				console.log( data );
745
				console.log( data );
655
			}
746
			}
656
		).fail( function() {
747
		).fail( function() {
657
			console.log( 'La régénération d´image ne s´est pas faite' );
748
			console.log( 'La régénération d´image ne s´est pas faite' );
658
		});
749
		});
659
	});
750
	});
660
};
751
};
661
 
752
 
662
WidgetPhotoPopup.prototype.formaterDate = function( sqlDate ) {
753
WidgetPhotoPopup.prototype.formaterDate = function( sqlDate ) {
663
	dateFormatee = sqlDate
754
	dateFormatee = sqlDate
664
		.substring( 0, 10 )
755
		.substring( 0, 10 )
665
		.split( '-' )
756
		.split( '-' )
666
		.reverse()
757
		.reverse()
667
		.join('/');
758
		.join('/');
668
 
759
 
669
	return dateFormatee;
760
	return dateFormatee;
670
};
761
};
671
 
762
 
672
WidgetPhotoPopup.prototype.afficherLien = function( url, nom ) {
763
WidgetPhotoPopup.prototype.afficherLien = function( url, nom ) {
673
	if( !/https?:\/\//.test( url ) ) {
764
	if( !/https?:\/\//.test( url ) ) {
674
		url = 'https://' + url;
765
		url = 'https://' + url;
675
	}
766
	}
676
	return '<a href="' + url + '" target="_blank">' + nom + '</a> ';
767
	return '<a href="' + url + '" target="_blank">' + nom + '</a> ';
677
};
768
};
678
 
769
 
679
WidgetPhotoPopup.prototype.fournirLienIdentiplante = function() {
770
WidgetPhotoPopup.prototype.fournirLienIdentiplante = function() {
680
	const lthis = this;
771
	const lthis = this;
681
	$( '.signaler-erreur-obs' ).each( function() {
772
	$( '.signaler-erreur-obs' ).each( function() {
682
		$( this ).attr( 'href', 'https://' + lthis.urlIP );
773
		$( this ).attr( 'href', 'https://' + lthis.urlIP );
683
	});
774
	});
684
};
775
};
685
 
776
 
686
WidgetPhotoPopup.prototype.initEvtsProtocole = function() {
777
WidgetPhotoPopup.prototype.initEvtsProtocole = function() {
687
	const lthis = this;
778
	const lthis = this;
688
	$('#bloc-notes-protocole').addClass('hidden');
779
	$('#bloc-notes-protocole').addClass('hidden');
689
	lthis.votes = null
780
	lthis.votes = null
690
	//On transforme la promesse en array
781
	//On transforme la promesse en array
691
	const PROTOCOLES_ARRAY = Object.values(lthis.protocoles);
782
	const PROTOCOLES_ARRAY = Object.values(lthis.protocoles);
692
 
783
 
693
	const $select = $('#protocole');
784
	const $select = $('#protocole');
694
	$select.empty(); // Clear existing options
785
	$select.empty(); // Clear existing options
695
 
786
 
696
	// Add the default hidden option
787
	// Add the default hidden option
697
	$select.append('<option value="" selected hidden>Choix du protocole</option>');
788
	$select.append('<option value="" selected hidden>Choix du protocole</option>');
698
 
789
 
699
	PROTOCOLES_ARRAY.forEach(protocoleData => {
790
	PROTOCOLES_ARRAY.forEach(protocoleData => {
700
		$select.append(`<option id="protocole_${protocoleData['protocole.id']}" value="protocole_${protocoleData['protocole.id']}">${protocoleData['protocole.intitule']}</option>`);
791
		$select.append(`<option id="protocole_${protocoleData['protocole.id']}" value="protocole_${protocoleData['protocole.id']}">${protocoleData['protocole.intitule']}</option>`);
701
	})
792
	})
702
 
793
 
703
	$( '#protocole').on( 'change', function( event ){
794
	$( '#protocole').on( 'change', function( event ){
704
		event.preventDefault();
795
		event.preventDefault();
705
		lthis.votes = null
796
		lthis.votes = null
706
 
797
 
707
		var id = $(this).children(":selected").attr("id");
798
		var id = $(this).children(":selected").attr("id");
708
		var protocole = id.split("_")[1];
799
		var protocole = id.split("_")[1];
709
 
800
 
710
		$('#bloc-notes-protocole').removeClass('hidden');
801
		$('#bloc-notes-protocole').removeClass('hidden');
711
 
802
 
712
		// Find the object corresponding to the selected id (protocole.id)
803
		// Find the object corresponding to the selected id (protocole.id)
713
		var selectedProtocoleData = PROTOCOLES_ARRAY.find(protocoleData => protocoleData['protocole.id'] === protocole);
804
		var selectedProtocoleData = PROTOCOLES_ARRAY.find(protocoleData => protocoleData['protocole.id'] === protocole);
714
 
805
 
715
		lthis.protocole = selectedProtocoleData['protocole.id'];
806
		lthis.protocole = selectedProtocoleData['protocole.id'];
716
		const message = selectedProtocoleData['protocole.descriptif'];
807
		const message = selectedProtocoleData['protocole.descriptif'];
717
 
808
 
718
		$('#message-protocole').html('<p>' + message + '</p>');
809
		$('#message-protocole').html('<p>' + message + '</p>');
719
 
810
 
720
		// On envoie le protocole sélectionné à la partie "vote"
811
		// On envoie le protocole sélectionné à la partie "vote"
721
		// On récupère tous les votes de l'image depuis pictoflora
812
		// On récupère tous les votes de l'image depuis pictoflora
722
		lthis.votes = lthis.getVotes(lthis.protocole)
813
		lthis.votes = lthis.getVotes(lthis.protocole)
723
 
814
 
724
		// Si l'utilisateur est connect, on vérifie s'il a déjà voté pour cette image et on affiche les étoiles
815
		// Si l'utilisateur est connect, on vérifie s'il a déjà voté pour cette image et on affiche les étoiles
725
		// correspondantes
816
		// correspondantes
726
		if(lthis.userId){
817
		if(lthis.userId){
727
			lthis.checkUserVote(lthis.userId, lthis.protocole, lthis.votes);
818
			lthis.checkUserVote(lthis.userId, lthis.protocole, lthis.votes);
728
		} else {
819
		} else {
729
			lthis.voteId = null;
820
			lthis.voteId = null;
730
			lthis.removeVoteStars()
821
			lthis.removeVoteStars()
731
		}
822
		}
732
 
823
 
733
		// Remove any previous click event listeners on rating stars
824
		// Remove any previous click event listeners on rating stars
734
		for (let i=1; i<=5; i++){
825
		for (let i=1; i<=5; i++){
735
			$("#rating-star-"+i).off("click");
826
			$("#rating-star-"+i).off("click");
736
		}
827
		}
737
 
828
 
738
		// Si l'utilisateur vote, on affiche les étoiles correspondantes et on l'envoie vers pictoflora
829
		// Si l'utilisateur vote, on affiche les étoiles correspondantes et on l'envoie vers pictoflora
739
		lthis.traiterVote();
830
		lthis.traiterVote();
740
	});
831
	});
741
}
832
}
742
 
833
 
743
WidgetPhotoPopup.prototype.traiterVote = function () {
834
WidgetPhotoPopup.prototype.traiterVote = function () {
744
	const lthis = this;
835
	const lthis = this;
745
	let starSelected = 0
836
	let starSelected = 0
746
	let mode = '';
837
	let mode = '';
747
 
838
 
748
	$("#note").attr("value", -1);
839
	$("#note").attr("value", -1);
749
 
840
 
750
	// Traitement du bouton suppression du vote
841
	// Traitement du bouton suppression du vote
751
	$("#note-remove").click(function (){
842
	$("#note-remove").click(function (){
752
		lthis.removeVoteStars();
843
		lthis.removeVoteStars();
753
		mode = 'DELETE';
844
		mode = 'DELETE';
754
		// On n'envoie le vote que si l'utilisateur est connecté
845
		// On n'envoie le vote que si l'utilisateur est connecté
755
		if (lthis.userId) {
846
		if (lthis.userId) {
756
			lthis.sendVote(lthis.userId, lthis.protocole, starSelected, mode, lthis.voteId);
847
			lthis.sendVote(lthis.userId, lthis.protocole, starSelected, mode, lthis.voteId);
757
		}
848
		}
758
	})
849
	})
759
 
850
 
760
	// Si l'utilisateur a déjà voté pour cette image on affiche son vote et on passe en mode modification
851
	// Si l'utilisateur a déjà voté pour cette image on affiche son vote et on passe en mode modification
761
	let userAVoter = lthis.checkUserVote(lthis.userId, lthis.protocole, lthis.votes);
852
	let userAVoter = lthis.checkUserVote(lthis.userId, lthis.protocole, lthis.votes);
762
	userAVoter ? mode = 'POST' : mode = 'PUT';
853
	userAVoter ? mode = 'POST' : mode = 'PUT';
763
 
854
 
764
	// Affichage du nombre d'étoiles sélectionnées et envoi du vote
855
	// Affichage du nombre d'étoiles sélectionnées et envoi du vote
765
	for (let i=1; i<=5; i++){
856
	for (let i=1; i<=5; i++){
766
		$("#rating-star-"+i).click(function () {
857
		$("#rating-star-"+i).click(function () {
767
			starSelected = i
858
			starSelected = i
768
			lthis.displayVote(starSelected);
859
			lthis.displayVote(starSelected);
769
			$("#note").attr("value", starSelected);
860
			$("#note").attr("value", starSelected);
770
			// On n'envoie le vote que si l'utilisateur est connecté
861
			// On n'envoie le vote que si l'utilisateur est connecté
771
			if (lthis.userId){
862
			if (lthis.userId){
772
				lthis.sendVote(lthis.userId, lthis.protocole, starSelected, mode);
863
				lthis.sendVote(lthis.userId, lthis.protocole, starSelected, mode);
773
			}
864
			}
774
		});
865
		});
775
	}
866
	}
776
};
867
};
777
 
868
 
778
// Envoi du vote vers la fonction sendVote() du fichier php
869
// Envoi du vote vers la fonction sendVote() du fichier php
779
WidgetPhotoPopup.prototype.sendVote = function (userId, protocole, note, mode, voteId){
870
WidgetPhotoPopup.prototype.sendVote = function (userId, protocole, note, mode, voteId){
780
	const lthis = this;
871
	const lthis = this;
781
 
872
 
782
	var xhttp = new XMLHttpRequest();
873
	var xhttp = new XMLHttpRequest();
783
	xhttp.onreadystatechange = function() {
874
	xhttp.onreadystatechange = function() {
784
		if (this.readyState == 4 && this.status == 200) {
875
		if (this.readyState == 4 && this.status == 200) {
785
 
876
 
786
			console.log('vote envoyé')
877
			console.log('vote envoyé')
787
		}
878
		}
788
	};
879
	};
789
 
880
 
790
	var url = "../widget:cel:photo/";
881
	var url = "../widget:cel:photo/";
791
 
882
 
792
	// Convertir les données en une chaîne JSON pour les envoyer dans le corps de la requête
883
	// Convertir les données en une chaîne JSON pour les envoyer dans le corps de la requête
793
	var data = {
884
	var data = {
794
		idImage: this.idImage,
885
		idImage: this.idImage,
795
		mode: mode,
886
		mode: mode,
796
		user: userId,
887
		user: userId,
797
		protocole: protocole,
888
		protocole: protocole,
798
		vote: note,
889
		vote: note,
799
		voteId: voteId
890
		voteId: voteId
800
	}
891
	}
801
	var jsonData = JSON.stringify(data);
892
	var jsonData = JSON.stringify(data);
802
 
893
 
803
	xhttp.open("POST", url+"?action=send_pf_vote", true);
894
	xhttp.open("POST", url+"?action=send_pf_vote", true);
804
	xhttp.setRequestHeader("Content-Type", "application/json");
895
	xhttp.setRequestHeader("Content-Type", "application/json");
805
	xhttp.send(jsonData);
896
	xhttp.send(jsonData);
806
}
897
}
807
 
898
 
808
WidgetPhotoPopup.prototype.getVotes = function (protocoleId){
899
WidgetPhotoPopup.prototype.getVotes = function (protocoleId){
809
	let votes = Object.values(this.item["votes"]);
900
	let votes = Object.values(this.item["votes"]);
810
	let noteMoyenne = 0;
901
	let noteMoyenne = 0;
811
	let nombreVotes= 0;
902
	let nombreVotes= 0;
812
	let noteTotal = 0;
903
	let noteTotal = 0;
813
	let itemVotes = [];
904
	let itemVotes = [];
814
 
905
 
815
	votes.forEach(vote => {
906
	votes.forEach(vote => {
816
		if (vote["protocole.id"] == protocoleId){
907
		if (vote["protocole.id"] == protocoleId){
817
			nombreVotes++
908
			nombreVotes++
818
			noteTotal += parseInt(vote["vote"]);
909
			noteTotal += parseInt(vote["vote"]);
819
			noteMoyenne = (noteTotal / nombreVotes).toFixed(1)
910
			noteMoyenne = (noteTotal / nombreVotes).toFixed(1)
820
			itemVotes.push(vote);
911
			itemVotes.push(vote);
821
		}
912
		}
822
	})
913
	})
823
 
914
 
824
	let elementNoteMoyenne = $("#note-moyenne .contenu");
915
	let elementNoteMoyenne = $("#note-moyenne .contenu");
825
	elementNoteMoyenne.text(noteMoyenne);
916
	elementNoteMoyenne.text(noteMoyenne);
826
 
917
 
827
	let elementNoteCount = $("#note-count .contenu");
918
	let elementNoteCount = $("#note-count .contenu");
828
	elementNoteCount.text(nombreVotes);
919
	elementNoteCount.text(nombreVotes);
829
 
920
 
830
	return itemVotes;
921
	return itemVotes;
831
}
922
}
832
 
923
 
833
WidgetPhotoPopup.prototype.displayVote = function (note){
924
WidgetPhotoPopup.prototype.displayVote = function (note){
834
	lthis.removeVoteStars();
925
	lthis.removeVoteStars();
835
 
926
 
836
	for (let i=1; i<=5; i++){
927
	for (let i=1; i<=5; i++){
837
		for (let j=1; j<=note; j++){
928
		for (let j=1; j<=note; j++){
838
			$("#rating-star-"+j).removeClass('far').addClass('fa').css("color", "#c3d45d");
929
			$("#rating-star-"+j).removeClass('far').addClass('fa').css("color", "#c3d45d");
839
		}
930
		}
840
	}
931
	}
841
}
932
}
842
 
933
 
843
WidgetPhotoPopup.prototype.removeVoteStars = function (){
934
WidgetPhotoPopup.prototype.removeVoteStars = function (){
844
	$(".notation-star").removeClass('fa').addClass('far').css("color", "grey");
935
	$(".notation-star").removeClass('fa').addClass('far').css("color", "grey");
845
	$("#note").attr("value", -1);
936
	$("#note").attr("value", -1);
846
}
937
}
847
 
938
 
848
WidgetPhotoPopup.prototype.checkUserVote = function (userId, protocoleId, votes){
939
WidgetPhotoPopup.prototype.checkUserVote = function (userId, protocoleId, votes){
849
	let userVote = null;
940
	let userVote = null;
850
 
941
 
851
	votes.forEach(vote => {
942
	votes.forEach(vote => {
852
		if (vote["protocole.id"] == protocoleId && vote["auteur.id"] == userId){
943
		if (vote["protocole.id"] == protocoleId && vote["auteur.id"] == userId){
853
			userVote = vote;
944
			userVote = vote;
854
		}
945
		}
855
	})
946
	})
856
 
947
 
857
	if (userVote){
948
	if (userVote){
858
		this.displayVote(userVote['vote']);
949
		this.displayVote(userVote['vote']);
859
		// this.traiterVote()
950
		// this.traiterVote()
860
		this.voteId = userVote['vote.id'];
951
		this.voteId = userVote['vote.id'];
861
 
952
 
862
		return true
953
		return true
863
	} else {
954
	} else {
864
		this.voteId = null;
955
		this.voteId = null;
865
		this.removeVoteStars()
956
		this.removeVoteStars()
866
	}
957
	}
867
}
958
}
868
 
959
 
869
WidgetPhotoPopup.prototype.pivoterImage = function() {
960
WidgetPhotoPopup.prototype.pivoterImage = function() {
870
	lthis = this;
961
	lthis = this;
871
	$( '#pivoter-droite' ).off( 'click' ).on( 'click', function( event ) {
962
	$( '#pivoter-droite' ).off( 'click' ).on( 'click', function( event ) {
872
		event.preventDefault();
963
		event.preventDefault();
873
 
964
 
874
		lthis.pivoter('droite');
965
		lthis.pivoter('droite');
875
	});
966
	});
876
 
967
 
877
	$( '#pivoter-gauche' ).off( 'click' ).on( 'click', function( event ) {
968
	$( '#pivoter-gauche' ).off( 'click' ).on( 'click', function( event ) {
878
		event.preventDefault();
969
		event.preventDefault();
879
 
970
 
880
		lthis.pivoter('gauche');
971
		lthis.pivoter('gauche');
881
	});
972
	});
882
};
973
};
883
 
974
 
884
WidgetPhotoPopup.prototype.pivoter = function(direction) {
975
WidgetPhotoPopup.prototype.pivoter = function(direction) {
885
	let imageSelected = $('img[src="' + lthis.urlThisImage + '"]').attr('id');
976
	let imageSelected = $('img[src="' + lthis.urlThisImage + '"]').attr('id');
886
	let angle = $('#' + imageSelected).data('angle');
977
	let angle = $('#' + imageSelected).data('angle');
887
 
978
 
888
	if (angle == 360 || angle == (-360) || angle == undefined){
979
	if (angle == 360 || angle == (-360) || angle == undefined){
889
		angle = 0
980
		angle = 0
890
	}
981
	}
891
	if (direction == 'droite'){
982
	if (direction == 'droite'){
892
		angle += 90;
983
		angle += 90;
893
	} else {
984
	} else {
894
		angle -= 90;
985
		angle -= 90;
895
	}
986
	}
896
 
987
 
897
	$('#' + imageSelected).css("transform", "rotate(" + angle + "deg) ");
988
	$('#' + imageSelected).css("transform", "rotate(" + angle + "deg) ");
898
	$('#' + imageSelected).data('angle', angle);
989
	$('#' + imageSelected).data('angle', angle);
899
}
990
}
900
 
991
 
901
// WidgetPhotoPopup.prototype.afficherTags = function() {
992
// WidgetPhotoPopup.prototype.afficherTags = function() {
902
// 	const lthis = this;
993
// 	const lthis = this;
903
// 	const TAGS_BASE = [
994
// 	const TAGS_BASE = [
904
// 		'port',
995
// 		'port',
905
// 		'fleur',
996
// 		'fleur',
906
// 		'fruit',
997
// 		'fruit',
907
// 		'feuille',
998
// 		'feuille',
908
// 		'ecorce',
999
// 		'ecorce',
909
// 		'rameau',
1000
// 		'rameau',
910
// 		'planche',
1001
// 		'planche',
911
// 		'insecte'
1002
// 		'insecte'
912
// 	];
1003
// 	];
913
 
1004
 
914
	
1005
	
915
// };
1006
// };