Skip to content

Commit 86a9f27

Browse files
committed
Detail view/instances section: Fix context, add makeDefault action
-Add 'makeDefault' action to set default NIC -Fix context passing for multi-actions, which wasn't passing the correct nic object previously.
1 parent ab245f5 commit 86a9f27

2 files changed

Lines changed: 80 additions & 31 deletions

File tree

‎ui/scripts/instances.js‎

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,35 @@
14901490
notification: { poll: pollAsyncJobResult }
14911491
},
14921492

1493+
makeDefault: {
1494+
label: 'Set default NIC',
1495+
messages: {
1496+
confirm: function() {
1497+
return 'Please confirm that you would like to make this NIC the default for this VM.';
1498+
},
1499+
notification: function(args) {
1500+
return 'Set default NIC'
1501+
}
1502+
},
1503+
action: function (args) {
1504+
$.ajax({
1505+
url: createURL('updateDefaultNicForVirtualMachine'),
1506+
data: {
1507+
virtualmachineid: args.context.instances[0].id,
1508+
nicid: args.context.nics[0].id
1509+
},
1510+
success: function(json) {
1511+
args.response.success({
1512+
_custom: { jobId: json.updatedefaultnicforvirtualmachineresponse.jobid }
1513+
});
1514+
}
1515+
});
1516+
},
1517+
notification: {
1518+
poll: pollAsyncJobResult
1519+
}
1520+
},
1521+
14931522
// Remove NIC/Network from VM
14941523
remove: {
14951524
label: 'label.action.delete.nic',
@@ -1506,7 +1535,7 @@
15061535
url: createURL('removeNicFromVirtualMachine'),
15071536
data: {
15081537
virtualmachineid: args.context.instances[0].id,
1509-
nicid: args.context.nics.id
1538+
nicid: args.context.nics[0].id
15101539
},
15111540
success: function(json) {
15121541
args.response.success({
@@ -1522,6 +1551,7 @@
15221551
},
15231552
fields: [
15241553
{
1554+
id: { label: 'ID' },
15251555
name: { label: 'label.name', header: true },
15261556
networkname: {label: 'Network Name' },
15271557
type: { label: 'label.type' },
@@ -1551,26 +1581,33 @@
15511581
}
15521582
},
15531583
dataProvider: function(args) {
1554-
$.ajax({
1555-
url:createURL("listVirtualMachines&details=nics&id=" + args.context.instances[0].id),
1556-
dataType: "json",
1557-
async:true,
1558-
success:function(json) {
1559-
// Handling the display of network name for a VM under the NICS tabs
1560-
args.response.success({
1561-
data: $.map(json.listvirtualmachinesresponse.virtualmachine[0].nic, function(nic, index) {
1562-
var name = 'NIC ' + (index + 1);
1563-
if (nic.isdefault) {
1564-
name += ' (' + _l('label.default') + ')';
1565-
}
1566-
return $.extend(nic, {
1584+
$.ajax({
1585+
url:createURL("listVirtualMachines&details=nics&id=" + args.context.instances[0].id),
1586+
dataType: "json",
1587+
async:true,
1588+
success:function(json) {
1589+
// Handling the display of network name for a VM under the NICS tabs
1590+
args.response.success({
1591+
actionFilter: function(args) {
1592+
if (args.context.item.isdefault) {
1593+
return [];
1594+
} else {
1595+
return ['remove', 'makeDefault'];
1596+
}
1597+
},
1598+
data: $.map(json.listvirtualmachinesresponse.virtualmachine[0].nic, function(nic, index) {
1599+
var name = 'NIC ' + (index + 1);
1600+
if (nic.isdefault) {
1601+
name += ' (' + _l('label.default') + ')';
1602+
}
1603+
return $.extend(nic, {
15671604
name: name
1568-
});
1569-
})
1570-
});
1571-
}
1572-
});
1573-
}
1605+
});
1606+
})
1607+
});
1608+
}
1609+
});
1610+
}
15741611
},
15751612

15761613
/**

‎ui/scripts/ui/widgets/detailView.js‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
action.notification : {};
7171
var messages = action.messages;
7272
var id = args.id;
73-
var context = $detailView.data('view-args').context;
73+
var context = args.context ? args.context : $detailView.data('view-args').context;
7474
var _custom = $detailView.data('_custom');
7575
var customAction = action.action.custom;
7676
var noAdd = action.noAdd;
@@ -180,7 +180,7 @@
180180
data: data,
181181
_custom: _custom,
182182
ref: options.ref,
183-
context: $detailView.data('view-args').context,
183+
context: context,
184184
$form: $form,
185185
response: {
186186
success: function(args) {
@@ -288,14 +288,14 @@
288288
after: function(args) {
289289
performAction(args.data, {
290290
ref: args.ref,
291-
context: $detailView.data('view-args').context,
291+
context: context,
292292
$form: args.$form
293293
});
294294
},
295295
ref: {
296296
id: id
297297
},
298-
context: $detailView.data('view-args').context
298+
context: context
299299
});
300300
}
301301
}
@@ -308,7 +308,7 @@
308308
uiActions.standard($detailView, args, {
309309
noRefresh: true,
310310
complete: function(args) {
311-
if (isMultiple) {
311+
if (isMultiple && $detailView.is(':visible')) {
312312
$detailView.find('.refresh').click(); // Reload tab
313313
} else {
314314
var $browser = $('#browser .container');
@@ -790,12 +790,13 @@
790790
var detailViewArgs = $detailView.data('view-args');
791791
var fields = tabData.fields;
792792
var hiddenFields;
793-
var context = detailViewArgs ? detailViewArgs.context : cloudStack.context;
793+
var context = $.extend(true, {}, detailViewArgs ? detailViewArgs.context : cloudStack.context);
794794
var isMultiple = tabData.multiple || tabData.isMultiple;
795795
var actions = tabData.actions;
796796

797797
if (isMultiple) {
798-
context[tabData.id] = data;
798+
context[tabData.id] = [data];
799+
$detailGroups.data('item-context', context);
799800
}
800801

801802
// Make header
@@ -1087,7 +1088,11 @@
10871088
tabData.viewAll.path,
10881089
{
10891090
updateContext: function(args) {
1090-
return { nics: [item] };
1091+
var obj = {};
1092+
1093+
obj[targetTabID] = [item];
1094+
1095+
return obj;
10911096
},
10921097
title: tabData.viewAll.title
10931098
}
@@ -1099,9 +1104,11 @@
10991104
// Add action bar
11001105
if (tabData.multiple && tabData.actions) {
11011106
var $actions = makeActionButtons(tabData.actions, {
1102-
actionFilter: tabData.actions.actionFilter,
1107+
actionFilter: actionFilter,
11031108
data: item,
1104-
context: $detailView.data('view-args').context,
1109+
context: $.extend(true, {}, $detailView.data('view-args').context, {
1110+
item: [item]
1111+
}),
11051112
ignoreAddAction: true
11061113
});
11071114

@@ -1357,16 +1364,21 @@
13571364
var $action = $target.closest('.action').find('[detail-action]');
13581365
var actionName = $action.attr('detail-action');
13591366
var actionCallback = $action.data('detail-view-action-callback');
1360-
var detailViewArgs = $action.closest('div.detail-view').data('view-args');
1367+
var detailViewArgs = $.extend(true, {}, $action.closest('div.detail-view').data('view-args'));
13611368
var additionalArgs = {};
13621369
var actionSet = uiActions;
1370+
var $details = $action.closest('.details');
13631371

13641372
var uiCallback = actionSet[actionName];
13651373
if (!uiCallback)
13661374
uiCallback = actionSet['standard'];
13671375

13681376
detailViewArgs.actionName = actionName;
13691377

1378+
if ($details.data('item-context')) {
1379+
detailViewArgs.context = $details.data('item-context');
1380+
}
1381+
13701382
uiCallback($target.closest('div.detail-view'), detailViewArgs, additionalArgs);
13711383

13721384
return false;

0 commit comments

Comments
 (0)