Skip to content

Commit

Permalink
B #5918: Fix VM instantiation with user inputs (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Borges authored and rsmontero committed Jul 27, 2022
1 parent 7fda29b commit cbfdb35
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ define(function(require) {
contextJSON[key] = "$" + name;
});

var userInputsOrder = UserInputs.retrieveOrder();

var start_script = WizardFields.retrieveInput($(".START_SCRIPT", context));
if (start_script != "") {
if ($(".ENCODE_START_SCRIPT", context).is(":checked")) {
Expand All @@ -257,7 +255,6 @@ define(function(require) {

if (!$.isEmptyObject(contextJSON)) { templateJSON["CONTEXT"] = contextJSON; };
if (!$.isEmptyObject(userInputsJSON)) { templateJSON["USER_INPUTS"] = userInputsJSON; };
templateJSON["INPUTS_ORDER"] = userInputsOrder;
}

return templateJSON;
Expand Down Expand Up @@ -305,7 +302,6 @@ define(function(require) {
}

delete templateJSON["USER_INPUTS"];
delete templateJSON["INPUTS_ORDER"];
}

if (contextJSON) {
Expand Down
179 changes: 68 additions & 111 deletions src/sunstone/public/app/utils/user-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,83 +147,68 @@ define(function(require) {

function _fill(context, templateJSON){
var userInputsJSON = templateJSON["USER_INPUTS"];
if(!templateJSON["INPUTS_ORDER"]){
var inputsOrderString = "";
$.each(userInputsJSON, function(key, value){
inputsOrderString += key + ",";
});
templateJSON["INPUTS_ORDER"] = inputsOrderString.slice(0,-1);
}

var order = templateJSON["INPUTS_ORDER"];
var orderJSON = order.split(",");

if(userInputsJSON){
$.each(orderJSON, function(key, value){
var nameOrder = value;
$.each(userInputsJSON, function(key, value) {
if(nameOrder == key){
$(".add_user_input_attr", context).trigger("click");
$.each(userInputsJSON, function(key, value) {
$(".add_user_input_attr", context).trigger("click");

var trcontext = $(".user_input_attrs tbody tr", context).last();

$(".user_input_name", trcontext).val(key);

var trcontext = $(".user_input_attrs tbody tr", context).last();
var attr = _unmarshall(value);

$(".user_input_name", trcontext).val(key);
if (templateJSON[key] != undefined){
attr.initial = templateJSON[key];
}
$(".user_input_type", trcontext).val(attr.type).change();
$(".user_input_description", trcontext).val(attr.description);

var attr = _unmarshall(value);
if (attr.mandatory){
$(".user_input_mandatory", trcontext).attr("checked", "checked");
} else {
$(".user_input_mandatory", trcontext).removeAttr("checked");
}

if (templateJSON[key] != undefined){
attr.initial = templateJSON[key];
switch(attr.type){
case "text":
case "text64":
case "number":
case "number-float":
case "fixed":
$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);
break;
case "boolean":
if(attr.initial == "YES"){
$("input#radio_yes", trcontext).attr("checked", "checked");
$("input#radio_no", trcontext).removeAttr("checked");
}
else {
$("input#radio_yes", trcontext).removeAttr("checked");
$("input#radio_no", trcontext).attr("checked", "checked");
}
$(".user_input_type", trcontext).val(attr.type).change();
$(".user_input_description", trcontext).val(attr.description);
break;
case "range":
case "range-float":
var values = attr.params.split(".."); // "2..8"

if (attr.mandatory){
$(".user_input_mandatory", trcontext).attr("checked", "checked");
if (values.length == 2){
$("."+attr.type+" input.user_input_params_min", trcontext).val(values[0]);
$("."+attr.type+" input.user_input_params_max", trcontext).val(values[1]);
} else {
$(".user_input_mandatory", trcontext).removeAttr("checked");
console.error("Wrong user input parameters for \""+key+"\". Expected \"MIN..MAX\", received \""+attr.params+"\"");
}

switch(attr.type){
case "text":
case "text64":
case "number":
case "number-float":
case "fixed":
$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);
break;
case "boolean":
if(attr.initial == "YES"){
$("input#radio_yes", trcontext).attr("checked", "checked");
$("input#radio_no", trcontext).removeAttr("checked");
}
else {
$("input#radio_yes", trcontext).removeAttr("checked");
$("input#radio_no", trcontext).attr("checked", "checked");
}
break;
case "range":
case "range-float":
var values = attr.params.split(".."); // "2..8"

if (values.length == 2){
$("."+attr.type+" input.user_input_params_min", trcontext).val(values[0]);
$("."+attr.type+" input.user_input_params_max", trcontext).val(values[1]);
} else {
console.error("Wrong user input parameters for \""+key+"\". Expected \"MIN..MAX\", received \""+attr.params+"\"");
}

$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);

break;

case "list":
case "list-multiple":
$("."+attr.type+" input.user_input_params", trcontext).val(attr.params);
$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);
break;
}
}
});
$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);

break;

case "list":
case "list-multiple":
$("."+attr.type+" input.user_input_params", trcontext).val(attr.params);
$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);
break;
}
});
}
}
Expand Down Expand Up @@ -502,51 +487,23 @@ define(function(require) {
html += "</fieldset>";
div.append(html);
html = "";
if(opts.defaults && opts.defaults.INPUTS_ORDER){
var order = opts.defaults.INPUTS_ORDER;
var orderJSON = order.split(",");
$.each(orderJSON, function(key, value){
var orderValue = value;
$.each(custom_attrs, function(index, custom_attr) {
if (custom_attr.name == orderValue){
var tooltip = "";
if (custom_attr.type === "list-multiple"){
tooltip = " <span class=\"tip\">" + Locale.tr("Use ctrl key for multiple selection") + "</span>";
}
$("."+custom_attr_class, div).append(
"<div class=\"row\">" +
"<div class=\"large-12 large-centered columns\">" +
"<label>" +
TemplateUtils.htmlEncode(custom_attr.description) +
tooltip +
_attributeInput(custom_attr) +
"</label>" +
"</div>" +
"</div>");
}
});
});
} else {
$.each(custom_attrs, function(index, custom_attr) {
var tooltip = "";
if(custom_attr && custom_attr.description){
if (custom_attr.type === "list-multiple"){
tooltip = " <span class=\"tip\">" + Locale.tr("Use ctrl key for multiple selection") + "</span>";
}
$("."+custom_attr_class, div).append(
"<div class=\"row\">" +
"<div class=\"large-12 large-centered columns\">" +
"<label>" +
TemplateUtils.htmlEncode(custom_attr.description) +
tooltip +
_attributeInput(custom_attr) +
"</label>" +
"</div>" +
"</div>"
);
}
});
}

$.each(custom_attrs, function(_, custom_attr) {
var tooltip = "";
if (custom_attr.type === "list-multiple"){
tooltip = " <span class=\"tip\">" + Locale.tr("Use ctrl key for multiple selection") + "</span>";
}
$("."+custom_attr_class, div).append(
"<div class=\"row\">" +
"<div class=\"large-12 large-centered columns\">" +
"<label>" +
TemplateUtils.htmlEncode(custom_attr.description) +
tooltip +
_attributeInput(custom_attr) +
"</label>" +
"</div>" +
"</div>");
});
}

//render Vmgroups_attr_values
Expand Down

0 comments on commit cbfdb35

Please sign in to comment.