mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-25 06:03:36 +03:00
parent
f4d6f8d97e
commit
e890154ec3
@ -111,24 +111,33 @@ define(function(require) {
|
||||
var roles_index = 0;
|
||||
|
||||
$(".add_service_network", context).on("click", function(){
|
||||
var nic_index = $(".service_network_name", context).length;
|
||||
|
||||
$(".service_networks tbody").append(
|
||||
'<tr>\
|
||||
<td>\
|
||||
<input class="service_network_name" type="text" pattern="^\\w+$"/>\
|
||||
<small class="form-error"><br/>'+Locale.tr("Can only contain alphanumeric and underscore characters")+'</small>\
|
||||
<input class="service_network_name" type="text" />\
|
||||
<small class="form-error"><br/>'+Locale.tr("Can only contain alphanumeric and underscore characters, and be unique")+'</small>\
|
||||
</td>\
|
||||
<td>\
|
||||
<textarea class="service_network_description"/>\
|
||||
</td>\
|
||||
<td>\
|
||||
<a href="#"><i class="fas fa-times-circle remove-tab"></i></a>\
|
||||
<a href="#"><i class="fas fa-times-circle remove-tab" data-index="'+nic_index+'"></i></a>\
|
||||
</td>\
|
||||
</tr>');
|
||||
});
|
||||
|
||||
$(".add_service_network", context).trigger("click");
|
||||
|
||||
context.on("change", ".service_network_name", function(){
|
||||
context.on("keyup", ".service_network_name", function(){
|
||||
// update pattern regex
|
||||
var otherNames = $("input.service_network_name").not($(this)).map(function() {
|
||||
return $(this).val();
|
||||
}).get().join("|");
|
||||
|
||||
$(this).attr("pattern", "^(?!(" + otherNames + ")$)(^\\w+$)");
|
||||
|
||||
_redo_service_networks_selector(context, that);
|
||||
});
|
||||
|
||||
@ -136,7 +145,7 @@ define(function(require) {
|
||||
var tr = $(this).closest('tr');
|
||||
tr.remove();
|
||||
|
||||
_redo_service_networks_selector(context, that);
|
||||
_redo_service_networks_selector(context, that, $(this).data("index"));
|
||||
});
|
||||
|
||||
$("#tf_btn_roles", context).bind("click", function(){
|
||||
@ -413,45 +422,36 @@ define(function(require) {
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function _redo_service_networks_selector(dialog, template){
|
||||
function _redo_service_networks_selector(dialog, template, nicToDelete){
|
||||
$('#roles_tabs_content .role_content', dialog).each(function(){
|
||||
var role_section = this;
|
||||
_redo_service_networks_selector_role(dialog, role_section, template);
|
||||
_redo_service_networks_selector_role(dialog, this, template, nicToDelete);
|
||||
});
|
||||
}
|
||||
|
||||
function _redo_service_networks_selector_role(dialog, role_section, template){
|
||||
var selected_networks = [];
|
||||
function _redo_service_networks_selector_role(dialog, role_section, template, nicToDelete){
|
||||
var checked_networks = [];
|
||||
$(".service_network_checkbox:checked", role_section).each(function(){
|
||||
selected_networks.push($(this).val());
|
||||
checked_networks.push($(this).data("index"))
|
||||
});
|
||||
|
||||
$(".networks_role", role_section).hide();
|
||||
$(".networks_role_rdp", role_section).hide();
|
||||
var service_networks = false;
|
||||
|
||||
var role_tab_id = $(role_section).attr('id');
|
||||
|
||||
var str = "";
|
||||
$(".service_networks .service_network_name", dialog).each(function(index, input){
|
||||
var othersNames = $("input.service_network_name").not(input).map(function(_, v) {
|
||||
return $(v).val();
|
||||
}).get().join("|");
|
||||
|
||||
$(this).attr("pattern", "^(?!"+othersNames+")(\\w+)$");
|
||||
|
||||
$(".service_networks .service_network_name", dialog).each(function(index, _){
|
||||
var name = $(this).val();
|
||||
var regexp = new RegExp("^(?!"+othersNames+")(\\w+)$", "gi");
|
||||
var regexp = new RegExp($(this).attr("pattern"), "gi");
|
||||
var wasChecked = checked_networks.includes(index) ? 'checked="checked"' : '';
|
||||
|
||||
if (name && othersNames === "" || name.match(regexp)) {
|
||||
service_networks = true;
|
||||
// Condition 1: Be unique
|
||||
// Condition 2: Can only contain alphanumeric and underscore characters
|
||||
if (name && name !== "" && regexp.test(name)) {
|
||||
var idNetwork = role_tab_id + "_" + index;
|
||||
var idName = idNetwork + "_name";
|
||||
|
||||
str += "<tr id='"+idNetwork+"'>\
|
||||
<td style='width:10%'>\
|
||||
<input class='service_network_checkbox check_item'\
|
||||
type='checkbox' value='"+name+"' id='"+idName+"' data-index='"+index+"'/>\
|
||||
type='checkbox' value='"+name+"' id='"+idName+"' data-index='"+index+"' "+wasChecked+" />\
|
||||
</td>\
|
||||
<td>\
|
||||
<label for='"+idName+"'>"+name+"</label>\
|
||||
@ -462,18 +462,13 @@ define(function(require) {
|
||||
|
||||
$(".networks_role_body", role_section).html(str);
|
||||
|
||||
if (service_networks) {
|
||||
$(".networks_role", role_section).show();
|
||||
$(".networks_role_rdp", role_section).show();
|
||||
}
|
||||
|
||||
$.each(selected_networks, function(){
|
||||
$(".service_network_checkbox[value='"+this+"']", role_section).attr('checked', true);
|
||||
$(".networks_role_rdp", role_section).each(function(){
|
||||
str ? $(this).show() : $(this).hide();
|
||||
});
|
||||
|
||||
if (template && template.roleTabObjects) {
|
||||
$(Object.values(template.roleTabObjects)).each(function(_, section) {
|
||||
section && section.refresh(role_section);
|
||||
$(Object.values(template.roleTabObjects)).each(function() {
|
||||
this.refresh(nicToDelete);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -248,8 +248,15 @@ define(function(require) {
|
||||
$.each(that.service_template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
|
||||
var div_id = "user_input_role_"+index;
|
||||
var tmp_json = {};
|
||||
var stringCustomValues = TemplateUtils.templateToString(extra_info.merge_template.custom_attrs_values);
|
||||
|
||||
$.extend( tmp_json, WizardFields.retrieve($("#"+div_id, context)) );
|
||||
role.user_inputs_values = tmp_json;
|
||||
if (stringCustomValues) {
|
||||
(role.vm_template_contents)
|
||||
? role.vm_template_contents += stringCustomValues
|
||||
: role.vm_template_contents = stringCustomValues;
|
||||
}
|
||||
extra_info.merge_template.roles.push(role);
|
||||
});
|
||||
if (!service_name.length){ //empty name
|
||||
|
@ -18,7 +18,6 @@ define(function(require) {
|
||||
// Dependencies
|
||||
var Locale = require('utils/locale');
|
||||
var Tips = require('utils/tips');
|
||||
var Locks = require('utils/lock');
|
||||
var TemplatesTable = require('tabs/templates-tab/datatable');
|
||||
var TemplateUtils = require('utils/template-utils');
|
||||
|
||||
@ -63,12 +62,11 @@ define(function(require) {
|
||||
var that = this;
|
||||
|
||||
Tips.setup(role_section);
|
||||
Locks.setup(role_section);
|
||||
|
||||
this.templatesTable.initialize();
|
||||
this.templatesTable.idInput().attr("required", "");
|
||||
|
||||
role_section.on("change", "#role_name", function(){
|
||||
role_section.on("keyup", "#role_name", function(){
|
||||
$("#" + that.html_role_id +" #role_name_text").html($(this).val());
|
||||
});
|
||||
|
||||
@ -107,22 +105,11 @@ define(function(require) {
|
||||
var index = $(this).data("index");
|
||||
var name = $(this).val();
|
||||
|
||||
updateOptionsRDP(that.global_template, role_section);
|
||||
updateOptionsRDP(role_section, that.global_template);
|
||||
|
||||
(this.checked)
|
||||
? that.global_template[index] = { "NETWORK_ID": "$"+name }
|
||||
: delete that.global_template[index];
|
||||
|
||||
updateTextareaTemplate(role_section, that.global_template);
|
||||
});
|
||||
|
||||
role_section.on("change", ".vm_template_contents", role_section, function(){
|
||||
var value = $(this).val();
|
||||
|
||||
var diff = diffWithTemplate(value, that.global_template);
|
||||
|
||||
updateExtraTemplate(role_section, that.global_template, diff)
|
||||
updateTextareaTemplate(role_section, that.global_template);
|
||||
});
|
||||
|
||||
role_section.on("change", ".networks_role_rdp select#rdp", role_section, function(){
|
||||
@ -133,50 +120,18 @@ define(function(require) {
|
||||
var nicIndex = network[0];
|
||||
var nicTemplate = network[1];
|
||||
|
||||
(nicIndex !== valueSelected && nicTemplate["RDP"])
|
||||
&& delete that.global_template[nicIndex]["RDP"];
|
||||
if (nicIndex !== valueSelected && nicTemplate["RDP"]) {
|
||||
delete that.global_template[nicIndex]["RDP"];
|
||||
}
|
||||
});
|
||||
|
||||
if (valueSelected !== "" && that.global_template[valueSelected]) {
|
||||
that.global_template[valueSelected]["RDP"] = "yes";
|
||||
}
|
||||
updateTextareaTemplate(role_section, that.global_template);
|
||||
});
|
||||
}
|
||||
|
||||
function updateExtraTemplate(roleSection, currentTemplate, extraValue) {
|
||||
var checkboxes = $(".service_network_checkbox", roleSection);
|
||||
var lastIndex = checkboxes.length > 100 ? checkboxes.length : 100;
|
||||
|
||||
currentTemplate[lastIndex] = String(extraValue);
|
||||
}
|
||||
|
||||
function diffWithTemplate(newValue, currentTemplate) {
|
||||
// map template with index checkbox
|
||||
var sortedTemplate = TemplateUtils.templateToString({
|
||||
NIC: Object.values(currentTemplate).filter(function(nic) {
|
||||
return typeof nic === "object"
|
||||
})
|
||||
})//.concat(Object.values(currentTemplate).filter(rest => typeof rest !== "object"));
|
||||
|
||||
var sortedValue = TemplateUtils.templateToString(TemplateUtils.stringToTemplate(newValue))
|
||||
|
||||
return sortedValue.split("").filter(function(c, i) {
|
||||
return sortedTemplate.split("")[i] !== c
|
||||
}).join("");
|
||||
}
|
||||
|
||||
function updateTextareaTemplate(roleContext, currentTemplate) {
|
||||
|
||||
var newTemplate = TemplateUtils.templateToString({
|
||||
NIC: Object.values(currentTemplate).filter(nic => typeof nic === "object")
|
||||
}).concat(Object.values(currentTemplate).filter(rest => typeof rest !== "object"));
|
||||
|
||||
var textareaTemplate = $(".vm_template_contents", roleContext);
|
||||
textareaTemplate.val(newTemplate);
|
||||
}
|
||||
|
||||
function updateOptionsRDP(currentTemplate, context) {
|
||||
function updateOptionsRDP(context, currentTemplate) {
|
||||
var selectRDP = $(".networks_role_rdp select#rdp", context);
|
||||
// empty all options in select rdp
|
||||
selectRDP.empty();
|
||||
@ -210,7 +165,7 @@ define(function(require) {
|
||||
role['vm_template'] = this.templatesTable.retrieveResourceTableSelect();
|
||||
role['shutdown_action'] = $('select[name="shutdown_action_role"]', context).val();
|
||||
role['parents'] = [];
|
||||
role['vm_template_contents'] = $(".vm_template_contents", context).val();
|
||||
role['vm_template_contents'] = TemplateUtils.templateToString({ NIC: Object.values(this.global_template) });
|
||||
|
||||
$('.parent_roles_body input.check_item:checked', context).each(function(){
|
||||
role['parents'].push($(this).val());
|
||||
@ -294,7 +249,10 @@ define(function(require) {
|
||||
|
||||
// map template with index checkbox
|
||||
var nics = TemplateUtils.stringToTemplate(value.vm_template_contents)["NIC"];
|
||||
if (nics && Array.isArray(nics)) {
|
||||
if (nics) {
|
||||
// if not array, transform it
|
||||
nics = Array.isArray(nics) ? nics : [nics];
|
||||
|
||||
$(network_names).each(function(index, name) {
|
||||
var nicTemplate = $.grep(nics, function(nic) {
|
||||
return (nic["NETWORK_ID"] === "$"+name) && nic;
|
||||
@ -305,17 +263,9 @@ define(function(require) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// add extra of strings at the end of template
|
||||
var extraTemplate = diffWithTemplate(value.vm_template_contents, that.global_template);
|
||||
|
||||
updateExtraTemplate(context, that.global_template, extraTemplate);
|
||||
|
||||
// update textarea template content
|
||||
updateTextareaTemplate(context, that.global_template);
|
||||
|
||||
// update options for RDP
|
||||
updateOptionsRDP(that.global_template, context);
|
||||
updateOptionsRDP(context, that.global_template);
|
||||
}
|
||||
|
||||
$("select[name='shutdown_action_role']", context).val(value.shutdown_action);
|
||||
@ -367,29 +317,14 @@ define(function(require) {
|
||||
}
|
||||
}
|
||||
|
||||
function _refreshVMTemplate(role_section) {
|
||||
var selected_networks = [];
|
||||
$(".service_network_checkbox:checked", role_section).each(function(){
|
||||
selected_networks.push($(this).val());
|
||||
});
|
||||
function _refreshVMTemplate(nicToDelete) {
|
||||
if (this.role_section && this.global_template && nicToDelete) {
|
||||
if (nicToDelete) {
|
||||
delete this.global_template[nicToDelete];
|
||||
}
|
||||
|
||||
Object.values(this.global_template)
|
||||
.filter(function(nic) { return typeof nic === "object" })
|
||||
.reduce(function(acc, nic, indexKey) {
|
||||
if (!selected_networks.find(
|
||||
function(net) {
|
||||
return nic && nic.NETWORK_ID && nic.NETWORK_ID === "$"+net
|
||||
})
|
||||
) {
|
||||
acc.push(indexKey);
|
||||
}
|
||||
return acc;
|
||||
}, [])
|
||||
.forEach(function(index) {
|
||||
delete this.global_template[index];
|
||||
}, this);
|
||||
|
||||
updateTextareaTemplate(role_section, this.global_template);
|
||||
updateOptionsRDP(this.role_section, this.global_template);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -150,15 +150,6 @@
|
||||
<div class="medium-6 columns">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="service_template_param st_man large-12 columns">
|
||||
<label for="vm_template_contents">{{tr "VM template content"}}
|
||||
<span class="tip">{{tr "This information will be merged with the original Virtual Machine template. Configuration attributes and network interfaces will be replaced by those provided by the user when the template is instantiated"}}</span>
|
||||
<span class="lock is-lock" data-msg='{{tr "Please take into account that changing this value manually will bypass Sunstone validation and may result on a malformed template"}}'></span>
|
||||
</label>
|
||||
<textarea type="text" rows="4" class="vm_template_contents monospace" name="vm_template_contents" placeholder='ATTRIBUTE = "VALUE"'/>
|
||||
</div>
|
||||
</div>
|
||||
{{/advancedSection}}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user