1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-30 22:50:10 +03:00

Feature #601: Adds custom variables section to the wizards.

This sections allows user to define their custom variables in the templates.
This commit is contained in:
Hector Sanjuan 2011-04-29 18:53:52 +02:00 committed by Daniel Molina
parent dd180620dd
commit 905b14f806

View File

@ -448,6 +448,32 @@ var create_template_tmpl = '<div id="template_create_tabs">\
</div>\
\
\
<!--custom variables -->\
<div class="vm_section" id="custom_var">\
<div class="show_hide" id="add_context_cb">\
<h3>Add custom variables <a id="add_custom_var" class="icon_left" href="#"><span class="ui-icon ui-icon-plus" /></a></h3>\
</div>\
<fieldset><legend>Custom variables</legend>\
<div class="vm_param kvm_opt xen_opt vmware_opt">\
<label for="custom_var_name">Name:</label>\
<input type="text" id="custom_var_name" name="custom_var_name" />\
<div class="tip">Name for the custom variable</div>\
</div>\
<div class="vm_param kvm_opt xen_opt">\
<label for="custom_var_value">Value:</label>\
<input type="text" id="custom_var_value" name="custom_var_value" />\
<div class="tip">Value of the custom variable</div>\
</div>\
<div class="">\
<button class="add_remove_button add_button" id="add_custom_var_button" value="add_custom_var">Add</button>\
<button class="add_remove_button" id="remove_custom_var_button" value="remove_custom_var">Remove selected</button>\
<div class="clear"></div>\
<label for="custom_var_box">Current variables:</label>\
<select id="custom_var_box" name="custom_var_box" style="width:150px;height:100px;" multiple>\
</select>\
</div>\
</fieldset>\
</div>\
<!-- submit -->\
<fieldset>\
<div class="form_buttons">\
@ -1607,6 +1633,38 @@ function setupCreateTemplateDialog(){
});
};
//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("Custom variable name and value must be\
filled in");
return false;
}
option= '<option value=\''+value+'\' name=\''+name+'\'>'+
name+'='+value+
'</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***
$('div#dialogs').append('<div title="Create VM Template" id="create_template_dialog"></div>');
@ -1644,6 +1702,7 @@ function setupCreateTemplateDialog(){
var section_context = $('#context');
var section_placement = $('#placement');
var section_raw = $('#raw');
var section_custom_var = $('#custom_var');
//Different selector for items of kvm and xen (mandatory and optional)
var items = '.vm_param input,.vm_param select';
@ -1686,12 +1745,14 @@ function setupCreateTemplateDialog(){
context_setup();
placement_setup();
raw_setup();
custom_variables_setup();
//Process form
$('button#create_template_form_easy').click(function(){
//validate form
var vm_json = {};
var name,value,boot_method;
//process capacity options
var scope = section_capacity;
@ -1741,7 +1802,6 @@ function setupCreateTemplateDialog(){
//context
scope = section_context;
var context = $('#CONTEXT',scope).val();
vm_json["CONTEXT"] = {};
$('#context_box option',scope).each(function(){
name = $(this).attr("name");
@ -1764,6 +1824,14 @@ function setupCreateTemplateDialog(){
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);