UI, instance nics tab: Implement 'add network' action

-Change detail widget to support 'add' action on per-nic/item detail groups

-Implement add network/NIC action on instances NIC tab
This commit is contained in:
Brian Federle 2013-04-03 14:22:15 -07:00
parent 21f953ffa4
commit 93db30e4e1
2 changed files with 80 additions and 0 deletions

View File

@ -1227,6 +1227,62 @@
nics: {
title: 'label.nics',
multiple: true,
actions: {
add: {
label: 'Add network to VM',
messages: {
confirm: function(args) {
return 'Please confirm that you would like to add a new VM NIC for this network.';
},
notification: function(args) {
return 'Add network to VM';
}
},
createForm: {
title: 'Add network to VM',
desc: 'Please specify the network that you would like to add this VM to. A new NIC will be added for this network.',
fields: {
networkid: {
label: 'label.network',
select: function(args) {
$.ajax({
url: createURL('listNetworks'),
data: {
listAll: true,
zoneid: args.context.instances[0].zoneid
},
success: function(json) {
args.response.success({
data: $.map(json.listnetworksresponse.network, function(network) {
return {
id: network.id,
description: network.name
};
})
});
}
});
}
}
}
},
action: function(args) {
$.ajax({
url: createURL('addNicToVirtualMachine'),
data: {
virtualmachineid: args.context.instances[0].id,
networkid: args.data.networkid
},
success: function(json) {
args.response.success({
_custom: { jobId: json.addnictovirtualmachineresponse.jobid }
});
}
});
},
notification: { poll: pollAsyncJobResult }
}
},
fields: [
{
name: { label: 'label.name', header: true },

View File

@ -771,6 +771,7 @@
var hiddenFields;
var context = detailViewArgs ? detailViewArgs.context : cloudStack.context;
var isMultiple = tabData.multiple || tabData.isMultiple;
var actions = tabData.actions;
if (isMultiple) {
context[tabData.id] = data;
@ -1074,6 +1075,29 @@
}
});
// Add item action
if (tabData.multiple && tabData.actions && tabData.actions.add) {
$tabContent.append(
$('<div>').addClass('button add').append(
$('<span>').addClass('icon').html('&nbsp;'),
$('<span>').html(_l(tabData.actions.add.label))
).click(function() {
uiActions.standard(
$detailView,
{ actions: tabData.actions, actionName: 'add' }, {
noRefresh: true,
complete: function(args) {
loadTabContent(
$detailView.find('div.detail-group:visible'),
$detailView.data('view-args')
);
}
}
)
})
);
}
return true;
}