1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00
This commit is contained in:
Tino Vazquez 2022-07-14 18:05:36 +02:00
commit d87725c5ed
14 changed files with 450 additions and 151 deletions

View File

@ -234,10 +234,7 @@ CommandParser::CmdParser.new(ARGV) do
Instantiate a Service Template
EOT
command :instantiate,
instantiate_desc,
:templateid,
[:file, nil],
command :instantiate, instantiate_desc, :templateid, [:file, nil],
:options => [MULTIPLE, Service::JSON_FORMAT, Service::TOP] do
number = options[:multiple] || 1
params = {}
@ -248,9 +245,12 @@ CommandParser::CmdParser.new(ARGV) do
params['merge_template'] = JSON.parse(File.read(args[1])) if args[1]
unless params['merge_template']
service_template = OpenNebula::ServiceTemplate
.new_with_id(args[0],
OpenNebula::Client.new)
secret = "#{options[:username]}:#{options[:password]}"
one_client = OpenNebula::Client.new(secret)
service_template = OpenNebula::ServiceTemplate.new_with_id(
args[0], one_client
)
service_template.info
body = JSON.parse(service_template['/DOCUMENT/TEMPLATE/BODY'])

View File

@ -98,6 +98,7 @@ const AddressRangeCard = memo(
return (
<Box
data-cy="ar"
className={classes.root}
sx={{
'&:hover': { bgcolor: 'action.hover' },

View File

@ -60,7 +60,7 @@ const MarketplaceCard = memo(
)
return (
<div {...rootProps} data-cy={`datastore-${ID}`}>
<div {...rootProps} data-cy={`marketplace-${ID}`}>
<div className={classes.main}>
<div className={classes.title}>
<StatusCircle color={stateColor} tooltip={stateName} />

View File

@ -172,12 +172,6 @@ const FieldComponent = memo(({ id, cy, dependOf, ...attributes }) => {
defaultValue: Array.isArray(dependOf) ? [] : undefined,
})
/* const valueOfDependField = useMemo(() => {
if (!dependOf) return null
return watch(nameOfDependField)
}, [dependOf, watch, nameOfDependField]) */
const { name, type, htmlType, grid, ...fieldProps } = Object.entries(
attributes
).reduce((field, attribute) => {

View File

@ -21,16 +21,24 @@ import {
OPTION_SORTERS,
arrayToOptions,
REG_V4,
REG_V6,
REG_MAC,
} from 'client/utils'
import { T, INPUT_TYPES } from 'client/constants'
const AR_TYPES = { IP4: 'IP4', IP4_6: 'IP4_6', IP6: 'IP6', ETHER: 'ETHER' }
const AR_TYPES = {
IP4: 'IP4',
IP4_6: 'IP4_6',
IP6: 'IP6',
IP6_STATIC: 'IP6_STATIC',
ETHER: 'ETHER',
}
const AR_TYPES_STR = {
[AR_TYPES.IP4]: 'IPv4',
[AR_TYPES.IP4_6]: 'IPv4/6',
[AR_TYPES.IP6]: 'IPv6',
[AR_TYPES.IP6_STATIC]: 'IPv6 (no-SLAAC)',
[AR_TYPES.IP4_6]: 'IPv4/6',
[AR_TYPES.ETHER]: 'Ethernet',
}
@ -58,18 +66,58 @@ const IP_FIELD = {
type: INPUT_TYPES.TEXT,
dependOf: TYPE_FIELD.name,
htmlType: (arType) =>
[AR_TYPES.IP6, AR_TYPES.ETHER].includes(arType) && INPUT_TYPES.HIDDEN,
[AR_TYPES.IP6, AR_TYPES.IP6_STATIC, AR_TYPES.ETHER].includes(arType) &&
INPUT_TYPES.HIDDEN,
validation: string()
.trim()
.default(() => undefined)
.when(TYPE_FIELD.name, {
is: (arType) => [AR_TYPES.IP6, AR_TYPES.ETHER].includes(arType),
is: (arType) =>
[AR_TYPES.IP6, AR_TYPES.IP6_STATIC, AR_TYPES.ETHER].includes(arType),
then: (schema) => schema.strip().notRequired(),
otherwise: (schema) =>
schema.required().matches(REG_V4, { message: T.InvalidIPv4 }),
}),
}
/** @type {Field} IPv6 field */
const IP6_FIELD = {
name: 'IP6',
label: T.FirstIPv6Address,
type: INPUT_TYPES.TEXT,
dependOf: TYPE_FIELD.name,
htmlType: (arType) =>
![AR_TYPES.IP6_STATIC, AR_TYPES.IP4_6].includes(arType) &&
INPUT_TYPES.HIDDEN,
validation: string()
.trim()
.default(() => undefined)
.when(TYPE_FIELD.name, {
is: (arType) => ![AR_TYPES.IP6_STATIC, AR_TYPES.IP4_6].includes(arType),
then: (schema) => schema.strip(),
otherwise: (schema) =>
schema.required().matches(REG_V6, { message: T.InvalidIPv6 }),
}),
}
/** @type {Field} Prefix length field */
const PREFIX_LENGTH_FIELD = {
name: 'PREFIX_LENGTH',
label: T.PrefixLength,
tooltip: T.PrefixLengthConcept,
type: INPUT_TYPES.TEXT,
dependOf: TYPE_FIELD.name,
htmlType: (arType) => AR_TYPES.IP6_STATIC !== arType && INPUT_TYPES.HIDDEN,
validation: string()
.trim()
.default(() => undefined)
.when(TYPE_FIELD.name, {
is: (arType) => AR_TYPES.IP6_STATIC !== arType,
then: (schema) => schema.strip(),
otherwise: (schema) => schema.required(),
}),
}
/** @type {Field} MAC field */
const MAC_FIELD = {
name: 'MAC',
@ -137,8 +185,10 @@ const FIELDS = [
TYPE_FIELD,
IP_FIELD,
MAC_FIELD,
IP6_FIELD,
SIZE_FIELD,
GLOBAL_PREFIX_FIELD,
PREFIX_LENGTH_FIELD,
ULA_PREFIX_FIELD,
]

View File

@ -87,6 +87,7 @@ export const DRIVER_FIELD = {
.required()
.default(() => drivers[0]),
grid: { md: 12 },
notNull: true,
}
/**

View File

@ -42,6 +42,145 @@ const GENERAL_FIELDS = ({ nics = [] } = {}) =>
label: T.RdpConnection,
type: INPUT_TYPES.SWITCH,
validation: boolean().yesOrNo(),
grid: { md: 12 },
},
{
name: 'RDP_SERVER_LAYOUT',
label: T.RdpLayout,
type: INPUT_TYPES.AUTOCOMPLETE,
dependOf: 'RDP',
values: [
{ text: T.PortugueseBr, value: 'pt-br-qwerty' },
{ text: T.EnglishGB, value: 'en-gb-qwerty' },
{ text: T.EnglishUS, value: 'en-us-qwerty' },
{ text: T.French, value: 'fr-fr-azerty' },
{ text: T.FrenchBe, value: 'fr-be-azerty' },
{ text: T.FrenchSw, value: 'fr-ch-qwertz' },
{ text: T.German, value: 'de-de-qwertz' },
{ text: T.GermanSw, value: 'de-ch-qwertz' },
{ text: T.Hungarian, value: 'hu-hu-qwertz' },
{ text: T.Italian, value: 'it-it-qwerty' },
{ text: T.Japanese, value: 'ja-jp-qwerty' },
{ text: T.SpanishEs, value: 'es-es-qwerty' },
{ text: T.SpanishLatam, value: 'es-latam-qwerty' },
{ text: T.Swedish, value: 'sv-se-qwerty' },
{ text: T.Turkish, value: 'tr-tr-qwerty' },
{ text: T.Other, value: 'failsafe' },
],
validation: string().trim().notRequired().default(undefined),
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
grid: { sm: 6 },
},
{
name: 'RDP_RESIZE_METHOD',
label: T.RdpRizeMethod,
type: INPUT_TYPES.SELECT,
dependOf: 'RDP',
values: [
{ text: T.DisplayUpdate, value: 'display-update' },
{ text: T.Reconnect, value: 'reconnect' },
],
validation: string().trim().notRequired().default('display-update'),
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
grid: { sm: 6 },
},
{
name: 'RDP_DISABLE_AUDIO',
label: T.DisableAudio,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_ENABLE_AUDIO_INPUT',
label: T.EnableAudioInput,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_ENABLE_WALLPAPER',
label: T.EnableWallpaper,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_ENABLE_THEMING',
label: T.EnableTheming,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_ENABLE_FONT_SMOOTHING',
label: T.EnableFontSmoothing,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_ENABLE_FULL_WINDOW_DRAG',
label: T.EnableFullWindowDrag,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_ENABLE_DESKTOP_COMPOSITION',
label: T.EnableDesktopComposition,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_ENABLE_MENU_ANIMATIONS',
label: T.EnableMenuAnimations,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_DISABLE_BITMAP_CACHING',
label: T.DisableBitmapCaching,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_DISABLE_OFFSCREEN_CACHING',
label: T.DisableOffscreenCaching,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
name: 'RDP_DISABLE_GLYPH_CACHING',
label: T.DisableGlyphCaching,
type: INPUT_TYPES.SWITCH,
dependOf: 'RDP',
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
},
{
@ -49,7 +188,7 @@ const GENERAL_FIELDS = ({ nics = [] } = {}) =>
label: T.SshConnection,
type: INPUT_TYPES.SWITCH,
validation: boolean().yesOrNo(),
grid: { sm: 6 },
grid: { md: 12 },
},
!!nics?.length && {
name: 'PARENT',

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { string, boolean, ObjectSchema } from 'yup'
import { string, boolean, ObjectSchema, lazy } from 'yup'
import {
Field,
@ -24,6 +24,44 @@ import {
import { T, INPUT_TYPES, HYPERVISORS } from 'client/constants'
const { vcenter, lxc, kvm } = HYPERVISORS
const CUSTOM_KEYMAP_VALUE = 'custom'
const KEYMAP_VALUES = {
ar: T.Arabic,
hr: T.Croatian,
cz: T.Czech,
da: T.Danish,
nl: T.Dutch,
'en-gb': T.EnglishGB,
'en-us': T.EnglishUS,
et: T.Estonian,
fo: T.Faroese,
fi: T.Finnish,
fr: T.French,
'fr-be': T.FrenchBe,
'fr-ca': T.FrenchCa,
bepo: T.FrenchBEPO,
'fr-ch': T.FrenchSw,
de: T.German,
'de-ch': T.GermanSw,
hu: T.Hungarian,
is: T.Icelandic,
it: T.Italian,
ja: T.Japanese,
lv: T.Latvian,
lt: T.Lithuanian,
mk: T.Macedonian,
no: T.Norwegian,
pl: T.Polish,
pt: T.Portuguese,
'pt-br': T.PortugueseBr,
ru: T.Russian,
sl: T.Slovenian,
es: T.SpanishEs,
sv: T.Swedish,
th: T.Thai,
tr: T.Turkish,
custom: T.Custom,
}
/** @type {Field} Type field */
export const TYPE = {
@ -79,14 +117,57 @@ export const PORT = {
export const KEYMAP = {
name: 'GRAPHICS.KEYMAP',
label: T.Keymap,
type: INPUT_TYPES.TEXT,
type: INPUT_TYPES.AUTOCOMPLETE,
dependOf: TYPE.name,
values: arrayToOptions(Object.entries(KEYMAP_VALUES), {
addEmpty: false,
getText: ([_, label]) => label,
getValue: ([keymap]) => keymap,
}),
htmlType: (noneType) => !noneType && INPUT_TYPES.HIDDEN,
validation: string()
.trim()
.notRequired()
.default(() => undefined),
fieldProps: { placeholder: 'en-us' },
.transform((value) =>
value && KEYMAP_VALUES[value] ? value : CUSTOM_KEYMAP_VALUE
)
.default(() => undefined)
.afterSubmit((value, { context }) =>
value === CUSTOM_KEYMAP_VALUE
? context.extra.GRAPHICS.CUSTOM_KEYMAP
: value
),
}
/** @type {Field} Custom keymap field */
export const CUSTOM_KEYMAP = {
name: 'GRAPHICS.CUSTOM_KEYMAP',
label: T.Keymap,
type: INPUT_TYPES.TEXT,
dependOf: KEYMAP.name,
htmlType: (selectedKeymap) =>
(!selectedKeymap ||
selectedKeymap?.toLowerCase() !== CUSTOM_KEYMAP_VALUE) &&
INPUT_TYPES.HIDDEN,
validation: lazy((_, { context }) =>
string()
.trim()
.when(`$extra.${KEYMAP.name}`, (keymap, schema) =>
keymap === CUSTOM_KEYMAP_VALUE
? schema.required()
: schema.notRequired()
)
.default(() => {
const keymapFromTemplate = context.extra?.GRAPHICS?.KEYMAP
return KEYMAP_VALUES[keymapFromTemplate]
? undefined
: keymapFromTemplate
})
// Modification type is not required in template
.afterSubmit(() => undefined)
),
grid: { md: 12 },
}
/** @type {Field} Password random field */
@ -136,7 +217,7 @@ export const COMMAND = {
*/
export const GRAPHICS_FIELDS = (hypervisor) =>
filterFieldsByHypervisor(
[TYPE, LISTEN, PORT, KEYMAP, PASSWD, RANDOM_PASSWD, COMMAND],
[TYPE, LISTEN, PORT, KEYMAP, CUSTOM_KEYMAP, PASSWD, RANDOM_PASSWD, COMMAND],
hypervisor
)

View File

@ -201,7 +201,7 @@ export const PIN_POLICY = {
/** @enum {string} Custom Hypervisor */
export const CUSTOM_HOST_HYPERVISOR = {
NAME: 'Custom',
SUNSTONE_NAME: T.CustomHypervisor,
SUNSTONE_NAME: T.Custom,
}
/**

View File

@ -69,7 +69,7 @@ module.exports = {
CreateProvider: 'Create Provider',
CreateProvision: 'Create Provision',
CreateServiceTemplate: 'Create Service Template',
CreateVirtualNetwork: 'Create VM Template',
CreateVirtualNetwork: 'Create Virtual Network',
CreateVmTemplate: 'Create VM Template',
CurrentGroup: 'Current group: %s',
CurrentOwner: 'Current owner: %s',
@ -456,6 +456,20 @@ module.exports = {
PartOf: 'Part of',
GuacamoleState: 'Guacamole State',
VMRCState: 'VMRC State',
RdpLayout: 'RDP keyboard layout',
RdpRizeMethod: 'RDP rezise method',
DisableAudio: 'Disable audio',
EnableAudioInput: 'Enable audio input',
EnableWallpaper: 'Render desktop wallpaper',
EnableTheming: 'Render windows theming control',
EnableFontSmoothing: 'Enable font smoothing',
EnableFullWindowDrag: 'Enable full window drag',
EnableDesktopComposition: 'Enable desktop composition',
EnableMenuAnimations: 'Enable menu animations',
DisableBitmapCaching: 'Disable bitmap caching',
DisableOffscreenCaching: 'Disable offscreen caching',
DisableGlyphCaching: 'Disable glyph caching',
Timezone: 'Timezone',
/* VM schema - info */
VmName: 'VM name',
UserTemplate: 'User Template',
@ -541,7 +555,7 @@ module.exports = {
/* VM Template schema */
/* VM Template schema - general */
CustomHypervisor: 'Custom',
Custom: 'Custom',
CustomVariables: 'Custom Variables',
CustomAttributes: 'Custom Attributes',
Hypervisor: 'Hypervisor',
@ -750,6 +764,45 @@ module.exports = {
GenerateRandomPassword: 'Generate random password',
Command: 'Command',
Bus: 'BUS',
ConnectionAttributes: '%s connection attributes',
/* VM Template schema - Input/Output - graphics - Remote Connections Keymaps */
Arabic: 'Arabic',
Croatian: 'Croatian',
Czech: 'Czech',
Danish: 'Danish',
Dutch: 'Dutch',
EnglishGB: 'English (United Kingdom)',
EnglishUS: 'English (United States)',
Estonian: 'Estonian',
Faroese: 'Faroese',
Finnish: 'Finnish',
French: 'French',
FrenchBe: 'French (Belgium)',
FrenchCa: 'French (Canada)',
FrenchBEPO: 'French (BEPO)',
FrenchSw: 'French (Switzerland)',
German: 'German',
GermanSw: 'German (Switzerland)',
Hungarian: 'Hungarian',
Icelandic: 'Icelandic',
Italian: 'Italian',
Japanese: 'Japanese',
Latvian: 'Latvian',
Lithuanian: 'Lithuanian',
Macedonian: 'Macedonian',
Norwegian: 'Norwegian',
Polish: 'Polish',
Portuguese: 'Portuguese',
PortugueseBr: 'Portuguese (Brazil)',
Russian: 'Russian',
Slovenian: 'Slovenian',
SpanishEs: 'Spanish (Spain)',
SpanishLatam: 'Spanish (Latin American)',
Swedish: 'Swedish',
Thai: 'Thai',
Turkish: 'Turkish',
/* VM Template schema - Input/Output - graphics - Remote connections */
DisplayUpdate: 'Display update',
/* VM Template schema - NUMA */
NumaTopology: 'NUMA Topology',
NumaTopologyConcept:
@ -892,13 +945,17 @@ module.exports = {
Addresses: 'Addresses',
AddressRange: 'Address Range',
FirstIPv4Address: 'First IPv4 address',
FirstIPv6Address: 'First IPv6 address',
FirstMacAddress: 'First MAC address',
PrefixLength: 'Prefix length',
PrefixLengthConcept: 'Length of the prefix to configure VM interfaces',
SLAAC: 'SLAAC',
IPv6GlobalPrefix: 'IPv6 Global prefix',
IPv6ULAPrefix: 'IPv6 ULA prefix',
IPAMDriver: 'IPAM driver',
InvalidAddress: 'Invalid address',
InvalidIPv4: 'Invalid IPv4',
InvalidIPv6: 'Invalid IPv6',
InvalidMAC: 'Invalid MAC',
DisabledAddressRangeInForm:
'Address Ranges need to be managed in the individual Virtual Network panel',

View File

@ -178,15 +178,7 @@ function Login() {
const AppLinks = () => {
const { appTitle } = useGeneral()
const isNotCurrentApp = (app) => app !== `${appTitle}`.toLowerCase()
const transformAppTitle = (app) =>
APPS_WITH_ONE_PREFIX.includes(app)
? `One${sentenceCase(app)}`
: sentenceCase(app)
const otherApps = APPS.filter(isNotCurrentApp).map(transformAppTitle)
const otherApps = APPS.filter((app) => app !== `${appTitle}`.toLowerCase())
if (otherApps?.length === 0) {
return null
@ -195,12 +187,20 @@ const AppLinks = () => {
return otherApps.map((app) => (
<Link
key={app}
data-cy={`goto-${app}`.toLowerCase()}
href={`${APP_URL}/${app}`.toLowerCase()}
variant="caption"
color="text.secondary"
padding={1}
>
<Translate word={T.TakeMeToTheAppGui} values={app} />
<Translate
word={T.TakeMeToTheAppGui}
values={
APPS_WITH_ONE_PREFIX.includes(app)
? `One${sentenceCase(app)}`
: sentenceCase(app)
}
/>
</Link>
))
}

View File

@ -265,7 +265,30 @@ const getRdpSettings = (vmInfo) => {
config.port = vmInfo.TEMPLATE?.CONTEXT?.RDP_PORT ?? '3389'
config.username = vmInfo.TEMPLATE?.CONTEXT?.USERNAME
config.password = vmInfo.TEMPLATE?.CONTEXT?.PASSWORD
config['resize-method'] = 'display-update'
config['server-layout'] = nicWithRdp?.RDP_SERVER_LAYOUT
config['resize-method'] = nicWithRdp?.RDP_RESIZE_METHOD ?? 'display-update'
config['disable-audio'] =
nicWithRdp?.RDP_DISABLE_AUDIO?.toLowerCase() === 'yes'
config['enable-audio-input'] =
nicWithRdp?.RDP_ENABLE_AUDIO_INPUT?.toLowerCase() === 'yes'
config['enable-wallpaper'] =
nicWithRdp?.RDP_ENABLE_WALLPAPER?.toLowerCase() === 'yes'
config['enable-theming'] =
nicWithRdp?.RDP_ENABLE_THEMING?.toLowerCase() === 'yes'
config['enable-font-smoothing'] =
nicWithRdp?.RDP_ENABLE_FONT_SMOOTHING?.toLowerCase() === 'yes'
config['enable-full-window-drag'] =
nicWithRdp?.RDP_ENABLE_FULL_WINDOW_DRAG?.toLowerCase() === 'yes'
config['enable-desktop-composition'] =
nicWithRdp?.RDP_ENABLE_DESKTOP_COMPOSITION?.toLowerCase() === 'yes'
config['enable-menu-animations'] =
nicWithRdp?.RDP_ENABLE_MENU_ANIMATIONS?.toLowerCase() === 'yes'
config['disable-bitmap-caching'] =
nicWithRdp?.RDP_DISABLE_BITMAP_CACHING?.toLowerCase() === 'yes'
config['disable-offscreen-caching'] =
nicWithRdp?.RDP_DISABLE_OFFSCREEN_CACHING?.toLowerCase() === 'yes'
config['disable-glyph-caching'] =
nicWithRdp?.RDP_DISABLE_GLYPH_CACHING?.toLowerCase() === 'yes'
if (config.username && config.password) config.security = 'nla'

View File

@ -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")) {
@ -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;
@ -305,7 +302,6 @@ define(function(require) {
}
delete templateJSON["USER_INPUTS"];
delete templateJSON["INPUTS_ORDER"];
}
if (contextJSON) {

View File

@ -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();
var trcontext = $(".user_input_attrs tbody tr", context).last();
$(".user_input_name", trcontext).val(key);
$(".user_input_name", trcontext).val(key);
var attr = _unmarshall(value);
var attr = _unmarshall(value);
if (templateJSON[key] != undefined){
attr.initial = templateJSON[key];
if (templateJSON[key] != undefined){
attr.initial = templateJSON[key];
}
$(".user_input_type", trcontext).val(attr.type).change();
$(".user_input_description", trcontext).val(attr.description);
if (attr.mandatory){
$(".user_input_mandatory", trcontext).attr("checked", "checked");
} else {
$(".user_input_mandatory", trcontext).removeAttr("checked");
}
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");
}
$(".user_input_type", trcontext).val(attr.type).change();
$(".user_input_description", trcontext).val(attr.description);
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 (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"
$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);
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+"\"");
}
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;
}
}
});
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;
}
});
}
}
@ -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