CS-15841: Better add VPC gateway flow

- Because only 1 gateway can exist per VPC, remove 'add' button from
  list view and immediately show create form on click if no gateway is
  present; show list view on successful creation. If there is a
  gateway, go to list view immediately.

- Rename "Gateways" -> "Private Gateway"
This commit is contained in:
Brian Federle 2012-08-03 12:26:12 -07:00
parent 17001a6cad
commit 015078b499
2 changed files with 130 additions and 67 deletions

View File

@ -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 = $('<ul>').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 = $('<div>').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
}
});
}

View File

@ -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'),