mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-17 02:03:15 +09:00
Feature #2909: Ask for user inputs in VM create wizard
This commit is contained in:
1 parent
482d4ceda8
commit
ce68ea6edf
2 files changed
+99
-45
No files matched your search
@@ -50,7 +50,7 @@ var netUsage = {
|
||||
var create_vm_tmpl ='\
|
||||
<div class="row">\
|
||||
<div class="large-12 columns">\
|
||||
<h3 id="create_vnet_header" class="subheader">'+tr("Create Virtual Machine")+'</h3>\
|
||||
<h3 class="subheader">'+tr("Create Virtual Machine")+'</h3>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="reveal-body">\
|
||||
@@ -59,20 +59,20 @@ var create_vm_tmpl ='\
|
||||
<legend>'+tr("Step 1: Specify a name and the number of instances")+'</legend>\
|
||||
<div class="row">\
|
||||
<div class="large-5 columns">\
|
||||
<label for="vm_name">'+tr("VM Name")+'\
|
||||
<label for="create_vm_name">'+tr("VM Name")+'\
|
||||
<span class="tip">'+tr("Defaults to template name when emtpy. 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")+'.</span>\
|
||||
</label>\
|
||||
<input type="text" name="vm_name" id="vm_name" />\
|
||||
<input type="text" name="create_vm_name" id="create_vm_name" />\
|
||||
</div>\
|
||||
<div class="large-4 columns">\
|
||||
<label for="vm_n_times">'+tr("Number of instances")+':\
|
||||
<label for="create_vm_n_times">'+tr("Number of instances")+':\
|
||||
<span class="tip">'+tr("Number of Virtual Machines that will be created using this template")+'.</span>\
|
||||
</label>\
|
||||
<input type="text" name="vm_n_times" id="vm_n_times" value="1">\
|
||||
<input type="text" name="create_vm_n_times" id="create_vm_n_times" value="1">\
|
||||
</div>\
|
||||
<div class="large-3 columns">\
|
||||
<input type="checkbox" name="hold" id="hold"/>\
|
||||
<label for="hold">'+tr("Hold")+'\
|
||||
<input type="checkbox" name="create_vm_hold" id="create_vm_hold"/>\
|
||||
<label for="create_vm_hold">'+tr("Hold")+'\
|
||||
<span class="tip">' + tr("Sets the new VM to hold state, instead of pending. The scheduler will not deploy VMs in this state. It can be released later, or deployed manually.") +'</span>\
|
||||
</label>\
|
||||
</div>\
|
||||
@@ -82,9 +82,16 @@ var create_vm_tmpl ='\
|
||||
<legend>'+tr("Step 2: Select a template")+'</legend>\
|
||||
'+generateTemplateTableSelect("vm_create")+'\
|
||||
</fieldset>\
|
||||
<div id="create_vm_inputs_step">\
|
||||
<fieldset>\
|
||||
<legend>'+tr("Step 3: Fill the required inputs")+'</legend>\
|
||||
<div id="create_vm_user_inputs">\
|
||||
</div>\
|
||||
</fieldset>\
|
||||
</div>\
|
||||
<div class="form_buttons reveal-footer">\
|
||||
<div class="form_buttons">\
|
||||
<button class="button radius right success" id="instantiate_vm_tenplate_proceed" value="Template.instantiate_vms">'+tr("Create")+'</button>\
|
||||
<button class="button radius right success" id="create_vm_template_proceed" value="Template.instantiate_vms">'+tr("Create")+'</button>\
|
||||
</div>\
|
||||
</div>\
|
||||
<a class="close-reveal-modal">×</a>\
|
||||
@@ -2669,27 +2676,62 @@ function setupCreateVMDialog(){
|
||||
$(document).foundation();
|
||||
//dialog.addClass("reveal-modal large max-height").attr("data-reveal", "");
|
||||
|
||||
$("#create_vm_template_proceed", dialog).attr("disabled", "disabled");
|
||||
$("#create_vm_inputs_step", dialog).hide();
|
||||
|
||||
setupTemplateTableSelect(dialog, "vm_create");
|
||||
|
||||
$('#refresh_button_vm_create', dialog).click();
|
||||
|
||||
$("#selected_resource_id_vm_create", dialog).on("change", function(){
|
||||
var template_id = $(this).val();
|
||||
|
||||
$("#create_vm_inputs_step", dialog).hide();
|
||||
$("#create_vm_user_inputs", dialog).empty();
|
||||
|
||||
OpenNebula.Template.show({
|
||||
data : {
|
||||
id: template_id
|
||||
},
|
||||
timeout: true,
|
||||
success: function (request, template_json){
|
||||
$("#create_vm_inputs_step", dialog).hide();
|
||||
$("#create_vm_user_inputs", dialog).empty();
|
||||
|
||||
var has_inputs = generateVMTemplateUserInputs(
|
||||
$("#create_vm_user_inputs", dialog),
|
||||
template_json,
|
||||
{text_header: ""});
|
||||
|
||||
if(has_inputs){
|
||||
$("#create_vm_inputs_step", dialog).show();
|
||||
}
|
||||
|
||||
$("#create_vm_template_proceed", dialog).removeAttr("disabled");
|
||||
},
|
||||
error: function(request,error_json, container){
|
||||
onError(request,error_json, container);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setupTips(dialog);
|
||||
|
||||
$('#create_vm_form',dialog).submit(function(){
|
||||
var vm_name = $('#vm_name',this).val();
|
||||
var vm_name = $('#create_vm_name',this).val();
|
||||
var template_id = $("#selected_resource_id_vm_create", this).val();
|
||||
var n_times = $('#vm_n_times',this).val();
|
||||
var n_times = $('#create_vm_n_times',this).val();
|
||||
var n_times_int=1;
|
||||
var hold = $('#hold',this).prop("checked");
|
||||
var hold = $('#create_vm_hold',this).prop("checked");
|
||||
|
||||
if (!template_id.length){
|
||||
notifyError(tr("You have not selected a template"));
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
if (n_times.length){
|
||||
n_times_int=parseInt(n_times,10);
|
||||
};
|
||||
}
|
||||
|
||||
var extra_msg = "";
|
||||
if (n_times_int > 1) {
|
||||
@@ -2702,14 +2744,17 @@ function setupCreateVMDialog(){
|
||||
'hold': hold
|
||||
};
|
||||
|
||||
var tmp_json = {};
|
||||
retrieveWizardFields($(this), tmp_json);
|
||||
|
||||
extra_info['template'] = tmp_json;
|
||||
|
||||
if (!vm_name.length){ //empty name use OpenNebula core default
|
||||
for (var i=0; i< n_times_int; i++){
|
||||
extra_info['vm_name'] = "";
|
||||
Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (vm_name.indexOf("%i") == -1){//no wildcard, all with the same name
|
||||
for (var i=0; i< n_times_int; i++){
|
||||
extra_info['vm_name'] = vm_name;
|
||||
|
||||
@@ -5099,10 +5099,10 @@ function setupResourceTableSelect(section, context_id, options) {
|
||||
$("td", this).addClass('markrow');
|
||||
$('input.check_item', this).attr('checked','checked');
|
||||
|
||||
$('#selected_resource_id_'+context_id, section).val(aData[options.id_index]);
|
||||
$('#selected_resource_id_'+context_id, section).val(aData[options.id_index]).change();
|
||||
$('#selected_resource_id_'+context_id, section).hide();
|
||||
|
||||
$('#selected_resource_name_'+context_id, section).text(aData[options.name_index]);
|
||||
$('#selected_resource_name_'+context_id, section).text(aData[options.name_index]).change();
|
||||
$('#selected_resource_name_'+context_id, section).show();
|
||||
|
||||
return true;
|
||||
@@ -5118,39 +5118,42 @@ function setupResourceTableSelect(section, context_id, options) {
|
||||
// It will replace the div's html with a row for each USER_INPUTS
|
||||
// opts.text_header: header text for the text & password inputs
|
||||
// opts.network_header: header text for the network inputs
|
||||
// returns true if at least one input was inserted
|
||||
function generateVMTemplateUserInputs(div, template_json, opts) {
|
||||
generateInstantiateUserInputs(
|
||||
return generateInstantiateUserInputs(
|
||||
div, template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS, opts);
|
||||
}
|
||||
|
||||
// It will replace the div's html with a row for each USER_INPUTS
|
||||
// opts.text_header: header text for the text & password inputs
|
||||
// opts.network_header: header text for the network inputs
|
||||
// returns true if at least one input was inserted
|
||||
function generateServiceTemplateUserInputs(div, template_json, opts) {
|
||||
generateInstantiateUserInputs(
|
||||
return generateInstantiateUserInputs(
|
||||
div, template_json.DOCUMENT.TEMPLATE.BODY.custom_attrs, opts);
|
||||
}
|
||||
|
||||
// It will replace the div's html with a row for each USER_INPUTS
|
||||
// opts.text_header: header text for the text & password inputs
|
||||
// opts.network_header: header text for the network inputs
|
||||
// returns true if at least one input was inserted
|
||||
function generateInstantiateUserInputs(div, user_inputs, opts) {
|
||||
|
||||
div.empty();
|
||||
|
||||
if(user_inputs == undefined){
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(opts == undefined){
|
||||
opts = {};
|
||||
}
|
||||
|
||||
if(!opts.text_header){
|
||||
if(opts.text_header == undefined){
|
||||
opts.text_header = tr("Custom Attributes");
|
||||
}
|
||||
|
||||
if(!opts.network_header){
|
||||
if(opts.network_header == undefined){
|
||||
opts.network_header = tr("Network");
|
||||
}
|
||||
|
||||
@@ -5181,17 +5184,19 @@ function generateInstantiateUserInputs(div, user_inputs, opts) {
|
||||
});
|
||||
|
||||
if (network_attrs.length > 0) {
|
||||
div.append(
|
||||
'<br>'+
|
||||
'<div class="row">'+
|
||||
'<div class="large-12 large-centered columns">'+
|
||||
'<h3 class="subheader">'+
|
||||
opts.network_header+
|
||||
'</h3>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'<div class="instantiate_user_inputs">'+
|
||||
'</div>');
|
||||
if(opts.network_header.length > 0){
|
||||
div.append(
|
||||
'<br>'+
|
||||
'<div class="row">'+
|
||||
'<div class="large-12 large-centered columns">'+
|
||||
'<h3 class="subheader">'+
|
||||
opts.network_header+
|
||||
'</h3>'+
|
||||
'</div>'+
|
||||
'</div>');
|
||||
}
|
||||
|
||||
div.append('<div class="instantiate_user_inputs"/>');
|
||||
|
||||
var separator = "";
|
||||
|
||||
@@ -5221,17 +5226,19 @@ function generateInstantiateUserInputs(div, user_inputs, opts) {
|
||||
}
|
||||
|
||||
if (text_attrs.length > 0) {
|
||||
div.append(
|
||||
'<br>'+
|
||||
'<div class="row">'+
|
||||
'<div class="large-12 large-centered columns">'+
|
||||
'<h3 class="subheader">'+
|
||||
opts.text_header+
|
||||
'</h3>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'<div class="instantiate_user_inputs">'+
|
||||
'</div>');
|
||||
if(opts.text_header.length > 0){
|
||||
div.append(
|
||||
'<br>'+
|
||||
'<div class="row">'+
|
||||
'<div class="large-12 large-centered columns">'+
|
||||
'<h3 class="subheader">'+
|
||||
opts.text_header+
|
||||
'</h3>'+
|
||||
'</div>'+
|
||||
'</div>');
|
||||
}
|
||||
|
||||
div.append('<div class="instantiate_user_inputs"/>');
|
||||
|
||||
$.each(text_attrs, function(index, custom_attr){
|
||||
$(".instantiate_user_inputs", div).append(
|
||||
@@ -5245,4 +5252,6 @@ function generateInstantiateUserInputs(div, user_inputs, opts) {
|
||||
'</div>');
|
||||
});
|
||||
}
|
||||
|
||||
return (network_attrs.length > 0 || text_attrs.length > 0);
|
||||
}
|
||||
Reference in new issue
Block a user