Subversion Repositories eFlore/Applications.cel

Rev

Rev 3980 | Rev 3984 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3980 Rev 3983
Line 11... Line 11...
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();
Line 38... Line 39...
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
};
Line 45... Line 45...
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();
-
 
54
	this.initEvtsTagsPF();
53
	this.initEvtsProtocole();
55
	this.initEvtsTagsCel();
Line 54... Line 56...
54
};
56
};
55
 
57
 
56
WidgetPhotoPopup.prototype.mettreAJourInfosImage = function() {
58
WidgetPhotoPopup.prototype.mettreAJourInfosImage = function() {
Line 100... Line 102...
100
};
102
};
Line 101... Line 103...
101
 
103
 
102
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
104
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
Line -... Line 105...
-
 
105
	const lthis = this;
-
 
106
 
103
	const lthis = this;
107
	$( '#precedent, #suivant' ).off('click');
104
 
108
 
-
 
109
	$( '#precedent, #suivant' ).on( 'click', function() {
105
	$( '#precedent, #suivant' ).on( 'click', function() {
110
		lthis.defilerImage( this.id );
Line 106... Line 111...
106
		lthis.defilerImage( this.id );
111
		lthis.initEvtsTagsPF();
Line 107... Line 112...
107
	});
112
	});
Line 166... Line 171...
166
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
171
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
167
		}
172
		}
168
	});
173
	});
169
};
174
};
Line -... Line 175...
-
 
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();
-
 
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
		}
180
		$( this ).toggleClass( 'actif' );
244
		//TODO post vers le del
-
 
245
	});
181
	});
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
Line 195... Line 260...
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;
Line 203... Line 269...
203
 
269
 
204
		event = ( event || window.event );
270
		event = ( event || window.event );
Line 224... Line 290...
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
};
Line 230... Line 297...
230
 
297
 
231
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
298
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
232
	if ( 'suivant' === sens ) {
299
	if ( 'suivant' === sens ) {
Line 328... Line 395...
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
};
Line -... Line 399...
-
 
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() {
Line 334... Line 420...
334
	const lthis = this;
420
	const lthis = this;
335
 
421
 
Line 349... Line 435...
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() );
Line 352... Line 438...
352
 
438
 
353
			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
439
			if( lthis.valOk( nouveauTagAttr ) && !lthis.valOk( $( '#' + nouveauTagAttr + '.tag' ) ) ) {
368
				$( '#tags-pf-supp' ).append(
440
				$( '#tags-pf-supp' ).append(
-
 
441
					'<a id="' + nouveauTagAttr + '" class="btn tag custom-tag actif">' +
369
					'<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>'
-
 
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
				});
372
				);
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
	});