aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav/templates
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-07-06 08:13:15 -0700
committerJames Lal <james@lightsofapollo.com>2012-07-06 08:13:15 -0700
commit20711f003e97a4a57d1e2838ba78a994c5faf6c0 (patch)
treeb060e5de05a9ffefc2ec836469c087fffa99dcef /lib/caldav/templates
parentc8e85fe1e0a1d2e15df580068244324ff536a23a (diff)
downloadjsCalDAV-20711f003e97a4a57d1e2838ba78a994c5faf6c0.tar.gz
webcals -> caldav rename (yes, back again)
Diffstat (limited to 'lib/caldav/templates')
-rw-r--r--lib/caldav/templates/calendar_data.js107
-rw-r--r--lib/caldav/templates/calendar_filter.js27
-rw-r--r--lib/caldav/templates/index.js13
3 files changed, 147 insertions, 0 deletions
diff --git a/lib/caldav/templates/calendar_data.js b/lib/caldav/templates/calendar_data.js
new file mode 100644
index 0000000..2c24569
--- /dev/null
+++ b/lib/caldav/templates/calendar_data.js
@@ -0,0 +1,107 @@
+(function(module, ns) {
+
+ function CalendarData() {
+ this._hasItems = false;
+ this.struct = {};
+ }
+
+ CalendarData.prototype = {
+
+ rootName: 'calendar-data',
+ compName: 'comp',
+ propName: 'prop',
+
+ /**
+ * 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;
+ this._hasItems = true;
+
+ if (!(type in struct)) {
+ struct[type] = [];
+ }
+
+ if (list instanceof Array) {
+ struct[type] = struct[type].concat(list);
+ } else {
+ struct[type] = 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', this.propName],
+ { name: value[i] }
+ );
+ }
+ }
+ output += template.tag(
+ ['caldav', this.compName],
+ { name: tag },
+ elementOutput || null
+ );
+ elementOutput = '';
+ }
+
+ return output;
+ },
+
+ /**
+ * Renders CalendarData with a template.
+ *
+ * @param {WebCals.Template} template calendar to render.
+ * @return {String} <calendardata /> xml output.
+ */
+ render: function(template) {
+ if (!this._hasItems) {
+ return template.tag(['caldav', this.rootName]);
+ }
+
+ var struct = this.struct;
+ var output = template.tag(
+ ['caldav', this.rootName],
+ template.tag(
+ ['caldav', this.compName],
+ { name: 'VCALENDAR' },
+ this._renderFieldset(template, struct)
+ )
+ );
+
+ return output;
+ }
+ };
+
+
+ module.exports = CalendarData;
+
+}.apply(
+ this,
+ (this.Caldav) ?
+ [Caldav('templates/calendar_data'), Caldav] :
+ [module, require('../caldav')]
+));
diff --git a/lib/caldav/templates/calendar_filter.js b/lib/caldav/templates/calendar_filter.js
new file mode 100644
index 0000000..aebd9fe
--- /dev/null
+++ b/lib/caldav/templates/calendar_filter.js
@@ -0,0 +1,27 @@
+(function(module, ns) {
+
+ var CalendarData = ns.require('templates/calendar_data');
+
+ function CalendarFilter() {
+ CalendarData.call(this);
+ }
+
+ CalendarFilter.prototype = {
+
+ __proto__: CalendarData.prototype,
+
+ add: CalendarData.prototype.select,
+
+ compName: 'comp-filter',
+ rootName: 'filter'
+ };
+
+ module.exports = CalendarFilter;
+
+}.apply(
+ this,
+ (this.Caldav) ?
+ [Caldav('templates/calendar_filter'), Caldav] :
+ [module, require('../caldav')]
+));
+
diff --git a/lib/caldav/templates/index.js b/lib/caldav/templates/index.js
new file mode 100644
index 0000000..4e06cfd
--- /dev/null
+++ b/lib/caldav/templates/index.js
@@ -0,0 +1,13 @@
+(function(module, ns) {
+
+ module.exports = {
+ CalendarData: ns.require('templates/calendar_data'),
+ CalendarFilter: ns.require('templates/calendar_filter')
+ };
+
+}.apply(
+ this,
+ (this.Caldav) ?
+ [Caldav('templates'), Caldav] :
+ [module, require('../caldav')]
+));