From 995a825dac081d04ca5fadd4dae45e836c787cf3 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 5 Feb 2016 14:40:27 +0100 Subject: [PATCH] Make JS Webdav work again with IE9-IE10 --- core/js/files/iedavclient.js | 96 +++++++++++++++--------------------- 1 file changed, 41 insertions(+), 55 deletions(-) diff --git a/core/js/files/iedavclient.js b/core/js/files/iedavclient.js index 4fd9a3a3bf4..e5b3968a197 100644 --- a/core/js/files/iedavclient.js +++ b/core/js/files/iedavclient.js @@ -17,73 +17,60 @@ 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 = - '\n' + - '\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+=' \n'; - } + if (xhr.readyState !== 4) { + return; + } - } - body+=' \n'; - body+=''; - - 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(':'); @@ -102,7 +89,6 @@ * @param {Array} */ parseMultiStatus : function(doc) { - var result = []; var resolver = function(foo) { var ii; -- 2.39.5