From 9b983b0ec14a5a7d10b160dd4f48d64d363fdbae Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 18 Jan 2013 18:24:25 +0100 Subject: [PATCH] feature #1664: Update template prompts the new wizard --- .../public/js/plugins/templates-tab.js | 1446 ++--------------- 1 file changed, 125 insertions(+), 1321 deletions(-) diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 1534f64b0a..2bf2619eaf 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -67,522 +67,6 @@ var create_template_tmpl = '
'+ '
'; -/* -var create_template_tmpl = '
\ - \ -
\ -
\ -
\ - \ -

'+ - tr("Fields marked with")+''+ - tr("are mandatory")+'
\ - '+tr("Fold / Unfold all sections")+'

\ -
\ -\ - \ -
\ -
\ -

'+tr("Capacity options")+'

\ -
\ -
'+tr("Capacity")+'\ -
\ - \ - \ -
'+tr("Name that the VM will get for description purposes. If NAME is not supplied a name generated by one will be in the form of one-<VID>.")+'
\ -
\ -
\ - \ - \ -
'+tr("Amount of RAM required for the VM, in Megabytes.")+'
\ -
\ -
\ - \ - \ -
'+tr("Percentage of CPU divided by 100 required for the Virtual Machine. Half a processor is written 0.5.")+'
\ -
\ -
\ - \ - \ -
'+tr("Number of virtual cpus. This value is optional, the default hypervisor behavior is used, usually one virtual CPU.")+'
\ -
\ -
\ -
\ - \ -
\ -
\ -

'+tr("Boot/OS options")+'

\ -
\ -
'+tr("OS and Boot options")+'\ -
\ - \ - \ -
'+tr("CPU architecture to virtualization")+'
\ -
\ - \ -
\ - \ - \ -
'+tr("Select boot method")+'
\ -
\ -
\ - \ - \ -
'+tr("Path to the OS kernel to boot the image")+'
\ -
\ -
\ - \ - \ -
'+tr("Path to the initrd image")+'
\ -
\ -
\ - \ - \ -
'+tr("Device to be mounted as root")+'
\ -
\ -
\ - \ - \ -
'+tr("Arguments for the booting kernel")+'
\ -
\ -
\ - \ - \ -
'+tr("Path to the bootloader executable")+'
\ -
\ -
\ - \ - \ -
'+tr("Boot device type")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Features")+'

\ -
\ -
'+tr("Features")+'\ -
\ - \ - \ -
'+tr("Physical address extension mode allows 32-bit guests to address more than 4 GB of memory")+'
\ -
\ -
\ - \ - \ -
'+tr("Useful for power management, for example, normally required for graceful shutdown to work")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add disks/images")+'

\ -
\ -
'+tr("Disks")+'\ -
\ - \ - '+tr("Volatile Disk")+'\ - \ - '+tr("Image")+'\ - \ -
\ -
\ -
\ - \ - \ -
'+tr("Name of the image to use")+'
\ - \ -
\ -
\ - \ - \ -
'+tr("Disk type")+'
\ -
\ -
\ - \ - \ - \ -
'+tr("Size in MB")+'
\ -
\ -
\ - \ - \ - \ -
'+tr("Filesystem type for the fs images")+'
\ -
\ -
\ - \ - \ -
'+tr("Device to map image disk. If set, it will overwrite the default device mapping")+'
\ -
\ -
\ - \ - \ -
'+tr("Specific image mapping driver. KVM: raw, qcow2. Xen:tap:aio:, file:. VMware unsupported")+'
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -\ - \ -
\ -
\ -

'+tr("Setup Networks")+'

\ -
\ -
'+tr("Network")+'\ - \ -
\ -
\ - \ - \ -
'+tr("Name of the network to attach this device")+'
\ - \ -
\ -
\ - \ - \ -
'+tr("Request an specific IP from the Network")+'
\ -
\ -
\ - \ - \ -
'+tr("HW address associated with the network interface")+'
\ -
\ -
\ - \ - \ -
'+tr("Name of the bridge the network device is going to be attached to")+'
\ -
\ -
\ - \ - \ -
'+tr("Name for the tun device created for the VM")+'
\ -
\ -
\ - \ - \ -
'+tr("Name of a shell script to be executed after creating the tun device for the VM")+'
\ -
\ -
\ - \ - \ -
'+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
'+tr("Permits access to the VM only through the specified ports in the TCP protocol")+'
\ -
\ -
\ - \ - \ -
'+tr("Disallow access to the VM through the specified ports in the TCP protocol")+'
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
'+tr("Permits access to the VM only through the specified ports in the UDP protocol")+'
\ -
\ -
\ - \ - \ -
'+tr("Disallow access to the VM through the specified ports in the UDP protocol")+'
\ -
\ -
\ - \ - \ -
'+tr("ICMP policy")+'
\ -
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add inputs")+'

\ -
\ -
'+tr("Inputs")+'\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add Graphics")+'

\ -
\ -
'+tr("Graphics")+'\ -
\ - \ - \ -
'+tr("VMware supports VNC only. SPICE is supported by KVM")+'
\ -
\ -
\ - \ - \ -
'+tr("IP to listen on")+'
\ -
\ -
\ - \ - \ -
'+tr("Port for the VNC/SPICE server")+'
\ -
\ -
\ - \ - \ -
'+tr("Password for the VNC/SPICE server")+'
\ -
\ -
\ - \ - \ -
'+tr("Keyboard configuration locale to use in the VNC/SPICE display")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add context variables")+'

