From 93db30e4e116b6aa36e1b127ef5f406072fa935b Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Wed, 3 Apr 2013 14:22:15 -0700 Subject: [PATCH] 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 --- ui/scripts/instances.js | 56 +++++++++++++++++++++++++++++ ui/scripts/ui/widgets/detailView.js | 24 +++++++++++++ 2 files changed, 80 insertions(+) diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js index 1e3ce45ce22..ddb562251e8 100644 --- a/ui/scripts/instances.js +++ b/ui/scripts/instances.js @@ -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 }, diff --git a/ui/scripts/ui/widgets/detailView.js b/ui/scripts/ui/widgets/detailView.js index 4b520f934ba..cd1135cd4b3 100644 --- a/ui/scripts/ui/widgets/detailView.js +++ b/ui/scripts/ui/widgets/detailView.js @@ -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( + $('
').addClass('button add').append( + $('').addClass('icon').html(' '), + $('').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; }