From aed341e98f2fc6dd907fde0b378c53b38d6efa92 Mon Sep 17 00:00:00 2001 From: Sebastian Listl <s.listl@adito.de> Date: Wed, 25 Aug 2021 16:13:48 +0200 Subject: [PATCH] 1083847 workflow notifications translation --- .../recordcontainers/jdito/contentProcess.js | 10 ++--- .../process.js | 45 ++++++++++++------- .../serviceTaskParameterProcess.js | 3 +- process/Employee_lib/process.js | 12 +++++ 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/entity/WorkflowDefinition_entity/recordcontainers/jdito/contentProcess.js b/entity/WorkflowDefinition_entity/recordcontainers/jdito/contentProcess.js index 115f011a72..d3c9e9c8c0 100644 --- a/entity/WorkflowDefinition_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/WorkflowDefinition_entity/recordcontainers/jdito/contentProcess.js @@ -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 diff --git a/process/CreateNotification_workflowService/process.js b/process/CreateNotification_workflowService/process.js index 52b6f6fa9f..65d5e32a41 100644 --- a/process/CreateNotification_workflowService/process.js +++ b/process/CreateNotification_workflowService/process.js @@ -1,39 +1,54 @@ +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); diff --git a/process/CreateNotification_workflowService/serviceTaskParameterProcess.js b/process/CreateNotification_workflowService/serviceTaskParameterProcess.js index fa7063a63b..3c5840a32f 100644 --- a/process/CreateNotification_workflowService/serviceTaskParameterProcess.js +++ b/process/CreateNotification_workflowService/serviceTaskParameterProcess.js @@ -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 diff --git a/process/Employee_lib/process.js b/process/Employee_lib/process.js index 68230ad249..5bd0f62bc0 100644 --- a/process/Employee_lib/process.js +++ b/process/Employee_lib/process.js @@ -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 * -- GitLab