diff options
Diffstat (limited to 'core/js/files/client.js')
-rw-r--r-- | core/js/files/client.js | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/core/js/files/client.js b/core/js/files/client.js index b736447d65e..55a8e2c485a 100644 --- a/core/js/files/client.js +++ b/core/js/files/client.js @@ -241,7 +241,7 @@ path = decodeURIComponent(path); - if (response.propStat.length === 1 && response.propStat[0].status !== 200) { + if (response.propStat.length === 0 || response.propStat[0].status !== 'HTTP/1.1 200 OK') { return null; } @@ -415,6 +415,77 @@ }, /** + * Fetches a flat list of files filtered by a given filter criteria. + * (currently only system tags is supported) + * + * @param {Object} filter filter criteria + * @param {Object} [filter.systemTagIds] list of system tag ids to filter by + * @param {Object} [options] options + * @param {Array} [options.properties] list of Webdav properties to retrieve + * + * @return {Promise} promise + */ + getFilteredFiles: function(filter, options) { + options = options || {}; + var self = this; + var deferred = $.Deferred(); + var promise = deferred.promise(); + var properties; + if (_.isUndefined(options.properties)) { + properties = this.getPropfindProperties(); + } else { + properties = options.properties; + } + + if (!filter || !filter.systemTagIds || !filter.systemTagIds.length) { + throw 'Missing filter argument'; + } + + var headers = _.extend({}, this._defaultHeaders); + // root element with namespaces + var body = '<oc:filter-files '; + var namespace; + for (namespace in this._client.xmlNamespaces) { + body += ' xmlns:' + this._client.xmlNamespaces[namespace] + '="' + namespace + '"'; + } + body += '>\n'; + + // properties query + body += ' <' + this._client.xmlNamespaces['DAV:'] + ':prop>\n'; + _.each(properties, function(prop) { + var property = self._client.parseClarkNotation(prop); + body += ' <' + self._client.xmlNamespaces[property.namespace] + ':' + property.name + ' />\n'; + }); + + body += ' </' + this._client.xmlNamespaces['DAV:'] + ':prop>\n'; + + // rules block + body += ' <oc:filter-rules>\n'; + _.each(filter.systemTagIds, function(systemTagIds) { + body += ' <oc:systemtag>' + escapeHTML(systemTagIds) + '</oc:systemtag>\n'; + }); + body += ' </oc:filter-rules>\n'; + + // end of root + body += '</oc:filter-files>\n'; + + this._client.request( + 'REPORT', + this._buildUrl(), + headers, + body + ).then(function(result) { + if (self._isSuccessStatus(result.status)) { + var results = self._parseResult(result.body); + deferred.resolve(result.status, results); + } else { + deferred.reject(result.status); + } + }); + return promise; + }, + + /** * Returns the file info of a given path. * * @param {String} path path |