Subversion Repositories eFlore/Applications.cel

Rev

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

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