Skip to content

Commit cd7287a

Browse files
committed
Site-to-site VPN UI: Show confirm dialog if no gateways exist
1 parent 4893969 commit cd7287a

2 files changed

Lines changed: 94 additions & 20 deletions

File tree

ui/modules/vpc/vpc.js

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,60 @@
168168
$dashboardItem.appendTo($dashboard);
169169

170170
$dashboardItem.click(function() {
171-
$('#browser .container').cloudBrowser('addPanel', {
172-
title: tier.name + ' - ' + dashboardItem.name,
173-
maximizeIfSelected: true,
174-
complete: function($panel) {
175-
var section = cloudStack.vpc.sections[id];
176-
var $section = $('<div>');
177-
178-
if ($.isFunction(section)) {
179-
section = cloudStack.vpc.sections[id]();
180-
}
171+
var section = cloudStack.vpc.sections[id];
172+
var $section = $('<div>');
173+
var $loading = $('<div>').addClass('loading-overlay');
174+
175+
if ($.isFunction(section)) {
176+
section = cloudStack.vpc.sections[id]();
177+
}
181178

182-
if (section.listView) {
183-
$section.listView($.extend(true, {}, section, {
184-
onActionComplete: function() {
185-
$dashboardItem.closest('.vpc-network-chart').trigger('reload');
186-
},
187-
context: context
188-
}));
189-
}
179+
var before = section.before;
180+
var load = function() {
181+
$('#browser .container').cloudBrowser('addPanel', {
182+
title: tier.name + ' - ' + dashboardItem.name,
183+
maximizeIfSelected: true,
184+
complete: function($panel) {
185+
if (section.listView) {
186+
$section.listView($.extend(true, {}, section, {
187+
onActionComplete: function() {
188+
$dashboardItem.closest('.vpc-network-chart').trigger('reload');
189+
},
190+
context: context
191+
}));
192+
}
190193

191-
$section.appendTo($panel);
194+
$section.appendTo($panel);
195+
}
196+
});
197+
};
198+
199+
before.check({
200+
context: context,
201+
response: {
202+
success: function(result) {
203+
// true means content exists
204+
if (result) {
205+
load();
206+
} else {
207+
cloudStack.dialog.confirm({
208+
message: before.messages.confirm,
209+
action: function() {
210+
$loading.appendTo($dashboardItem.closest('.vpc-network-chart'));
211+
before.action({
212+
context: context,
213+
response: {
214+
success: function() {
215+
$loading.remove();
216+
$dashboardItem.closest('.vpc-network-chart').trigger('reload');
217+
load();
218+
}
219+
}
220+
});
221+
}
222+
})
223+
}
224+
}
192225
}
193226
});
194227
});

ui/scripts/vpc.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,48 @@
801801
// 'listView' block
802802
//
803803
// -- use this as a flag for VPC chart to render as a list view
804-
listView: true
804+
listView: true,
805+
before: {
806+
messages: {
807+
confirm: 'Please confirm that you would like to create a site-to-site VPN gateway for this VPC.',
808+
notification: 'Create site-to-site VPN gateway'
809+
},
810+
check: function(args) {
811+
var items;
812+
813+
$.ajax({
814+
url: createURL('listVpnGateways&listAll=true'),
815+
data: {
816+
vpcid: args.context.vpc[0].id
817+
},
818+
success: function(json) {
819+
var items = json.listvpngatewaysresponse.vpngateway;
820+
821+
args.response.success(items && items.length);
822+
}
823+
});
824+
},
825+
action: function(args) {
826+
$.ajax({
827+
url: createURL("createVpnGateway"),
828+
data: {
829+
vpcid: args.context.vpc[0].id
830+
},
831+
success: function(json) {
832+
var jid = json.createvpngatewayresponse.jobid;
833+
var pollTimer = setInterval(function() {
834+
pollAsyncJobResult({
835+
_custom: { jobId: jid },
836+
complete: function() {
837+
clearInterval(pollTimer);
838+
args.response.success();
839+
}
840+
});
841+
}, g_queryAsyncJobResultInterval);
842+
}
843+
});
844+
}
845+
}
805846
});
806847
}
807848
},

0 commit comments

Comments
 (0)