summaryrefslogtreecommitdiffstats
path: root/core/js/sharedialogview.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/js/sharedialogview.js')
-rw-r--r--core/js/sharedialogview.js90
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);