aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-27 12:27:09 +0200
committerJames Lal <james@lightsofapollo.com>2012-06-27 12:27:09 +0200
commitd74007aca2c501ac2fe56f8c440f01f6f6ceaa1f (patch)
tree2daea94d4e4028d2e4b2cd5217faf18045153de6
parent20420489ef9ded9b16852bc84b4b36d5bf363680 (diff)
downloadjsCalDAV-d74007aca2c501ac2fe56f8c440f01f6f6ceaa1f.tar.gz
integrate calendar data
-rw-r--r--Makefile1
-rw-r--r--lib/webcals/request/calendar_query.js13
-rw-r--r--lib/webcals/request/propfind.js5
-rw-r--r--test/webcals/request/calendar_query_test.js33
4 files changed, 33 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index ca50ad0..5d798da 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ test:
--reporter $(REPORTER) \
--growl test/helper.js \
test/webcals/sax/*_test.js \
+ test/webcals/templates/*_test.js \
test/webcals/request/*_test.js \
test/webcals/*_test.js
diff --git a/lib/webcals/request/calendar_query.js b/lib/webcals/request/calendar_query.js
index b25a1c1..b39853f 100644
--- a/lib/webcals/request/calendar_query.js
+++ b/lib/webcals/request/calendar_query.js
@@ -1,6 +1,7 @@
(function(module, ns) {
var Propfind = ns.require('request/propfind');
+ var CalendarData = ns.require('templates/calendar_data');
/**
* Creates a calendar query request.
@@ -15,10 +16,20 @@
this.xhr.headers['Depth'] = this.depth || 1;
this.xhr.method = 'REPORT';
+ this.fields = new CalendarData();
+ this.template.rootTag = 'calendar-query';
}
CalendarQuery.prototype = {
- __proto__: Propfind.prototype
+ __proto__: Propfind.prototype,
+
+ _createPayload: function() {
+ var props = this._props.join('');
+ props += this.fields.render(this.template);
+ var content = this.template.tag('prop', props);
+ return this.template.render(content);
+ }
+
};
module.exports = CalendarQuery;
diff --git a/lib/webcals/request/propfind.js b/lib/webcals/request/propfind.js
index d73530c..e5f6f26 100644
--- a/lib/webcals/request/propfind.js
+++ b/lib/webcals/request/propfind.js
@@ -34,9 +34,10 @@
*
* @param {String|Array} tagDesc tag description.
* @param {Object} [attr] optional tag attrs.
+ * @param {Obj} [content] optional content.
*/
- prop: function(tagDesc, attr) {
- this._props.push(this.template.tag(tagDesc, attr));
+ prop: function(tagDesc, attr, content) {
+ this._props.push(this.template.tag(tagDesc, attr, content));
},
_createPayload: function() {
diff --git a/test/webcals/request/calendar_query_test.js b/test/webcals/request/calendar_query_test.js
index 803b09a..f960e15 100644
--- a/test/webcals/request/calendar_query_test.js
+++ b/test/webcals/request/calendar_query_test.js
@@ -3,8 +3,8 @@ requireLib('request/propfind');
requireLib('request/calendar_query');
suite('webcals/request/propfind', function() {
- var Abstract,
- Propfind,
+ var Propfind,
+ CalendarData,
FakeXhr,
CalendarQuery,
Xhr,
@@ -17,6 +17,7 @@ suite('webcals/request/propfind', function() {
suiteSetup(function() {
Propfind = Webcals.require('request/propfind');
+ CalendarData = Webcals.require('templates/calendar_data');
CalendarQuery = Webcals.require('request/calendar_query');
SaxResponse = Webcals.require('sax/dav_response');
FakeXhr = Webcals.require('support/fake_xhr');
@@ -41,31 +42,31 @@ suite('webcals/request/propfind', function() {
assert.deepEqual(subject._props, []);
assert.equal(subject.xhr.headers['Depth'], 1);
assert.equal(subject.xhr.method, 'REPORT');
- });
-
- test('#prop', function() {
- var expected = subject.template.tag('test');
- subject.prop('test');
-
- assert.deepEqual(subject._props, [expected]);
+ assert.instanceOf(subject.fields, CalendarData);
});
test('#_createPayload', function() {
- return;
- subject.prop('foo');
- subject.prop('bar');
+ subject.prop('getetag');
+ subject.fields.select('VEVENT', ['NAME']);
var tags = [
- '<N0:foo />',
- '<N0:bar />'
+ '<N0:getetag />',
+ '<N1:calendar-data>',
+ '<N1:comp name="VCALENDAR">',
+ '<N1:comp name="VEVENT">',
+ '<N1:prop name="NAME" />',
+ '</N1:comp>',
+ '</N1:comp>',
+ '</N1:calendar-data>'
].join('');
var expected = [
subject.template.doctype,
- '<N0:propfind xmlns:N0="DAV:">',
+ '<N0:calendar-query xmlns:N0="DAV:" ',
+ 'xmlns:N1="urn:ietf:params:xml:ns:caldav">',
'<N0:prop>', tags, '</N0:prop>',
- '</N0:propfind>'
+ '</N0:calendar-query>'
].join('');
assert.equal(subject._createPayload(), expected);