aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/caldav/index.js2
-rw-r--r--lib/caldav/request/calendar_query.js24
-rw-r--r--lib/caldav/templates/calendar_data.js115
-rw-r--r--lib/caldav/templates/calendar_filter.js32
-rw-r--r--lib/caldav/templates/index.js13
5 files changed, 17 insertions, 169 deletions
diff --git a/lib/caldav/index.js b/lib/caldav/index.js
index 4dd6852..cdce101 100644
--- a/lib/caldav/index.js
+++ b/lib/caldav/index.js
@@ -5,9 +5,9 @@
exports.Responder = ns.require('responder');
exports.Sax = ns.require('sax');
exports.Template = ns.require('template');
+ exports.QueryBuilder = ns.require('query_builder');
exports.Xhr = ns.require('xhr');
exports.Request = ns.require('request');
- exports.Templates = ns.require('templates');
exports.Connection = ns.require('connection');
exports.Resources = ns.require('resources');
diff --git a/lib/caldav/request/calendar_query.js b/lib/caldav/request/calendar_query.js
index 6ee1ec4..0d48788 100644
--- a/lib/caldav/request/calendar_query.js
+++ b/lib/caldav/request/calendar_query.js
@@ -1,8 +1,7 @@
(function(module, ns) {
var Propfind = ns.require('request/propfind');
- var CalendarData = ns.require('templates/calendar_data');
- var CalendarFilter = ns.require('templates/calendar_filter');
+ var Builder = ns.require('query_builder');
/**
* Creates a calendar query request.
@@ -17,10 +16,19 @@
this.xhr.headers['Depth'] = this.depth || 1;
this.xhr.method = 'REPORT';
- this.fields = new CalendarData();
- this.filters = new CalendarFilter();
this.template.rootTag = ['caldav', 'calendar-query'];
+
+ this.data = new Builder({
+ template: this.template
+ });
+
+ this.filter = new Builder({
+ template: this.template,
+ tag: ['caldav', 'filter'],
+ propTag: ['caldav', 'prop-filter'],
+ compTag: ['caldav', 'comp-filter']
+ });
}
CalendarQuery.prototype = {
@@ -32,14 +40,14 @@
props = this._props.join('');
- if (this.fields) {
- props += this.fields.render(this.template);
+ if (this.data) {
+ props += this.data.toString();
}
content = this.template.tag('prop', props);
- if (this.filters) {
- content += this.filters.render(this.template);
+ if (this.filter) {
+ content += this.filter.toString();
}
return this.template.render(content);
diff --git a/lib/caldav/templates/calendar_data.js b/lib/caldav/templates/calendar_data.js
deleted file mode 100644
index 5fcc4e8..0000000
--- a/lib/caldav/templates/calendar_data.js
+++ /dev/null
@@ -1,115 +0,0 @@
-(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) {
- if (typeof(list) === 'undefined') {
- list = true;
- }
-
- 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;
- },
-
- _defaultRender: function(template) {
- return template.tag(['caldav', this.rootName]);
- },
-
- /**
- * Renders CalendarData with a template.
- *
- * @param {WebCals.Template} template calendar to render.
- * @return {String} <calendardata /> xml output.
- */
- render: function(template) {
- if (!this._hasItems) {
- return this._defaultRender(template);
- }
-
- 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
deleted file mode 100644
index a16f985..0000000
--- a/lib/caldav/templates/calendar_filter.js
+++ /dev/null
@@ -1,32 +0,0 @@
-(function(module, ns) {
-
- var CalendarData = ns.require('templates/calendar_data');
-
- function CalendarFilter() {
- CalendarData.call(this);
- }
-
- CalendarFilter.prototype = {
-
- __proto__: CalendarData.prototype,
-
- add: CalendarData.prototype.select,
-
- _defaultRender: function(template) {
- var inner = this._renderFieldset(template, { VCALENDAR: [{ VEVENT: true }] });
- return template.tag(['caldav', this.rootName], inner);
- },
-
- 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
deleted file mode 100644
index 4e06cfd..0000000
--- a/lib/caldav/templates/index.js
+++ /dev/null
@@ -1,13 +0,0 @@
-(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')]
-));