aboutsummaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-24 22:07:08 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-24 22:07:08 +0200
commite0b0115f99d8b93adfb9a9494aa1273f5e2f2200 (patch)
tree52e7d5ffb2ef78bc2ff6b6d78204c290ecb72d94 /core/js
parent3ab295893086e40fe956ca918f0dcb333dcec683 (diff)
downloadnextcloud-server-e0b0115f99d8b93adfb9a9494aa1273f5e2f2200.tar.gz
nextcloud-server-e0b0115f99d8b93adfb9a9494aa1273f5e2f2200.zip
Extract common ajax call for addShare and updateShare
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'core/js')
-rw-r--r--core/js/shareitemmodel.js53
1 files changed, 17 insertions, 36 deletions
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index 15af6df2c32..8144d8faa21 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -156,7 +156,6 @@
addShare: function(attributes, options) {
var shareType = attributes.shareType;
- options = options || {};
attributes = _.extend({}, attributes);
// Default permissions are Edit (CRUD) and Share
@@ -180,61 +179,43 @@
attributes.path = this.fileInfoModel.getFullPath();
}
- var self = this;
- return $.ajax({
+ return this._addOrUpdateShare({
type: 'POST',
url: this._getUrl('shares'),
data: attributes,
dataType: 'json'
- }).always(function() {
- if (_.isFunction(options.complete)) {
- options.complete(self);
- }
- }).done(function() {
- self.fetch().done(function() {
- if (_.isFunction(options.success)) {
- options.success(self);
- }
- });
- }).fail(function(xhr) {
- var msg = t('core', 'Error');
- var result = xhr.responseJSON;
- if (result && 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'));
- }
- });
+ }, options);
},
updateShare: function(shareId, attrs, options) {
- var self = this;
- options = options || {};
- return $.ajax({
+ return this._addOrUpdateShare({
type: 'PUT',
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
data: attrs,
dataType: 'json'
- }).always(function() {
+ }, options);
+ },
+
+ _addOrUpdateShare: function(ajaxSettings, options) {
+ var self = this;
+ options = options || {};
+
+ return $.ajax(
+ ajaxSettings
+ ).always(function() {
if (_.isFunction(options.complete)) {
options.complete(self);
}
}).done(function() {
- self.fetch({
- success: function() {
- if (_.isFunction(options.success)) {
- options.success(self);
- }
+ self.fetch().done(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) {
+ if (result && result.ocs && result.ocs.meta) {
msg = result.ocs.meta.message;
}