Feature #2967: Service template instantiate uses a dialog

Service Template intpus, and individual role inputs are
also asked to the user
This commit is contained in:
Carlos Martín committed 2014-06-30 16:18:08 +02:00
1 parent 9a4624a52b
commit 0cf5f5b9c6
3 files changed
+336 -39

No files matched your search

@@ -399,6 +399,40 @@ function generate_elasticity_accordion(role_id, context) {
$(document).foundation();
}
var instantiate_service_template_tmpl ='\
<div class="row">\
<h3 class="subheader">'+tr("Instantiate Service Template")+'</h3>\
</div>\
<form id="instantiate_service_template_form" action="">\
<div class="row">\
<div class="large-6 columns">\
<label for="service_name">'+tr("Service Name")+
'<span class="tip">'+tr("Defaults to template name when emtpy. You can use the wildcard &#37;i. When creating several Services, &#37;i will be replaced with a different number starting from 0 in each of them")+'.</span>'+
'</label>\
<input type="text" name="service_name" id="service_name" />\
</div>\
</div>\
<div class="row">\
<div class="large-6 columns">\
<label for="service_n_times">'+tr("Number of instances")+
'<span class="tip">'+tr("Number of Services that will be created using this template")+'.</span>'+
'</label>\
<input type="text" name="service_n_times" id="service_n_times" value="1">\
</div>\
</div>\
<div id="instantiate_service_user_inputs">\
<i class="fa fa-spinner fa-spin"></i>\
</div>\
<div id="instantiate_service_role_user_inputs">\
</div>\
<div class="form_buttons">\
<button class="button radius right success" id="instantiate_service_tenplate_proceed" value="ServiceTemplate.instantiate">'+tr("Instantiate")+'</button>\
</div>\
<a class="close-reveal-modal">&#215;</a>\
</form>';
var dataTable_service_templates;
var $create_service_template_dialog;
@@ -494,6 +528,13 @@ var service_template_actions = {
notify: true
},
"ServiceTemplate.instantiate_dialog" : {
type: "custom",
call: function(){
popUpInstantiateServiceTemplateDialog();
}
},
"ServiceTemplate.refresh" : {
type: "custom",
call: function () {
@@ -570,7 +611,7 @@ var service_template_buttons = {
type: "create_dialog",
layout: "create"
},
"ServiceTemplate.instantiate" : {
"ServiceTemplate.instantiate_dialog" : {
type: "action",
layout: "main",
text: tr("Instantiate")
@@ -1668,6 +1709,183 @@ function fillUpUpdateServiceTemplateDialog(request, response){
dialog.foundation('reveal', 'open');
}
function popUpInstantiateServiceTemplateDialog(){
var selected_nodes = getSelectedNodes(dataTable_service_templates);
if ( selected_nodes.length != 1 )
{
notifyMessage("Please select one (and just one) template to instantiate.");
return false;
}
setupInstantiateServiceTemplateDialog();
$instantiate_service_template_dialog.foundation().foundation('reveal', 'open');
$("input#service_name",$instantiate_service_template_dialog).focus();
}
// Instantiate dialog
// Sets up the instiantiate template dialog and all the processing associated to it
function setupInstantiateServiceTemplateDialog(){
dialogs_context.append('<div id="instantiate_service_template_dialog"></div>');
//Insert HTML in place
$instantiate_service_template_dialog = $('#instantiate_service_template_dialog')
var dialog = $instantiate_service_template_dialog;
dialog.html(instantiate_service_template_tmpl);
dialog.addClass("reveal-modal medium").attr("data-reveal", "");
dialog.removeClass("max-height");
$("#instantiate_service_tenplate_proceed", dialog).attr("disabled", "disabled");
var selected_nodes = getSelectedNodes(dataTable_service_templates);
var template_id = ""+selected_nodes[0];
var service_template_json;
OpenNebula.ServiceTemplate.show({
data : {
id: template_id
},
timeout: true,
success: function (request, template_json){
service_template_json = template_json;
$("#instantiate_service_user_inputs", dialog).empty();
generateServiceTemplateUserInputs(
$("#instantiate_service_user_inputs", dialog),
template_json);
n_roles = template_json.DOCUMENT.TEMPLATE.BODY.roles.length;
n_roles_done = 0;
$.each(template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
var div_id = "user_input_role_"+index;
$("#instantiate_service_role_user_inputs", dialog).append(
'<div class="row">\
<div id="'+div_id+'" class="large-6 columns">\
</div>\
</div>'
);
OpenNebula.Template.show({
data : {
id: role.vm_template
},
timeout: true,
success: function (request, vm_template_json){
$("#"+div_id, dialog).empty();
generateVMTemplateUserInputs(
$("#"+div_id, dialog),
vm_template_json,
{
text_header: tr("Custom Attributes for Role") + " " + role.name
}
);
n_roles_done += 1;
if(n_roles_done == n_roles){
$("#instantiate_service_tenplate_proceed", dialog).removeAttr("disabled");
}
},
error: function(request,error_json, container){
onError(request,error_json, container);
$("#instantiate_vm_user_inputs", dialog).empty();
}
});
});
},
error: function(request,error_json, container){
onError(request,error_json, container);
$("#instantiate_service_user_inputs", dialog).empty();
}
});
setupTips(dialog);
$('#instantiate_service_template_form',dialog).submit(function(){
var service_name = $('#service_name',this).val();
var n_times = $('#service_n_times',this).val();
var n_times_int=1;
var template_id
if ($("#TEMPLATE_ID", this).val()) {
template_id = $("#TEMPLATE_ID", this).val();
} else {
var selected_nodes = getSelectedNodes(dataTable_service_templates);
template_id = ""+selected_nodes[0];
}
if (n_times.length){
n_times_int=parseInt(n_times,10);
};
var extra_msg = "";
if (n_times_int > 1) {
extra_msg = n_times_int+" times";
}
var extra_info = {
'merge_template': {}
};
var tmp_json = {};
retrieveWizardFields($("#instantiate_service_user_inputs", dialog), tmp_json);
extra_info.merge_template.custom_attrs_values = tmp_json;
extra_info.merge_template.roles = [];
$.each(service_template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
var div_id = "user_input_role_"+index;
tmp_json = {};
retrieveWizardFields($("#"+div_id, dialog), tmp_json);
role.user_inputs_values = tmp_json;
extra_info.merge_template.roles.push(role);
});
if (!service_name.length){ //empty name
for (var i=0; i< n_times_int; i++){
Sunstone.runAction("ServiceTemplate.instantiate", [template_id], extra_info);
}
}
else
{
if (service_name.indexOf("%i") == -1){//no wildcard, all with the same name
extra_info['merge_template']['name'] = service_name;
for (var i=0; i< n_times_int; i++){
Sunstone.runAction(
"ServiceTemplate.instantiate",
[template_id], extra_info);
}
} else { //wildcard present: replace wildcard
for (var i=0; i< n_times_int; i++){
extra_info['merge_template']['name'] = service_name.replace(/%i/gi,i);
Sunstone.runAction(
"ServiceTemplate.instantiate",
[template_id], extra_info);
}
}
}
$instantiate_service_template_dialog.foundation('reveal', 'close')
return false;
});
}
//The DOM is ready at this point
$(document).ready(function(){
var tab_name = "oneflow-templates";
+11 -12
View File
@@ -93,7 +93,7 @@ var instantiate_vm_template_tmpl ='\
<i class="fa fa-spinner fa-spin"></i>\
</div>\
<div class="form_buttons">\
<button class="button radius right success" id="instantiate_vm_tenplate_proceed" value="Template.instantiate_vms">'+tr("Instantiate")+'</button>\
<button class="button radius right success" id="instantiate_vm_template_proceed" value="Template.instantiate_vms">'+tr("Instantiate")+'</button>\
</div>\
<a class="close-reveal-modal">&#215;</a>\
</form>';
@@ -213,7 +213,7 @@ var easy_provision_vm_template_tmpl ='\
</div>\
</fieldset>\
<div class="form_buttons reveal-footer">\
<button class="button radius right success" id="instantiate_vm_tenplate_proceed" value="Template.instantiate_vms">'+tr("Instantiate")+'</button>\
<button class="button radius right success" id="instantiate_vm_template_proceed" value="Template.instantiate_vms">'+tr("Instantiate")+'</button>\
</div>\
<a class="close-reveal-modal">&#215;</a>\
</form>\
@@ -4839,10 +4839,10 @@ function setupInstantiateTemplateDialog(easy_provision){
dialog.addClass("reveal-modal").attr("data-reveal", "");
dialog.removeClass("max-height");
$("#instantiate_vm_tenplate_proceed", dialog).attr("disabled", "disabled");
$("#instantiate_vm_template_proceed", dialog).attr("disabled", "disabled");
var selected_nodes = getSelectedNodes(dataTable_templates);
template_id = ""+selected_nodes[0];
var template_id = ""+selected_nodes[0];
OpenNebula.Template.show({
data : {
@@ -4850,15 +4850,14 @@ function setupInstantiateTemplateDialog(easy_provision){
},
timeout: true,
success: function (request, template_json){
if (template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS) {
generateVMTemplateUserInputs(
$("#instantiate_vm_user_inputs", dialog),
template_json);
} else {
$("#instantiate_vm_user_inputs", dialog).empty();
}
$("#instantiate_vm_tenplate_proceed", dialog).removeAttr("disabled");
$("#instantiate_vm_user_inputs", dialog).empty();
generateVMTemplateUserInputs(
$("#instantiate_vm_user_inputs", dialog),
template_json);
$("#instantiate_vm_template_proceed", dialog).removeAttr("disabled");
},
error: function(request,error_json, container){
onError(request,error_json, container);
+106 -26
View File
@@ -4756,10 +4756,10 @@ function generateVNetTableSelect(context_id){
return generateResourceTableSelect(context_id, columns, options);
}
// opts.bVisible: dataTable bVisible option. If not set, the .yaml visibility will be used
// opts.filter_fn: boolean function to filter which vnets to show
function setupVNetTableSelect(section, context_id, opts){
var bVisible = opts.bVisible;
if(opts == undefined){
opts = {};
}
@@ -4927,53 +4927,133 @@ function setupResourceTableSelect(section, context_id, options) {
}
// It will replace the div's html with a row for each USER_INPUTS
function generateVMTemplateUserInputs(div, template_json) {
// opts.text_header: header text for the text & password inputs
// opts.network_header: header text for the network inputs
function generateVMTemplateUserInputs(div, template_json, opts) {
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
function generateServiceTemplateUserInputs(div, template_json, opts) {
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
function generateInstantiateUserInputs(div, user_inputs, opts) {
div.empty();
if(user_inputs == undefined){
return;
}
if(opts == undefined){
opts = {};
}
if(!opts.text_header){
opts.text_header = tr("Custom Attributes");
}
if(!opts.network_header){
opts.network_header = tr("Network");
}
var network_attrs = [];
var text_attrs = [];
$.each(template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS, function(key, value){
$.each(user_inputs, function(key, value){
var parts = value.split("|");
// 0 mandatory; 1 type; 2 desc;
var attrs = {
"name": key,
"mandatory": parts[0],
"type": parts[1],
"description": parts[2],
"name": key,
"mandatory": parts[0],
"type": parts[1],
"description": parts[2],
}
switch (parts[1]) {
case "text":
text_attrs.push(attrs)
break;
case "password":
text_attrs.push(attrs)
break;
case "vnet_id":
network_attrs.push(attrs)
break;
case "text":
text_attrs.push(attrs)
break;
case "password":
text_attrs.push(attrs)
break;
}
});
if (text_attrs.length > 0) {
div.html(
if (network_attrs.length > 0) {
div.append(
'<br>'+
'<div class="row">'+
'<div class="large-12 large-centered columns">'+
'<h3 class="subheader">'+
tr("Custom Attributes")+
opts.network_header+
'</h3>'+
'</div>'+
'</div>'+
'<div class="instantiate_user_inputs">'+
'</div>');
var separator = "";
$.each(text_attrs, function(index, custom_attr){
$(".instantiate_user_inputs", div).append(
$.each(network_attrs, function(index, vnet_attr){
var unique_id = "user_input_"+vnet_attr.name;
$(".instantiate_user_inputs", div).append(
'<div class="row">'+
'<div class="large-12 large-centered columns">'+
separator+
'<label>' +
htmlDecode(vnet_attr.description) +
'</label>'+
generateVNetTableSelect(unique_id)+
'</div>'+
'</div>');
separator = "<hr/>";
setupVNetTableSelect(div, unique_id);
$('#refresh_button_'+unique_id).click();
$("input#selected_resource_id_"+unique_id, div).attr(
"wizard_field", vnet_attr.name);
});
}
if (text_attrs.length > 0) {
div.append(
'<br>'+
'<div class="row">'+
'<div class="large-12 large-centered columns">'+
'<label>' +
htmlDecode(custom_attr.description) +
'<input type="'+custom_attr.type+'" wizard_field="'+custom_attr.name+'"/>'+
'</label>'+
'<h3 class="subheader">'+
opts.text_header+
'</h3>'+
'</div>'+
'</div>'+
'<div class="instantiate_user_inputs">'+
'</div>');
})
}
}
$.each(text_attrs, function(index, custom_attr){
$(".instantiate_user_inputs", div).append(
'<div class="row">'+
'<div class="large-12 large-centered columns">'+
'<label>' +
htmlDecode(custom_attr.description) +
'<input type="'+custom_attr.type+'" wizard_field="'+custom_attr.name+'"/>'+
'</label>'+
'</div>'+
'</div>');
});
}
}