]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make JS Webdav work again with IE9-IE10
authorVincent Petry <pvince81@owncloud.com>
Fri, 5 Feb 2016 13:40:27 +0000 (14:40 +0100)
committerVincent Petry <pvince81@owncloud.com>
Fri, 5 Feb 2016 13:48:10 +0000 (14:48 +0100)
core/js/files/iedavclient.js

index 4fd9a3a3bf4a56eb5aba84acbcd84fd72448c016..e5b3968a197791bce45000e290157bad9227af31 100644 (file)
        dav.Client.prototype = _.extend({}, dav.Client.prototype, {
 
                /**
-                * Generates a propFind request.
+                * Performs a HTTP request, and returns a Promise
                 *
-                * @param {string} url Url to do the propfind request on
-                * @param {Array} properties List of properties to retrieve.
+                * @param {string} method HTTP method
+                * @param {string} url Relative or absolute url
+                * @param {Object} headers HTTP headers as an object.
+                * @param {string} body HTTP request body.
                 * @return {Promise}
                 */
-               propFind : function(url, properties, depth) {
+               request : function(method, url, headers, body) {
 
-                       if(typeof depth == "undefined") {
-                               depth = 0;
+                       var self = this;
+                       var xhr = this.xhrProvider();
+
+                       if (this.userName) {
+                               headers['Authorization'] = 'Basic ' + btoa(this.userName + ':' + this.password);
+                               // xhr.open(method, this.resolveUrl(url), true, this.userName, this.password);
+                       }
+                       xhr.open(method, this.resolveUrl(url), true);
+                       var ii;
+                       for(ii in headers) {
+                               xhr.setRequestHeader(ii, headers[ii]);
                        }
+                       xhr.send(body);
 
-                       var headers = {
-                               Depth          : depth,
-                               'Content-Type' : 'application/xml; charset=utf-8'
-                       };
+                       return new Promise(function(fulfill, reject) {
 
-                       var body =
-                               '<?xml version="1.0"?>\n' +
-                               '<d:propfind ';
+                               xhr.onreadystatechange = function() {
 
-                       var namespace;
-                       for (namespace in this.xmlNamespaces) {
-                               body += ' xmlns:' + this.xmlNamespaces[namespace] + '="' + namespace + '"';
-                       }
-                       body += '>\n' +
-                               '  <d:prop>\n';
-
-                       for(var ii in properties) {
-                               var propText = properties[ii];
-                               if (typeof propText !== 'string') {
-                                       // can happen on IE8
-                                       continue;
-                               }
-                               var property = this.parseClarkNotation(properties[ii]);
-                               if (this.xmlNamespaces[property.namespace]) {
-                                       body+='    <' + this.xmlNamespaces[property.namespace] + ':' + property.name + ' />\n';
-                               } else {
-                                       body+='    <x:' + property.name + ' xmlns:x="' + property.namespace + '" />\n';
-                               }
+                                       if (xhr.readyState !== 4) {
+                                               return;
+                                       }
 
-                       }
-                       body+='  </d:prop>\n';
-                       body+='</d:propfind>';
-
-                       return this.request('PROPFIND', url, headers, body).then(
-                               function(result) {
-                                       var elements = this.parseMultiStatus(result.xhr.responseXML);
-                                       var response;
-                                       if (depth===0) {
-                                               response = {
-                                                       status: result.status,
-                                                       body: elements[0]
-                                               };
-                                       } else {
-                                               response = {
-                                                       status: result.status,
-                                                       body: elements
-                                               };
+                                       var resultBody = xhr.response;
+                                       if (xhr.status === 207) {
+                                               resultBody = self.parseMultiStatus(xhr.responseXML);
                                        }
-                                       return response;
 
-                               }.bind(this)
-                       );
+                                       fulfill({
+                                               body: resultBody,
+                                               status: xhr.status,
+                                               xhr: xhr
+                                       });
 
-               },
+                               };
+
+                               xhr.ontimeout = function() {
+
+                                       reject(new Error('Timeout exceeded'));
+
+                               };
+
+                       });
 
+               },
 
                _getElementsByTagName: function(node, name, resolver) {
                        var parts = name.split(':');
                 * @param {Array}
                 */
                parseMultiStatus : function(doc) {
-
                        var result = [];
                        var resolver = function(foo) {
                                var ii;