Extract code to restore the UI after confirming a share

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2018-03-20 13:44:28 +01:00
parent 9a0fbe307d
commit a2c52cd6a5
1 changed files with 15 additions and 30 deletions

View File

@ -484,6 +484,15 @@
$shareWithField.autocomplete('close'); $shareWithField.autocomplete('close');
$shareWithField.autocomplete('disable'); $shareWithField.autocomplete('disable');
var restoreUI = function() {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
$shareWithField.prop('disabled', false);
$shareWithField.focus();
};
var perPage = 200; var perPage = 200;
var onlyExactMatches = true; var onlyExactMatches = true;
this._getSuggestions( this._getSuggestions(
@ -493,12 +502,7 @@
onlyExactMatches onlyExactMatches
).done(function(suggestions, exactMatches) { ).done(function(suggestions, exactMatches) {
if (suggestions.length === 0) { if (suggestions.length === 0) {
$loading.addClass('hidden'); restoreUI();
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
$shareWithField.prop('disabled', false);
$shareWithField.focus();
$shareWithField.autocomplete('enable'); $shareWithField.autocomplete('enable');
@ -511,12 +515,7 @@
} }
if (exactMatches.length !== 1) { if (exactMatches.length !== 1) {
$loading.addClass('hidden'); restoreUI();
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
$shareWithField.prop('disabled', false);
$shareWithField.focus();
$shareWithField.autocomplete('enable'); $shareWithField.autocomplete('enable');
@ -524,27 +523,18 @@
} }
var actionSuccess = function() { var actionSuccess = function() {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
// Adding a share changes the suggestions. // Adding a share changes the suggestions.
self._lastSuggestions = undefined; self._lastSuggestions = undefined;
$shareWithField.val(''); $shareWithField.val('');
$shareWithField.prop('disabled', false);
$shareWithField.focus(); restoreUI();
$shareWithField.autocomplete('enable'); $shareWithField.autocomplete('enable');
}; };
var actionError = function(obj, msg) { var actionError = function(obj, msg) {
$loading.addClass('hidden'); restoreUI();
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
$shareWithField.prop('disabled', false);
$shareWithField.focus();
$shareWithField.autocomplete('enable'); $shareWithField.autocomplete('enable');
@ -556,12 +546,7 @@
error: actionError error: actionError
}); });
}).fail(function(message) { }).fail(function(message) {
$loading.addClass('hidden'); restoreUI();
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
$shareWithField.prop('disabled', false);
$shareWithField.focus();
$shareWithField.autocomplete('enable'); $shareWithField.autocomplete('enable');