diff --git a/ui/scripts/ui-custom/vpc.js b/ui/scripts/ui-custom/vpc.js
index 7b716970ad3..fc319eeaedf 100644
--- a/ui/scripts/ui-custom/vpc.js
+++ b/ui/scripts/ui-custom/vpc.js
@@ -18,7 +18,7 @@
var siteToSiteVPN = args.siteToSiteVPN;
var links = {
'ip-addresses': 'IP Addresses',
- 'gateways': 'Gateways',
+ 'gateways': 'Private Gateway',
'site-to-site-vpn': 'Site-to-site VPN'
};
var $links = $('
').addClass('links');
@@ -48,14 +48,62 @@
});
break;
case 'gateways':
- $browser.cloudBrowser('addPanel', {
- title: 'Gateways',
- maximizeIfSelected: true,
- complete: function($panel) {
- //ipAddresses.listView is a function
- $panel.listView(gateways.listView(), {context: gateways.context});
- }
- });
+ //siteToSiteVPN is an object
+ var addAction = gateways.add;
+ var isGatewayPresent = addAction.preCheck({ context: gateways.context });
+ var showGatewayListView = function() {
+ $browser.cloudBrowser('addPanel', {
+ title: 'Private Gateway',
+ maximizeIfSelected: true,
+ complete: function($panel) {
+ $panel.listView(gateways.listView(), { context: gateways.context });
+ }
+ });
+ };
+
+ if (isGatewayPresent) {
+ showGatewayListView();
+ } else {
+ cloudStack.dialog.createForm({
+ form: addAction.createForm,
+ after: function(args) {
+ var data = args.data;
+ var $loading = $('').addClass('loading-overlay').appendTo($chart);
+ var error = function(message) {
+ $loading.remove();
+ cloudStack.dialog.notice({ message: message });
+ };
+
+ addAction.action({
+ data: data,
+ context: gateways.context,
+ response: {
+ success: function(args) {
+ var _custom = args._custom;
+ var notification = {
+ poll: addAction.notification.poll,
+ _custom: _custom,
+ desc: addAction.messages.notification()
+ };
+ var success = function(args) {
+ if (!$chart.is(':visible')) return;
+
+ $loading.remove();
+ showGatewayListView();
+ };
+
+ cloudStack.ui.notifications.add(
+ notification,
+ success, {},
+ error, {}
+ );
+ },
+ error: error
+ }
+ });
+ }
+ });
+ }
break;
case 'site-to-site-vpn':
//siteToSiteVPN is an object
@@ -63,7 +111,7 @@
var isVPNPresent = addAction.preCheck({ context: siteToSiteVPN.context });
var showVPNListView = function() {
$browser.cloudBrowser('addPanel', {
- title: 'Site-to-site VPNs',
+ title: 'Site-to-site VPN',
maximizeIfSelected: true,
complete: function($panel) {
$panel.listView(siteToSiteVPN, {context: siteToSiteVPN.context});
@@ -105,7 +153,8 @@
success, {},
error, {}
);
- }
+ },
+ error: error
}
});
}
diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js
index 89aa5c17045..aa79cc1d207 100644
--- a/ui/scripts/vpc.js
+++ b/ui/scripts/vpc.js
@@ -437,6 +437,76 @@
}
},
gateways: {
+ add: {
+ preCheck: function(args) {
+ var items;
+
+ $.ajax({
+ url: createURL('listPrivateGateways'),
+ async: false,
+ data: {
+ vpcid: args.context.vpc[0].id,
+ listAll: true
+ },
+ success: function(json) {
+ items = json.listprivategatewaysresponse.privategateway;
+ args.response.success({ data: items });
+ }
+ });
+
+ if (items && items.length) {
+ return true;
+ }
+
+ return false;
+ },
+ label: 'Add new gateway',
+ messages: {
+ notification: function(args) {
+ return 'Add new gateway';
+ }
+ },
+ createForm: {
+ title: 'Add new gateway',
+ desc: 'Please specify the information to add a new gateway to this VPC.',
+ fields: {
+ ipaddress: { label: 'label.ip.address', validation: { required: true }},
+ gateway: { label: 'label.gateway', validation: { required: true }},
+ netmask: { label: 'label.netmask', validation: { required: true }},
+ vlan: { label: 'label.vlan', validation: { required: true }}
+ }
+ },
+ action: function(args) {
+ $.ajax({
+ url: createURL('createPrivateGateway'),
+ data: {
+ vpcid: args.context.vpc[0].id,
+ ipaddress: args.data.ipaddress,
+ gateway: args.data.gateway,
+ netmask: args.data.netmask,
+ vlan: args.data.vlan
+ },
+ success: function(json) {
+ var jid = json.createprivategatewayresponse.jobid;
+ args.response.success(
+ {_custom:
+ {jobId: jid,
+ getUpdatedItem: function(json) {
+ return json.queryasyncjobresultresponse.jobresult.privategateway;
+ }
+ }
+ }
+ );
+ },
+ error: function(json) {
+ args.response.error(parseXMLHttpResponse(json));
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
+ },
listView: function() {
return {
listView: {
@@ -447,62 +517,6 @@
netmask: { label: 'label.netmask', validation: { required: true }},
vlan: { label: 'label.vlan', validation: { required: true }}
},
- actions: {
- add: {
- label: 'Add new gateway',
- preFilter: function(args) {
- if(isAdmin())
- return true;
- else
- return false;
- },
- messages: {
- notification: function(args) {
- return 'Add new gateway';
- }
- },
- createForm: {
- title: 'Add new gateway',
- desc: 'Please specify the information to add a new gateway to this VPC.',
- fields: {
- ipaddress: { label: 'label.ip.address', validation: { required: true }},
- gateway: { label: 'label.gateway', validation: { required: true }},
- netmask: { label: 'label.netmask', validation: { required: true }},
- vlan: { label: 'label.vlan', validation: { required: true }}
- }
- },
- action: function(args) {
- $.ajax({
- url: createURL('createPrivateGateway'),
- data: {
- vpcid: args.context.vpc[0].id,
- ipaddress: args.data.ipaddress,
- gateway: args.data.gateway,
- netmask: args.data.netmask,
- vlan: args.data.vlan
- },
- success: function(json) {
- var jid = json.createprivategatewayresponse.jobid;
- args.response.success(
- {_custom:
- {jobId: jid,
- getUpdatedItem: function(json) {
- return json.queryasyncjobresultresponse.jobresult.privategateway;
- }
- }
- }
- );
- },
- error: function(json) {
- args.response.error(parseXMLHttpResponse(json));
- }
- });
- },
- notification: {
- poll: pollAsyncJobResult
- }
- }
- },
dataProvider: function(args) {
$.ajax({
url: createURL('listPrivateGateways'),