-
Notifications
You must be signed in to change notification settings - Fork 0
/
agenda-overzicht.xml
154 lines (140 loc) · 5.85 KB
/
agenda-overzicht.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="CGK Agenda overzicht"
directory_title="CGK Agenda overzicht"
description="Google Calendar overzicht als activiteiten lijst"
author="R.Brouwer"
author_email="r-gg-cgk@corine-robert.nl">
<Require feature="dynamic-height"/>
<Require feature="setprefs"/>
</ModulePrefs>
<UserPref name="feed" display_name="Calendar XML Feed" default_value="http://www.google.com/calendar/feeds/cgk-utrechtwest.nl_cl113v8kbb328q7b3c61n4gth4%40group.calendar.google.com/public/basic" datatype="string" required="true"/>
<UserPref name="days-ahead" display_name="Days ahead" default_value="30" datatype="string" required="true"/>
<UserPref name="max-items" display_name="Maximum number of items" default_value="5" datatype="string" required="true"/>
<Content type="html">
<![CDATA[
<style type="text/css">
html,div#content_div, td.agendaitem {
font-family:arial,sans-serif;
font-size: 12px;
font-style:normal;
font-weight:normal;
line-height:15px;
}
</style>
<div id="content_div"></div>
<script type="text/javascript">
// get prefs
var prefs = new gadgets.Prefs();
//convert an Atom-formatted date string to a javascript-compatible date string
function convertAtomDateString(str)
{
//YYYY-MM-DDThh:mm:ss[.f*](Z|-hh:mm|+hh:mm)
var atomFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d*)?(Z|[+-]\d{2}:\d{2})$/i;
if(!atomFormat.test(str)) return ""; //invalid format
var months = new Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var year, month, date, hour, minute, second, offset;
year = str.slice(0,4);
month = months[1*str.slice(5,7)]; //Jan-Dec
date = str.slice(8,10); //01-31
hour = str.slice(11,13); //00-23
minute = str.slice(14,16); //00-59
second = str.slice(17,19); //00-59
offset = "GMT";
if(str.indexOf("Z") == -1) //time zone offset specified
{
var x = str.lastIndexOf(":");
offset += str.slice(x-3,x) + str.slice(x+1);
}
//DD MMM YYYY hh:mm:ss GMT[(+|-)hhmm]
return date+" "+month+" "+year+" "+hour+":"+minute+":"+second+" "+offset;
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
// Get the date
function makeRFCDate(delta) {
d = new Date();
d = new Date(d.getTime()+delta*24*60*60*1000);
mon = d.getMonth()+1;
if (mon.toString().length == 1) mon = "0" + mon;
day = d.getDate();
if (day.toString().length == 1) day = "0" + day;
hour = d.getHours();
if (hour.toString().length == 1) hour = "0" + hour;
min = d.getMinutes();
if (min.toString().length == 1) min = "0" + min;
sec = d.getSeconds();
if (sec.toString().length == 1) sec = "0" + sec;
return d.getFullYear()+"-"+mon+"-"+day+"T"+hour+":"+min+":"+sec;
}
function makeDOMRequest() {
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
var feed_url = prefs.getString("feed");
var start_min = makeRFCDate(0);
var start_max = makeRFCDate(prefs.getString("days-ahead"));
// http://code.google.com/intl/nl/apis/calendar/data/2.0/reference.html
// enhanced the query for more correct retrieval of interesing events.
var url = feed_url.replace('/basic','/full')+"?start-min=" + start_min + "&start-max=" + start_max + "&orderby=starttime&singleevents=true&sortorder=ascending";
// var url = feed_url.replace('/basic','/full');
gadgets.io.makeRequest(url, response, params);
};
function response(obj) {
var months=new Array('jan','feb','mrt','apr','mei','jun','jul','aug','sep','okt','nov','dec');
var weekday=new Array('Zo','Ma','Di','Wo','Do','Vr','Za');
// Start building HTML string that will be displayed in <div>.
// Set the style for the <div>.
var html = "<table>";
var html_rows = "";
// obj.data contains a Document DOM element corresponding to the
// page that was requested
var domdata = obj.data;
if (!domdata) {
document.getElementById('content_div').innerHTML = 'No data found in '+obj;
return;
}
// Get all entries in the agenda...
var max_items = prefs.getString("max-items");
var itemList = domdata.getElementsByTagName("entry");
for (var i = 0; i < itemList.length && i < max_items; i++) {
var nodeList = itemList.item(i).childNodes;
// Loop through child nodes. Extract data from the text nodes that are
// the children of the associated name, price, and calories element nodes.
var cdate;
var cstart;
var cend;
var cwhere;
var title;
for (var j = 0; j < nodeList.length ; j++) {
var node = nodeList.item(j);
if (node.nodeName == "title") {
title = node.firstChild.nodeValue;
}
if (node.nodeName == "gd:when") {
cstart = new Date(convertAtomDateString(node.getAttribute('startTime')));
cend = new Date(convertAtomDateString(node.getAttribute('endTime')));
}
if (node.nodeName == "gd:where") {
cwhere = node.getAttribute('valueString');
}
}
cdate=weekday[cstart.getDay()]+" "+cstart.getDate()+" "+months[ cstart.getMonth() ]+" "+cstart.getFullYear();
var cstend=pad(cstart.getHours(),1)+":"+pad(cstart.getMinutes(),2)+" tot "+pad(cend.getHours(),1)+":"+pad(cend.getMinutes(),2);
html_entry= "<tr><td class=\"agendaitem\"><b>"+cdate+"</b></td><td class=\"agendaitem\">"+title+"</td></tr>";
html_entry+= "<tr><td class=\"agendaitem\">"+cwhere+"</td><td class=\"agendaitem\">"+cstend+"</td></tr>";
html_rows+=html_entry;
}
html += html_rows + "</table>";
document.getElementById('content_div').innerHTML = html;
gadgets.window.adjustHeight();
}
gadgets.util.registerOnLoadHandler(makeDOMRequest);
</script>
]]>
</Content>
</Module>