Skip to content

Commit

Permalink
Expose XHR response in share dialog autocomplete callback
Browse files Browse the repository at this point in the history
This makes it possible for apps that override the handler to have access
to the actual response and also exact matches.
  • Loading branch information
Vincent Petry committed Oct 13, 2017
1 parent 2ac86a5 commit 7fddd51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
$('.shareWithField').removeClass('error')
.tooltip('hide')
.autocomplete("option", "autoFocus", true);
response(suggestions);
response(suggestions, result);
} else {
var title = t('core', 'No users or groups found for {search}', {search: $('.shareWithField').val()});
if (!view.configModel.get('allowGroupSharing')) {
Expand All @@ -266,10 +266,10 @@
})
.tooltip('fixTitle')
.tooltip('show');
response();
response(undefined, result);
}
} else {
response();
response(undefined, result);
}
}
).fail(function() {
Expand Down
30 changes: 16 additions & 14 deletions core/js/tests/specs/sharedialogviewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('OC.Share.ShareDialogView', function() {
jsonData
);

expect(response.calledWithExactly([
expect(response.getCall(0).args[0]).toEqual([
{
"label": "Peter A.",
"value": {
Expand All @@ -301,7 +301,8 @@ describe('OC.Share.ShareDialogView', function() {
"shareWith": "Petra"
}
}
])).toEqual(true);
]);
expect(response.getCall(0).args[1].ocs).toBeDefined();
});
it('triggers autocomplete display and focus with data when ajax search succeeds', function () {
dialog.render();
Expand Down Expand Up @@ -331,7 +332,7 @@ describe('OC.Share.ShareDialogView', function() {
{'Content-Type': 'application/json'},
jsonData
);
expect(response.calledWithExactly(JSON.parse(jsonData).ocs.data.users)).toEqual(true);
expect(response.getCall(0).args[0]).toEqual(JSON.parse(jsonData).ocs.data.users);
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
});

Expand Down Expand Up @@ -379,10 +380,10 @@ describe('OC.Share.ShareDialogView', function() {
{'Content-Type': 'application/json'},
jsonData
);
expect(response.calledWithExactly([{
expect(response.getCall(0).args[0]).toEqual([{
'label': 'bobby',
'value': {'shareType': 0, 'shareWith': 'imbob'}
}])).toEqual(true);
}]);
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
});

Expand Down Expand Up @@ -437,10 +438,10 @@ describe('OC.Share.ShareDialogView', function() {
{'Content-Type': 'application/json'},
jsonData
);
expect(response.calledWithExactly([{
expect(response.getCall(0).args[0]).toEqual([{
'label': 'bobby',
'value': {'shareType': 0, 'shareWith': 'imbob'}
}])).toEqual(true);
}]);
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
});

Expand Down Expand Up @@ -517,10 +518,10 @@ describe('OC.Share.ShareDialogView', function() {
{'Content-Type': 'application/json'},
jsonData
);
expect(response.calledWithExactly([{
expect(response.getCall(0).args[0]).toEqual([{
'label': 'bobby',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
}])).toEqual(true);
}]);
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
});

Expand Down Expand Up @@ -567,10 +568,10 @@ describe('OC.Share.ShareDialogView', function() {
{'Content-Type': 'application/json'},
jsonData
);
expect(response.calledWithExactly([{
expect(response.getCall(0).args[0]).toEqual([{
'label': 'group2',
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group2'}
}])).toEqual(true);
}]);
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
});

Expand Down Expand Up @@ -617,10 +618,10 @@ describe('OC.Share.ShareDialogView', function() {
{'Content-Type': 'application/json'},
jsonData
);
expect(response.calledWithExactly([{
expect(response.getCall(0).args[0]).toEqual([{
'label': 'foo2@bar.com/baz',
'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo2@bar.com/baz'}
}])).toEqual(true);
}]);
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
});
});
Expand All @@ -643,7 +644,8 @@ describe('OC.Share.ShareDialogView', function() {
{'Content-Type': 'application/json'},
jsonData
);
expect(response.calledWithExactly()).toEqual(true);
expect(response.getCall(0).args[0]).not.toBeDefined();
expect(response.getCall(0).args[1].ocs).toBeDefined();
});

it('throws a notification when the ajax search lookup fails', function () {
Expand Down

0 comments on commit 7fddd51

Please sign in to comment.