-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·297 lines (252 loc) · 10.9 KB
/
index.html
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!DOCTYPE html>
<head>
<title>Turgeman and Lailari Calendar</title>
<link rel="stylesheet" type="text/css" href="calendarPageStyle.css">
<script type="text/javascript" src="extensible/Extensible-config.js"></script>
<script type="text/javascript" src="remote.js"></script>
<script type="text/javascript">
var loginForm;
var userFunctionsForm;
var currentUserName;
document.addEventListener("DOMContentLoaded", domLoaded, false);
function domLoaded() {
document.getElementById("log_in").addEventListener("click",checkLogin,false);
document.getElementById("register").addEventListener("click",register,false);
document.getElementById("addCalendar").addEventListener("click",addCostumeCalendar,false);
document.getElementById("deleteCalendarBtn").addEventListener("click",deleteCalendar,false);
document.getElementById("shareEventBtn").addEventListener("click",shareEvent,false);
loginForm = document.getElementById("loginRegistrationForm");
checkIfAlreadyLogedIn();
userFunctionsForm = document.getElementById("userFunctionsForm");
document.getElementById("userFunctionsForm").remove();
loadCalendarData();
}
function checkLogin() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "backend/login.php", true);
xmlHttp.addEventListener("load", checkLoginCallBack, false);
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("username=" + encodeURIComponent(username) + "&password=" + encodeURIComponent(password));
}
function checkLoginCallBack() {
var loginResponse = JSON.parse(event.target.responseText);
if (loginResponse.success) {
document.getElementById("body").appendChild(userFunctionsForm);
document.getElementById("loginRegistrationForm").remove()
document.getElementById("helloUser").innerHTML = Ext.String.htmlEncode(loginResponse.username);
currentUserName = Ext.String.htmlEncode(loginResponse.username);
reloadCalendarData();
reloadEventsData();
loadUserCalendarsListToDOM();
loadUserEventsListToDOM();
loadUsersListToDOM();
} else {
if (loginResponse.tryToLogin) {
alert("EROOR: " + loginResponse.message);
}
}
}
function checkIfAlreadyLogedIn() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "backend/isLogin.php", true);
xmlHttp.addEventListener("load", checkLoginCallBack, false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(null);
}
function registerCallback() {
checkLogin();
}
function register() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "backend/addUser.php", true);
xmlHttp.addEventListener("load", registerCallback, false);
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("username=" + encodeURIComponent(username) + "&password=" + encodeURIComponent(password));
}
function addCostumeCalendar() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "backend/addCalendar.php", true);
xmlHttp.addEventListener("load", addCostumeCalendarCallBack, false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var calendarName = document.getElementById("calendarName").value;
document.getElementById("calendarName").value = "";
var calendarColor = document.getElementById("calendarColor").value;
document.getElementById("calendarColor").value = "";
var sessionToken = document.getElementById("hiddenToekn").value;
xmlHttp.send("calendarName=" + encodeURIComponent(calendarName)
+ "&calendarColor=" + encodeURIComponent(calendarColor)
+ "&token=" + encodeURIComponent(sessionToken));
}
function addCostumeCalendarCallBack(event) {
var addCostumeCalendarResponse = JSON.parse(event.target.responseText);
if (addCostumeCalendarResponse.success) {
Extensible.example.msg('Add', 'Added New Calendar "' + Ext.util.Format.htmlEncode(addCostumeCalendarResponse.calendarName) + '"');
loadUserCalendarsListToDOM();
reloadCalendarData();
} else {
Extensible.example.msg('ERROR', encodeURIComponent(addCostumeCalendarResponse.message));
}
}
function loadUsersListToDOM() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "./backend/app.php/users?", true);
xmlHttp.addEventListener("load",
function(event) {
var usersListElement = document.getElementById("usersList");
usersListElement.innerHTML = "";
var usersList = JSON.parse(event.target.responseText);
var option;
var currentUser;
for (var i = 0; i < usersList.length; i++) {
currentUser = usersList[i];
option = document.createElement("option");
option.setAttribute("value", currentUser.id);
option.innerHTML = currentUser.userName;
usersListElement.appendChild(option);
}
}
, false);
xmlHttp.send(null);
}
function loadUserCalendarsListToDOM() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "./backend/app.php/calendars", true);
xmlHttp.addEventListener("load", loadUserCalendarsListToDOMCallBack, false);
xmlHttp.send(null);
}
function loadUserCalendarsListToDOMCallBack(event) {
var userCalendarsListElement = document.getElementById("userCalendarsList");
userCalendarsListElement.innerHTML = "";
var calendarsList = JSON.parse(event.target.responseText).calendars;
var option;
var currentCalendarName;
for (var i = 0; i < calendarsList.length; i++) {
currentCalendar = calendarsList[i];
option = document.createElement("option");
option.setAttribute("value", currentCalendar.id);
option.innerHTML = currentCalendar.title;
userCalendarsListElement.appendChild(option);
}
}
function loadUserEventsListToDOM() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "./backend/app.php/events?", true);
xmlHttp.addEventListener("load",
function(event) {
var eventsListElement = document.getElementById("userEventsList");
eventsListElement.innerHTML = "";
var eventsList = JSON.parse(event.target.responseText).data;
var option;
var currentEvent;
for (var i = 0; i < eventsList.length; i++) {
currentEvent = eventsList[i];
option = document.createElement("option");
option.setAttribute("value", currentEvent.id);
option.innerHTML = currentEvent.title;
eventsListElement.appendChild(option);
}
}
, false);
xmlHttp.send(null);
}
function shareEvent() {
var recieverUserElement = document.getElementById("usersList");
var recieverUser = recieverUserElement.options[recieverUserElement.selectedIndex].value;
var senderEventToShareElement = document.getElementById("userEventsList");
var senderEventToShare = senderEventToShareElement.options[senderEventToShareElement.selectedIndex].value;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "./backend/shareEvent.php", true);
xmlHttp.addEventListener("load", function(event){
Extensible.example.msg('Event Shared', "Event was shared!");
}
, false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("eventId=" + encodeURIComponent(senderEventToShare)
+ "&senderUserName=" + encodeURIComponent(currentUserName)
+ "&recieverUserId=" + encodeURIComponent(recieverUser));
}
function deleteCalendar() {
var userCalendarsListElement = document.getElementById("userCalendarsList");
var calendarIdToDelete = userCalendarsListElement.options[userCalendarsListElement.selectedIndex].value;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "./backend/app.php/calendars", true);
xmlHttp.addEventListener("load", function(event){
reloadCalendarData();
reloadEventsData();
loadUserCalendarsListToDOM();
}
, false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("calendarId=" + encodeURIComponent(calendarIdToDelete));
}
function reloadCalendarData() {
Ext.getStore("Calendars").loadData([], false);
Ext.getStore("Calendars").load();
}
function reloadEventsData() {
Ext.getStore("Events").loadData([], false);
Ext.getStore("Events").load();
}
function logout() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "backend/logout.php", true);
xmlHttp.addEventListener("load", logoutCallBack, false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(null);
}
function logoutCallBack() {
reloadCalendarData();
reloadEventsData();
document.getElementById("userFunctionsForm").remove();
document.getElementById("body").appendChild(loginForm);
}
</script>
</head>
<body id="body">
<div id="cal" class="sample-ct" ></div>
<div id="loginRegistrationForm">
<label for="username">Username: </label>
<input type="text" id="username" required name="username"/>
<br/>
<label for="password">Password: </label>
<input type="password" id="password" required name="password"/>
<br/>
<button value="login" value="Login" id="log_in">Login</button>
<button value="Register" id="register">Register</button>
</div>
<div id="token" style="display: none;" value="<?php require 'safeSession.php'; startSessionSafe(); echo $_SESSION['token'];?>" />
<input type="hidden" name="token" id="hiddenToekn" value="<?php echo $_SESSION['token'];?>" />
<div id="userFunctionsForm">
<h1>Hello, <span id=helloUser></span> (<a id="logout" href="#" onclick="logout();return false;">Logout</a>)</h1>
<h2>Add your own calendar</h2>
<label for="calendarName">Calendar Name: </label>
<input type="text" id="calendarName" required name="calendarName"/>
<br>
<label for="calendarColor">Color: </label>
<input type="number" id="calendarColor" required />
<br/>
<button value="addCalendar" id="addCalendar">Add</button>
<br/>
<h2>Delete your calendar:</h2>
<label for="userCalendarsList">Calendar: </label>
<select id="userCalendarsList">
</select>
<br>
<button value="deleteCalendar" id="deleteCalendarBtn">Delete Calendar</button>
<br>
<h2>Share event with a friend</h2>
<label for="userEventsList">Event Name: </label>
<select id="userEventsList">
</select>
<br>
<label for="usersList">Username: </label>
<select id="usersList">
</select>
<button value="shareEventBtn" id="shareEventBtn">Share</button>
</div>
</body>
</html>