mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
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.
This commit is contained in:
parent
ab245f5b19
commit
86a9f27692
@ -1490,6 +1490,35 @@
|
||||
notification: { poll: pollAsyncJobResult }
|
||||
},
|
||||
|
||||
makeDefault: {
|
||||
label: 'Set default NIC',
|
||||
messages: {
|
||||
confirm: function() {
|
||||
return 'Please confirm that you would like to make this NIC the default for this VM.';
|
||||
},
|
||||
notification: function(args) {
|
||||
return 'Set default NIC'
|
||||
}
|
||||
},
|
||||
action: function (args) {
|
||||
$.ajax({
|
||||
url: createURL('updateDefaultNicForVirtualMachine'),
|
||||
data: {
|
||||
virtualmachineid: args.context.instances[0].id,
|
||||
nicid: args.context.nics[0].id
|
||||
},
|
||||
success: function(json) {
|
||||
args.response.success({
|
||||
_custom: { jobId: json.updatedefaultnicforvirtualmachineresponse.jobid }
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
notification: {
|
||||
poll: pollAsyncJobResult
|
||||
}
|
||||
},
|
||||
|
||||
// Remove NIC/Network from VM
|
||||
remove: {
|
||||
label: 'label.action.delete.nic',
|
||||
@ -1506,7 +1535,7 @@
|
||||
url: createURL('removeNicFromVirtualMachine'),
|
||||
data: {
|
||||
virtualmachineid: args.context.instances[0].id,
|
||||
nicid: args.context.nics.id
|
||||
nicid: args.context.nics[0].id
|
||||
},
|
||||
success: function(json) {
|
||||
args.response.success({
|
||||
@ -1522,6 +1551,7 @@
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
id: { label: 'ID' },
|
||||
name: { label: 'label.name', header: true },
|
||||
networkname: {label: 'Network Name' },
|
||||
type: { label: 'label.type' },
|
||||
@ -1551,26 +1581,33 @@
|
||||
}
|
||||
},
|
||||
dataProvider: function(args) {
|
||||
$.ajax({
|
||||
url:createURL("listVirtualMachines&details=nics&id=" + args.context.instances[0].id),
|
||||
dataType: "json",
|
||||
async:true,
|
||||
success:function(json) {
|
||||
// Handling the display of network name for a VM under the NICS tabs
|
||||
args.response.success({
|
||||
data: $.map(json.listvirtualmachinesresponse.virtualmachine[0].nic, function(nic, index) {
|
||||
var name = 'NIC ' + (index + 1);
|
||||
if (nic.isdefault) {
|
||||
name += ' (' + _l('label.default') + ')';
|
||||
}
|
||||
return $.extend(nic, {
|
||||
$.ajax({
|
||||
url:createURL("listVirtualMachines&details=nics&id=" + args.context.instances[0].id),
|
||||
dataType: "json",
|
||||
async:true,
|
||||
success:function(json) {
|
||||
// Handling the display of network name for a VM under the NICS tabs
|
||||
args.response.success({
|
||||
actionFilter: function(args) {
|
||||
if (args.context.item.isdefault) {
|
||||
return [];
|
||||
} else {
|
||||
return ['remove', 'makeDefault'];
|
||||
}
|
||||
},
|
||||
data: $.map(json.listvirtualmachinesresponse.virtualmachine[0].nic, function(nic, index) {
|
||||
var name = 'NIC ' + (index + 1);
|
||||
if (nic.isdefault) {
|
||||
name += ' (' + _l('label.default') + ')';
|
||||
}
|
||||
return $.extend(nic, {
|
||||
name: name
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -70,7 +70,7 @@
|
||||
action.notification : {};
|
||||
var messages = action.messages;
|
||||
var id = args.id;
|
||||
var context = $detailView.data('view-args').context;
|
||||
var context = args.context ? args.context : $detailView.data('view-args').context;
|
||||
var _custom = $detailView.data('_custom');
|
||||
var customAction = action.action.custom;
|
||||
var noAdd = action.noAdd;
|
||||
@ -180,7 +180,7 @@
|
||||
data: data,
|
||||
_custom: _custom,
|
||||
ref: options.ref,
|
||||
context: $detailView.data('view-args').context,
|
||||
context: context,
|
||||
$form: $form,
|
||||
response: {
|
||||
success: function(args) {
|
||||
@ -288,14 +288,14 @@
|
||||
after: function(args) {
|
||||
performAction(args.data, {
|
||||
ref: args.ref,
|
||||
context: $detailView.data('view-args').context,
|
||||
context: context,
|
||||
$form: args.$form
|
||||
});
|
||||
},
|
||||
ref: {
|
||||
id: id
|
||||
},
|
||||
context: $detailView.data('view-args').context
|
||||
context: context
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -308,7 +308,7 @@
|
||||
uiActions.standard($detailView, args, {
|
||||
noRefresh: true,
|
||||
complete: function(args) {
|
||||
if (isMultiple) {
|
||||
if (isMultiple && $detailView.is(':visible')) {
|
||||
$detailView.find('.refresh').click(); // Reload tab
|
||||
} else {
|
||||
var $browser = $('#browser .container');
|
||||
@ -790,12 +790,13 @@
|
||||
var detailViewArgs = $detailView.data('view-args');
|
||||
var fields = tabData.fields;
|
||||
var hiddenFields;
|
||||
var context = detailViewArgs ? detailViewArgs.context : cloudStack.context;
|
||||
var context = $.extend(true, {}, detailViewArgs ? detailViewArgs.context : cloudStack.context);
|
||||
var isMultiple = tabData.multiple || tabData.isMultiple;
|
||||
var actions = tabData.actions;
|
||||
|
||||
if (isMultiple) {
|
||||
context[tabData.id] = data;
|
||||
context[tabData.id] = [data];
|
||||
$detailGroups.data('item-context', context);
|
||||
}
|
||||
|
||||
// Make header
|
||||
@ -1087,7 +1088,11 @@
|
||||
tabData.viewAll.path,
|
||||
{
|
||||
updateContext: function(args) {
|
||||
return { nics: [item] };
|
||||
var obj = {};
|
||||
|
||||
obj[targetTabID] = [item];
|
||||
|
||||
return obj;
|
||||
},
|
||||
title: tabData.viewAll.title
|
||||
}
|
||||
@ -1099,9 +1104,11 @@
|
||||
// Add action bar
|
||||
if (tabData.multiple && tabData.actions) {
|
||||
var $actions = makeActionButtons(tabData.actions, {
|
||||
actionFilter: tabData.actions.actionFilter,
|
||||
actionFilter: actionFilter,
|
||||
data: item,
|
||||
context: $detailView.data('view-args').context,
|
||||
context: $.extend(true, {}, $detailView.data('view-args').context, {
|
||||
item: [item]
|
||||
}),
|
||||
ignoreAddAction: true
|
||||
});
|
||||
|
||||
@ -1357,9 +1364,10 @@
|
||||
var $action = $target.closest('.action').find('[detail-action]');
|
||||
var actionName = $action.attr('detail-action');
|
||||
var actionCallback = $action.data('detail-view-action-callback');
|
||||
var detailViewArgs = $action.closest('div.detail-view').data('view-args');
|
||||
var detailViewArgs = $.extend(true, {}, $action.closest('div.detail-view').data('view-args'));
|
||||
var additionalArgs = {};
|
||||
var actionSet = uiActions;
|
||||
var $details = $action.closest('.details');
|
||||
|
||||
var uiCallback = actionSet[actionName];
|
||||
if (!uiCallback)
|
||||
@ -1367,6 +1375,10 @@
|
||||
|
||||
detailViewArgs.actionName = actionName;
|
||||
|
||||
if ($details.data('item-context')) {
|
||||
detailViewArgs.context = $details.data('item-context');
|
||||
}
|
||||
|
||||
uiCallback($target.closest('div.detail-view'), detailViewArgs, additionalArgs);
|
||||
|
||||
return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user