Skip to content

Commit a59f809

Browse files
author
Jessica Wang
committed
CLOUDSTACK-4966: UI: (1) detailView widget: extend detailView widget to support destroy action that will close detailView and remove item from listView when toRemove parameter is passed.
(2)Destroy Instance action: add expunge option for root-admin and domain-admin. When expunge is set to true, instance will be expunged right after destroyed.
1 parent d188534 commit a59f809

2 files changed

Lines changed: 73 additions & 8 deletions

File tree

ui/scripts/instances.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,26 +535,51 @@
535535
destroy: {
536536
label: 'label.action.destroy.instance',
537537
compactLabel: 'label.destroy',
538-
messages: {
539-
confirm: function(args) {
540-
return 'message.action.destroy.instance';
538+
createForm: {
539+
title: 'label.action.destroy.instance',
540+
desc: 'Please confirm that you want to destroy this instance',
541+
preFilter: function(args) {
542+
if (isAdmin() || isDomainAdmin()) {
543+
args.$form.find('.form-item[rel=expunge]').css('display', 'inline-block');
544+
} else {
545+
args.$form.find('.form-item[rel=expunge]').hide();
546+
}
541547
},
548+
fields: {
549+
expunge: {
550+
label: 'Expunge',
551+
isBoolean: true,
552+
isChecked: false
553+
}
554+
}
555+
},
556+
messages: {
542557
notification: function(args) {
543558
return 'label.action.destroy.instance';
544559
}
545560
},
546561
action: function(args) {
562+
var data = {
563+
id: args.context.instances[0].id
564+
};
565+
if (args.data.expunge == 'on') {
566+
$.extend(data, {
567+
expunge: true
568+
});
569+
}
547570
$.ajax({
548-
url: createURL("destroyVirtualMachine&id=" + args.context.instances[0].id),
549-
dataType: "json",
550-
async: true,
571+
url: createURL('destroyVirtualMachine'),
572+
data: data,
551573
success: function(json) {
552574
var jid = json.destroyvirtualmachineresponse.jobid;
553575
args.response.success({
554576
_custom: {
555577
jobId: jid,
556578
getUpdatedItem: function(json) {
579+
if ('virtualmachine' in json.queryasyncjobresultresponse.jobresult) //destroy without expunge
557580
return json.queryasyncjobresultresponse.jobresult.virtualmachine;
581+
else //destroy with expunge
582+
return { 'toRemove': true };
558583
},
559584
getActionFilter: function() {
560585
return vmActionfilter;

ui/scripts/ui/widgets/detailView.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
}
232232
if (additional && additional.complete) additional.complete($.extend(true, args, {
233233
$detailView: $detailView
234-
}));
234+
}), args2);
235235

236236
replaceListViewItem($detailView, args.data ? args.data : args2.data);
237237

@@ -368,8 +368,48 @@
368368
}
369369
});
370370
},
371+
372+
destroy: function($detailView, args) {
373+
var tab = args.tabs[args.activeTab];
374+
var isMultiple = tab.multiple;
371375

372-
/**
376+
uiActions.standard($detailView, args, {
377+
noRefresh: true,
378+
complete: function(args, args2) {
379+
if ((!('id' in args2.data)) && ('toRemove' in args2.data) && (args2.data.toRemove == true)) {
380+
if (isMultiple && $detailView.is(':visible')) {
381+
$detailView.find('.refresh').click(); // Reload tab
382+
} else {
383+
var $browser = $('#browser .container');
384+
var $panel = $detailView.closest('.panel');
385+
386+
if ($detailView.is(':visible')) {
387+
$browser.cloudBrowser('selectPanel', {
388+
panel: $panel.prev()
389+
});
390+
}
391+
392+
if ($detailView.data("list-view-row") != null) {
393+
var $row = $detailView.data('list-view-row');
394+
var $tbody = $row.closest('tbody');
395+
396+
$row.remove();
397+
if (!$tbody.find('tr').size()) {
398+
$("<tr>").addClass('empty').append(
399+
$("<td>").html(_l('label.no.data'))
400+
).appendTo($tbody);
401+
}
402+
$tbody.closest('table').dataTable('refresh');
403+
}
404+
}
405+
} else {
406+
$detailView.find('.refresh').click(); // Reload tab
407+
}
408+
}
409+
});
410+
},
411+
412+
/**
373413
* Convert editable fields to text boxes; clicking again saves data
374414
*
375415
* @param $detailView

0 commit comments

Comments
 (0)