Skip to content
Snippets Groups Projects
Commit a0a9a4bd authored by Martin Groppe's avatar Martin Groppe
Browse files

Merge branch '1083847_workflowTranslation' into '2021.1'

1083847 workflow notifications translation

See merge request xrm/basic!1237
parents 44a35114 aed341e9
No related branches found
No related tags found
No related merge requests found
......@@ -60,14 +60,10 @@ result.object((function ()
];
});
var possibleKeysMap = null;
var possibleKeys = null;
if (context)
{
possibleKeysMap = {};
WorkflowUtils.getPossibleWorkflowDefinitions(context).forEach(function (key)
{
this[key] = true;
}, possibleKeysMap);
possibleKeys = new Set(WorkflowUtils.getPossibleWorkflowDefinitions(context));
}
var filterFn;
......@@ -77,7 +73,7 @@ result.object((function ()
{
filterFn = function (currDef)
{
return newestVersions[currDef[4]] == currDef[5] && (possibleKeysMap ? possibleKeysMap[currDef[4]] : true);
return newestVersions[currDef[4]] == currDef[5] && (!possibleKeys || possibleKeys.has(currDef[4]));
};
}
else
......
import("system.translate");
import("Employee_lib");
import("KeywordRegistry_basic");
import("system.text");
import("system.vars");
import("system.notification");
var variables = JSON.parse(vars.get("$local.value"));
var caption = variables.notificationCaption || "";
var description = variables.notificationDescription || "";
var userIds;
try
{
userIds = JSON.parse(variables.notificationUser);
}
catch (e) // Throw an exeption when the variable can't parse to an JSON-Object.
{
userIds = [variables.notificationUser || variables.USER_ID];
}
if (!variables.skipTranslation && userIds.length === 1)
{
var userLocale = EmployeeUtils.getUserLocale(userIds[0]);
caption = translate.text(caption, userLocale);
description = translate.text(description, userLocale);
}
var config = notification.createConfig()
.notificationType(variables.notificationType || "WorkflowNotification")
.caption(variables.notificationCaption || "")
.description(variables.notificationDescription || "");
.caption(caption)
.description(description)
.addUsersWithIds(userIds);
try {
config.addUsersWithIds(JSON.parse(variables.notificationUser));
} catch (e) { // Throw an exeption when the variable can't parse to an JSON-Object.
config.addUsersWithIds([variables.notificationUser || variables.USER_ID])
}
var prio;
switch (variables.notificationPriority){
case $KeywordRegistry.notificationPriority$none:
prio = notification.PRIO_NONE
switch (variables.notificationPriority)
{
case $KeywordRegistry.notificationPriority$none():
prio = notification.PRIO_NONE;
break;
case $KeywordRegistry.notificationPriority$low():
prio = notification.PRIO_LOW
prio = notification.PRIO_LOW;
break;
case $KeywordRegistry.notificationPriority$hight():
prio = notification.PRIO_HIGH
prio = notification.PRIO_HIGH;
break;
case $KeywordRegistry.notificationPriority$max():
prio = notification.PRIO_MAX
prio = notification.PRIO_MAX;
break;
case $KeywordRegistry.notificationPriority$normal():
default:
prio = notification.PRIO_NORMAL
break;
prio = notification.PRIO_NORMAL;
}
config.forcedPriority(prio);
......
......@@ -21,5 +21,6 @@ users = users.map(function (user)
result.object([
new WorkflowServiceTaskParameter("notificationCaption", "Caption", WorkflowServiceTaskParameter.STRING()),
new WorkflowServiceTaskParameter("notificationDescription", "Description", WorkflowServiceTaskParameter.STRING()),
new WorkflowServiceTaskParameter("notificationUser", "User", WorkflowServiceTaskParameter.ENUM(), users)
new WorkflowServiceTaskParameter("notificationUser", "User", WorkflowServiceTaskParameter.ENUM(), users),
new WorkflowServiceTaskParameter("skipTranslation", "Skip translation", WorkflowServiceTaskParameter.BOOLEAN())
]);
\ No newline at end of file
......@@ -177,6 +177,18 @@ EmployeeUtils.getUsersDepartment = function(pContactId, pDepartmentAsDisplayable
return department;
}
/**
* Gets the locale of the specified user. This is the locale from the users last log in.
*
* @param {String} pUserId user id
* @return {String} locale of the user, can be null if the user doesn't exist or has never logged in before
*/
EmployeeUtils.getUserLocale = function (pUserId)
{
var user = tools.getUserByAttribute(tools.NAME, pUserId, tools.PROFILE_DEFAULT);
return user && user[tools.PARAMS][tools.LOCALE] || null;
}
/**
* Provides functions for employeesrole
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment