aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-27 11:31:51 +0200
committerJames Lal <james@lightsofapollo.com>2012-06-27 11:31:51 +0200
commitc3db57754c540129bd004137ab88be69788217d2 (patch)
tree758acbd7c7fcb42f392838a55125d090697a336c /lib
parent95d50ef280c46ce6a29454285ccd7fc42cbcac61 (diff)
downloadjsCalDAV-c3db57754c540129bd004137ab88be69788217d2.tar.gz
Add calendar data / calendar query
Diffstat (limited to 'lib')
-rw-r--r--lib/webcals/request/calendar_query.js31
-rw-r--r--lib/webcals/templates/calendar_data.js93
2 files changed, 124 insertions, 0 deletions
diff --git a/lib/webcals/request/calendar_query.js b/lib/webcals/request/calendar_query.js
new file mode 100644
index 0000000..b25a1c1
--- /dev/null
+++ b/lib/webcals/request/calendar_query.js
@@ -0,0 +1,31 @@
+(function(module, ns) {
+
+ var Propfind = ns.require('request/propfind');
+
+ /**
+ * Creates a calendar query request.
+ *
+ * Defaults to Depth of 1.
+ *
+ * @param {String} url location to make request.
+ * @param {Object} options options for calendar query.
+ */
+ function CalendarQuery(url, options) {
+ Propfind.apply(this, arguments);
+
+ this.xhr.headers['Depth'] = this.depth || 1;
+ this.xhr.method = 'REPORT';
+ }
+
+ CalendarQuery.prototype = {
+ __proto__: Propfind.prototype
+ };
+
+ module.exports = CalendarQuery;
+
+}.apply(
+ this,
+ (this.Webcals) ?
+ [Webcals('request/calendar_query'), Webcals] :
+ [module, require('../webcals')]
+));
diff --git a/lib/webcals/templates/calendar_data.js b/lib/webcals/templates/calendar_data.js
new file mode 100644
index 0000000..9ff2a1e
--- /dev/null
+++ b/lib/webcals/templates/calendar_data.js
@@ -0,0 +1,93 @@
+(function(module, ns) {
+
+ function CalendarData() {
+ this.struct = {};
+ }
+
+ CalendarData.prototype = {
+
+ /**
+ * Appends a list of fields
+ * to a given iCalendar field set.
+ *
+ * @param {String} type iCal fieldset (VTODO, VEVENT,...).
+ */
+ select: function(type, list) {
+ var struct = this.struct;
+
+ if (!(type in struct)) {
+ struct[type] = [];
+ }
+
+ struct[type] = struct[type].concat(list);
+
+ return this;
+ },
+
+ /**
+ * Accepts an object full of arrays
+ * recuse when encountering another object.
+ */
+ _renderFieldset: function(template, element) {
+ var tag;
+ var value;
+ var i;
+ var output = '';
+ var elementOutput = '';
+
+ for (tag in element) {
+ value = element[tag];
+ for (i = 0; i < value.length; i++) {
+ if (typeof(value[i]) === 'object') {
+ elementOutput += this._renderFieldset(
+ template,
+ value[i]
+ );
+ } else {
+ elementOutput += template.tag(
+ ['caldav', 'prop'],
+ { name: value[i] }
+ );
+ }
+ }
+ output += template.tag(
+ ['caldav', 'comp'],
+ { name: tag },
+ elementOutput
+ );
+ elementOutput = '';
+ }
+
+ return output;
+ },
+
+ /**
+ * Renders CalendarData with a template.
+ *
+ * @param {WebCals.Template} template calendar to render.
+ * @return {String} <calendardata /> xml output.
+ */
+ render: function(template) {
+ var struct = this.struct;
+ var output = template.tag(
+ ['caldav', 'calendar-data'],
+ template.tag(
+ ['caldav', 'comp'],
+ { name: 'VCALENDAR' },
+ this._renderFieldset(template, struct)
+ )
+ );
+
+ return output;
+ }
+ };
+
+
+ module.exports = CalendarData;
+
+}.apply(
+ this,
+ (this.Webcals) ?
+ [Webcals('templates/calendar_data'), Webcals] :
+ [module, require('../webcals')]
+));