From bfb4de0aaaeb382088afd9f33ff885a75d193a0b Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 13 Mar 2013 12:15:42 +0100 Subject: [PATCH] feature #1664: Refresh disk info after actions --- src/sunstone/public/js/plugins/vms-tab.js | 235 +++++++--------------- 1 file changed, 74 insertions(+), 161 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 7a8b6428d6..8d88d28684 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -193,6 +193,16 @@ var vm_actions = { error: onError }, + "VM.showdisks" : { + type: "single", + call: OpenNebula.VM.show, + callback: function(request, vm){ + updateVMachineElement(request, vm); + updateVMDisksInfo(request, vm); + }, + error: onError + }, + "VM.refresh" : { type: "custom", call : function (){ @@ -328,7 +338,9 @@ var vm_actions = { "VM.saveas" : { type: "single", call: OpenNebula.VM.saveas, - callback: vmShow, + callback: function(request) { + Sunstone.runAction("VM.showdisks", request.request.data[0]); + }, error:onError, notify: true }, @@ -523,17 +535,18 @@ var vm_actions = { "VM.attachdisk" : { type: "single", call: OpenNebula.VM.attachdisk, - callback: vmShow, + callback: function(request) { + Sunstone.runAction("VM.showdisks", request.request.data[0]); + }, error: onError, notify: true }, "VM.detachdisk" : { type: "single", call: OpenNebula.VM.detachdisk, - //callback: function(req,res){ - // setTimeout(vmShow,1000,req); - //}, - callback: vmShow, + callback: function(request) { + Sunstone.runAction("VM.showdisks", request.request.data[0]); + }, error: onError, notify: true }, @@ -1351,38 +1364,43 @@ function updateVMInfo(request,vm){ setPermissionsTable(vm_info,''); } +function updateVMDisksInfo(request,vm){ + $("li#vm_hotplugging_tabTab").html(printDisks(vm.VM)); +} + // Generates the HTML for the hotplugging tab // This is a list of disks with the save_as, detach options. // And a form to attach a new disk to the VM, if it is running. function printDisks(vm_info){ - //var im_sel = makeSelectOptions(dataTable_images, - // 1, //id col - trick -> reference by name! - // 4, //name col - // [10,10,10], - // [tr("DISABLED"),tr("LOCKED"),tr("ERROR")] - // ); var html ='\ -
\ -
\ -
\ -
\ -
' + tr("Attach new disk") +'
\ -
\ -
\ -
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '; +
\ +
\ + ' + + // If VM is not RUNNING, then we forget about the attach disk form. + if (vm_info.STATE == "3"){ + html += '\ +
\ +
' + tr("Attach new disk") +'
\ +
\ +
\ +
' + } + + html += '\ +
\ +
'+tr("ID")+''+tr("Target")+''+tr("Image / Format-Size")+''+tr("Persistent")+''+tr("Save as")+''+tr("Actions")+'
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; var disks = [] @@ -1392,9 +1410,10 @@ function printDisks(vm_info){ disks = [vm_info.TEMPLATE.DISK] if (!disks.length){ - html += ''; + html += '\ + \ + \ + '; } else { @@ -1412,111 +1431,18 @@ function printDisks(vm_info){ '+tr("Detach")+'\ \ '; - - // html += ''; - // html += ''; } } - html += '\ + html += '\ + \
'+tr("ID")+''+tr("Target")+''+tr("Image / Format-Size")+''+tr("Persistent")+''+tr("Save as")+''+tr("Actions")+'
\ - '+tr("No disks to show")+'\ -
' + tr("No disks to show") + '
'; - // html += disk.DISK_ID + ' - ' + - // (disk.IMAGE ? disk.IMAGE : "Volatile") + '\ - //'+(vm_info.STATE == "3" ? '\ - // \ - //' : '')+'\ - // \ - // \ - // ' - // +'\ - //
\ -
'; - - // If VM is not RUNNING, then we forget about the attach disk form. - if (vm_info.STATE != "3"){ - html +=''; - return html; - } -// -// // Attach disk form -// html += '\ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -// \ -//\ -// \ -// \ -// \ -// \ -//
'+tr("Attach disk to running VM")+'
\ -// \ -//
\ -// \ -//
\ -// \ -//
\ -// \ -//
\ -// \ -//
\ -// \ -//
\ -// \ -//
'; +
\ + '; return html; } -function popUpSaveAsDialog(vm_id, disk_id){ - $('#vm_id',$save_as_dialog).val(vm_id); - $('#disk_id',$save_as_dialog).val(disk_id); - $save_as_dialog.reveal(); -} - function setupSaveAsDialog(){ dialogs_context.append('
'); $save_as_dialog = $('#save_as_dialog',dialogs_context); @@ -1585,18 +1511,9 @@ function setupSaveAsDialog(){ ×\ ') - //Prepare jquery dialog - //dialog.dialog({ - // autoOpen: false, - // modal:true, - // width: 400 - //}); - dialog.addClass("reveal-modal"); setupTips(dialog); - //$('button',dialog).button(); - $('#save_as_form',dialog).submit(function(){ var vm_id = $('#vm_id', this).val(); var image_name = $('#image_name', this).val(); @@ -1619,18 +1536,17 @@ function setupSaveAsDialog(){ }); }; - - - - - - - -function popUpAttachDiskDialog(vm_id){ - $('#vm_id',$attach_disk_dialog).val(vm_id); - $attach_disk_dialog.reveal(); +function popUpSaveAsDialog(vm_id, disk_id){ + $('#vm_id',$save_as_dialog).val(vm_id); + $('#disk_id',$save_as_dialog).val(disk_id); + $save_as_dialog.reveal(); } + + + + + function setupAttachDiskDialog(){ dialogs_context.append('
'); $attach_disk_dialog = $('#attach_disk_dialog',dialogs_context); @@ -1662,20 +1578,11 @@ function setupAttachDiskDialog(){ ×\ ') - //Prepare jquery dialog - //dialog.dialog({ - // autoOpen: false, - // modal:true, - // width: 400 - //}); - dialog.addClass("reveal-modal large"); setupTips(dialog); setup_disk_tab_content(dialog, "attach_disk", "attach_disk") - //$('button',dialog).button(); - $('#attach_disk_form',dialog).submit(function(){ var vm_id = $('#vm_id', this).val(); @@ -1690,6 +1597,12 @@ function setupAttachDiskDialog(){ }); }; +function popUpAttachDiskDialog(vm_id){ + $('#vm_id',$attach_disk_dialog).val(vm_id); + $attach_disk_dialog.reveal(); +} + + // Listeners to the disks operations (detach, saveas, attach) function hotpluggingOps(){ setupSaveAsDialog();