Extract common ajax call for addShare and updateShare
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
3ab2958930
commit
e0b0115f99
|
@ -156,7 +156,6 @@
|
||||||
|
|
||||||
addShare: function(attributes, options) {
|
addShare: function(attributes, options) {
|
||||||
var shareType = attributes.shareType;
|
var shareType = attributes.shareType;
|
||||||
options = options || {};
|
|
||||||
attributes = _.extend({}, attributes);
|
attributes = _.extend({}, attributes);
|
||||||
|
|
||||||
// Default permissions are Edit (CRUD) and Share
|
// Default permissions are Edit (CRUD) and Share
|
||||||
|
@ -180,13 +179,30 @@
|
||||||
attributes.path = this.fileInfoModel.getFullPath();
|
attributes.path = this.fileInfoModel.getFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
return this._addOrUpdateShare({
|
||||||
return $.ajax({
|
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: this._getUrl('shares'),
|
url: this._getUrl('shares'),
|
||||||
data: attributes,
|
data: attributes,
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
}).always(function() {
|
}, options);
|
||||||
|
},
|
||||||
|
|
||||||
|
updateShare: function(shareId, attrs, options) {
|
||||||
|
return this._addOrUpdateShare({
|
||||||
|
type: 'PUT',
|
||||||
|
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
|
||||||
|
data: attrs,
|
||||||
|
dataType: 'json'
|
||||||
|
}, options);
|
||||||
|
},
|
||||||
|
|
||||||
|
_addOrUpdateShare: function(ajaxSettings, options) {
|
||||||
|
var self = this;
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
return $.ajax(
|
||||||
|
ajaxSettings
|
||||||
|
).always(function() {
|
||||||
if (_.isFunction(options.complete)) {
|
if (_.isFunction(options.complete)) {
|
||||||
options.complete(self);
|
options.complete(self);
|
||||||
}
|
}
|
||||||
|
@ -211,41 +227,6 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
updateShare: function(shareId, attrs, options) {
|
|
||||||
var self = this;
|
|
||||||
options = options || {};
|
|
||||||
return $.ajax({
|
|
||||||
type: 'PUT',
|
|
||||||
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
|
|
||||||
data: attrs,
|
|
||||||
dataType: 'json'
|
|
||||||
}).always(function() {
|
|
||||||
if (_.isFunction(options.complete)) {
|
|
||||||
options.complete(self);
|
|
||||||
}
|
|
||||||
}).done(function() {
|
|
||||||
self.fetch({
|
|
||||||
success: function() {
|
|
||||||
if (_.isFunction(options.success)) {
|
|
||||||
options.success(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).fail(function(xhr) {
|
|
||||||
var msg = t('core', 'Error');
|
|
||||||
var result = xhr.responseJSON;
|
|
||||||
if (result.ocs && result.ocs.meta) {
|
|
||||||
msg = result.ocs.meta.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_.isFunction(options.error)) {
|
|
||||||
options.error(self, msg);
|
|
||||||
} else {
|
|
||||||
OC.dialogs.alert(msg, t('core', 'Error while sharing'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the share with the given id
|
* Deletes the share with the given id
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue