-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreservation.js
More file actions
151 lines (138 loc) · 4.97 KB
/
Copy pathreservation.js
File metadata and controls
151 lines (138 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
class Reservation {
constructor() {
this.timerDiv = document.getElementById('timer');
this.timer = 0;
//------------------------------------------------------------- Evenements -------------------------------------------------------------
$('#reserSignature').click(this.displayReserv.bind(this));
$('#reserSignature').click(this.startTimer.bind(this));
$('.annuler').click(this.cancelReservation.bind(this));
$('#yesReserv').click(this.newReservYes.bind(this));
$('#noReserv').click(this.newReservNo.bind(this));
//Indexation des blocks formulaires, Affichages
$('#reserForm').click(this.displayFormInfo.bind(this));
//Sécurité formulaire nom prénom
$('#signez').click(this.errorMsg.bind(this));
if (window.sessionStorage.getItem('TimerMin')) {
this.startTimer();
}
}
//------------------------------------------------------------- Methods ------------------------------------------------------------
// Persistance d'une reservation en cours ET associée au bouton "Oui"
activReserv() {
if (window.sessionStorage.getItem('TimerMin')) {
$('#reservation').show();
$('.station').html(sessionStorage.getItem('Station'));
$('.nomReserv').html(localStorage.getItem('nom'));
$('.prenomReserv').html(localStorage.getItem('prénom'));
}
}
// Affichage div formulaire
displayFormInfo() {
$('#formInfo').fadeIn(1000);
$('#nom').val(localStorage.getItem('nom'));
$('#prenom').val(localStorage.getItem('prénom'));
$('#infos_station').hide();
if (window.sessionStorage.getItem('TimerMin')) {
$('#blockNewReservChoice').show();
$('#signez').hide();
}
}
// Message d'erreur SI formulaire incomplet
errorMsg() {
var nom = $('#nom').val();
var prenom = $('#prenom').val();
if (nom.length == 0 || prenom.length == 0) {
$('.erreur').show();
} else {
$('#signature').fadeIn(1000);
localStorage.setItem("nom", nom);
localStorage.setItem("prénom", prenom);
$('#formInfo').hide();
$('.erreur').hide();
}
}
// Afficher la div réservation
displayReserv() {
clearInterval(this.timer);
$('#reservation').fadeIn();
$('.expReserv').hide();
window.scrollTo(0, document.body.scrollHeight); // Scroll auto en bas de la page
$('#signature').hide();
$('#map').animate({
width: '100%',
});
$('.station').html(sessionStorage.getItem('Station'));
$('.nomReserv').html(localStorage.getItem('nom'));
$('.prenomReserv').html(localStorage.getItem('prénom'));
this.timerDiv.textContent = '';
}
// Timer de 20:00 ET conditions d'expiration du Timer
startTimer() {
let that = this;
let seconds = 0;
let minutes = 20;
let timerMin = window.sessionStorage.getItem('TimerMin');
let timerSec = window.sessionStorage.getItem('TimerSec');
if (timerMin && timerSec) {
minutes = timerMin;
seconds = timerSec;
}
this.timer = setInterval(function () {
timerMin = window.sessionStorage.setItem('TimerMin', minutes);
timerSec = window.sessionStorage.setItem('TimerSec', seconds);
if (seconds < 10) {
seconds = "0" + seconds;
}
if (minutes == 0 && seconds == 0) {
clearInterval(that.timer);
$('#reservation').hide();
$('.expReserv').show();
$('#blockNewReservChoice').hide();
$('#formInfo').hide();
$('#infos_station').hide();
$('#map').css('width', '100%');
$('#signez').show();
sessionStorage.clear();
canvas.delete();
} else if (seconds == 0) {
minutes = minutes - 1;
seconds = 59;
} else {
seconds = seconds - 1;
}
that.timerDiv.textContent = sessionStorage.getItem('TimerMin') + ':' + (('' + sessionStorage.getItem('TimerSec')).length > 1 ? '' : '0') + sessionStorage.getItem('TimerSec'); // Affichage du timer en html
}, 1000);
}
// Annuler réservation
cancelReservation() {
sessionStorage.clear();
canvas.delete();
$('.cancelReserv').fadeIn().delay(3000).fadeOut(1000);
$('#reservation').hide();
$('#blockNewReservChoice').hide();
$('#signez').show();
$('#map').css('width', '100%');
$('#formInfo').hide();
$('#infos_station').hide();
clearInterval(this.timer);
this.timerDiv.textContent = '';
}
// Nouvelle réservation
newReservYes() {
this.timerDiv.textContent = '';
sessionStorage.removeItem('TimerMin');
sessionStorage.removeItem('TimerSec');
canvas.delete();
$('.cancelReserv').fadeIn().delay(3000).fadeOut(1000);
$('#reservation').hide();
$('.expReserv').hide();
$('#blockNewReservChoice').hide();
$('#signez').show();
clearInterval(this.timer);
}
// Methode associé au bouton "Non"
newReservNo() {
$('#map').css('width', '100%');
$('#formInfo').hide();
}
}