983 |
aurelien |
1 |
/**
|
|
|
2 |
* var g_idObservation : id de l'observation en cours de consultation
|
|
|
3 |
* var g_idUtilisateur : id utilisateur
|
|
|
4 |
*/
|
|
|
5 |
var g_idObservation = '726365';
|
|
|
6 |
var boutonClique = null;
|
|
|
7 |
|
|
|
8 |
function gererEvenementsClicsVotes() {
|
|
|
9 |
$('.bouton_vote').click(function(event) {
|
|
|
10 |
boutonClique = $(this);
|
|
|
11 |
voter(getValeurVote());
|
|
|
12 |
});
|
|
|
13 |
}
|
|
|
14 |
|
|
|
15 |
function voter(ouiOuNon) {
|
|
|
16 |
var idProposition = obtenirIdProposition();
|
|
|
17 |
var urlVote = getUrlVoteProposition(idProposition);
|
|
|
18 |
$.ajax({
|
|
|
19 |
url : urlVote,
|
|
|
20 |
type: "PUT",
|
|
|
21 |
data: "utilisateur="+g_idUtilisateur+"&valeur="+ouiOuNon,
|
|
|
22 |
}).done(function(data) {
|
|
|
23 |
boutonClique.effect("highlight", {}, 1000);
|
|
|
24 |
mettreAJourNbVotes();
|
|
|
25 |
boutonClique = null;
|
|
|
26 |
});
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
function getValeurVote() {
|
|
|
30 |
valeur = "0";
|
|
|
31 |
if(boutonClique.hasClass('bouton_vote_oui')) {
|
|
|
32 |
valeur = "1";
|
|
|
33 |
}
|
|
|
34 |
return valeur;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
function mettreAJourNbVotes() {
|
|
|
38 |
valeurNbVotes = boutonClique.next().html();
|
|
|
39 |
valeurNbVotes++;
|
|
|
40 |
boutonClique.next().html(valeurNbVotes);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
function obtenirIdProposition() {
|
|
|
44 |
var chaineProposition = boutonClique.parent().attr('id');
|
|
|
45 |
return chaineProposition.replace('vote_determination_', '');
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
function getUrlVoteProposition(idProposition) {
|
|
|
49 |
return 'http://localhost/del/services/0.1/observations/'+g_idObservation+'/'+idProposition+'/vote/';
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
function gererEvenementClicImageSecondaire() {
|
|
|
53 |
$('.image_secondaire').click(function(event) {
|
|
|
54 |
$('.image_secondaire').removeClass('image_active');
|
|
|
55 |
|
|
|
56 |
var urlImageSecondaire = $(this).attr('src');
|
|
|
57 |
urlImageSecondaireAgrandie = urlImageSecondaire.replace('XS','CRS');
|
|
|
58 |
|
|
|
59 |
var urlImagePrincipale = $('#image_principale').attr('src');
|
|
|
60 |
urlImagePrincipaleMiniature = urlImagePrincipale.replace('CRS','XS');
|
|
|
61 |
|
|
|
62 |
$(this).addClass('image_active');
|
|
|
63 |
$('#image_principale').attr('src', urlImageSecondaireAgrandie);
|
|
|
64 |
});
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
$(document).ready(function() {
|
|
|
68 |
gererEvenementsClicsVotes();
|
|
|
69 |
gererEvenementClicImageSecondaire();
|
|
|
70 |
});
|