mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
Backlog #2038: Update flow vm_template to new tables
This commit is contained in:
parent
37b8eeb025
commit
38d90d71e8
@ -123,24 +123,21 @@ var role_tab_content = '\
|
||||
'</label>\
|
||||
<input type="text" id="role_name" name="name" required/>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="row">\
|
||||
<div class="service_template_param service_role large-6 columns">\
|
||||
<label for="vm_template">' + tr("VM template") +
|
||||
'<span class="tip">'+ tr("Template associated to this role") +'</span>'+
|
||||
'</label>\
|
||||
<div id="vm_template">\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="service_template_param service_role large-2 columns">\
|
||||
<div class="service_template_param service_role large-2 columns end">\
|
||||
<label for="cardinality">' + tr("VMs") +
|
||||
'<span class="tip">'+ tr("Number of VMs to instantiate with this role") +'</span>'+
|
||||
'</label>\
|
||||
<input type="text" id="cardinality" name="cardinality" value="1" />\
|
||||
</div>\
|
||||
<div class="large-2 columns">\
|
||||
</div>\
|
||||
<div class="large-2 columns">\
|
||||
</div>\
|
||||
<div class="row">\
|
||||
<div class="service_template_param service_role small-12 columns">\
|
||||
<label for="vm_template">' + tr("VM template") +
|
||||
'<span class="tip">'+ tr("Template associated to this role") +'</span>'+
|
||||
'</label>\
|
||||
'+generateTemplateTableSelect("role_vm_template")+'\
|
||||
<div id="vm_template">\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="row">\
|
||||
@ -1088,7 +1085,11 @@ function setup_policy_tab_content(policy_section, html_policy_id) {
|
||||
function setup_role_tab_content(role_section, html_role_id) {
|
||||
setupTips(role_section);
|
||||
|
||||
insertSelectOptions('div#vm_template', role_section, "Template", null, false);
|
||||
var unique_id = "role_vm_template";
|
||||
setupTemplateTableSelect(role_section, unique_id);
|
||||
refreshTemplateTableSelect(role_section, unique_id);
|
||||
|
||||
$("input#selected_resource_id_"+unique_id, role_section).attr("required", "")
|
||||
|
||||
$("#role_name", role_section).change(function(){
|
||||
$("#" + html_role_id +" #role_name_text").html($(this).val());
|
||||
@ -1487,7 +1488,7 @@ function generate_json_service_template_from_form(dialog) {
|
||||
var role = {};
|
||||
role['name'] = $('input[name="name"]', this).val();
|
||||
role['cardinality'] = $('input[name="cardinality"]', this).val();
|
||||
role['vm_template'] = $('#vm_template .resource_list_select', this).val();
|
||||
role['vm_template'] = retrieveTemplateTableSelect(this, "role_vm_template");
|
||||
role['shutdown_action'] = $('select[name="shutdown_action_role"]', this).val();
|
||||
role['parents'] = [];
|
||||
role['vm_template_contents'] = $(".vm_template_contents", this).val();
|
||||
@ -1646,12 +1647,7 @@ function fillUpUpdateServiceTemplateDialog(response, dialog){
|
||||
|
||||
$("#cardinality", context).val(htmlDecode(value.cardinality));
|
||||
|
||||
// The vm_template select is already initialized, but we need to select
|
||||
// the template retrived from the service_template. Since the initialization
|
||||
// is async, we can't assume the .resource_list_select exists yet.
|
||||
// Calling the initialization again with the correct init_val should
|
||||
// use the cache anyway
|
||||
insertSelectOptions('div#vm_template', context, "Template", value.vm_template, false);
|
||||
selectTemplateTableSelect(context, "role_vm_template", {ids: value.vm_template});
|
||||
|
||||
$("select[name='shutdown_action_role']", context).val(value.shutdown_action);
|
||||
$("#min_vms", context).val(htmlDecode(value.min_vms));
|
||||
|
@ -6190,6 +6190,12 @@ function generateTemplateTableSelect(context_id){
|
||||
// opts.bVisible: dataTable bVisible option. If not set, the .yaml visibility will be used
|
||||
// opts.filter_fn: boolean function to filter which elements to show
|
||||
// opts.select_callback(aData, options): function called after a row is selected
|
||||
// opts.multiple_choice: boolean true to enable multiple element selection
|
||||
// opts.read_only: boolean true so user is not asked to select elements
|
||||
// opts.fixed_ids: Array of IDs to show. Any other ID will be filtered out. If
|
||||
// an ID is not returned by the pool, it will be included as a
|
||||
// blank row
|
||||
// opts.zone_id: Retrieves elements from this zone, instead of the current one
|
||||
function setupTemplateTableSelect(section, context_id, opts){
|
||||
|
||||
if(opts == undefined){
|
||||
@ -6208,6 +6214,18 @@ function setupTemplateTableSelect(section, context_id, opts){
|
||||
opts.bVisible = config;
|
||||
}
|
||||
|
||||
if(opts.multiple_choice == undefined){
|
||||
opts.multiple_choice = false;
|
||||
}
|
||||
|
||||
var fixed_ids_map_orig = {};
|
||||
|
||||
if(opts.fixed_ids != undefined){
|
||||
$.each(opts.fixed_ids,function(){
|
||||
fixed_ids_map_orig[this] = true;
|
||||
});
|
||||
}
|
||||
|
||||
var options = {
|
||||
"dataTable_options": {
|
||||
"bAutoWidth":false,
|
||||
@ -6223,32 +6241,74 @@ function setupTemplateTableSelect(section, context_id, opts){
|
||||
]
|
||||
},
|
||||
|
||||
"multiple_choice": opts.multiple_choice,
|
||||
"read_only": opts.read_only,
|
||||
"fixed_ids": opts.fixed_ids,
|
||||
|
||||
"id_index": 1,
|
||||
"name_index": 4,
|
||||
"uname_index": 2,
|
||||
|
||||
"update_fn": function(datatable){
|
||||
OpenNebula.Template.list({
|
||||
timeout: true,
|
||||
success: function (request, resource_list){
|
||||
var list_array = [];
|
||||
var success_func = function (request, resource_list){
|
||||
var list_array = [];
|
||||
|
||||
$.each(resource_list,function(){
|
||||
var add = true;
|
||||
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
|
||||
|
||||
if(opts.filter_fn){
|
||||
add = opts.filter_fn(this.VMTEMPLATE);
|
||||
}
|
||||
$.each(resource_list,function(){
|
||||
var add = true;
|
||||
|
||||
if(add){
|
||||
list_array.push(templateElementArray(this));
|
||||
}
|
||||
});
|
||||
if(opts.filter_fn){
|
||||
add = opts.filter_fn(this.VMTEMPLATE);
|
||||
}
|
||||
|
||||
updateView(list_array, datatable);
|
||||
},
|
||||
error: onError
|
||||
});
|
||||
if(opts.fixed_ids != undefined){
|
||||
add = (add && fixed_ids_map[this.VMTEMPLATE.ID]);
|
||||
}
|
||||
|
||||
if(add){
|
||||
list_array.push(templateElementArray(this));
|
||||
|
||||
delete fixed_ids_map[this.VMTEMPLATE.ID];
|
||||
}
|
||||
});
|
||||
|
||||
var n_columns = 6; // SET FOR EACH RESOURCE
|
||||
|
||||
$.each(fixed_ids_map, function(id,v){
|
||||
var empty = [];
|
||||
|
||||
for(var i=0; i<=n_columns; i++){
|
||||
empty.push("");
|
||||
}
|
||||
|
||||
empty[1] = id; // SET FOR EACH RESOURCE, id_index
|
||||
|
||||
list_array.push(empty);
|
||||
});
|
||||
|
||||
updateView(list_array, datatable);
|
||||
}
|
||||
|
||||
var error_func = function(request,error_json, container){
|
||||
success_func(request, []);
|
||||
onError(request,error_json, container);
|
||||
}
|
||||
|
||||
if (opts.zone_id == undefined) {
|
||||
OpenNebula.Template.list({
|
||||
timeout: true,
|
||||
success: success_func,
|
||||
error: error_func
|
||||
});
|
||||
} else {
|
||||
OpenNebula.Template.list_in_zone({
|
||||
data: { zone_id: opts.zone_id },
|
||||
timeout: true,
|
||||
success: success_func,
|
||||
error: error_func
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
"select_callback": opts.select_callback
|
||||
@ -6257,6 +6317,23 @@ function setupTemplateTableSelect(section, context_id, opts){
|
||||
return setupResourceTableSelect(section, context_id, options);
|
||||
}
|
||||
|
||||
// Clicks the refresh button
|
||||
function refreshTemplateTableSelect(section, context_id){
|
||||
return refreshResourceTableSelect(section, context_id);
|
||||
}
|
||||
|
||||
// Returns an ID, or an array of IDs for opts.multiple_choice
|
||||
function retrieveTemplateTableSelect(section, context_id){
|
||||
return retrieveResourceTableSelect(section, context_id);
|
||||
}
|
||||
|
||||
// Clears the current selection, and selects the given IDs
|
||||
// opts.ids must be a single ID, or an array of IDs for options.multiple_choice
|
||||
// opts.names must be an array of {name, uname}
|
||||
function selectTemplateTableSelect(section, context_id, opts){
|
||||
return selectResourceTableSelect(section, context_id, opts);
|
||||
}
|
||||
|
||||
function generateHostTableSelect(context_id){
|
||||
|
||||
var columns = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user