]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update davclient.js to 0.1.1 3997/head
authorVincent Petry <pvince81@owncloud.com>
Fri, 10 Mar 2017 07:06:03 +0000 (08:06 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Wed, 22 Mar 2017 23:58:52 +0000 (17:58 -0600)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
bower.json
core/vendor/davclient.js/.bower.json
core/vendor/davclient.js/lib/client.js

index 0735f4eb5a045ebbfbc7af3c428baa6d8aa087fd..6a64e184b07fa1629e43a72b3f177eef5a8487b7 100644 (file)
@@ -29,7 +29,7 @@
     "underscore": "~1.8.0",
     "bootstrap": "~3.3.6",
     "backbone": "~1.2.3",
-    "davclient.js": "https://github.com/evert/davclient.js.git",
+    "davclient.js": "https://github.com/evert/davclient.js.git#0.1.1",
     "es6-promise": "https://github.com/jakearchibald/es6-promise.git#~2.3.0",
     "base64": "~0.3.0",
     "clipboard": "^1.5.12",
index 5ae36dac53409e1719ed8a8a03c335ff83db64e1..485af9e0885535face2938a75c9d3e5b85f3d24e 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "davclient.js",
-  "version": "0.0.1",
+  "version": "0.1.1",
   "authors": [
     "Evert Pot <me@evertpot.com>"
   ],
     "test",
     "tests"
   ],
-  "_release": "0.0.1",
+  "_release": "0.1.1",
   "_resolution": {
     "type": "version",
-    "tag": "0.0.1",
-    "commit": "2d054c63ba5bf7f7d40de904a742f3ad9c71e63c"
+    "tag": "0.1.1",
+    "commit": "a2731f81540816b212c09d14596621cb070a4f10"
   },
   "_source": "https://github.com/evert/davclient.js.git",
-  "_target": "*",
-  "_originalSource": "https://github.com/evert/davclient.js.git"
+  "_target": "0.1.1",
+  "_originalSource": "https://github.com/evert/davclient.js.git",
+  "_direct": true
 }
\ No newline at end of file
index db1a1954affd39406a45001ac25f6794b22ac11a..0fc3f61f9f6d24c4a46e060f33a77a17db7a1a5c 100644 (file)
@@ -1,3 +1,8 @@
+/*
+ * vim: expandtab shiftwidth=4 softtabstop=4
+ */
+
+/* global dav */
 if (typeof dav == 'undefined') { dav = {}; };
 
 dav._XML_CHAR_MAP = {
@@ -99,11 +104,43 @@ dav.Client.prototype = {
 
     },
 
+    /**
+     * Renders a "d:set" block for the given properties.
+     *
+     * @param {Object.<String,String>} properties
+     * @return {String} XML "<d:set>" block
+     */
+    _renderPropSet: function(properties) {
+        var body = '  <d:set>\n' +
+            '   <d:prop>\n';
+
+        for(var ii in properties) {
+            var property = this.parseClarkNotation(ii);
+            var propName;
+            var propValue = properties[ii];
+            if (this.xmlNamespaces[property.namespace]) {
+                propName = this.xmlNamespaces[property.namespace] + ':' + property.name;
+            } else {
+                propName = 'x:' + property.name + ' xmlns:x="' + property.namespace + '"';
+            }
+
+            // FIXME: hard-coded for now until we allow properties to
+            // specify whether to be escaped or not
+            if (propName !== 'd:resourcetype') {
+                propValue = dav._escapeXml(propValue);
+            }
+            body += '      <' + propName + '>' + propValue + '</' + propName + '>\n';
+        }
+        body +='    </d:prop>\n';
+        body +='  </d:set>\n';
+        return body;
+    },
+
     /**
      * Generates a propPatch request.
      *
      * @param {string} url Url to do the proppatch request on
-     * @param {Array} properties List of properties to store.
+     * @param {Object.<String,String>} properties List of properties to store.
      * @param {Object} [headers] headers
      * @return {Promise}
      */
@@ -119,27 +156,48 @@ dav.Client.prototype = {
         for (namespace in this.xmlNamespaces) {
             body += ' xmlns:' + this.xmlNamespaces[namespace] + '="' + namespace + '"';
         }
-        body += '>\n' +
-            '  <d:set>\n' +
-            '   <d:prop>\n';
+        body += '>\n' + this._renderPropSet(properties);
+        body += '</d:propertyupdate>';
 
-        for(var ii in properties) {
+        return this.request('PROPPATCH', url, headers, body).then(
+            function(result) {
+                return {
+                    status: result.status,
+                    body: result.body,
+                    xhr: result.xhr
+                };
+            }.bind(this)
+        );
 
-            var property = this.parseClarkNotation(ii);
-            var propName;
-            var propValue = properties[ii];
-            if (this.xmlNamespaces[property.namespace]) {
-                propName = this.xmlNamespaces[property.namespace] + ':' + property.name;
-            } else {
-                propName = 'x:' + property.name + ' xmlns:x="' + property.namespace + '"';
+    },
+
+    /**
+     * Generates a MKCOL request.
+     * If attributes are given, it will use an extended MKCOL request.
+     *
+     * @param {string} url Url to do the proppatch request on
+     * @param {Object.<String,String>} [properties] list of properties to store.
+     * @param {Object} [headers] headers
+     * @return {Promise}
+     */
+    mkcol : function(url, properties, headers) {
+        var body = '';
+        headers = headers || {};
+        headers['Content-Type'] = 'application/xml; charset=utf-8';
+
+        if (properties) {
+            body =
+                '<?xml version="1.0"?>\n' +
+                '<d:mkcol';
+            var namespace;
+            for (namespace in this.xmlNamespaces) {
+                body += ' xmlns:' + this.xmlNamespaces[namespace] + '="' + namespace + '"';
             }
-            body += '      <' + propName + '>' + dav._escapeXml(propValue) + '</' + propName + '>\n';
+            body += '>\n' + this._renderPropSet(properties);
+            body +='</d:mkcol>';
         }
-        body+='    </d:prop>\n';
-        body+='  </d:set>\n';
-        body+='</d:propertyupdate>';
 
-        return this.request('PROPPATCH', url, headers, body).then(
+        return this.request('MKCOL', url, headers, body).then(
             function(result) {
                 return {
                     status: result.status,
@@ -293,10 +351,9 @@ dav.Client.prototype = {
             var propStatNode = propStatIterator.iterateNext();
 
             while(propStatNode) {
-
                 var propStat = {
                     status : doc.evaluate('string(d:status)', propStatNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
-                    properties : [],
+                    properties : {},
                 };
 
                 var propIterator = doc.evaluate('d:prop/*', propStatNode, resolver, XPathResult.ANY_TYPE, null);