Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a share when clicking on the confirm button
Clicking on the confirm button now adds a share, but only if there is
just a single exact match. If there are no exact matches or there is
more than one exact match no share is added, and the autocomplete
dropdown is shown again with all the suggestions.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Mar 20, 2018
commit 9371b61c4df9eb9dc6285e988431ac9cae228952
90 changes: 89 additions & 1 deletion core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@

events: {
'focus .shareWithField': 'onShareWithFieldFocus',
'input .shareWithField': 'onShareWithFieldChanged'
'input .shareWithField': 'onShareWithFieldChanged',
'click .shareWithConfirm': '_confirmShare'
},

initialize: function(options) {
Expand Down Expand Up @@ -438,6 +439,93 @@
}});
},

_confirmShare: function() {
var self = this;
var $shareWithField = $('.shareWithField');
var $loading = this.$el.find('.shareWithLoading');
var $confirm = this.$el.find('.shareWithConfirm');

$loading.removeClass('hidden');
$loading.addClass('inlineblock');
$confirm.addClass('hidden');

$shareWithField.prop('disabled', true);

var perPage = 200;
var onlyExactMatches = true;
this._getSuggestions(
$shareWithField.val(),
perPage,
this.model,
onlyExactMatches
).done(function(suggestions, exactMatches) {
if (suggestions.length === 0) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');

$shareWithField.prop('disabled', false);
$shareWithField.focus();

// There is no need to show an error message here; it will
// be automatically shown when the autocomplete is activated
// again (due to the focus on the field) and it finds no
// matches.

return;
}

if (exactMatches.length !== 1) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');

$shareWithField.prop('disabled', false);
$shareWithField.focus();

return;
}

var actionSuccess = function() {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');

$shareWithField.val('');
$shareWithField.prop('disabled', false);
$shareWithField.focus();
};

var actionError = function(obj, msg) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');

$shareWithField.prop('disabled', false);
$shareWithField.focus();

OC.Notification.showTemporary(msg);
};

self.model.addShare(exactMatches[0].value, {
success: actionSuccess,
error: actionError
});
}).fail(function(message) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');

$shareWithField.prop('disabled', false);
$shareWithField.focus();

// There is no need to show an error message here; it will be
// automatically shown when the autocomplete is activated again
// (due to the focus on the field) and getting the suggestions
// fail.
});
},

_toggleLoading: function(state) {
this._loading = state;
this.$el.find('.subView').toggleClass('hidden', state);
Expand Down
Loading