diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 61a6a7bd44..40ac74218c 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -173,7 +173,6 @@ var update_vm_tmpl = var vmachine_list_json = {}; var dataTable_vMachines; var $create_vm_dialog; -var $saveas_vm_dialog; var $vnc_dialog; var rfb; @@ -342,26 +341,12 @@ var vm_actions = { notify: true }, - "VM.saveasmultiple" : { - type: "custom", - call: function(){ - var elems = vmElements(); - popUpSaveasDialog(elems); - } - }, - "VM.saveas" : { type: "single", call: OpenNebula.VM.saveas, callback: vmShow, - error:onError - }, - - "VM.saveas_disks" : { - type: "single", - call: OpenNebula.VM.show, - callback: saveasDisksCallback, - error: onError + error:onError, + notify: true }, "VM.shutdown" : { @@ -612,10 +597,6 @@ var vm_buttons = { text: tr("Reset"), tip: tr("This will perform a hard reboot on selected VMs") }, - "VM.saveasmultiple" : { - type: "action", - text: tr("Save as") - }, "VM.cancel" : { type: "confirm", text: tr("Cancel"), @@ -1120,8 +1101,10 @@ function printDisks(vm_info){ html += ''; html += disk.DISK_ID + ' - ' + (disk.IMAGE ? disk.IMAGE : "Volatile") + ''; - html += ''+disk.TYPE+''; - html += ' '; + html += '\ + \ + \ + '; } html += '\ @@ -1203,16 +1186,34 @@ function printDisks(vm_info){ } function hotpluggingOps(){ - $('i.detach_disk').live('click', function(){ - var i = $(this); - var vm_id = i.parents('form').attr('vmid'); - var disk_id = i.parents('tr').attr('disk_id'); - var parent = i.parent(); + $('button.detachdisk').live('click', function(){ + var b = $(this); + var vm_id = b.parents('form').attr('vmid'); + var disk_id = b.parents('tr').attr('disk_id'); + var parent = b.parent(); Sunstone.runAction('VM.detachdisk', vm_id, disk_id); - i.remove(); - parent.append(spinner); + b.html(spinner); + return false; + }); + + $('button.saveas').live('click', function(){ + var b = $(this); + var vm_id = b.parents('form').attr('vmid'); + var disk_id = b.parents('tr').attr('disk_id'); + var parent = b.parent(); + var image_name = 'saveas_'+vm_id+'_'+disk_id; + + var obj = { + disk_id : disk_id, + image_name : image_name, + type: "" + }; + + Sunstone.runAction('VM.saveas', vm_id, obj); + + b.html(spinner); return false; }); @@ -1323,142 +1324,6 @@ function popUpCreateVMDialog(){ $create_vm_dialog.dialog('open'); } -//Prepares a dialog to saveas a VM -function setupSaveasDialog(){ - //Append to DOM - dialogs_context.append('
'); - $saveas_vm_dialog = $('#saveas_vm_dialog',dialogs_context); - var dialog = $saveas_vm_dialog; - - //Put HTML in place - dialog.html('\ -
\ -
\ -
\ -
\ - \ - \ -
\ - \ -
'); - - dialog.dialog({ - autoOpen:false, - width:600, - modal:true, - height:350, - resizable:true, - }); - - $('#saveas_vm_form',dialog).submit(function(){ - var elems = $('#saveas_tabs div.saveas_tab',this); - var args = []; - $.each(elems,function(){ - var id = $('#vm_id',this).text(); - var disk_id = $('#vm_disk_id',this).val(); - var image_name = $('#image_name',this).val(); - var type = $('#image_type',this).val(); - - if (!id.length || !disk_id.length || !image_name.length) { - notifyError(tr("Skipping VM ")+id+". "+ - tr("No disk id or image name specified")); - } - else { - var obj = { - disk_id : disk_id, - image_name : image_name, - type: type - }; - args.push(id); - Sunstone.runAction("VM.saveas",id,obj); - } - }); - if (args.length > 0){ - notifySubmit("VM.saveas",args); - } - - $saveas_vm_dialog.dialog('close'); - return false; - }); - - $('#vm_saveas_cancel',dialog).click(function(){ - $saveas_vm_dialog.dialog('close'); - return false; - }); - -} - -function popUpSaveasDialog(elems){ - var dialog = $saveas_vm_dialog; - $('#saveas_tabs',dialog).tabs('destroy'); - $('#saveas_tabs',dialog).empty(); - $('#saveas_tabs',dialog).html(''); - - $.each(elems,function(){ - var li = '
  • VM '+this+'
  • ' - $('#saveas_tabs ul',dialog).append(li); - var tab = '
    \ -
    '+tr("Saveas for VM with ID")+' '+this+'
    \ -
    \ -
    \ - \ - \ -
    \ -
    \ - \ - \ -
    \ -
    \ - \ - \ -
    \ -
    \ -
    '; - $('#saveas_tabs',dialog).append(tab); - Sunstone.runAction("VM.saveas_disks",this); - }); - $('#saveas_tabs',dialog).tabs(); - $('button',dialog).button(); - dialog.dialog('open'); -} - -function saveasDisksCallback(req,response){ - var vm_info = response.VM; - var id=vm_info.ID; - var select=""; - - var gen_option = function(id, name, source){ - if (name){ - return ''; - } - else { - return ''; - } - } - - var disks = vm_info.TEMPLATE.DISK; - if (!disks) { select = '';} - else if (disks.constructor == Array) //several disks - { - for (var i=0;i'); @@ -1730,7 +1595,6 @@ $(document).ready(function(){ setupCreateVMDialog(); setupVMTemplateUpdateDialog(); - setupSaveasDialog(); setVMAutorefresh(); setupVNC(); hotpluggingOps();