Skip to content

Commit

Permalink
Extract code to restore the UI after confirming a share
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Mar 20, 2018
1 parent ac4fb0d commit d3c6d3a
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@
$shareWithField.autocomplete('close');
$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 onlyExactMatches = true;
this._getSuggestions(
Expand All @@ -490,12 +499,7 @@
onlyExactMatches
).done(function(suggestions, exactMatches) {
if (suggestions.length === 0) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');

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

$shareWithField.autocomplete('enable');

Expand All @@ -508,37 +512,23 @@
}

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

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

$shareWithField.autocomplete('enable');

return;
}

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

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

restoreUI();

$shareWithField.autocomplete('enable');
};

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

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

$shareWithField.autocomplete('enable');

Expand All @@ -550,12 +540,7 @@
error: actionError
});
}).fail(function(message) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');

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

$shareWithField.autocomplete('enable');

Expand Down

0 comments on commit d3c6d3a

Please sign in to comment.