diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index fe9e040e1b..7846ed36d0 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -66,7 +66,7 @@ var templates_tab_content = '\
\ ?\

\ -'+tr("Clicking `instantiate` will instantly create new Virtual Machines from the selected templates and name one-id. If you want to assign a specific name to a new VM, or launch several instances at once, use Virtual Machines->New button.")+'\ +'+tr("Clicking `instantiate` will create new Virtual Machines from the selected templates and name one-id. You will be able to assign a specific name to a new VM, or launch several instances at once if the template doesn't reference any persistent image.")+'\

\

\ '+tr("You can clone a template to obtain a copy from an existing template. This copy will be owned by you.")+'\ @@ -149,6 +149,43 @@ var update_template_tmpl = \ '; +var instantiate_vm_template_tmpl ='\ +

\ +

\ + '+tr("Instantiate VM Template")+'\ +

\ +
\ +
\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ +
'+tr("Defaults to template name when emtpy")+'.
\ +
\ +
\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ +
'+tr("You can use the wildcard %i. When creating several VMs, %i will be replaced with a different number starting from 0 in each of them")+'.
\ +
\ +
\ +
\ +
\ + \ + \ +
\ +×\ +
'; + var dataTable_templates; var $create_template_dialog; @@ -275,9 +312,17 @@ var template_actions = { type: "custom", call: function(){ nodes = getSelectedNodes(dataTable_templates); - $.each(nodes,function(){ + if (nodes.length == 1) + { + popUpInstantiateVMTemplateDialog(); + } + else + { + $.each(nodes,function(){ Sunstone.runAction("Template.instantiate",this,""); - }); + }); + } + Sunstone.runAction("VM.refresh"); } }, @@ -4025,6 +4070,56 @@ function setTemplateAutorefresh() { },INTERVAL+someTime()); }; +// Instantiate dialog +// Sets up the instiantiate template dialog and all the processing associated to it +function setupInstantiateTemplateDialog(){ + + dialogs_context.append('
'); + //Insert HTML in place + $instantiate_vm_template_dialog = $('#instantiate_vm_template_dialog') + var dialog = $instantiate_vm_template_dialog; + dialog.html(instantiate_vm_template_tmpl); + + + dialog.addClass("reveal-modal"); + + setupTips(dialog); + + $('#instantiate_vm_template_form',dialog).submit(function(){ + var vm_name = $('#vm_name',this).val(); + var n_times = $('#vm_n_times',this).val(); + var n_times_int=1; + + if (n_times.length){ + n_times_int=parseInt(n_times,10); + }; + + if (!vm_name.length){ + vm_name = getTemplateName(template_id); + }; + + if (vm_name.indexOf("%i") == -1){ //no wildcard + for (var i=0; i< n_times_int; i++){ + Sunstone.runAction("Template.instantiate",template_id,vm_name); + }; + } else { //wildcard present: replace wildcard + var name = ""; + for (var i=0; i< n_times_int; i++){ + name = vm_name.replace(/%i/gi,i); + Sunstone.runAction("Template.instantiate",template_id,name); + }; + }; + + $instantiate_vm_template_dialog.trigger("reveal:close") + return false; + }); +} + +// Open creation dialog +function popUpInstantiateVMTemplateDialog(){ + $instantiate_vm_template_dialog.reveal(); +} + //The DOM is ready at this point $(document).ready(function(){ @@ -4051,7 +4146,7 @@ $(document).ready(function(){ // spinner, // '','','','',''],dataTable_templates); Sunstone.runAction("Template.list"); - + setupInstantiateTemplateDialog(); setupCreateTemplateDialog(); setupTemplateTemplateUpdateDialog(); setupTemplateCloneDialog(); diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 27dedd3519..871e2b3e6c 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -104,7 +104,7 @@ var vms_tab_content = '\ var create_vm_tmpl ='\
\

\ - '+tr("Create Virtual Network")+'\ + '+tr("Create Virtual Machine")+'\

\
\
\