From 47729370032473c39d9ee3ef9745485b7fea2f9f Mon Sep 17 00:00:00 2001 From: "j.goderbauer" <j.goderbauer@adito.de> Date: Fri, 31 Aug 2018 15:03:34 +0200 Subject: [PATCH] added more keyword-lib-functions --- process/Keyword_lib/process.js | 61 ++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/process/Keyword_lib/process.js b/process/Keyword_lib/process.js index f5a0424067..d2006f201b 100644 --- a/process/Keyword_lib/process.js +++ b/process/Keyword_lib/process.js @@ -2,21 +2,17 @@ import("system.logging"); import("system.translate"); function KeywordUtils(){ - - this.getViewValue = function(keywordType, key){ - var keyword = this.getStandardArray(keywordType); - for(var i = 0; i < keyword.length; i++) - if(keyword[i][0] == key) - return keyword[i][1]; - return ""; - } - this.getStandardArray = function(keywordType){ return this.createKeyword(keywordType).toArray(); } + this.getViewValue = function(keywordType, key){ + var k = this.createKeyword(keywordType); + return k.getPropForKey(key, "name") || ""; + } + this.createKeyword = function(keywordType){ - var valueContainer, _toArrayFn; + var valueContainer, _toArrayFn, _getPropForKeyFn, _getPropsForKeyFn; switch (keywordType){ case "RELATION.STATUS": @@ -97,24 +93,43 @@ function KeywordUtils(){ break; } + + _getPropForKeyFn = function(key, field) { + var keyObject = valueContainer[key]; + if (keyObject == undefined) + return undefined; + return keyObject[field]; + } + + _getPropsForKeyFn = function(key, fields) { + var keyObject, i, l, currentRow, currentField; + + keyObject = valueContainer[key]; + if (keyObject == undefined) + return [];//TODO: throw error instead? + l = fields.length; + currentRow = []; + for (i = 0; i < l; i++){ + currentField = fields[i]; + //check if the passed fieldnames match the existing fieldnames (<=> properties in the object) + //to prevent errors and unexpected behaviour + if (keyObject[currentField]) + currentRow.push(keyObject[currentField]); + else + currentRow.push(""); + } + return currentRow; + } + _toArrayFn = function(fields){ - var res, id, i, l, currentRow, currentField; + var res, id, currentRow; res = []; if (!fields) fields = ["id", "name"]; l = fields.length; for (id in valueContainer){ - currentRow = []; - for (i = 0; i < l; i++){ - currentField = fields[i]; - //check if the passed fieldnames match the existing fieldnames (<=> properties in the object) - //to prevent errors and unexpected behaviour - if (valueContainer[id][currentField]) - currentRow.push(valueContainer[id][currentField]); - else - currentRow.push(""); - } + currentRow = _getPropsForKeyFn(id, fields); res.push(currentRow); } return res; @@ -124,7 +139,9 @@ function KeywordUtils(){ /* *test **/ - "toArray": _toArrayFn + "toArray": _toArrayFn + ,"getPropForKey": _getPropForKeyFn + ,"getPropsForKey": _getPropsForKeyFn } } -- GitLab