From e6c3e59e39c6b2e86d6af8a1fb021ee53714acb9 Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Thu, 25 Oct 2012 14:39:24 -0700 Subject: [PATCH] UI custom actions/enable static NAT: fix loading state Fixes a bug where the loading state is not immediataly set for the detail view on performing certain custom UI actions, particularly enable static NAT. This passes a separate 'start' function to the custom widgets, which triggers the loading state, and 'complete' when the action completes (i.e., the server call is done) --- ui/scripts/ui-custom/enableStaticNAT.js | 2 ++ ui/scripts/ui/widgets/detailView.js | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ui/scripts/ui-custom/enableStaticNAT.js b/ui/scripts/ui-custom/enableStaticNAT.js index 405813e7a39..47d5dd298db 100644 --- a/ui/scripts/ui-custom/enableStaticNAT.js +++ b/ui/scripts/ui-custom/enableStaticNAT.js @@ -89,7 +89,9 @@ } var complete = args.complete; + var start = args.start; + start(); $dataList.fadeOut(function() { action({ tierID: $dataList.find('.tier-select select').val(), diff --git a/ui/scripts/ui/widgets/detailView.js b/ui/scripts/ui/widgets/detailView.js index 838bfbddcf4..4fc2689ab4e 100644 --- a/ui/scripts/ui/widgets/detailView.js +++ b/ui/scripts/ui/widgets/detailView.js @@ -98,21 +98,27 @@ var $form = options.$form; var viewArgs = $detailView.data('view-args'); + var $loading = $('
').addClass('loading-overlay'); + + var setLoadingState = function() { + if (viewArgs && viewArgs.onPerformAction) { + viewArgs.onPerformAction(); + } + + $detailView.addClass('detail-view-loading-state'); + $detailView.prepend($loading); + }; if (customAction && !noAdd) { customAction({ context: context, $detailView: $detailView, + start: setLoadingState, complete: function(args) { - if (viewArgs && viewArgs.onPerformAction) { - viewArgs.onPerformAction(); + if (!$detailView.hasClass('detail-view-loading-state')) { + setLoadingState(); } - - // Set loading appearance - var $loading = $('
').addClass('loading-overlay'); - - $detailView.prepend($loading); - + args = args ? args : {}; var $item = args.$item; @@ -134,6 +140,7 @@ if (!$detailView.parents('html').size()) return; $loading.remove(); + $detailView.removeClass('detail-view-loading-state'); replaceListViewItem($detailView, args.data); if (!noRefresh) {