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
|
/**
@namespace
*/
(function(module, ns) {
var CalendarQuery = ns.require('request/calendar_query');
/**
* Represents a (Web/Cal)Dav resource type.
*
* @param {Caldav.Connection} connection connection details.
* @param {Object} options public options on prototype.
*/
function Calendar(connection, options) {
if (typeof(options) === 'undefined') {
options = {};
}
if (options.url) {
this.url = options.url;
}
this.connection = connection;
this.updateFromServer(options);
}
Calendar.prototype = {
_map: {
'displayname': 'name',
'calendar-color': 'color',
'calendar-description': 'description',
'getctag': 'ctag',
'resourcetype': {
field: 'resourcetype',
defaults: []
},
'current-user-privilege-set': {
field: 'privilegeSet',
defaults: []
}
},
/**
* location of calendar resource
*/
url: null,
/**
* displayname as defined by webdav spec
* Maps to: displayname
*/
name: null,
/**
* color of calendar as defined by ical spec
* Maps to: calendar-color
*/
color: null,
/**
* description of calendar as described by caldav spec
* Maps to: calendar-description
*/
description: null,
/**
* change tag (as defined by calendarserver spec)
* used to determine if a change has occurred to this
* calendar resource.
*
* Maps to: getctag
*/
ctag: null,
/**
* Resource types of this resource will
* always contain 'calendar'
*
* Maps to: resourcetype
*
* @type Array
*/
resourcetype: null,
/**
* Set of privileges available to the user.
*
* Maps to: current-user-privilege-set
*/
privilegeSet: null,
/**
* Updates calendar details from server.
*/
updateFromServer: function(options) {
var key;
var defaultTo;
var mapName;
var value;
var descriptor;
if (typeof(options) === 'undefined') {
options = {};
}
for (key in options) {
if (options.hasOwnProperty(key)) {
if (key in this._map) {
descriptor = this._map[key];
value = options[key];
if (typeof(descriptor) === 'object') {
defaultTo = descriptor.defaults;
mapName = descriptor.field;
} else {
defaultTo = '';
mapName = descriptor;
}
if (value.status !== '200') {
this[mapName] = defaultTo;
} else {
this[mapName] = value.value;
}
}
}
}
},
/**
* Creates a query request for this calendar resource.
*
* @return {CalDav.Request.CalendarQuery} query object.
*/
createQuery: function() {
return new CalendarQuery(this.connection, {
url: this.url
});
}
};
module.exports = Calendar;
}.apply(
this,
(this.Caldav) ?
[Caldav('resources/calendar'), Caldav] :
[module, require('../caldav')]
));
|