From d3c6d3a25809fe7bdd0750a41ef0ee1af105a149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Tue, 20 Mar 2018 13:44:28 +0100 Subject: [PATCH] Extract code to restore the UI after confirming a share MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- core/js/sharedialogview.js | 45 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 2845af0e83727..0a4178356ebe3 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -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( @@ -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'); @@ -508,12 +512,7 @@ } if (exactMatches.length !== 1) { - $loading.addClass('hidden'); - $loading.removeClass('inlineblock'); - $confirm.removeClass('hidden'); - - $shareWithField.prop('disabled', false); - $shareWithField.focus(); + restoreUI(); $shareWithField.autocomplete('enable'); @@ -521,24 +520,15 @@ } 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'); @@ -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');