summaryrefslogtreecommitdiffstats
path: root/core/js/shareitemmodel.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-01-28 17:07:51 +0100
committerVincent Petry <pvince81@owncloud.com>2016-01-28 17:18:33 +0100
commitdf3f6fee10f70d7a083fb51a03fd8f797ca51b21 (patch)
treec568c9282858f80ac0c7f153ab00b248d9dd8299 /core/js/shareitemmodel.js
parent8b3d7d09d52ba169953d6a7d03ab570eb3ceed7a (diff)
downloadnextcloud-server-df3f6fee10f70d7a083fb51a03fd8f797ca51b21.tar.gz
nextcloud-server-df3f6fee10f70d7a083fb51a03fd8f797ca51b21.zip
Properly forward error messages in share dialog
Diffstat (limited to 'core/js/shareitemmodel.js')
-rw-r--r--core/js/shareitemmodel.js53
1 files changed, 46 insertions, 7 deletions
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index c9fc85c91b2..a7764dd6266 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -123,7 +123,7 @@
shareId = this.get('linkShare').id;
// note: update can only update a single value at a time
- call = this.updateShare(shareId, attributes);
+ call = this.updateShare(shareId, attributes, options);
} else {
attributes = _.defaults(attributes, {
password: '',
@@ -133,7 +133,7 @@
shareType: OC.Share.SHARE_TYPE_LINK
});
- call = this.addShare(attributes);
+ call = this.addShare(attributes, options);
}
return call;
@@ -189,8 +189,9 @@
}
}
});
- }).fail(function(result) {
+ }).fail(function(xhr) {
var msg = t('core', 'Error');
+ var result = xhr.responseJSON;
if (result.ocs && result.ocs.meta) {
msg = result.ocs.meta.message;
}
@@ -203,15 +204,34 @@
});
},
- updateShare: function(shareId, attrs) {
+ updateShare: function(shareId, attrs, options) {
var self = this;
+ options = options || {};
return $.ajax({
type: 'PUT',
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
data: attrs,
dataType: 'json'
}).done(function() {
- self.fetch();
+ 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'));
+ }
});
},
@@ -221,13 +241,32 @@
* @param {int} shareId share id
* @return {jQuery}
*/
- removeShare: function(shareId) {
+ removeShare: function(shareId, options) {
var self = this;
+ options = options || {};
return $.ajax({
type: 'DELETE',
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
}).done(function() {
- self.fetch();
+ 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 removing share'));
+ }
});
},