From 51b55d53206ec8731611e6a36bf8d7e3317a451a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 12 Feb 2016 14:01:15 +0100 Subject: [PATCH 1/2] Provide proper feedback when creating a share in the webUI Fixes #22304 Creating a share is not instant (especially not for federated shares) so we should show that something is happening in the webUI properly. --- core/js/sharedialogview.js | 14 ++++++++++++-- core/js/shareitemmodel.js | 8 +++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 4cebf7962e..02e0e673ca 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -233,8 +233,18 @@ _onSelectRecipient: function(e, s) { e.preventDefault(); - $(e.target).val(''); - this.model.addShare(s.item.value); + $(e.target).attr('disabled', true) + .val(s.item.label); + var $loading = this.$el.find('.shareWithLoading'); + $loading.removeClass('hidden') + .addClass('inlineblock'); + + this.model.addShare(s.item.value, {success: function() { + $(e.target).val('') + .attr('disabled', false); + $loading.addClass('hidden') + .removeClass('inlineblock'); + }}); }, _toggleLoading: function(state) { diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index a28bcac91c..292230d26d 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -183,11 +183,9 @@ data: attributes, dataType: 'json' }).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) { From 92c131b481b675907881af1b6a1d33f4191ee809 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 12 Feb 2016 14:31:00 +0100 Subject: [PATCH 2/2] Updated unit tests --- core/js/tests/specs/sharedialogviewSpec.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js index 6899e625c4..3a94379789 100644 --- a/core/js/tests/specs/sharedialogviewSpec.js +++ b/core/js/tests/specs/sharedialogviewSpec.js @@ -956,9 +956,12 @@ describe('OC.Share.ShareDialogView', function() { it('calls addShare after selection', function() { dialog.render(); + + var shareWith = $('.shareWithField')[0]; + var $shareWith = $(shareWith); var addShareStub = sinon.stub(shareModel, 'addShare'); var autocompleteOptions = autocompleteStub.getCall(0).args[0]; - autocompleteOptions.select(new $.Event('select'), { + autocompleteOptions.select(new $.Event('select', {target: shareWith}), { item: { label: 'User Two', value: { @@ -974,6 +977,17 @@ describe('OC.Share.ShareDialogView', function() { shareWith: 'user2' }); + //Input is locked + expect($shareWith.val()).toEqual('User Two'); + expect($shareWith.attr('disabled')).toEqual('disabled'); + + //Callback is called + addShareStub.firstCall.args[1].success(); + + //Input is unlocked + expect($shareWith.val()).toEqual(''); + expect($shareWith.attr('disabled')).toEqual(undefined); + addShareStub.restore(); }); });