MOD #133 (à tester)
[cl7.git] / js / cl7.js
1 /**
2 * coding: utf-8
3 * Quelques bouts de JS pour le site de la corcelles-lan 7.
4 * Necessite la lib jQuery.
5 */
6
7 var cl7 = {};
8
9 cl7.verification_formulaire_inscription = function(util) {
10 if ($('#formulaireInscription input[name="pseudo"]').val() === "") {
11 util.messageDialogue("Le pseudo ne peut pas être vide");
12 return false;
13 }
14 if ($('#formulaireInscription input[name="pass1"]').val() === "" &&
15 $('#formulaireInscription input[name="pass2"]').val() === "") {
16 util.messageDialogue("Le password ne peut pas être vide");
17 return false;
18 }
19 if ($('#formulaireInscription input[name="pass1"]').val() !== $('#formulaireInscription input[name="pass2"]').val()) {
20 util.messageDialogue("Les passwords ne correspondent pas");
21 return false;
22 }
23 if ($('#formulaireInscription input[name="pass1"]').val().length < 3) {
24 util.messageDialogue("La taille de password doit être d'au moins 3 caractères");
25 return false;
26 }
27 if ($('#formulaireInscription input[name="nom"]').val() === "") {
28 util.messageDialogue("Le nom ne peut pas être vide");
29 return false;
30 }
31 if ($('#formulaireInscription input[name="prenom"]').val() === "") {
32 util.messageDialogue("Le prénom ne peut pas être vide");
33 return false;
34 }
35 if ($('#formulaireInscription input[name="e_mail"]').val() === "") {
36 util.messageDialogue("L'email ne peut pas être vide");
37 return false;
38 }
39 if ($('#formulaireInscription input[name="accord"]').length === 1 && !$('#formulaireInscription input[name="accord"]').attr("checked")) {
40 util.messageDialogue("Vous devez être d'accord avec le préambule");
41 return false;
42 }
43 return true;
44 };
45
46 cl7.maj_prix_inscription = function() {
47 var prixTotal = (int)($('meta[name="cout_total"]').attr('content'));
48 var prixPeriode = (int)($('meta[name="cout_periode"]').attr('content'));
49 var nbPeriodesTotal = (int)($('meta[name="nb_periodes"]').attr('content'));
50 var nbPeriodesCheck = (int)($('#formulaireInscription input[name="periodes[]"]:checked').length);
51
52 var prix = 5;
53 if (nbPeriodesCheck === nbPeriodesTotal) {
54 prix = prixTotal;
55 } else if (nbPeriodesCheck != 0) {
56 prix = prixPeriode * nbPeriodesCheck;
57 }
58 $('#formulaireInscription span#prix').html(prix.toString());
59 };
60
61 $(document).ready(
62 function() {
63 var util = new cl7.Util();
64 $('form#formulaireInscription').submit(function() {
65 return cl7.verification_formulaire_inscription(util);
66 });
67
68 var messageUtilisateur = $('meta[name="messageUtilisateur"]').attr('content');
69 if (messageUtilisateur !== undefined) {
70 util.messageDialogue(messageUtilisateur);
71 }
72
73 $('form#formulaireInscription select[name="clanChoix"]').change(function() {
74 if ($(this).val() === '0') {
75 return;
76 }
77 $clan = $(this).val().split(';');
78 $('form#formulaireInscription input[name="clan_nom"]').val($clan[0]);
79 $('form#formulaireInscription input[name="clan_tag"]').val($clan[1]);
80 });
81
82 // inscrit les emails codés (page contacts)
83 $('a#contactPifou').attr('href', util.rot13('znvygb:tert.oheev@tznvy.pbz'));
84 $('a#contactLePiaf').attr('href', util.rot13('znvygb:tyrcvns695@zfa.pbz'));
85
86 $('#formulaireInscription input[name="periodes[]"]').change(function() {
87 cl7.maj_prix_inscription();
88 });
89 // met à jour le prix d'inscription
90 cl7.maj_prix_inscription();
91
92 // permet d'éviter de faire plus de choix qu'il n'en faut sur la page des jeux joués
93 var nbVotesMax = 3;
94 var coches = [];
95 $('#formulaireJeuxJoues input[name="votes[]"]:checked').each(function() {
96 coches.unshift(parseInt($(this).attr("value")));
97 });
98 $('#formulaireJeuxJoues input[name="votes[]"]').change(function() {
99 if($(this).attr("checked")) {
100 if (coches.length >= nbVotesMax) {
101 $('#formulaireJeuxJoues input[value="' + coches.pop() + '"]').attr("checked", false);
102 }
103 coches.unshift(parseInt($(this).attr("value")));
104 } else {
105 for (var i = 0; i < coches.length; i ++) {
106 if (coches[i] == parseInt($(this).attr("value"))) {
107 coches.splice(i, 1);
108 break;
109 }
110 }
111 }
112 });
113 }
114 );