79bb411d
Geoffrey PREUD'HOMME
Possibilité de se...
|
1
2
3
4
5
6
7
8
9
10
11
|
// Constantes
var JETON_TAILLE = 30 // Taille d'un jeton
var JETON_DUREE = 10*60 // Temps de validité du jeton en secondes
var TRANSACTION_CREATION = 1
var TRANSACTION_RECHARGEMENT = 2
var TRANSACTION_PAIEMENT = 3
var TRANSACTION_VIDANGE = 4
var TRANSACTION_DUREE = 60
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
12
13
|
var PEUT_NFC = false
|
07329faa
Geoffrey PREUD'HOMME
Simplification de...
|
14
|
// Préparation de l'interactivité
|
bf26706c
Geoffrey PREUD'HOMME
Écran principal
|
15
16
17
|
$(function(){
$('.button-collapse').sideNav();
$('.modal-trigger').leanModal()
|
07329faa
Geoffrey PREUD'HOMME
Simplification de...
|
18
|
$('form').submit(function() { return false });
|
4525b510
Geoffrey PREUD'HOMME
Des trucs useless
|
19
|
$('[name=idCarte]').characterCounter();
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
20
|
});
|
bf26706c
Geoffrey PREUD'HOMME
Écran principal
|
21
|
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
22
|
// Application
|
79bb411d
Geoffrey PREUD'HOMME
Possibilité de se...
|
23
|
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
24
25
26
|
var app = new Vue({
el: 'body',
data: {
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
27
28
29
|
// Constantes
PEUT_NFC: PEUT_NFC,
// Affichage
|
e5e2f19a
Geoffrey PREUD'HOMME
Mutli-pages
|
30
|
page: 'connexion',
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
31
32
|
erreurTitre: '',
erreurMessage: '',
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
33
34
|
// Session
connecte: false,
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
35
36
37
38
39
40
41
42
43
|
date: 1,
},
methods: {
// API
apiBrute: function(chemin, donnees, cb) {
$.post('api/' + chemin, donnees, function(data) {
cb(data['status'], data);
})
},
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
44
45
46
47
|
api: function(chemin, donnees, cb) {
donnees['jeton'] = this.jeton
this.apiBrute(chemin, donnees, cb)
},
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
48
49
50
51
52
53
54
55
56
|
// Affichage
toast: function(texte) {
Materialize.toast(texte, 4000);
},
erreur: function(retour, donnees) {
this.erreurTitre = retour
this.erreurMessage = donnees['message']
$("#modalErreur").openModal();
},
|
c450b12e
Geoffrey PREUD'HOMME
Annulation + ombres
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
annuler(id) {
var that = this
this.api("annuler", {idTransaction: id}, function(retour, donnees) {
switch(retour) {
case "ok":
that.toast("Client " + donnees.client + " : " + donnees.soldeAncien + " → " + donnees.soldeNouveau)
break;
default:
that.erreur(retour, donnees);
break;
}
});
},
transaction(id, texte) {
var that = this
var interieur = $('<span>').text(texte + ' ').append($('<a>').text('Annuler').one('click', function() {
that.annuler(id)
}))
that.toast(interieur);
},
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
78
79
|
// Fonctionnement
connecter: function() {
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
80
81
82
83
84
85
86
87
88
|
var that = this;
this.apiBrute("utilisateur/connexion", {login: this.login , mdp: this.mdp} , function(retour, donnees) {
that.mdp = ''
switch(retour) {
case "ok":
that.login = donnees.login
that.droit = donnees.droit
that.jeton = donnees.jeton
that.connecte = that.date
|
e5e2f19a
Geoffrey PREUD'HOMME
Mutli-pages
|
89
90
|
that.toast("Correctement identifié en tant que " + that.login + " pour " + JETON_DUREE/60+ " minutes")
that.page = 'operations'
|
c450b12e
Geoffrey PREUD'HOMME
Annulation + ombres
|
91
|
break;
|
79bb411d
Geoffrey PREUD'HOMME
Possibilité de se...
|
92
|
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
93
94
95
96
97
|
default:
that.erreur(retour, donnees);
break;
}
})
|
07329faa
Geoffrey PREUD'HOMME
Simplification de...
|
98
|
return false
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
99
|
},
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
100
|
creer: function() {
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
101
102
103
104
|
var that = this
this.api("client/ajouter", {idCarte: this.idCarte, solde: this.solde}, function(retour, donnees) {
switch(retour) {
case "ok":
|
c450b12e
Geoffrey PREUD'HOMME
Annulation + ombres
|
105
|
that.transaction(donnees.idTransaction, "Client " + that.idCarte + " crée avec un solde de " + that.solde + " €")
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
106
107
|
break;
|
1dc9797d
Geoffrey PREUD'HOMME
Reste des transac...
|
108
109
110
111
112
113
114
115
116
117
118
|
default:
that.erreur(retour, donnees);
break;
}
});
},
recharger: function() {
var that = this
this.api("client/recharger", {idCarte: this.idCarte, montant: this.credit}, function(retour, donnees) {
switch(retour) {
case "ok":
|
c450b12e
Geoffrey PREUD'HOMME
Annulation + ombres
|
119
|
that.transaction(donnees.idTransaction, "Client " + that.idCarte + " rechargé : " + donnees.soldeAncien + " + " + that.credit + " → " + donnees.soldeNouveau + " €")
|
344a37ad
Geoffrey PREUD'HOMME
Création de clients
|
120
121
122
123
124
125
126
|
break;
default:
that.erreur(retour, donnees);
break;
}
});
|
1dc9797d
Geoffrey PREUD'HOMME
Reste des transac...
|
127
128
129
130
131
132
133
134
135
136
137
138
|
},
payer: function(quantite) {
var that = this
var options = {idCarte: this.idCarte}
if (typeof(quantite) == 'number') {
options.quantite = quantite
} else {
options.montant = that.prix
}
this.api("client/payer", options, function(retour, donnees) {
switch(retour) {
case "ok":
|
c450b12e
Geoffrey PREUD'HOMME
Annulation + ombres
|
139
|
that.transaction(donnees.idTransaction, "Client " + that.idCarte + " débité : " + donnees.soldeAncien + " - " + donnees.montant + " → " + donnees.soldeNouveau + " €")
|
1dc9797d
Geoffrey PREUD'HOMME
Reste des transac...
|
140
141
142
143
144
145
146
147
148
149
150
151
152
|
break;
default:
that.erreur(retour, donnees);
break;
}
});
},
vidanger: function() {
var that = this
this.api("client/vidange", {idCarte: this.idCarte}, function(retour, donnees) {
switch(retour) {
case "ok":
|
c450b12e
Geoffrey PREUD'HOMME
Annulation + ombres
|
153
|
that.transaction(donnees.idTransaction, "Client " + that.idCarte + " vidé : " + donnees.soldeAncien + " → 0 €")
|
1dc9797d
Geoffrey PREUD'HOMME
Reste des transac...
|
154
155
156
157
158
159
160
161
|
break;
default:
that.erreur(retour, donnees);
break;
}
});
},
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
162
163
|
},
computed: {
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
164
165
|
timer: function() {
var secondes = this.connecte + JETON_DUREE - this.date
|
e5e2f19a
Geoffrey PREUD'HOMME
Mutli-pages
|
166
167
168
|
var minutes = Math.floor(secondes/60)
var secondes = secondes % 60
return minutes + ':' + (secondes < 10 ? '0' : '') + secondes
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
169
170
171
|
}
},
})
|
79bb411d
Geoffrey PREUD'HOMME
Possibilité de se...
|
172
|
|
2146d35a
Geoffrey PREUD'HOMME
Vue interactive
|
173
174
175
|
setInterval(function actualiserDate() {
app.$data.date = Math.floor(Date.now()/1000)
}, 1000);
|
79bb411d
Geoffrey PREUD'HOMME
Possibilité de se...
|
176
|
|
79bb411d
Geoffrey PREUD'HOMME
Possibilité de se...
|
177
178
|
// Placeholder
|
bf26706c
Geoffrey PREUD'HOMME
Écran principal
|
179
180
181
182
183
184
185
186
187
188
|
function vendu() {
var interieur = $("<span>").text("Vendu 1 bière à KAE1EET2YI (15,30 € → 13,50 €) ").append(
$("<a>").attr("href", "#!").text("Annuler")
);
Materialize.toast(interieur, 4000);
}
function soldeInsuffisant() {
$("#soldeInsuffisant").openModal();
}
|
79bb411d
Geoffrey PREUD'HOMME
Possibilité de se...
|
|
|