-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathvip_unauth.js
More file actions
93 lines (78 loc) · 1.98 KB
/
vip_unauth.js
File metadata and controls
93 lines (78 loc) · 1.98 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
//////////////////////////////////////////////////////////////////////
function UnAuthCal()
{
// initialise
this.datespan = {dtStart: null, dtEnd: null};
this.forwardEvent = function(){};
this.api_key = "";
// private
this.calendars = {};
}
UnAuthCal.prototype.addCal = function(id)
{
this.calendars[id] = {clr: "#2b67cf"};
}
UnAuthCal.prototype.setCalClr = function(id, clr)
{
this.calendars[id].clr = clr;
}
UnAuthCal.prototype.loadEvents = function()
{
this.isoStart = this.datespan.dtStart.toISOString();
this.isoEnd = this.datespan.dtEnd.toISOString();
for (id in this.calendars)
this.reqEvents(id);
}
UnAuthCal.prototype.reqEvents = function(id, tok)
{
var path =
"https://www.googleapis.com/calendar/v3/calendars/" + encodeURIComponent(id) + "/events" +
"?timeMin=" + this.isoStart +
"&timeMax=" + this.isoEnd +
"&key=" + this.api_key +
"&singleEvents=true"
;
if (tok)
path += ("&pageToken=" + tok);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = this.rcvEvents.bind(this, xhttp, id);
xhttp.open("GET", path);
xhttp.send();
}
UnAuthCal.prototype.rcvEvents = function(xhttp, callsign)
{
if (xhttp.readyState == 4 && xhttp.status == 200)
{
var response = JSON.parse(xhttp.responseText);
var cal = this.calendars[callsign];
for (var i in response.items)
{
var item = response.items[i];
if (item.kind == "calendar#event")
if (item.status != "cancelled")
if (!item.hasOwnProperty("recurrence"))
if (item.hasOwnProperty("start"))
{
var evt = {
id: item.id,
title: item.summary,
colour: cal.clr,
calendar: response.summary
};
if ("dateTime" in item.start)
{
evt.timed = true;
evt.timespan = {start: item.start.dateTime, end: item.end.dateTime};
}
else
{
evt.timed = false;
evt.datespan = {start: item.start.date, end: item.end.date};
}
this.forwardEvent(evt);
}
}
if (response.nextPageToken)
this.reqEvents(callsign, response.nextPageToken);
}
}