2021-04-01 16:51:28 +02:00
|
|
|
|
<script>const _=
|
2021-11-01 22:15:56 +01:00
|
|
|
|
<#macro objectToJson_please_ignore_errors object depth>
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<@compress>
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local isHash = false>
|
|
|
|
|
<#attempt>
|
|
|
|
|
<#local isHash = object?is_hash || object?is_hash_ex>
|
|
|
|
|
<#recover>
|
|
|
|
|
/* can't evaluate if object is hash */
|
|
|
|
|
undefined
|
|
|
|
|
<#return>
|
|
|
|
|
</#attempt>
|
|
|
|
|
<#if isHash>
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local keys = "">
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-04-01 23:42:31 +02:00
|
|
|
|
<#attempt>
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local keys = object?keys>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
<#recover>
|
2021-06-22 12:37:21 +02:00
|
|
|
|
/* can't list keys of object */
|
|
|
|
|
undefined
|
|
|
|
|
<#return>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
</#attempt>
|
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
{${'\n'}
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#list keys as key>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#if key == "class">
|
|
|
|
|
/* skipping "class" property of object */
|
|
|
|
|
<#continue>
|
|
|
|
|
</#if>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local value = "">
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#attempt>
|
|
|
|
|
<#local value = object[key]>
|
|
|
|
|
<#recover>
|
|
|
|
|
/* couldn't dereference ${key} of object */
|
|
|
|
|
<#continue>
|
|
|
|
|
</#attempt>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-10-18 14:50:04 +02:00
|
|
|
|
<#if depth gt 7>
|
2021-06-22 12:37:21 +02:00
|
|
|
|
/* Avoid calling recustively too many times depth: ${depth}, key: ${key} */
|
|
|
|
|
<#continue>
|
|
|
|
|
</#if>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-11-01 22:15:56 +01:00
|
|
|
|
"${key}": <@objectToJson_please_ignore_errors object=value depth=depth+1/>,
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
</#list>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
}${'\n'}
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#return>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
</#if>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local isMethod = "">
|
2021-04-01 23:42:31 +02:00
|
|
|
|
<#attempt>
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local isMethod = object?is_method>
|
|
|
|
|
<#recover>
|
|
|
|
|
/* can't test if object is a method */
|
|
|
|
|
undefined
|
|
|
|
|
<#return>
|
|
|
|
|
</#attempt>
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#if isMethod>
|
|
|
|
|
undefined
|
|
|
|
|
<#return>
|
|
|
|
|
</#if>
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local isBoolean = "">
|
|
|
|
|
<#attempt>
|
|
|
|
|
<#local isBoolean = object?is_boolean>
|
|
|
|
|
<#recover>
|
|
|
|
|
/* can't test if object is a boolean */
|
|
|
|
|
undefined
|
|
|
|
|
<#return>
|
|
|
|
|
</#attempt>
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#if isBoolean>
|
|
|
|
|
${object?c}
|
|
|
|
|
<#return>
|
|
|
|
|
</#if>
|
2021-04-01 17:15:28 +02:00
|
|
|
|
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#local isEnumerable = "">
|
|
|
|
|
<#attempt>
|
|
|
|
|
<#local isEnumerable = object?is_enumerable>
|
|
|
|
|
<#recover>
|
|
|
|
|
/* can't test if object is enumerable */
|
|
|
|
|
undefined
|
|
|
|
|
<#return>
|
|
|
|
|
</#attempt>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#if isEnumerable>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
[${'\n'}
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#list object as item>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-11-01 22:15:56 +01:00
|
|
|
|
<@objectToJson_please_ignore_errors object=item depth=depth+1/>,
|
2021-04-01 17:15:28 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
</#list>
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
]${'\n'}
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#return>
|
|
|
|
|
</#if>
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
|
|
|
|
|
2021-04-01 23:42:31 +02:00
|
|
|
|
<#attempt>
|
2021-06-30 22:01:01 +02:00
|
|
|
|
"${object?replace('"', '\\"')?no_esc}"
|
2021-06-22 12:37:21 +02:00
|
|
|
|
<#recover>
|
|
|
|
|
/* couldn't convert into string non hash, non method, non boolean, non enumerable object */
|
|
|
|
|
undefined;
|
|
|
|
|
<#return>
|
|
|
|
|
</#attempt>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
</@compress>
|
|
|
|
|
</#macro>
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-06-22 12:37:21 +02:00
|
|
|
|
(()=>{
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-10-11 13:46:47 +02:00
|
|
|
|
const nonAutomaticallyConvertible = {
|
|
|
|
|
"messagesPerField": {
|
2021-04-01 17:15:28 +02:00
|
|
|
|
|
2021-10-11 13:46:47 +02:00
|
|
|
|
<#assign fieldNames = ["global", "userLabel", "username", "email", "firstName", "lastName", "password", "password-confirm"]>
|
2021-10-11 03:25:02 +02:00
|
|
|
|
|
2021-10-11 13:46:47 +02:00
|
|
|
|
<#attempt>
|
|
|
|
|
<#list profile.attributes as attribute>
|
|
|
|
|
<#assign fieldNames += [attribute.name]>
|
|
|
|
|
</#list>
|
|
|
|
|
<#recover>
|
|
|
|
|
</#attempt>
|
2021-10-11 03:25:02 +02:00
|
|
|
|
|
2021-10-11 13:46:47 +02:00
|
|
|
|
"printIfExists": function (fieldName, x) {
|
|
|
|
|
<#list fieldNames as fieldName>
|
|
|
|
|
if(fieldName === "${fieldName}" ){
|
|
|
|
|
<#attempt>
|
|
|
|
|
return "${messagesPerField.printIfExists(fieldName,'1')}" ? x : undefined;
|
|
|
|
|
<#recover>
|
|
|
|
|
</#attempt>
|
|
|
|
|
}
|
|
|
|
|
</#list>
|
|
|
|
|
throw new Error("There is no " + fieldName + " field");
|
2021-06-22 12:37:21 +02:00
|
|
|
|
},
|
2021-10-11 13:46:47 +02:00
|
|
|
|
"existsError": function (fieldName) {
|
|
|
|
|
<#list fieldNames as fieldName>
|
|
|
|
|
if(fieldName === "${fieldName}" ){
|
|
|
|
|
<#attempt>
|
|
|
|
|
return <#if messagesPerField.existsError('${fieldName}')>true<#else>false</#if>;
|
|
|
|
|
<#recover>
|
|
|
|
|
</#attempt>
|
|
|
|
|
}
|
|
|
|
|
</#list>
|
|
|
|
|
throw new Error("There is no " + fieldName + " field");
|
|
|
|
|
},
|
|
|
|
|
"get": function (fieldName) {
|
|
|
|
|
<#list fieldNames as fieldName>
|
|
|
|
|
if(fieldName === "${fieldName}" ){
|
|
|
|
|
<#attempt>
|
|
|
|
|
<#if messagesPerField.existsError('${fieldName}')>
|
|
|
|
|
return "${messagesPerField.get('${fieldName}')?no_esc}";
|
|
|
|
|
</#if>
|
|
|
|
|
<#recover>
|
|
|
|
|
</#attempt>
|
|
|
|
|
}
|
|
|
|
|
</#list>
|
|
|
|
|
throw new Error("There is no " + fieldName + " field");
|
|
|
|
|
},
|
|
|
|
|
"exists": function (fieldName) {
|
|
|
|
|
<#list fieldNames as fieldName>
|
|
|
|
|
if(fieldName === "${fieldName}" ){
|
|
|
|
|
<#attempt>
|
|
|
|
|
return <#if messagesPerField.exists('${fieldName}')>true<#else>false</#if>;
|
|
|
|
|
<#recover>
|
|
|
|
|
</#attempt>
|
|
|
|
|
}
|
|
|
|
|
</#list>
|
|
|
|
|
throw new Error("There is no " + fieldName + " field");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"msg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); },
|
|
|
|
|
"advancedMsg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const out = {};
|
|
|
|
|
|
|
|
|
|
Object.deepAssign(
|
|
|
|
|
out,
|
|
|
|
|
//Removing all the undefined
|
2021-11-01 22:15:56 +01:00
|
|
|
|
JSON.parse(JSON.stringify(<@objectToJson_please_ignore_errors object=.data_model depth=0 />))
|
2021-06-22 12:37:21 +02:00
|
|
|
|
);
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-10-11 13:46:47 +02:00
|
|
|
|
Object.deepAssign(
|
|
|
|
|
out,
|
|
|
|
|
nonAutomaticallyConvertible
|
|
|
|
|
);
|
2021-04-01 23:42:31 +02:00
|
|
|
|
|
2021-10-11 13:46:47 +02:00
|
|
|
|
return out;
|
2021-04-01 16:51:28 +02:00
|
|
|
|
|
2021-10-11 13:46:47 +02:00
|
|
|
|
})()
|
2021-04-01 16:51:28 +02:00
|
|
|
|
</script>
|