From e1fd86ccb6a7b4e3d705829a5eb6c27b5085b4cd Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 16 Feb 2016 19:40:44 +0100 Subject: [PATCH 1/2] Unlock sharee input field when sharing fails Fixes #22441 When addShares fails (for whatever reason) we should unlock the sharee input field so the user does not have to reload the page. --- core/js/sharedialogview.js | 6 ++++ core/js/tests/specs/sharedialogviewSpec.js | 37 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index e7435877cb..b406299a07 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -281,6 +281,12 @@ .attr('disabled', false); $loading.addClass('hidden') .removeClass('inlineblock'); + }, error: function(obj, msg) { + OC.Notification.showTemporary(msg); + $(e.target).val('') + .attr('disabled', false); + $loading.addClass('hidden') + .removeClass('inlineblock'); }}); }, diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js index 3a94379789..23214a7fe8 100644 --- a/core/js/tests/specs/sharedialogviewSpec.js +++ b/core/js/tests/specs/sharedialogviewSpec.js @@ -990,6 +990,43 @@ describe('OC.Share.ShareDialogView', function() { addShareStub.restore(); }); + + it('calls addShare after selection and fail to share', 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', {target: shareWith}), { + item: { + label: 'User Two', + value: { + shareType: OC.Share.SHARE_TYPE_USER, + shareWith: 'user2' + } + } + }); + + expect(addShareStub.calledOnce).toEqual(true); + expect(addShareStub.firstCall.args[0]).toEqual({ + shareType: OC.Share.SHARE_TYPE_USER, + shareWith: 'user2' + }); + + //Input is locked + expect($shareWith.val()).toEqual('User Two'); + expect($shareWith.attr('disabled')).toEqual('disabled'); + + //Callback is called + addShareStub.firstCall.args[1].error(); + + //Input is unlocked + expect($shareWith.val()).toEqual('User Two'); + expect($shareWith.attr('disabled')).toEqual(undefined); + + addShareStub.restore(); + }); }); describe('reshare permissions', function() { it('does not show sharing options when sharing not allowed', function() { From a9a3947e6177cc8f1e379e55453bf0d54ac0b01c Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 17 Feb 2016 09:19:21 +0100 Subject: [PATCH 2/2] Do not clear sharee input on failed share --- core/js/sharedialogview.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index b406299a07..4412d139c3 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -283,8 +283,8 @@ .removeClass('inlineblock'); }, error: function(obj, msg) { OC.Notification.showTemporary(msg); - $(e.target).val('') - .attr('disabled', false); + $(e.target).attr('disabled', false) + .autocomplete('search', $(e.target).val()); $loading.addClass('hidden') .removeClass('inlineblock'); }});