aboutsummaryrefslogtreecommitdiffstats
path: root/lib/webcals
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-26 12:16:49 +0200
committerJames Lal <james@lightsofapollo.com>2012-06-26 12:16:49 +0200
commit816243091b923cc64d87250f8cbd0854a1348312 (patch)
tree1b28fa3a5a357507fdf848b370230a3b5d3dad0a /lib/webcals
parente961e32348203c71bfae7a9142f5d7c0b8ef4e6f (diff)
downloadjsCalDAV-816243091b923cc64d87250f8cbd0854a1348312.tar.gz
Basic propfind request
Diffstat (limited to 'lib/webcals')
-rw-r--r--lib/webcals/request/abstract.js12
-rw-r--r--lib/webcals/request/propfind.js56
2 files changed, 61 insertions, 7 deletions
diff --git a/lib/webcals/request/abstract.js b/lib/webcals/request/abstract.js
index fe47de9..ac0ceb5 100644
--- a/lib/webcals/request/abstract.js
+++ b/lib/webcals/request/abstract.js
@@ -25,16 +25,14 @@
this[key] = options[key];
}
}
+
+ this.xhr = new XHR({
+ url: this.url
+ });
}
Abstract.prototype = {
- _createXhr: function() {
- return new XHR({
- url: this.url
- });
- },
-
_createPayload: function() {
return '';
},
@@ -48,7 +46,7 @@
*/
send: function(callback) {
var self = this;
- var req = this.xhr = this._createXhr();
+ var req = this.xhr;
req.data = this._createPayload();
// in the future we may stream data somehow
diff --git a/lib/webcals/request/propfind.js b/lib/webcals/request/propfind.js
new file mode 100644
index 0000000..9e06b49
--- /dev/null
+++ b/lib/webcals/request/propfind.js
@@ -0,0 +1,56 @@
+(function(module, ns) {
+
+ var Abstract = ns.require('request/abstract'),
+ Template = ns.require('template'),
+ DavResponse = ns.require('sax/dav_response');
+
+ /**
+ * Creates a propfind request.
+ *
+ * @param {String} url location to make request.
+ * @param {Object} options options for propfind.
+ */
+ function Propfind(url, options) {
+ Abstract.apply(this, arguments);
+
+ this.template = new Template('propfind');
+ this._props = [];
+ this.sax.registerHandler(
+ 'DAV:/response',
+ DavResponse
+ );
+
+ this.xhr.headers['Depth'] = this.depth;
+ this.xhr.method = 'PROPFIND';
+ }
+
+ Propfind.prototype = {
+ __proto__: Abstract.prototype,
+
+ depth: 0,
+
+ /**
+ * Adds property to request.
+ *
+ * @param {String|Array} tagDesc tag description.
+ * @param {Object} [attr] optional tag attrs.
+ */
+ prop: function(tagDesc, attr) {
+ this._props.push(this.template.tag(tagDesc, attr));
+ },
+
+ _createPayload: function() {
+ var content = this.template.tag('prop', this._props.join(''));
+ return this.template.render(content);
+ }
+
+ };
+
+ module.exports = Propfind;
+
+}.apply(
+ this,
+ (this.Webcals) ?
+ [Webcals('request/abstract'), Webcals] :
+ [module, require('../webcals')]
+));