Subversion Repositories eFlore/Applications.del

Rev

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

Rev 983 Rev 984
Line 1... Line 1...
1
/**
1
/**
2
 * var g_idObservation : id de l'observation en cours de consultation
2
 * var g_idObservation : id de l'observation en cours de consultation
-
 
3
 * var g_urlServiceVotes : url du service web des votes à appeler
3
 * var g_idUtilisateur : id utilisateur
4
 * var g_urlServiceUtilisateurs : url du service web utilisateur à appeler
-
 
5
 * var g_votes : tableau des votes 
4
 */
6
 */
5
var g_idObservation = '726365';
-
 
6
var boutonClique = null;
7
var boutonClique = null;
-
 
8
var g_idUtilisateur = null
Line 7... Line 9...
7
 
9
 
8
function gererEvenementsClicsVotes() {
10
function gererEvenementsClicsVotes() {
9
	$('.bouton_vote').click(function(event) {
11
	$('.bouton_vote').click(function(event) {
10
		boutonClique = $(this);
12
		boutonClique = $(this);
Line 13... Line 15...
13
}
15
}
Line 14... Line 16...
14
 
16
 
15
function voter(ouiOuNon) {
17
function voter(ouiOuNon) {
16
	var idProposition = obtenirIdProposition();
18
	var idProposition = obtenirIdProposition();
-
 
19
	var urlVote = getUrlVoteProposition(idProposition);
-
 
20
	var type = getMethodeRequete(idProposition, g_idUtilisateur);
17
	var urlVote = getUrlVoteProposition(idProposition);
21
	
18
	$.ajax({
22
	$.ajax({
19
		url : urlVote,
23
		url : urlVote,
20
		type: "PUT",
24
		type: type,
21
		data: "utilisateur="+g_idUtilisateur+"&valeur="+ouiOuNon,
25
		data: "utilisateur="+g_idUtilisateur+"&valeur="+ouiOuNon
-
 
26
	}).done(function(data) {
-
 
27
		mettreAjourTableauVotes(idProposition, g_idUtilisateur, ouiOuNon);
22
	}).done(function(data) {
28
		mettreAJourNbVotes(idProposition);
23
		boutonClique.effect("highlight", {}, 1000);
-
 
24
		mettreAJourNbVotes();
29
		boutonClique.effect("highlight", {}, 1000);
25
		boutonClique = null;
30
		boutonClique = null;
26
	});					
31
	});					
Line -... Line 32...
-
 
32
}
-
 
33
 
-
 
34
function getMethodeRequete(idProposition, idUtilisateur) {
-
 
35
	var methode = "PUT";
-
 
36
	if(g_votes[idProposition] != undefined && g_votes[idProposition] != null &&
-
 
37
			g_votes[idProposition][idUtilisateur] != undefined && g_votes[idProposition][idUtilisateur] != null) {
-
 
38
		methode = "POST";
-
 
39
	}
-
 
40
	return methode;
-
 
41
}
-
 
42
 
-
 
43
function mettreAjourTableauVotes(idProposition, idUtilisateur, valeurVote) {
-
 
44
	if(g_votes[idProposition] == undefined) {
-
 
45
		g_votes[idProposition] = new Array();
-
 
46
	}
-
 
47
	g_votes[idProposition][idUtilisateur] = valeurVote;
27
}
48
}
28
 
49
 
29
function getValeurVote() {
50
function getValeurVote() {
30
	valeur = "0";
51
	valeur = "0";
31
	if(boutonClique.hasClass('bouton_vote_oui')) {
52
	if(boutonClique.hasClass('bouton_vote_oui')) {
32
		valeur = "1";
53
		valeur = "1";
33
	}
54
	}
Line 34... Line 55...
34
	return valeur;
55
	return valeur;
35
}
56
}
-
 
57
 
-
 
58
function mettreAJourNbVotes(idProposition) {
-
 
59
	affichageVotes = boutonClique.parent().find(".nb_votes");
-
 
60
	affichageVotes.each(function() {
-
 
61
		if($(this).hasClass("nb_votes_oui")) {
-
 
62
			$(this).html(calculerVotesOui(idProposition));
-
 
63
		}
-
 
64
		
-
 
65
		if($(this).hasClass("nb_votes_non")) {
-
 
66
			$(this).html(calculerVotesNon(idProposition));
-
 
67
		}
-
 
68
	});
-
 
69
}
-
 
70
 
-
 
71
function calculerVotesOui(id_proposition) {
-
 
72
	var nbOui = 0;
-
 
73
	g_votes[id_proposition]
-
 
74
	for (var votant in g_votes[id_proposition]) {
-
 
75
		if(g_votes[id_proposition][votant] == 1) {
-
 
76
			nbOui++;
-
 
77
		}
-
 
78
	}
-
 
79
	return nbOui;
36
 
80
}
-
 
81
 
37
function mettreAJourNbVotes() {
82
function calculerVotesNon(id_proposition) {
-
 
83
	var nbNon = 0;
-
 
84
	g_votes[id_proposition]
-
 
85
	for (var votant in g_votes[id_proposition]) {
-
 
86
		if(g_votes[id_proposition][votant] == 0) {
-
 
87
			nbNon++;
38
	valeurNbVotes = boutonClique.next().html();
88
		}
Line 39... Line 89...
39
	valeurNbVotes++;
89
	}
40
	boutonClique.next().html(valeurNbVotes);
90
	return nbNon;
41
}
91
}
42
 
92
 
Line 43... Line 93...
43
function obtenirIdProposition() {
93
function obtenirIdProposition() {
44
	var chaineProposition = boutonClique.parent().attr('id');
94
	var chaineProposition = boutonClique.parent().attr('id');
45
	return chaineProposition.replace('vote_determination_', '');
95
	return chaineProposition.replace('vote_determination_', '');
Line 46... Line 96...
46
}
96
}
47
 
97
 
48
function getUrlVoteProposition(idProposition) {
98
function getUrlVoteProposition(idProposition) {
Line 62... Line 112...
62
		$(this).addClass('image_active');
112
		$(this).addClass('image_active');
63
		$('#image_principale').attr('src', urlImageSecondaireAgrandie);
113
		$('#image_principale').attr('src', urlImageSecondaireAgrandie);
64
	});
114
	});
65
}
115
}
Line -... Line 116...
-
 
116
 
-
 
117
function getIdUtilisateur() {
-
 
118
	$.getJSON(g_urlServiceUtilisateurs, function(data) {
-
 
119
		g_idUtilisateur = data.id_utilisateur;
-
 
120
	});
-
 
121
}
66
 
122
 
-
 
123
$(document).ready(function() {
67
$(document).ready(function() {
124
	getIdUtilisateur();
68
	gererEvenementsClicsVotes();
125
	gererEvenementsClicsVotes();
69
	gererEvenementClicImageSecondaire();
126
	gererEvenementClicImageSecondaire();