From df3f6fee10f70d7a083fb51a03fd8f797ca51b21 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 28 Jan 2016 17:07:51 +0100 Subject: Properly forward error messages in share dialog --- core/js/shareitemmodel.js | 53 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'core/js/shareitemmodel.js') 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')); + } }); }, -- cgit v1.2.3