Merge pull request #3881 from nextcloud/downstream-26842
Backbone Webdav Adapter MKCOL support
This commit is contained in:
commit
0c0ce25b3c
|
@ -120,7 +120,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var parts = url.split('/');
|
var parts = url.split('/');
|
||||||
return parts[parts.length - 1];
|
var result;
|
||||||
|
do {
|
||||||
|
result = parts[parts.length - 1];
|
||||||
|
parts.pop();
|
||||||
|
// note: first result can be empty when there is a trailing slash,
|
||||||
|
// so we take the part before that
|
||||||
|
} while (!result && parts.length > 0);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSuccessStatus(status) {
|
function isSuccessStatus(status) {
|
||||||
|
@ -190,6 +198,25 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function callMkCol(client, options, model, headers) {
|
||||||
|
// call MKCOL without data, followed by PROPPATCH
|
||||||
|
return client.request(
|
||||||
|
options.type,
|
||||||
|
options.url,
|
||||||
|
headers,
|
||||||
|
null
|
||||||
|
).then(function(result) {
|
||||||
|
if (!isSuccessStatus(result.status)) {
|
||||||
|
if (_.isFunction(options.error)) {
|
||||||
|
options.error(result);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callPropPatch(client, options, model, headers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function callMethod(client, options, model, headers) {
|
function callMethod(client, options, model, headers) {
|
||||||
headers['Content-Type'] = 'application/json';
|
headers['Content-Type'] = 'application/json';
|
||||||
return client.request(
|
return client.request(
|
||||||
|
@ -206,7 +233,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isFunction(options.success)) {
|
if (_.isFunction(options.success)) {
|
||||||
if (options.type === 'PUT' || options.type === 'POST') {
|
if (options.type === 'PUT' || options.type === 'POST' || options.type === 'MKCOL') {
|
||||||
// pass the object's own values because the server
|
// pass the object's own values because the server
|
||||||
// does not return anything
|
// does not return anything
|
||||||
var responseJson = result.body || model.toJSON();
|
var responseJson = result.body || model.toJSON();
|
||||||
|
@ -247,6 +274,8 @@
|
||||||
return callPropFind(client, options, model, headers);
|
return callPropFind(client, options, model, headers);
|
||||||
} else if (options.type === 'PROPPATCH') {
|
} else if (options.type === 'PROPPATCH') {
|
||||||
return callPropPatch(client, options, model, headers);
|
return callPropPatch(client, options, model, headers);
|
||||||
|
} else if (options.type === 'MKCOL') {
|
||||||
|
return callMkCol(client, options, model, headers);
|
||||||
} else {
|
} else {
|
||||||
return callMethod(client, options, model, headers);
|
return callMethod(client, options, model, headers);
|
||||||
}
|
}
|
||||||
|
@ -259,10 +288,17 @@
|
||||||
var params = {type: methodMap[method] || method};
|
var params = {type: methodMap[method] || method};
|
||||||
var isCollection = (model instanceof Backbone.Collection);
|
var isCollection = (model instanceof Backbone.Collection);
|
||||||
|
|
||||||
if (method === 'update' && (model.usePUT || (model.collection && model.collection.usePUT))) {
|
if (method === 'update') {
|
||||||
|
// if a model has an inner collection, it must define an
|
||||||
|
// attribute "hasInnerCollection" that evaluates to true
|
||||||
|
if (model.hasInnerCollection) {
|
||||||
|
// if the model itself is a Webdav collection, use MKCOL
|
||||||
|
params.type = 'MKCOL';
|
||||||
|
} else if (model.usePUT || (model.collection && model.collection.usePUT)) {
|
||||||
// use PUT instead of PROPPATCH
|
// use PUT instead of PROPPATCH
|
||||||
params.type = 'PUT';
|
params.type = 'PUT';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that we have a URL.
|
// Ensure that we have a URL.
|
||||||
if (!options.url) {
|
if (!options.url) {
|
||||||
|
|
Loading…
Reference in New Issue