-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
374 lines (306 loc) · 9.75 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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// calendar
var CLIENT_ID = '368873152645-6817bgr1i23hk3aig7du1u2bu6s82o3q.apps.googleusercontent.com';
var API_KEY = 'AIzaSyBjtLM_O5xj5ASZixVzGRkempSuZAHGymQ';
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://www.googleapis.com/auth/calendar";
var authorizeButton = document.getElementById('authorize-button');
var signoutButton = document.getElementById('signout-button');
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
gapi.client.init({
apiKey: API_KEY,
clientId: CLIENT_ID,
discoveryDocs: DISCOVERY_DOCS,
scope: SCOPES
}).then(function () {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
authorizeButton.onclick = handleAuthClick;
signoutButton.onclick = handleSignoutClick;
});
}
/**
* Called when the signed in status changes, to update the UI
* appropriately. After a sign-in, the API is called.
*/
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
authorizeButton.style.display = 'none';
signoutButton.style.display = 'inline-block';
} else {
authorizeButton.style.display = 'inline-block';
signoutButton.style.display = 'none';
}
}
/**
* Sign in the user upon button click.
*/
function handleAuthClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
/**
* Sign out the user upon button click.
*/
function handleSignoutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
// AJAX - load from txt file
function loaddata()
{
// get details from localStorage
var details = JSON.parse(localStorage.getItem('details'));
//console.log(details);
// change colors if not theme1
if(details.theme != "1")
{
$('link[href="./main1.css"]').attr({href : "./main" + details.theme.replace("theme", "") + ".css"});
$("#roomdiv").attr("class", "list-group-item list-group-item-dark");
$("#phonediv").attr("class", "list-group-item list-group-item-secondary");
$("#emaildiv").attr("class", "list-group-item list-group-item-dark");
$("#p1").attr("class", "list-group-item list-group-item-dark");
$("#p2").attr("class", "list-group-item list-group-item-secondary");
$("#p3").attr("class", "list-group-item list-group-item-dark");
$("#p4").attr("class", "list-group-item list-group-item-secondary");
$(".badge").attr("class", "badge badge-dark float-right badge-pill");
}
var headingname, maintitle, headingtitle, email, imgsrc, room, phone;
// AJAX calls to different files
// name
$.ajax({
url:"./data/name.txt",
success: function (data){
//console.log(data);
var lines = data.split('\n');
headingname = lines[details.pos];
$("#headingname").text(headingname);
maintitle = headingname + " at IIT Guwahati";
document.title = maintitle;
initialarray = headingname.split(' ');
initials = "";
for(pos in initialarray)
{
initials += initialarray[pos].charAt(0);
}
$("a[class='navbar-brand']").text(initials);
// google search for papers
$.ajax({
type: "POST",
url:"./papers.php",
data: { fullname : headingname},
success: function (){
console.log("added research papers.");
$.ajax({
url:"./data/papers.txt",
success: function (data){
var lines = data.split('\n');
// remove empty strings
for (var i = 1; i <= 4; i++)
{
var linktext;
if(lines[i].split('*').filter(Boolean)[0].length > 75)
{
linktext = lines[i].split('*').filter(Boolean)[0].substr(0, 75) + "...";
}
else
{
linktext = lines[i].split('*').filter(Boolean)[0];
}
$('#link' + i).text(linktext);
$('#p' + i).attr("href", lines[i].split('*').filter(Boolean)[1]);
}
}
});
}
});
}
});
// title
$.ajax({
url:"./data/title.txt",
success: function (data){
//console.log(data);
var lines = data.split('\n');
headingtitle = lines[details.pos];
$("#headingtitle").text(headingtitle);
}
});
// research
$.ajax({
url:"./data/research.txt",
success: function (data){
//console.log(data);
var lines = data.split('\n');
$("#research").text(lines[details.pos]);
}
});
// room
$.ajax({
url:"./data/room.txt",
success: function (data){
// console.log(data);
var lines = data.split('\n');
room = lines[details.pos] + ", CSE Department";
$("#room").text(room);
}
});
// phone
$.ajax({
url:"./data/phone.txt",
success: function (data){
// console.log(data);
var lines = data.split('\n');
phone = lines[details.pos];
$("#phone").text(phone);
}
});
email = details.webmail;
$("#email").text(email);
imgsrc = details.imgsrc;
if(imgsrc != "NULL")
{
$("#headingimage").attr("src", "./images/" + imgsrc);
}
// only once calendar is loaded
$("#calendar").one('load', function() {
$.ajax({
url:"./data/timet.txt",
success: function (data){
//console.log(data);
var lines = data.split('\n');
var coursename;
for (var i = 0; i < lines.length; i++) {
var times = lines[i].split(/\s+/);
var coursename = times[0].trim();
var valid = false;
for(var property in details)
{
if((details.hasOwnProperty(property)) && (property.indexOf(coursename) !== -1))
{
//console.log(property, "and", coursename);
if(details[property] == true)
{
valid = true;
coursename = property;
break;
}
}
}
if(!valid)
{
// console.log(coursename, "not taken.");
continue;
}
else
{
// console.log(coursename, "taken!");
}
for (var j = 1; j < times.length; ++j)
{
if((times[j] != "NULL") && (times[j].length != 0))
{
// console.log(times[j]);
var starttime = moment(times[j], 'YYYY-MM-DD HH:mm:ss').subtract(5, 'weeks').format();
var endtime = moment(times[j], 'YYYY-MM-DD HH:mm:ss').subtract(5, 'weeks').add(1, 'hours').format();
//console.log(starttime, endtime, coursename);
addevent(starttime, endtime, coursename, ["RRULE:FREQ=WEEKLY;UNTIL=20180301T170000Z"]);
}
}
}
}
});
});
};
$(document).ready(function() {loaddata();});
// date
$(function () {
$('#datetimepicker1').datetimepicker();
});
// hide alerts
$("#requestmeeting").one("click", function (){
$('#alertbox1').hide();
$('#alertbox2').hide();
});
$('#alertbox1').hide();
$('#alertbox2').hide();
// alert message
$("#submitModal").on("hidden.bs.modal", function(){
$('#alertbox1').hide();
$('#alertbox2').hide();
});
$("#submitModal").on("show", function(){
$('#alertbox1').hide();
$('#alertbox2').hide();
});
function addmeeting()
{
var fullname = document.getElementById('fullname').value;
var starttime = moment(document.getElementById('datetime').value, 'MM/DD/YYYY hh:mm A').format();
var endtime = moment(document.getElementById('datetime').value, 'MM/DD/YYYY hh:mm A').add(1, 'hours').format();
console.log(starttime, endtime);
var rval = addevent(starttime, endtime, "Meeting with " + fullname);
return rval;
}
function addevent(starttime, endtime, title, recurrence = [])
{
// check if free first
var busyquery = gapi.client.calendar.freebusy.query({
"timeMin": starttime,
"timeMax": endtime,
"timeZone": "Asia/Kolkata",
"items": [
{
"id": "primary"
}
]
});
var free = false;
busyquery.execute(function(resp) {
if(resp.calendars.primary.busy.length > 0)
{
console.log("I'm busy");
$("#alertbox1").show();
$("#alertbox2").hide();
return;
}
else {
console.log("Free!");
$("#alertbox1").hide();
$("#alertbox2").show();
free = true;
}
if(free)
{
var resource = {
"end": {
"dateTime": endtime,
"timeZone": "Asia/Kolkata"
},
"start": {
"dateTime": starttime,
"timeZone": "Asia/Kolkata"
},
"summary": title,
"recurrence": recurrence
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': resource
});
request.execute();
// reload calendar
document.getElementById('calendar').src = document.getElementById('calendar').src;
return true;
}
});
};