Skip to content

Commit b58371e

Browse files
committed
List view: Fix action pre-filter for multiselect actions
Evaluates pre-filter for individual actions (i.e., when action.preFilter is specified) every time a multi-select row is checked orunchecked. This allows multi-select actions to be shown/hidden on a per-row basis.
1 parent 733102c commit b58371e

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

ui/scripts/ui/widgets/listView.js

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,12 +1748,21 @@
17481748
// List view header actions
17491749
if (listViewData.actions) {
17501750
$.each(listViewData.actions, function(actionName, action) {
1751-
if (!action.isHeader || (
1752-
action.preFilter && !action.preFilter({
1751+
var preFilter = function(extendContext) {
1752+
var context = $.extend(true, {},
1753+
$listView.data('view-args').context ? $listView.data('view-args').context : cloudStack.context);
1754+
1755+
if (extendContext) {
1756+
$.extend(context, extendContext);
1757+
}
1758+
1759+
return action.preFilter ? action.preFilter({
17531760
id: listViewData.id,
1754-
context: $listView.data('view-args').context ? $listView.data('view-args').context : cloudStack.context
1755-
})
1756-
)) return true;
1761+
context: context
1762+
}) : null;
1763+
}
1764+
1765+
if (!action.isHeader || (action.preFilter && !preFilter())) return true;
17571766

17581767
var $action = $('<div>')
17591768
.addClass('button action main-action reduced-hide').addClass(actionName)
@@ -1764,6 +1773,10 @@
17641773
if (action.isMultiSelectAction) {
17651774
$action.addClass('multiSelectAction');
17661775
$action.hide();
1776+
1777+
if (action.preFilter) {
1778+
$action.data('list-view-action-prefilter', preFilter);
1779+
}
17671780
}
17681781

17691782
$toolbar.append($action)
@@ -2234,9 +2247,32 @@
22342247
};
22352248

22362249
var toggleMultiSelectActions = function($listView, enabled) {
2250+
var $multiSelectActions = $listView.find('div.main-action.multiSelectAction');
2251+
22372252
$listView.find('div.action.add')[enabled ? 'hide' : 'show']();
22382253
$listView.find('div.main-action:not(.multiSelectAction)')[enabled ? 'hide' : 'show']();
2239-
$listView.find('div.main-action.multiSelectAction')[enabled ? 'show' : 'hide']();
2254+
$multiSelectActions.hide();
2255+
2256+
if (enabled) {
2257+
$multiSelectActions.filter(function() {
2258+
var preFilter = $(this).data('list-view-action-prefilter');
2259+
var $selectedVMs;
2260+
var context = {};
2261+
2262+
if (preFilter) {
2263+
$selectedVMs = $listView.find('tbody tr').filter(function() {
2264+
return $(this).find('td.multiselect input[type=checkbox]:checked').size()
2265+
});
2266+
context[$listView.data('view-args').activeSection] = $selectedVMs.map(function(index, item) {
2267+
return $(item).data('json-obj');
2268+
});
2269+
2270+
return preFilter(context);
2271+
}
2272+
2273+
return true;
2274+
}).show();
2275+
}
22402276
}
22412277

22422278
$.fn.listView = function(args, options) {

0 commit comments

Comments
 (0)