Commit 344a37adf85c8c6450e7a4f4d969814265548eae
1 parent
e5e2f19a
Création de clients
Showing
2 changed files
with
56 additions
and
4 deletions
Show diff stats
index.html
... | ... | @@ -104,7 +104,7 @@ |
104 | 104 | </div> |
105 | 105 | </form> |
106 | 106 | </div> |
107 | - <div v-if="peutNFC"> | |
107 | + <div v-if="PEUT_NFC"> | |
108 | 108 | <h5>Avec votre carte étudiant</h5> |
109 | 109 | <p>Passez-la simplement devant le lecteur</p> |
110 | 110 | </div> |
... | ... | @@ -116,12 +116,16 @@ |
116 | 116 | <h5>Créer un nouveau client</h5> |
117 | 117 | <div class="row"> |
118 | 118 | <form class="col s12"> |
119 | + <div class="input-field col s12" v-if="!PEUT_NFC"> | |
120 | + <input type="text" name="idCarte" maxlength="8" v-model="idCarte"> | |
121 | + <label for="idCarte">Identifiant de la carte</label> | |
122 | + </div> | |
119 | 123 | <div class="input-field col s12"> |
120 | - <input type="number" name="solde"> | |
124 | + <input type="number" name="solde" v-model="solde"> | |
121 | 125 | <label for="solde">Solde initial (€)</label> |
122 | 126 | </div> |
123 | 127 | <div class="row center"> |
124 | - <a class="btn-large waves-effect waves-light">Créer</a> | |
128 | + <a class="btn-large waves-effect waves-light" @click="creer" :class="{'disabled': !peutCreer}">Créer</a> | |
125 | 129 | </div> |
126 | 130 | </form> |
127 | 131 | </div> |
... | ... | @@ -130,6 +134,10 @@ |
130 | 134 | <h5>Recharger un client</h5> |
131 | 135 | <div class="row"> |
132 | 136 | <form class="col s12"> |
137 | + <div class="input-field col s12" v-if="!PEUT_NFC"> | |
138 | + <input type="text" name="idCarte" maxlength="8" v-model="idCarte"> | |
139 | + <label for="idCarte">Identifiant de la carte</label> | |
140 | + </div> | |
133 | 141 | <div class="input-field col s12"> |
134 | 142 | <input type="number" name="credit"> |
135 | 143 | <label for="credit">Crédit (€)</label> |
... | ... | @@ -144,6 +152,12 @@ |
144 | 152 | <h5>Vendre à un client</h5> |
145 | 153 | <div class="row"> |
146 | 154 | <form class="col s12"> |
155 | + <div class="input-field col s12" v-if="!PEUT_NFC"> | |
156 | + <input type="text" name="idCarte" maxlength="8" v-model="idCarte"> | |
157 | + <label for="idCarte">Identifiant de la carte</label> | |
158 | + </div> | |
159 | + <br/> | |
160 | + <h6>En spécifiant le nombre de consommations</h6> | |
147 | 161 | <div id="grilleBieres"> |
148 | 162 | <div class="row"> |
149 | 163 | <div class="col s4"><a class="waves-effect waves-light btn">1</a></div> |
... | ... | @@ -156,6 +170,8 @@ |
156 | 170 | <div class="col s4"><a class="waves-effect waves-light btn">6</a></div> |
157 | 171 | </div> |
158 | 172 | </div> |
173 | + <br/> | |
174 | + <h6>En spécifiant un montant</h6> | |
159 | 175 | <div class="row"> |
160 | 176 | <div class="input-field col s12"> |
161 | 177 | <input type="number" name="prix"> |
... | ... | @@ -170,6 +186,10 @@ |
170 | 186 | </div> |
171 | 187 | <div id="vidange"> |
172 | 188 | <h5>Vider le contenu de la carte d'un client</h5> |
189 | + <div class="input-field col s12" v-if="!PEUT_NFC"> | |
190 | + <input type="text" name="idCarte" maxlength="8" v-model="idCarte"> | |
191 | + <label for="idCarte">Identifiant de la carte</label> | |
192 | + </div> | |
173 | 193 | <div class="row center"> |
174 | 194 | <a class="btn-large waves-effect waves-light">Vider</a> |
175 | 195 | </div> | ... | ... |
js/init.js
... | ... | @@ -9,6 +9,8 @@ var TRANSACTION_VIDANGE = 4 |
9 | 9 | |
10 | 10 | var TRANSACTION_DUREE = 60 |
11 | 11 | |
12 | +var PEUT_NFC = false | |
13 | + | |
12 | 14 | // Fonctions pour Materialize |
13 | 15 | $(function(){ |
14 | 16 | $('.button-collapse').sideNav(); |
... | ... | @@ -20,10 +22,14 @@ $(function(){ |
20 | 22 | var app = new Vue({ |
21 | 23 | el: 'body', |
22 | 24 | data: { |
25 | + // Constantes | |
26 | + PEUT_NFC: PEUT_NFC, | |
27 | + // Affichage | |
23 | 28 | page: 'connexion', |
24 | - connecte: false, | |
25 | 29 | erreurTitre: '', |
26 | 30 | erreurMessage: '', |
31 | + // Session | |
32 | + connecte: false, | |
27 | 33 | date: 1, |
28 | 34 | }, |
29 | 35 | methods: { |
... | ... | @@ -33,6 +39,10 @@ var app = new Vue({ |
33 | 39 | cb(data['status'], data); |
34 | 40 | }) |
35 | 41 | }, |
42 | + api: function(chemin, donnees, cb) { | |
43 | + donnees['jeton'] = this.jeton | |
44 | + this.apiBrute(chemin, donnees, cb) | |
45 | + }, | |
36 | 46 | // Affichage |
37 | 47 | toast: function(texte) { |
38 | 48 | Materialize.toast(texte, 4000); |
... | ... | @@ -68,11 +78,33 @@ var app = new Vue({ |
68 | 78 | } |
69 | 79 | }) |
70 | 80 | }, |
81 | + creer: function() { | |
82 | + if (!this.peutCreer) return | |
83 | + var that = this | |
84 | + this.api("client/ajouter", {idCarte: this.idCarte, solde: this.solde}, function(retour, donnees) { | |
85 | + switch(retour) { | |
86 | + case "ok": | |
87 | + that.toast("Client " + that.idCarte + " crée avec un solde de " + that.solde + " €") | |
88 | + break; | |
89 | + | |
90 | + case "solde_negatif": | |
91 | + that.toast("Solde négatif") | |
92 | + break; | |
93 | + | |
94 | + default: | |
95 | + that.erreur(retour, donnees); | |
96 | + break; | |
97 | + } | |
98 | + }); | |
99 | + } | |
71 | 100 | }, |
72 | 101 | computed: { |
73 | 102 | peutConnecter: function() { |
74 | 103 | return this.login && this.mdp; |
75 | 104 | }, |
105 | + peutCreer: function() { | |
106 | + return this.solde && (this.PEUT_NFC || this.idCarte) | |
107 | + }, | |
76 | 108 | timer: function() { |
77 | 109 | var secondes = this.connecte + JETON_DUREE - this.date |
78 | 110 | var minutes = Math.floor(secondes/60) | ... | ... |