\ -
\ -
'+tr("Context")+'\ -
\ - \ - \ -
'+tr("Name for the context variable")+'
\ -
\ -
\ - \ - \ -
'+tr("Value of the context variable")+'
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add placement options")+'

\ -
\ -
'+tr("Placement")+'\ -
\ - \ - \ -
'+tr("Boolean expression that rules out provisioning hosts from list of machines suitable to run this VM")+'
\ -
\ -
\ - \ - \ -
'+tr("This field sets which attribute will be used to sort the suitable hosts for this VM. Basically, it defines which hosts are more suitable than others")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add Hypervisor raw options")+'

\ -
\ -
'+tr("Raw")+'\ - \ -
\ - \ - \ - \ -
'+tr("Raw data to be passed directly to the hypervisor")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add custom variables")+'

\ -
\ -
'+tr("Custom variables")+'\ -
\ - \ - \ -
'+tr("Name for the custom variable")+'
\ -
\ -
\ - \ - \ -
'+tr("Value of the custom variable")+'
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -

'+tr("Write the Virtual Machine template here")+'

\ -
\ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
'; -*/ var update_template_tmpl = '
\

'+tr("Please, choose and modify the template you want to update")+':

\ @@ -684,6 +168,13 @@ var template_actions = { } }, + "Template.show_to_update" : { + type: "single", + call: OpenNebula.Template.show, + callback: fillTemplatePopUp, + error: onError + }, + "Template.update_dialog" : { type: "custom", call: popUpTemplateTemplateUpdateDialog @@ -990,132 +481,6 @@ function updateTemplateInfo(request,template){ function setupCreateTemplateDialog(){ //Helper functions for the dialog operations - // Called when changing tabs. Since we use the same form for both - // KVM, XEN and others we need to do some operation to update it - var vmTabChange = function(event,ui){ - // ui.tab // anchor element of the selected (clicked) tab - // ui.panel // element, that contains the selected/clicked tab contents - // ui.index // zero-based index of the selected (clicked) tab - - //disable all items - //$(items,dialog).attr('disabled','disabled'); - //hide all mandatory icons - $('.vm_param .man_icon',dialog).css("display","none"); - - //empty selects - $('select#BOOT',section_os_boot).empty(); - - //hide options about boot method - $('div#kernel_bootloader',section_os_boot).show(); - $('.kernel, .bootloader', section_os_boot).hide(); - $('select#BOOT',section_os_boot).parent().hide(); - //unselect boot method - $('select#boot_method option',section_os_boot).removeAttr('selected'); - - //hide non common sections - $(section_inputs).hide(); - - switch(ui.index){ - case 0: - enable_kvm(); - break; - case 1: - enable_xen(); - break; - case 2: - enable_vmware(); - case 3: - break; - } - //hide_disabled(); - //show_enabled(); - } - - //~ var hide_disabled = function(context) { - //~ var $disabled; - //~ if (!context) { - //~ $disabled = $('.vm_param input:disabled,.vm_param select:disabled'); - //~ } else { - //~ $disabled = $('.vm_param input:disabled,.vm_param select:disabled',context); - //~ } - //~ - //~ $disabled.each(function(){ - //~ $(this).parent('.vm_param').hide(); - //~ }); - //~ } - //~ - //~ var show_enabled = function(context){ - //~ var $enabled; - //~ if (!context) { - //~ $enabled = $('.vm_param input:enabled,.vm_param select:enabled'); - //~ } else { - //~ $enabled = $('.vm_param input:enabled,.vm_param select:enabled',context); - //~ } - //~ - //~ $enabled.parent('.vm_param').show(); - //~ } - - //Using kvm wizard. - var enable_kvm = function(){ - man_class="kvm"; - opt_class="kvm_opt"; - $(kvm_items,dialog).removeAttr('disabled'); - $('.kvm .man_icon',dialog).css("display","inline-block"); - - //KVM particularities: - // * Add custom boot options - // * Show boot options - // * Set the raw type to kvm - // * Show the inputs and graphics section - - var boot_opts = - '\ - \ - \ - '; - - $('select#BOOT',section_os_boot).html(boot_opts); - $('select#BOOT',section_os_boot).parent().show(); - $('select#boot_method option#no_boot',section_os_boot).html(tr("Driver default")); - - $('input#TYPE', section_raw).val("kvm"); - - $(section_inputs).show(); - }; - - // Using XEN wizard. - var enable_xen = function(){ - man_class="xen"; - opt_class="xen_opt"; - $(xen_items,dialog).removeAttr('disabled'); - $('.xen .man_icon',dialog).css("display","inline-block"); - - // XEN particularities: - // * Remove driver default boot method - // * Set the raw section to XEN - // * Show the graphics section - - $('select#boot_method option#no_boot',section_os_boot).html(tr("Please choose")); - - $('input#TYPE', section_raw).val("xen"); - }; - - //VMWare wizard - var enable_vmware = function() { - man_class="vmware"; - opt_class="vmware_opt"; - $(vmware_items,dialog).removeAttr('disabled'); - $('.vmware .man_icon',dialog).css("display","inline-block"); - - //VMWARE particularities - // * Hide boot method field - // * Set the raw type to vmware - - $('div#kernel_bootloader',section_os_boot).hide(); - - $('input#TYPE', section_raw).val("vmware"); - }; - //This function checks that all mandatory items within a section //have some value. Returns true if so, false if not. var mandatory_filter = function(context){ @@ -1372,7 +737,7 @@ function setupCreateTemplateDialog(){ '
'+ '' - tabs.append(html_tab_content).tabs('add', '#capacity_tab', 'General', 0); + tabs.append(html_tab_content).tabs('add', '#capacity_tab', 'General'); // Enhace buttons $('button',dialog).button(); @@ -1468,11 +833,11 @@ function setupCreateTemplateDialog(){ var add_disks_tab = function() { var html_tab_content = '
'+ ''+ '
'; - tabs.append(html_tab_content).tabs('add', '#template_create_disks_tabs', 'Storage', 1); + tabs.append(html_tab_content).tabs('add', '#template_create_disks_tabs', 'Storage'); var disk_tabs = $( "#template_create_disks_tabs", dialog).tabs({ tabTemplate: "
  • #{label}Remove Tab
  • ", @@ -1489,7 +854,7 @@ function setupCreateTemplateDialog(){ $('div#'+$('a', parent).text()).remove(); disks_index--; - disk_tabs.tabs( "select", disks_index-1); + disk_tabs.tabs( "select", -1); disk_tabs.tabs( "remove", index ); }); @@ -1824,11 +1189,11 @@ function setupCreateTemplateDialog(){ var add_nics_tab = function() { var html_tab_content = '
    '+ ''+ '
    '; - tabs.append(html_tab_content).tabs('add', '#template_create_nics_tabs', 'Network', 2); + tabs.append(html_tab_content).tabs('add', '#template_create_nics_tabs', 'Network'); var nic_tabs = $( "#template_create_nics_tabs", dialog).tabs({ tabTemplate: "
  • #{label}Remove Tab
  • ", @@ -1847,8 +1212,11 @@ function setupCreateTemplateDialog(){ $('div#'+$('a', parent).text()).remove(); - nics_index--; - nic_tabs.tabs( "select", nics_index-1); + if (nics_index > 0) { + nics_index--; + } + + nic_tabs.tabs( "select", -1); nic_tabs.tabs( "remove", index ); }); @@ -2082,48 +1450,20 @@ function setupCreateTemplateDialog(){ nics_index++; } - var advanced_tab_added = false; - - var add_advanced_tabs = function() { - var temp_index = disks_index+nics_index+3; - - if (advanced_tab_added == false) { - advanced_tab_added = true; - - add_os_tab(temp_index); - tabs.tabs( "select", temp_index); - - temp_index++; - add_io_tab(temp_index); - - temp_index++; - add_context_tab(temp_index); - - temp_index++; - add_placement_tab(temp_index); - - temp_index++; - add_other_tab(temp_index); - } - else { - tabs.tabs( "select", temp_index); - } - } - /************************************************************************** OS TAB **************************************************************************/ - var add_os_tab = function(temp_index) { + var add_os_tab = function() { var html_tab_content = '
    '+ '
    '+ '
    '+ '
    '+ '
    '+ '
    '+ - ''+ + ''+ '
    '+ '
    '+ ''+ @@ -2154,7 +1494,7 @@ function setupCreateTemplateDialog(){ '
    '+ '
    '+ '
    '+ - ''+ + ''+ '
    '+ '
    '+ ''+ @@ -2167,7 +1507,7 @@ function setupCreateTemplateDialog(){ '
    '+ '
    '+ '
    '+ - ''+ + ''+ '
    '+ '
    '+ ''+ @@ -2178,7 +1518,7 @@ function setupCreateTemplateDialog(){ '
    '+ '
    '+ '
    '+ - ''+ + ''+ '
    '+ '
    '+ ''+ @@ -2307,7 +1647,7 @@ function setupCreateTemplateDialog(){ '
    ' // Append the new div containing the tab and add the tab to the list - tabs.append(html_tab_content).tabs('add', '#os_tab', 'OS Booting', temp_index); + tabs.append(html_tab_content).tabs('add', '#os_tab', 'OS Booting'); $( "#template_create_tabs a[href='#os_tab']").parent().remove("span") // Select Image or Volatile disk. The div is hidden depending on the selection, and the @@ -2498,7 +1838,7 @@ function setupCreateTemplateDialog(){ **************************************************************************/ - var add_io_tab = function(temp_index) { + var add_io_tab = function() { var html_tab_content = '
    '+ ''+ '
    '+ @@ -2614,7 +1954,7 @@ function setupCreateTemplateDialog(){ '
    ' // Append the new div containing the tab and add the tab to the list - tabs.append(html_tab_content).tabs('add', '#io_tab', 'Input/Output', temp_index); + tabs.append(html_tab_content).tabs('add', '#io_tab', 'Input/Output'); $("input[name='graphics_type']").change(function(){ $("#LISTEN", $('div#io_tab')).val("0.0.0.0") @@ -2658,7 +1998,7 @@ function setupCreateTemplateDialog(){ **************************************************************************/ - var add_context_tab = function(temp_index) { + var add_context_tab = function() { var html_tab_content = '
    '+ ''+ '
    '+ @@ -2738,7 +2078,7 @@ function setupCreateTemplateDialog(){ '
    ' // Append the new div containing the tab and add the tab to the list - tabs.append(html_tab_content).tabs('add', '#context_tab', 'Context', temp_index); + tabs.append(html_tab_content).tabs('add', '#context_tab', 'Context'); $('#add_context', $('div#context_tab')).click(function() { var table = $('#context_table', $('div#context_tab'))[0]; @@ -2777,7 +2117,7 @@ function setupCreateTemplateDialog(){ **************************************************************************/ - var add_placement_tab = function(temp_index) { + var add_placement_tab = function() { var html_tab_content = '
    '+ ''+ '
    '+ @@ -2865,7 +2205,7 @@ function setupCreateTemplateDialog(){ '
    ' // Append the new div containing the tab and add the tab to the list - tabs.append(html_tab_content).tabs('add', '#placement_tab', 'Placement', temp_index); + tabs.append(html_tab_content).tabs('add', '#placement_tab', 'Placement'); // hOSTS TABLE dataTable_template_hosts = $("#datatable_template_hosts",dialog).dataTable({ @@ -3073,7 +2413,7 @@ function setupCreateTemplateDialog(){ **************************************************************************/ - var add_other_tab = function(temp_index) { + var add_other_tab = function() { var html_tab_content = '
    '+ '
    '+ '
    '+ @@ -3086,467 +2426,9 @@ function setupCreateTemplateDialog(){ '
    ' // Append the new div containing the tab and add the tab to the list - tabs.append(html_tab_content).tabs('add', '#other_tab', 'Other', temp_index); + tabs.append(html_tab_content).tabs('add', '#other_tab', 'Other'); } - //Sets up the OS_BOOT section - var os_boot_setup = function(){ - $('fieldset',section_os_boot).hide(); - $('.bootloader, .kernel',section_os_boot).hide(); - - $('#add_os_boot_opts',section_os_boot).click(function(){ - $('fieldset',section_os_boot).toggle(); - return false; - }); - - //Depending on the boot method we enable/disable some options - $('#boot_method',section_os_boot).change(function(){ - select = $(this).val(); - switch (select) - { - case "kernel": - $('.bootloader',section_os_boot).hide(); - $('.bootloader',section_os_boot).attr('disabled','disabled'); - $('.kernel',section_os_boot).show(); - $('.kernel',section_os_boot).removeAttr('disabled'); - break; - case "bootloader": - $('.kernel',section_os_boot).hide(); - $('.kernel',section_os_boot).attr('disabled','disabled'); - $('.bootloader',section_os_boot).show(); - $('.bootloader',section_os_boot).removeAttr('disabled'); - break; - default: - $('.kernel, .bootloader',section_os_boot).hide(); - $('.kernel, .bootloader',section_os_boot).attr('disabled','disabled'); - $('.kernel input, .bootloader input',section_os_boot).val(""); - }; - }); - }; - - // Sets up the features section - var features_setup = function(){ - $('fieldset',section_features).hide(); - - $('#add_features',section_features).click(function(){ - $('fieldset',section_features).toggle(); - return false; - }); - }; - - // Sets up the disk section - var disks_setup = function(){ - -// $('input:checkbox', $("#datatable_template_images")).live('change', function(){ -// if($(this).is(':checked')){ -// addDiskTab(); -// console.log(this); -// } else { -// console.log(this); -// } -// }); -// - //$('fieldset',section_disks).hide(); - //$('.vm_param', section_disks).hide(); - ////$('#image_vs_disk',section_disks).show(); -// - //$('#add_disks', section_disks).click(function(){ - // $('fieldset',section_disks).toggle(); - // return false; - //}); -// - ////Auto-set IMAGE_UNAME hidden field value - //$('#IMAGE', section_disks).change(function(){ - // var option = $('option:selected',this); - // var uname = getValue(option.attr('elem_id'),1,2,dataTable_images); - // $('input#IMAGE_UNAME',section_disks).val(uname); - // var target = getValue(option.attr('elem_id'),1,12,dataTable_images); - // if (target && target != "--") - // $('input#TARGET',section_disks).val(target); - // else - // $('input#TARGET',section_disks).val(''); - //}); -// - ////Depending on adding a disk or a image we need to show/hide - ////different options and make then mandatory or not - //$('#image_vs_disk input',section_disks).click(function(){ - // //$('fieldset',section_disks).show(); - // $('.vm_param', section_disks).show(); - // var select = $(this).val(); - // switch (select) - // { - // case "disk": - // $('.add_image',section_disks).hide(); - // $('.add_image',section_disks).attr('disabled','disabled'); - // $('.add_disk',section_disks).show(); - // $('.add_disk',section_disks).removeAttr('disabled'); - // // Trigger since disk type is preselected - // $('select#TYPE', section_disks).trigger('change'); - // break; - // case "image": - // $('.add_disk',section_disks).hide(); - // $('.add_disk',section_disks).attr('disabled','disabled'); - // $('.add_image',section_disks).show(); - // $('.add_image',section_disks).removeAttr('disabled'); - // break; - // } - // //hide_disabled(section_disks); - //}); -// - ////Depending on the type of disk we need to show/hide - ////different options and make then mandatory or not - //$('select#TYPE',section_disks).change(function(){ - // var select = $(this).val(); - // switch (select) { - // //size,format,target - // case "swap": - // //size mandatory - // $('#SIZE',section_disks).parent().show(); - // $('#SIZE',section_disks).parent().removeAttr('disabled'); -// - // //format hidden - // $('#FORMAT',section_disks).parent().hide(); - // $('#FORMAT',section_disks).parent().attr('disabled','disabled'); - // break; - // case "fs": - // //size mandatory - // $('#SIZE',section_disks).parent().show(); - // $('#SIZE',section_disks).parent().removeAttr('disabled'); -// - // //format mandatory - // $('#FORMAT',section_disks).parent().show(); - // $('#FORMAT',section_disks).parent().removeAttr('disabled'); - // $('#FORMAT',section_disks).parent().removeClass(opt_class); - // $('#FORMAT',section_disks).parent().addClass(man_class); -// -// break; -/* As of 3.8 the following dont exist */ -/* - case "block": - //size shown and optional - $('#SIZE',section_disks).parent().show(); - $('#SIZE',section_disks).parent().removeAttr('disabled'); - $('#SIZE',section_disks).parent().removeClass(man_class); - $('#SIZE',section_disks).parent().addClass(opt_class); - - //target mandatory - $('#TARGET',section_disks).parent().removeClass(opt_class); - $('#TARGET',section_disks).parent().addClass(man_class); - - //format hidden - $('#FORMAT',section_disks).parent().hide(); - $('#FORMAT',section_disks).parent().attr('disabled','disabled'); - - //source hidden - $('#SOURCE',section_disks).parent().hide(); - $('#SOURCE',section_disks).parent(). - attr('disabled','disabled'); - break; - case "floppy": - case "disk": - case "cdrom": - default: - //size hidden - $('#SIZE',section_disks).parent().hide(); - $('#SIZE',section_disks).parent().attr('disabled','disabled'); - - //target mandatory - $('#TARGET',section_disks).parent().removeClass(opt_class); - $('#TARGET',section_disks).parent().addClass(man_class); - - //format optional - $('#FORMAT',section_disks).parent().hide(); - $('#FORMAT',section_disks).parent().attr('disabled','disabled'); - - //source shown - $('#SOURCE',section_disks).parent().show(); - $('#SOURCE',section_disks).parent(). - removeAttr('disabled'); -*/ -// } - //hide_disabled(section_disks); - //}; - - //Our filter for the disks section fields is the standard - //mandatory filter applied for this section - //var diskFilter = function(){ - // return mandatory_filter(section_disks); - //}; -// - //$('#add_disk_button',section_disks).click(function(){ - // box_add_element(section_disks,'#disks_box',diskFilter); - // return false; - //}); - //$('#remove_disk_button',section_disks).click(function(){ - // box_remove_element(section_disks,'#disks_box'); - // return false; - //}); - }; - - // Sets up the network section - var networks_setup = function(){ - - $('.vm_param',section_networks).hide(); - $('.firewall_select',section_networks).hide(); - $('fieldset',section_networks).hide(); - - $('#add_networks',section_networks).click(function(){ - $('fieldset',section_networks).toggle(); - return false; - }); - - //Auto-set IMAGE_UNAME hidden field value - $('#NETWORK', section_networks).change(function(){ - var option = $('option:selected',this); - var uname = getValue(option.attr('elem_id'),1,2,dataTable_vNetworks); - $('input#NETWORK_UNAME',section_networks).val(uname); - }); - - //Depending on adding predefined network or not we show/hide - //some fields - $('#network_vs_niccfg input',section_networks).click(function(){ - - //firewall - $('.firewall',section_networks).hide(); - $('.firewall',section_networks).attr('disabled','disabled'); - $('.firewall_select',section_networks).show(); - $('.firewall_select select option',section_networks).removeAttr('selected'); - - select = $(this).val(); - switch (select) { - case "network": - $('.niccfg',section_networks).hide(); - $('.niccfg',section_networks).attr('disabled','disabled'); - $('.network',section_networks).show(); - $('.network',section_networks).removeAttr('disabled'); - break; - case "niccfg": - $('.network',section_networks).hide(); - $('.network',section_networks).attr('disabled','disabled'); - $('.niccfg',section_networks).show(); - $('.niccfg',section_networks).removeAttr('disabled'); - break; - } - //hide_disabled(section_networks); - }); - - $('#black_white_tcp',section_networks).change(function(){ - switch ($(this).val()) { - case "whitelist": - $('#BLACK_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_TCP',section_networks).parent().hide(); - $('#WHITE_PORTS_TCP',section_networks).parent().removeAttr('disabled'); - $('#WHITE_PORTS_TCP',section_networks).parent().show(); - break; - case "blacklist": - $('#WHITE_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_TCP',section_networks).parent().hide(); - $('#BLACK_PORTS_TCP',section_networks).parent().removeAttr('disabled'); - $('#BLACK_PORTS_TCP',section_networks).parent().show(); - break; - default: - $('#WHITE_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_TCP',section_networks).parent().hide(); - $('#BLACK_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_TCP',section_networks).parent().hide(); - }; - }); - - $('#black_white_udp',section_networks).change(function(){ - switch ($(this).val()) { - case "whitelist": - $('#BLACK_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_UDP',section_networks).parent().hide(); - $('#WHITE_PORTS_UDP',section_networks).parent().removeAttr('disabled'); - $('#WHITE_PORTS_UDP',section_networks).parent().show(); - break; - case "blacklist": - $('#WHITE_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_UDP',section_networks).parent().hide(); - $('#BLACK_PORTS_UDP',section_networks).parent().removeAttr('disabled'); - $('#BLACK_PORTS_UDP',section_networks).parent().show(); - break; - default: - $('#WHITE_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_UDP',section_networks).parent().hide(); - $('#BLACK_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_UDP',section_networks).parent().hide(); - }; - }); - - //The filter to add a new network checks that we have selected a - //network, or that the ip or mac are set - //TODO: Improve this check - var nicFilter = function(){ - return mandatory_filter(section_networks); - }; - - $('#add_nic_button',section_networks).click(function(){ - box_add_element(section_networks,'#nics_box',nicFilter); - return false; - }); - $('#remove_nic_button',section_networks).click(function(){ - box_remove_element(section_networks,'#nics_box'); - return false; - }); - - //preselect now hidden option - $('#network_vs_niccfg input#add_network',section_networks).trigger('click'); - }; - - //Sets up the input section - basicly enabling adding and removing from box - var inputs_setup = function() { - $('fieldset',section_inputs).hide(); - - $('#add_inputs',section_inputs).click(function(){ - $('fieldset',section_inputs).toggle(); - return false; - }); - - $('#add_input_button',section_inputs).click(function(){ - //no filter - box_add_element(section_inputs,'#inputs_box',function(){return true}); - return false; - }); - $('#remove_input_button',section_inputs).click(function(){ - box_remove_element(section_inputs,'#inputs_box'); - return false; - }); - }; - - //Set up the graphics section - var graphics_setup = function(){ - $('fieldset',section_graphics).hide(); - $('.vm_param',section_graphics).hide(); - $('select#TYPE',section_graphics).parent().show(); - - $('#add_graphics',section_graphics).click(function(){ - $('fieldset',section_graphics).toggle(); - return false; - }); - - $('select#TYPE',section_graphics).change(function(){ - g_type = $(this).val(); - switch (g_type) { - case "vnc": - case "spice": - $('#LISTEN',section_graphics).parent().show(); - $('#PORT',section_graphics).parent().show(); - $('#PASSWD',section_graphics).parent().show(); - $('#KEYMAP',section_graphics).parent().show(); - $('#LISTEN',section_graphics).parent().removeAttr('disabled'); - $('#PORT',section_graphics).parent().removeAttr('disabled'); - $('#PASSWD',section_graphics).parent().removeAttr('disabled'); - $('#KEYMAP',section_graphics).parent().removeAttr('disabled'); - break; - case "sdl": - $('#LISTEN',section_graphics).parent().show(); - $('#LISTEN',section_graphics).parent().removeAttr('disabled'); - $('#PORT',section_graphics).parent().hide(); - $('#PASSWD',section_graphics).parent().hide(); - $('#KEYMAP',section_graphics).parent().hide(); - $('#PORT',section_graphics).parent().attr('disabled','disabled'); - $('#PASSWD',section_graphics).parent().attr('disabled','disabled'); - $('#KEYMAP',section_graphics).parent().attr('disabled','disabled'); - break; - default: - $('#LISTEN', - section_graphics).parent().hide().attr('disabled', - 'disabled'); - $('#PORT', - section_graphics).parent().hide().attr('disabled', - 'disabled'); - $('#PASSWD', - section_graphics).parent().hide().attr('disabled', - 'disabled'); - $('#KEYMAP', - section_graphics).parent().hide().attr('disabled', - 'disabled'); - } - }); - - }; - - //Set up the context section - TODO: Apply improvements here... - var context_setup = function(){ - $('fieldset',section_context).hide(); - - $('#add_context',section_context).click(function(){ - $('fieldset',section_context).toggle(); - return false; - }); - - $('#add_context_button', section_context).click(function(){ - var name = $('#var_name',section_context).val(); - var value = $('#var_value',section_context).val(); - if (!name.length || !value.length) { - notifyError(tr("Context variable name and value must be filled in")); - return false; - } - option= ''; - $('select#context_box',section_context).append(option); - return false; - }); - - $('#remove_context_button', section_context).click(function(){ - box_remove_element(section_context,'#context_box'); - return false; - }); - }; - - // Set up the placement section - var placement_setup = function(){ - $('fieldset',section_placement).hide(); - - $('#add_placement',section_placement).click(function(){ - $('fieldset',section_placement).toggle(); - return false; - }); - - }; - - // Set up the raw section - var raw_setup = function(){ - $('fieldset',section_raw).hide(); - - $('#add_raw',section_raw).click(function(){ - $('fieldset',section_raw).toggle(); - return false; - }); - }; - - //set up the custom variables section - var custom_variables_setup = function(){ - $('fieldset',section_custom_var).hide(); - - $('#add_custom_var',section_custom_var).click(function(){ - $('fieldset',section_custom_var).toggle(); - return false; - }); - - $('#add_custom_var_button', section_custom_var).click( - function(){ - var name = $('#custom_var_name',section_custom_var).val(); - var value = $('#custom_var_value',section_custom_var).val(); - if (!name.length || !value.length) { - notifyError(tr("Custom variable name and value must be filled in")); - return false; - } - option= ''; - $('select#custom_var_box',section_custom_var).append(option); - return false; - }); - - $('#remove_custom_var_button', section_custom_var).click( - function(){ - box_remove_element(section_custom_var,'#custom_var_box'); - return false; - }); - } //***CREATE VM DIALOG MAIN BODY*** @@ -3573,10 +2455,6 @@ function setupCreateTemplateDialog(){ var tabs = $( "#template_create_tabs", dialog).tabs().addClass("ui-tabs-vertical"); $(".ui-tabs-vertical .ui-tabs-nav", dialog).removeClass("ui-tabs-nav").addClass("ui-tabs-nav-vert") - $('.next-tab, .prev-tab').live("click", function() { - tabs.tabs('select', parseInt($(this).attr("rel"))); - return false; - }); $('#wizard_next').click(function(){ var selected = tabs.tabs('option', 'selected'); @@ -3589,24 +2467,13 @@ function setupCreateTemplateDialog(){ }); add_capacity_tab(); - add_disks_tab(); add_nics_tab(); - - var temp_index = 3 - add_os_tab(temp_index); - - temp_index++; - add_io_tab(temp_index); - - temp_index++; - add_context_tab(temp_index); - - temp_index++; - add_placement_tab(temp_index); - - temp_index++; - add_other_tab(temp_index); + add_os_tab(); + add_io_tab(); + add_context_tab(); + add_placement_tab(); + add_other_tab(); // Re-Setup tips setupTips(dialog); @@ -3629,37 +2496,10 @@ function setupCreateTemplateDialog(){ //Different selector for items of kvm and xen (mandatory and optional) var items = '.vm_param input,.vm_param select'; - var kvm_man_items = '.kvm input,.kvm select'; - var kvm_opt_items = '.kvm_opt input, .kvm_opt select'; - var kvm_items = kvm_man_items +','+kvm_opt_items; - var xen_man_items = '.xen input,.xen select'; - var xen_opt_items = '.xen_opt input, .xen_opt select'; - var xen_items = xen_man_items +','+ xen_opt_items; - var vmware_man_items = '.vmware input,.vmware select'; - var vmware_opt_items = '.vmware_opt input, .vmware_opt select'; - var vmware_items = vmware_man_items +','+ vmware_opt_items; - //Starting template type, optional items class and mandatory items class - var templ_type = "kvm"; - var opt_class=".kvm_opt"; - var man_class=".kvm"; - - vmTabChange(0,{index : 0}); //enable kvm foldUnfoldToggle(); - //initialise all sections - os_boot_setup(); - features_setup(); - disks_setup(); - networks_setup(); - inputs_setup(); - graphics_setup(); - context_setup(); - placement_setup(); - raw_setup(); - custom_variables_setup(); - // Enhace buttons $('button',dialog).button(); @@ -3673,41 +2513,21 @@ function setupCreateTemplateDialog(){ // // CAPACITY // - var scope = section_capacity; - - if (!mandatory_filter(scope)){ - notifyError(tr("There are mandatory fields missing in the capacity section")); - return false; - }; - addSectionJSON(vm_json,scope); - - ////process os_boot_opts - //scope= section_os_boot; - //switch (templ_type){ - //case "xen": - // boot_method = $('#boot_method option:selected',scope).val(); - // if (!boot_method.length){ - // notifyError(tr("Xen templates must specify a boot method")); - // return false;} - //}; +// var scope = section_capacity; // - //if (!mandatory_filter(scope)){ - // notifyError(tr("There are mandatory fields missing in the OS Boot options section")); - // return false; - //}; +// if (!mandatory_filter(scope)){ +// notifyError(tr("There are mandatory fields missing in the capacity section")); +// return false; +// }; + addSectionJSON(vm_json,$('div#capacity_tab',dialog)); + // // OS // vm_json["OS"] = {}; addSectionJSON(vm_json["OS"],$('div#os_tab',dialog)); -// - ////Fetch pae and acpi options - //scope = section_features; - //vm_json["FEATURES"] = {}; - //addSectionJSON(vm_json["FEATURES"],scope); -// - ////process disks -> fetch from box + // // DISK // @@ -3813,52 +2633,6 @@ function setupCreateTemplateDialog(){ addSectionJSON(vm_json,$('div#placement_tab',dialog)); - console.log(vm_json) - ////process nics -> fetch from box - //scope = section_networks; - //vm_json["NIC"] = addBoxJSON(scope,'#nics_box'); -// - ////process inputs -> fetch from box - //scope = section_inputs; - //vm_json["INPUT"] = addBoxJSON(scope,'#inputs_box'); -// - ////process graphics -> fetch fields with value - //scope = section_graphics; - //vm_json["GRAPHICS"] = {}; - //addSectionJSON(vm_json["GRAPHICS"],scope); -// - ////context - //scope = section_context; - //vm_json["CONTEXT"] = {}; - //$('#context_box option',scope).each(function(){ - // name = $(this).attr('name'); - // value = $(this).val(); - // vm_json["CONTEXT"][name]=value; - //}); -// - ////placement -> fetch with value, escape double quotes - //scope = section_placement; - //var requirements = $('input#REQUIREMENTS',scope).val(); - //requirements = escapeDoubleQuotes(requirements); - //$('input#REQUIREMENTS',scope).val(requirements); - //var rank = $('input#RANK',scope).val(); - //rank = escapeDoubleQuotes(rank); - //$('input#RANK',scope).val(rank); - //addSectionJSON(vm_json,scope); -// - ////raw -> if value set type to driver and fetch - //scope = section_raw; - //vm_json["RAW"] = {}; - //addSectionJSON(vm_json["RAW"],scope); -// - ////custom vars - //scope = section_custom_var; - //$('#custom_var_box option',scope).each(function(){ - // name = $(this).attr('name'); - // value = $(this).val(); - // vm_json[name]=value; - //}); - // remove empty elements vm_json = removeEmptyObjects(vm_json); @@ -3869,6 +2643,9 @@ function setupCreateTemplateDialog(){ Sunstone.runAction("Template.create",vm_json); $create_template_dialog.dialog('close'); + $create_template_dialog.empty(); + setupCreateTemplateDialog(); + return false; }); @@ -3895,23 +2672,6 @@ function setupCreateTemplateDialog(){ } function popUpCreateTemplateDialog(){ - //Repopulate images select - var im_sel = makeSelectOptions(dataTable_images, - 4, //id col - trick -> reference by name! - 4, //name col - [10,10,10], - [tr("DISABLED"),tr("LOCKED"),tr("ERROR")] - ); - $('div#disks select#IMAGE',$create_template_dialog).html(im_sel); - //Repopulate network select - var vn_sel = makeSelectOptions(dataTable_vNetworks, - 4, //id col - trick -> reference by name! - 4, - [], - [] - ); - $('div#networks select#NETWORK',$create_template_dialog).html(vn_sel); - $create_template_dialog.dialog('open'); }; @@ -3979,42 +2739,86 @@ function setupTemplateTemplateUpdateDialog(){ }; function popUpTemplateTemplateUpdateDialog(){ - var select = makeSelectOptions(dataTable_templates, - 1,//id_col - 4,//name_col - [], - [] - ); - var sel_elems = getSelectedNodes(dataTable_templates); + var selected_nodes = getSelectedNodes(dataTable_templates); + + if ( selected_nodes.length != 1 ) + { + notifyMessage("Please select one (and just one) template to update."); + return false; + } + + // Get proper cluster_id + var template_id = ""+selected_nodes[0]; - - var dialog = $('#template_template_update_dialog'); - $('#template_template_update_select',dialog).html(select); - $('#template_template_update_textarea',dialog).val(""); - $('.permissions_table input',dialog).removeAttr('checked'); - $('.permissions_table',dialog).removeAttr('update'); - - if (sel_elems.length >= 1){ //several items in the list are selected - //grep them - var new_select= sel_elems.length > 1? '' : ""; - $('option','').each(function(){ - var val = $(this).val(); - if ($.inArray(val,sel_elems) >= 0){ - new_select+=''; - }; - }); - $('#template_template_update_select',dialog).html(new_select); - if (sel_elems.length == 1) { - $('#template_template_update_select option',dialog).attr('selected','selected'); - $('#template_template_update_select',dialog).trigger("change"); - }; - }; - - dialog.dialog('open'); - return false; + Sunstone.runAction("Template.show_to_update", template_id); +// var select = makeSelectOptions(dataTable_templates, +// 1,//id_col +// 4,//name_col +// [], +// [] +// ); +// var sel_elems = getSelectedNodes(dataTable_templates); +// +// +// var dialog = $('#template_template_update_dialog'); +// $('#template_template_update_select',dialog).html(select); +// $('#template_template_update_textarea',dialog).val(""); +// $('.permissions_table input',dialog).removeAttr('checked'); +// $('.permissions_table',dialog).removeAttr('update'); +// +// if (sel_elems.length >= 1){ //several items in the list are selected +// //grep them +// var new_select= sel_elems.length > 1? '' : ""; +// $('option','').each(function(){ +// var val = $(this).val(); +// if ($.inArray(val,sel_elems) >= 0){ +// new_select+=''; +// }; +// }); +// $('#template_template_update_select',dialog).html(new_select); +// if (sel_elems.length == 1) { +// $('#template_template_update_select option',dialog).attr('selected','selected'); +// $('#template_template_update_select',dialog).trigger("change"); +// }; +// }; +// +// dialog.dialog('open'); +// return false; }; +function fillTemplatePopUp(request, response){ + $create_template_dialog.empty(); + setupCreateTemplateDialog(); + console.log(response.VMTEMPLATE) + + var template = response.VMTEMPLATE.TEMPLATE; + + var capacity_section = $('div#capacity_tab',$create_template_dialog); + + + if (template.NAME) { + $('#NAME', capacity_section).val(template.NAME); + } + + if (template.CPU) { + $('#CPU', capacity_section).val(template.CPU); + //$('#cpu_slider', capacity_section).slider( "value", template.CPU ); + } + + if (template.MEMORY) { + $('#MEMORY', capacity_section).val(template.MEMORY); + //$('#memory_slider', capacity_section).slider( "value", template.MEMORY ); + } + + if (template.VCPU) { + $('#VCPU', capacity_section).val(template.VCPU); + //$('#vcpu_slider', capacity_section).slider( "value", template.VCPU ); + } + + + popUpCreateTemplateDialog(); +} // Template clone dialog function setupTemplateCloneDialog(){