From ad51b8edfbb7e110db45368b118b55f89c7b7cba Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Fri, 25 Oct 2013 13:48:38 -0700 Subject: [PATCH] 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. --- ui/scripts/instances.js | 43 +++++++++++++++++++++++------ ui/scripts/ui/widgets/detailView.js | 43 ++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js index b729c4bcc1f..ac8605a4f1d 100644 --- a/ui/scripts/instances.js +++ b/ui/scripts/instances.js @@ -535,26 +535,51 @@ destroy: { label: 'label.action.destroy.instance', compactLabel: 'label.destroy', - messages: { - confirm: function(args) { - return 'message.action.destroy.instance'; + createForm: { + title: 'label.action.destroy.instance', + desc: 'Please confirm that you want to destroy this instance', + preFilter: function(args) { + if (isAdmin() || isDomainAdmin()) { + args.$form.find('.form-item[rel=expunge]').css('display', 'inline-block'); + } else { + args.$form.find('.form-item[rel=expunge]').hide(); + } }, + fields: { + expunge: { + label: 'Expunge', + isBoolean: true, + isChecked: false + } + } + }, + messages: { notification: function(args) { return 'label.action.destroy.instance'; } }, - action: function(args) { + action: function(args) { + var data = { + id: args.context.instances[0].id + }; + if (args.data.expunge == 'on') { + $.extend(data, { + expunge: true + }); + } $.ajax({ - url: createURL("destroyVirtualMachine&id=" + args.context.instances[0].id), - dataType: "json", - async: true, + url: createURL('destroyVirtualMachine'), + data: data, success: function(json) { var jid = json.destroyvirtualmachineresponse.jobid; args.response.success({ _custom: { jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.virtualmachine; + getUpdatedItem: function(json) { + if ('virtualmachine' in json.queryasyncjobresultresponse.jobresult) //destroy without expunge + return json.queryasyncjobresultresponse.jobresult.virtualmachine; + else //destroy with expunge + return { 'toRemove': true }; }, getActionFilter: function() { return vmActionfilter; diff --git a/ui/scripts/ui/widgets/detailView.js b/ui/scripts/ui/widgets/detailView.js index 7bb0e1334c9..65f71b3af6e 100644 --- a/ui/scripts/ui/widgets/detailView.js +++ b/ui/scripts/ui/widgets/detailView.js @@ -231,7 +231,7 @@ } if (additional && additional.complete) additional.complete($.extend(true, args, { $detailView: $detailView - })); + }), args2); replaceListViewItem($detailView, args.data ? args.data : args2.data); @@ -374,6 +374,47 @@ var isMultiple = tab.multiple; uiActions.remove($detailView, args); }, + + destroy: function($detailView, args) { + var tab = args.tabs[args.activeTab]; + var isMultiple = tab.multiple; + + uiActions.standard($detailView, args, { + noRefresh: true, + complete: function(args, args2) { + if ((!('id' in args2.data)) && ('toRemove' in args2.data) && (args2.data.toRemove == true)) { + if (isMultiple && $detailView.is(':visible')) { + $detailView.find('.refresh').click(); // Reload tab + } else { + var $browser = $('#browser .container'); + var $panel = $detailView.closest('.panel'); + + if ($detailView.is(':visible')) { + $browser.cloudBrowser('selectPanel', { + panel: $panel.prev() + }); + } + + if ($detailView.data("list-view-row") != null) { + var $row = $detailView.data('list-view-row'); + var $tbody = $row.closest('tbody'); + + $row.remove(); + if (!$tbody.find('tr').size()) { + $("").addClass('empty').append( + $("").html(_l('label.no.data')) + ).appendTo($tbody); + } + $tbody.closest('table').dataTable('refresh'); + } + } + } else { + $detailView.find('.refresh').click(); // Reload tab + } + } + }); + }, + /** * Convert editable fields to text boxes; clicking again saves data