This repository has been archived by the owner on Oct 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
216 lines (215 loc) · 6.91 KB
/
main.js
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
var testUser = false;
var eventId = -1;
var pastEvent = false;
$(document).ready(function(){
//burger menu when little screen
$('#menu').click(function(){
$(this).toggleClass('fa-times');
$('.navbar').toggleClass('nav-toggle');
});
//default parameters
if($('#content')){
//verification if User is connected
checkUser();
home();
}
//change of content with de navbar
$('#home').click(function(event) {
event.preventDefault();
resetNavBar();
if(testUser)document.getElementById("log").classList.add("active");
pastEvent = false;
home();
});
$('#pastEvent').click(function(event) {
event.preventDefault();
resetNavBar();
document.getElementById("pastEvent").classList.add("active");
if(testUser)document.getElementById("log").classList.add("active");
pastEvent = true;
$('#content').load('php/displayPastEvent.php');
});
$('#futurEvent').click(function(event) {
event.preventDefault();
resetNavBar();
document.getElementById("futurEvent").classList.add("active");
if(testUser)document.getElementById("log").classList.add("active");
pastEvent = false;
$('#content').load('php/displayFuturEvent.php');
});
$('#cart').click(function(event) {
event.preventDefault();
resetNavBar();
document.getElementById("cart").classList.add("active");
if(testUser)document.getElementById("log").classList.add("active");
var intervalID = window.setInterval(function(){
if(document.getElementById("cart").className=="fas fa-shopping-cart active"){
createCookie("sizeScreen",window.screen.availWidth);
$('#content').load('php/displayCart.php');
}
},1000);
});
$('#log').click(function(event) {
event.preventDefault();
resetNavBar();
document.getElementById("log").classList.add("active");
if(testUser){
$('#content').load('php/displayProfil.php');
}else{
$('#content').load('php/displayLogin.php');
}
});
});
$(document).on('click','#btnSearch',function(event){
event.preventDefault();
resetNavBar();
if(testUser)document.getElementById("log").classList.add("active");
$.ajax({url:"php/search.php",
type:'POST',
data:$('#searchForm').serialize(),
success:function(){
$('#content').load('php/displaySearch.php');
}
});
});
$(document).on('keypress','#search',function(event){
if (event.key === 'Enter' || event.keyCode === 13) {
event.preventDefault();
resetNavBar();
if(testUser)document.getElementById("log").classList.add("active");
$.ajax({url:"php/search.php",
type:'POST',
data:$('#searchForm').serialize(),
success:function(){
$('#content').load('php/displaySearch.php');
}
});
}
});
$(document).on('click','.overlay a',function(event){
event.preventDefault();
resetNavBar();
if(testUser)document.getElementById("log").classList.add("active");
createCookie("eventId", this.id);
createCookie("eventPast", pastEvent);
$('#content').load('php/displayEvent.php');
});
$(document).on('click','td a',function(event){
event.preventDefault();
$.ajax({url:"php/removeCart.php",
type: 'POST',
data:{rowNumber:this.id},
success:function(){
$('#content').load('php/displayCart.php');
}
});
});
$(document).on('click','#addCart',function(event) {
event.preventDefault();
$.ajax({url:"php/addCart.php",
type:'POST',
data:$('#addCartForm').serialize(),
success:function(){
resetNavBar();
document.getElementById("cart").classList.add("active");
if(testUser)document.getElementById("log").classList.add("active");
var intervalID = window.setInterval(function(){
if(document.getElementById("cart").className=="fas fa-shopping-cart active"){
createCookie("sizeScreen",window.screen.availWidth);
$('#content').load('php/displayCart.php');
}
},1000);
}
});
});
$(document).on('click','#PaymentShop',function(event) {
event.preventDefault();
$.ajax({url:"php/payementAtShop.php",
success:function(){
resetNavBar();
document.getElementById("log").classList.add("active")
$('#content').load('php/displayProfil.php');
}
});
});
$(document).on('click','#PaymentPayPal',function(event) {
event.preventDefault();
$.ajax({url:"php/payementValidation.php",
type:'POST',
data:{typePayement:"Paypal"},
success:function(){
resetNavBar();
document.getElementById("log").classList.add("active")
$('#content').load('php/displayProfil.php');
}
});
});
$(document).on('click','#PaymentCreditCard',function(event) {
event.preventDefault();
$.ajax({url:"php/payementValidation.php",
type:'POST',
data:{typePayement:"Credit Card"},
success:function(){
resetNavBar();
document.getElementById("log").classList.add("active")
$('#content').load('php/displayProfil.php');
}
});
});
$(document).on('click','#btnSignin',function(event) {
event.preventDefault();
$.ajax({url:"php/signin.php",
type:'POST',
data:$('#signinForm').serialize(),
success:function(){
resetNavBar();
home();
}
});
});
$(document).on('click','#btnUpdate',function(event) {
event.preventDefault();
$.ajax({url:"php/update.php",
type:'POST',
data:$('#updateForm').serialize(),
success:function(){
$('#content').load('php/displayProfil.php');
}
});
});
$(document).on('click','#btnLogout',function(event) {
event.preventDefault();
resetNavBar();
$('#content').load('php/logout.php');
alert("You have been disconnected");
checkUser();
home();
});
//reset all the navbar
function checkUser(){
$.ajax({
url: "php/checkUserConnection.php",
dataType: 'json'
}).done(function(data) {
testUser = data;
if(testUser)document.getElementById("log").classList.add("active");
});
}
function home(){
document.getElementById("home").classList.add("active");
$('#content').load('php/displayHome.php');
}
function resetNavBar(){
document.getElementById("home").classList.remove("active");
document.getElementById("pastEvent").classList.remove("active");
document.getElementById("futurEvent").classList.remove("active");
document.getElementById("cart").classList.remove("active");
document.getElementById("log").classList.remove("active");
}
function createCookie(name, value) {
var expires;
var date = new Date();
date.setTime(date.getTime() + (1 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}