<@script name="EnumMgr" also="Fields" hide="y"> Implements the %STUDIO% enumerations manager (c) SAP AG 2003-2006. All rights reserved. ////////////////////////////////////////////////////////////////////////////////////// // FUNCTIONS <@func name="EXISTS_ENUM"> Tests whether a specified enumeration exists in the global enumerations manager The enumeration id The test results function EXISTS_ENUM(enumID) { return (UPPER(enumID) in __ENUMS); } <@func name="GET_ENUM" also="GET_ENUM_ITEM SET_ENUM"> Gets a specified enumeration object The enumeration id An expression returning a valid enumeration object (prefix the expression with @ symbol) The requested enumeration object function GET_ENUM(enumID) { if (enumID && enumID.charAt(0) == '@') { try { return eval(enumID.substring(1)); } catch (e) { return {}; } } else { return __ENUMS[UPPER(enumID)] || {}; } } <@func name="SET_ENUM" also="SET_ENUM_ITEM GET_ENUM"> Sets a specified enumeration object The enumeration id The enumeration object function SET_ENUM(enumID, enumData) { __ENUMS[UPPER(enumID)] = enumData || {}; } <@func name="GET_ENUMS" also="SET_ENUMS"> Gets the collection of all enumerations The enumerations collection function GET_ENUMS() { return __ENUMS || {}; } <@func name="SET_ENUMS" also="SET_ENUM"> Sets a given collection of enumerations The new enumerations collection function SET_ENUMS(enumsList) { if (!__ENUMS) __ENUMS = {}; for (var k in enumsList) __ENUMS[k] = enumsList[k]; } <@func name="RESET_ENUMS" also="SET_ENUMS"> Clears the collection of all enumerations function RESET_ENUMS() { __ENUMS = {}; } <@func name="GET_ENUM_ITEM" also="SET_ENUM_ITEM GET_ENUM"> Gets a specified enumeration item The enumeration id The enumeration item value The enumeration item text function GET_ENUM_ITEM(enumID, value) { var en=GET_ENUM(enumID); return en ? (en[value] || '') : ''; } <@func name="SET_ENUM_ITEM" also="GET_ENUM_ITEM SET_ENUM"> Sets a specified enumeration item The enumeration id The enumeration item value The enumeration item text function SET_ENUM_ITEM(enumID, value, text) { var en=GET_ENUM(enumID); if (en) en[value] = text; } <@func name="GET_ENUM_VALUES" also="GET_ENUM_TEXTS"> Gets the ordered list of all values in a given enumeration The enumeration object The enumeration values function GET_ENUM_VALUES(data) { var A=[]; if (!data || !data.$ORDER) return A; for (var i=0, O=data.$ORDER, len=O.length; i Gets the ordered list of all texts in a given enumeration The enumeration object The enumeration texts function GET_ENUM_TEXTS(data) { var A=[]; if (!data || !data.$ORDER) return A; for (var i=0, O=data.$ORDER, len=O.length; i Append an item to enumeration object The enumeration object The new item value The new item text If an item with this value exists - nothing is done function ENUM_APPEND(enumData, value, text) { if (!enumData || !enumData.$ORDER || enumData[value] !== undefined) return; enumData[value] = text; enumData.$ORDER.push(value); } <@func name="ENUM2STR" also="STR2ENUM ENUM2ARR ARR2ENUM"> Converts an enumeration to string representation The enumeration object The string representation of the requested enumeration function ENUM2STR(enumData) { if (!enumData || !enumData.$ORDER) return ''; var A=[]; for (var i=0, O=enumData.$ORDER, len=O.length; i Converts a string to an enumeration The string representation of the enumeration function STR2ENUM(enumStr) { var data={$ORDER:[]}; for (var i=0, A=(enumStr||'').split(';'), len=A.length; i Converts an enumeration to an array The enumeration object The array representation of the requested enumeration function ENUM2ARR(enumData) { var A=[]; if (!enumData || !enumData.$ORDER) return A; for (var i=0, O=enumData.$ORDER, len=O.length; i Converts an array to an enumeration The array representation of the enumeration function ARR2ENUM(enumArr) { var data={$ORDER:[]}; for (var i=0, len=enumArr.length; i Allocates and returns a new enumeration id The new enumeration id function ALLOC_ENUM() { return '$'+(__ENUMS_ALLOC++); } function REMOVE_ENUM(enumId){ delete __ENUMS[enumId]; } /////////////////////////////////////////////////////////////////////////////////////////////////// // INTERNAL var __ENUMS = {}; var __ENUMS_ALLOC = 0;