diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-03-19 18:54:27 +0100 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-03-20 19:09:05 +0100 |
commit | 9371b61c4df9eb9dc6285e988431ac9cae228952 (patch) | |
tree | 332ea56b7fb3e9ea6054bfbb5d9f9b78240b538d /core/js/sharedialogview.js | |
parent | 5e2a8cca1b79d7ab5574bcc4d7309bcf0f7a2522 (diff) | |
download | nextcloud-server-9371b61c4df9eb9dc6285e988431ac9cae228952.tar.gz nextcloud-server-9371b61c4df9eb9dc6285e988431ac9cae228952.zip |
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 <danxuliu@gmail.com>
Diffstat (limited to 'core/js/sharedialogview.js')
-rw-r--r-- | core/js/sharedialogview.js | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index d67ff89e281..89bd2e2dbfc 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -67,7 +67,8 @@ events: { 'focus .shareWithField': 'onShareWithFieldFocus', - 'input .shareWithField': 'onShareWithFieldChanged' + 'input .shareWithField': 'onShareWithFieldChanged', + 'click .shareWithConfirm': '_confirmShare' }, initialize: function(options) { @@ -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); |