From 314c1f90c4236b76fc7495c63b48441142dfd1fe Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Fri, 9 Dec 2011 09:12:25 -0800 Subject: [PATCH] Clean up handling for UI refresh events -Always unbind event if object isn't visible -Use widget-specific refresh event for multi-edit actions, to prevent other widgets from being refreshed unecessarily. --- ui/scripts/ui-custom/zoneChart.js | 11 ++++++++--- ui/scripts/ui/multiEdit.js | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ui/scripts/ui-custom/zoneChart.js b/ui/scripts/ui-custom/zoneChart.js index df85cf4cd54..50d3059976b 100644 --- a/ui/scripts/ui-custom/zoneChart.js +++ b/ui/scripts/ui-custom/zoneChart.js @@ -439,9 +439,14 @@ return false; }); - $(window).bind('cloudStack.fullRefresh', function(event) { - refreshChart(); - }); + var fullRefreshEvent = function(event) { + if ($charts.is(':visible')) { + refreshChart(); + } else { + $(window).unbind('cloudStack.fullRefresh', fullRefreshEvent); + } + }; + $(window).bind('cloudStack.fullRefresh', fullRefreshEvent); }; loadNetworkData(); diff --git a/ui/scripts/ui/multiEdit.js b/ui/scripts/ui/multiEdit.js index 12bd68a013b..b6e03ac2879 100644 --- a/ui/scripts/ui/multiEdit.js +++ b/ui/scripts/ui/multiEdit.js @@ -159,7 +159,7 @@ $loading.remove(); $dataItem.remove(); } else { - $(window).trigger('cloudStack.fullRefresh'); + $multi.trigger('refresh'); } complete(); @@ -168,7 +168,7 @@ error(args); $loading.remove(); $dataItem.show(); - + return cloudStack.dialog.error; } }); @@ -513,7 +513,7 @@ complete: function(completeArgs) { complete(args); $loading.remove(); - $(window).trigger('cloudStack.fullRefresh'); + getData(); }, error: function(args) { @@ -555,10 +555,10 @@ 'input[type=radio]:checked, input[type=checkbox]:checked' ).size()) { cloudStack.dialog.notice({ message: 'Please select an instance '}); - + return false; } - + $dataList.fadeOut(function() { addItem($.map( $dataList.find('tr.multi-edit-selected'), @@ -631,11 +631,15 @@ // Get existing data getData(); - $(window).bind('cloudStack.fullRefresh', function(event) { + var fullRefreshEvent = function(event) { if ($multi.is(':visible')) { - getData(); + getData(); + } else { + $(window).unbind('cloudStack.fullRefresh', fullRefreshEvent); } - }); + }; + $(window).bind('cloudStack.fullRefresh', fullRefreshEvent); + $multi.bind('refresh', fullRefreshEvent); $multi.bind('change select', function() { _medit.refreshItemWidths($multi);