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)
This commit is contained in:
Brian Federle 2012-10-25 14:39:24 -07:00
parent 0b2e5f1b17
commit e6c3e59e39
2 changed files with 17 additions and 8 deletions

View File

@ -89,7 +89,9 @@
}
var complete = args.complete;
var start = args.start;
start();
$dataList.fadeOut(function() {
action({
tierID: $dataList.find('.tier-select select').val(),

View File

@ -98,21 +98,27 @@
var $form = options.$form;
var viewArgs = $detailView.data('view-args');
var $loading = $('<div>').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 = $('<div>').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) {