Skip to content
Snippets Groups Projects
Commit 47729370 authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

added more keyword-lib-functions

parent 7be5aa98
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
}
......
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