/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| BI and PM: prmt *| (C) Copyright IBM Corp. 2002, 2014 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ /** @fileOverview Parameter Values (interface). */ /** @name cognos.Value @class JSON structure to represent parameter values.
Possible arributes for this object are children, display, end, inclusive, start and use.
inclusive is always optional, default is true.
Examples: */ cognos.Value = function( v_oProps ) { if (v_oProps instanceof cognos.Value) { return v_oProps; } if (typeof v_oProps == "string") { return v_oProps; } if (v_oProps && v_oProps.length) { var a = []; for (var i = 0; i < v_oProps.length; i++) { var v_oVal = new cognos.Value(v_oProps[i]); if ( v_oVal instanceof cognos.Value ) { a.push( v_oVal ); } } return a; } if ( v_oProps && v_oProps.n ) { if ( v_oProps.n == "selectChoices" && v_oProps.c && v_oProps.c.length > 0 ) { this.f_initWithSelectOptions( v_oProps.c[0] ); } else { this.f_initWithSelectOptions( v_oProps ); } } else { Object.f_extend( this, v_oProps ); } }; /** @static @private @return {boolean} */ cognos.Value.equals = function(v1, v2) { var v_bRetval = false; var v_oVa1 = cognos.Value.getValue(v1); if (v_oVa1) { var v_oVa2 = cognos.Value.getValue(v2); if (v_oVa2) { v_bRetval = v_oVa1.f_equals(v_oVa2); } } return v_bRetval; } /** Cast a {use:'',display:''} object to a cognos.Value object. @private @param {cognos.Value} v_oObj object to cast. @return {cognos.Value} */ cognos.Value.getValue = function( v_oObj ) { var v_oVal = null; if (v_oObj) { if ( v_oObj instanceof cognos.Value || typeof v_oObj == "string") { v_oVal = v_oObj; } else if (v_oObj && v_oObj.length) { v_oVal = []; for (var i = 0; i < v_oObj.length; i++) { var v_oTemp = cognos.Value.getValue(v_oObj[i]); if (v_oTemp) { v_oVal.push( v_oTemp ); } } if (v_oVal.length == 0) { v_oVal = null; } else if (v_oVal.length == 1) { v_oVal = v_oVal[0]; } } else { v_oVal = new cognos.Value(v_oObj); } } return v_oVal; } /** @private @return {void} */ cognos.Value.prototype.f_initWithSelectOptions = function( v_oNode ) { switch( v_oNode.n ) { case "selectBoundRange": case "selectUnboundedEndRange": case "selectUnboundedStartRange": if ( v_oNode.c && v_oNode.c.length > 0 ) { var v_bSelected = ( v_oNode["@selected"] ? true : false ); for ( var v_idxChild = 0; v_idxChild < v_oNode.c.length; v_idxChild++) { var v_oChildNode = v_oNode.c[ v_idxChild ]; var v_oPV = cognos.Value.getValue( v_oChildNode ); v_oPV["use"] = sDecodeU003( v_oChildNode["@useValue"] ); v_oPV["display"] = sDecodeU003( v_oChildNode["@displayValue"] ); this[ v_oChildNode.n ] = v_oPV; } } break; default: Object.f_extend( this, v_oNode ); this["use"] = sDecodeU003( v_oNode["@useValue"] ); this["display"] = sDecodeU003( v_oNode["@displayValue"] ); break; } }; /** @private @return {boolean} */ cognos.Value.prototype.f_equals = function(v_o) { return ( v_o ? (this.f_getXML() == v_o.f_getXML()) : false ); }; /** Used by range control with multiple choices, to format the values selected as "Between x and y." @private @return {String} */ cognos.Value.prototype.f_formatDisplay = function( v_sKey, v_sValue1, v_sValue2 ) { var v_sRetVal = null; var v_sBidiMarker = null; if ( typeof v_sKey == K_PRMT_sSTRING ) { if ( v_sKey == "between" && (v_sValue1 === null || typeof v_sValue1 == K_PRMT_sUNDEFINED || v_sValue2 === null || typeof v_sValue2 == K_PRMT_sUNDEFINED) ) { v_sValue1 = v_sValue2 = null; } if ( v_sValue1 !== null && typeof v_sValue1 !== K_PRMT_sUNDEFINED ) { var v_re1 = new RegExp( "\\^1", K_PRMT_sG); var v_sValKey = this.f_getString( v_sKey ); if (this.contentTextDir) { v_sValue1 = PRMT_BidiUtils.enforceBidiDirection(v_sValue1, this.contentTextDir); v_sBidiMarker = (PRMT_BidiUtils.containsRTLChar(v_sValKey) ? PRMT_BidiUtils.BIDI_CHAR_RLM : PRMT_BidiUtils.BIDI_CHAR_LRM); v_sValue1 = v_sBidiMarker + v_sValue1; } v_sRetVal = v_sValKey.replace( v_re1, v_sValue1 ); } if ( v_sValue2 !== null && typeof v_sValue2 !== K_PRMT_sUNDEFINED && typeof v_sRetVal == K_PRMT_sSTRING ) { var v_re2 = new RegExp( "\\^2", K_PRMT_sG); if (this.contentTextDir) { v_sValue2 = PRMT_BidiUtils.enforceBidiDirection(v_sValue2, this.contentTextDir); v_sValue2 = v_sBidiMarker + v_sValue2; } v_sRetVal = v_sRetVal.replace( v_re2, v_sValue2 ); } if ( v_sRetVal && v_sBidiMarker ) { v_sRetVal = (v_sBidiMarker == PRMT_BidiUtils.BIDI_CHAR_LRM ? PRMT_BidiUtils.BIDI_CHAR_LRE : PRMT_BidiUtils.BIDI_CHAR_RLE) + v_sRetVal + PRMT_BidiUtils.BIDI_CHAR_PDF; } } return v_sRetVal; }; /** @private @return {String} */ cognos.Value.prototype.getDisplayValue = function() { return (this.f_getDisplay()); }; /** @private @return {String} */ cognos.Value.prototype.f_getDisplay = function( v_bReturnNullForMissingDisplayValues ) { var v_sDisplay = null; if ( this.display || this.display == K_PRMT_sEMPTY ) { v_sDisplay = this.display; } else { var v_pvStart = this.f_getStart(); var v_pvEnd = this.f_getEnd(); var v_sKey = null; var v_sValue1 = null; var v_sValue2 = null; if ( v_pvStart ) { v_sValue1 = v_pvStart.f_getDisplay( v_bReturnNullForMissingDisplayValues ); if ( v_pvEnd ) { v_sKey = ( v_pvStart.f_equals( v_pvEnd ) ? "eq" : "between" ); v_sValue2 = v_pvEnd.f_getDisplay( v_bReturnNullForMissingDisplayValues ); } else { v_sKey = "gt"; } } else if ( v_pvEnd ) { v_sKey = "lt"; v_sValue1 = v_pvEnd.f_getDisplay( v_bReturnNullForMissingDisplayValues ); } v_sDisplay = this.f_formatDisplay( v_sKey, v_sValue1, v_sValue2 ); } if ( v_sDisplay === null && !v_bReturnNullForMissingDisplayValues ) { v_sDisplay = this.f_getUse(); } return v_sDisplay; }; /** @private @return {String} */ cognos.Value.prototype.f_getString = function( v_sKey ) { var v_s = v_sKey; switch( v_sKey ) { case 'eq': v_s = PMT_RNG_FILTER_EQUAL_STRING; break; break; case 'between': switch (this.promptType) { case "cognos.Prompt.Control.Date": case "cognos.Prompt.Control.SelectHTML5Date": v_s = PMT_RNG_FILTER_BETWEEN_DATE; break; case "cognos.Prompt.Control.DateTime": case "cognos.Prompt.Control.SelectHTML5DateTime": v_s = PMT_RNG_FILTER_BETWEEN_DATETIME; break; case "cognos.Prompt.Control.Time": case "cognos.Prompt.Control.SelectHTML5Time": v_s = PMT_RNG_FILTER_BETWEEN_TIME; break; case "cognos.Prompt.Control.Interval": v_s = PMT_RNG_FILTER_BETWEEN_INTERVAL; break; default: v_s = PMT_RNG_FILTER_BETWEEN_STRING; break; }; break; case 'lt': switch (this.promptType) { case "cognos.Prompt.Control.Date": case "cognos.Prompt.Control.SelectHTML5Date": v_s = PMT_RNG_FILTER_LESS_THAN_EQUAL_TO_DATE; break; case "cognos.Prompt.Control.DateTime": case "cognos.Prompt.Control.SelectHTML5DateTime": v_s = PMT_RNG_FILTER_LESS_THAN_EQUAL_TO_DATETIME; break; case "cognos.Prompt.Control.Time": case "cognos.Prompt.Control.SelectHTML5Time": v_s = PMT_RNG_FILTER_LESS_THAN_EQUAL_TO_TIME; break; case "cognos.Prompt.Control.Interval": v_s = PMT_RNG_FILTER_LESS_THAN_EQUAL_TO_INTERVAL; break; default: v_s = PMT_RNG_FILTER_LESS_THAN_EQUAL_TO_STRING; break; }; break; case 'gt': switch (this.promptType) { case "cognos.Prompt.Control.Date": case "cognos.Prompt.Control.SelectHTML5Date": v_s = PMT_RNG_FILTER_GREATER_THAN_EQUAL_TO_DATE; break; case "cognos.Prompt.Control.DateTime": case "cognos.Prompt.Control.SelectHTML5DateTime": v_s = PMT_RNG_FILTER_GREATER_THAN_EQUAL_TO_DATETIME; break; case "cognos.Prompt.Control.Time": case "cognos.Prompt.Control.SelectHTML5Time": v_s = PMT_RNG_FILTER_GREATER_THAN_EQUAL_TO_TIME; break; case "cognos.Prompt.Control.Interval": v_s = PMT_RNG_FILTER_GREATER_THAN_EQUAL_TO_INTERVAL; break; default: v_s = PMT_RNG_FILTER_GREATER_THAN_EQUAL_TO_STRING; break; }; break; }; return v_s; }; /** @private @return {String} */ cognos.Value.prototype.f_getXML = function() { var v_sXML = K_PRMT_sEMPTY; if ( this.f_isRange() ) { var v_pvStart = this.f_getStart(); var v_pvEnd = this.f_getEnd(); if ( v_pvStart && v_pvEnd ) { if ( v_pvStart.f_equals(v_pvEnd) ) { v_sXML = this.f_getAsXMLElement("selectOption"); } else { v_sXML = '' + v_pvStart.f_getAsXMLElement( "start" ) + v_pvEnd.f_getAsXMLElement( "end" ) + ''; } } else if ( v_pvStart ) { v_sXML= '' + v_pvStart.f_getAsXMLElement( "start" ) + ''; } else if ( v_pvEnd ) { v_sXML= '' + v_pvEnd.f_getAsXMLElement( "end" ) + ''; } } else { v_sXML = this.f_getAsXMLElement("selectOption"); } return v_sXML; }; /** @private @return {void} */ cognos.Value.prototype.f_getAsXMLElement = function( v_sTag ) { var v_sXML = K_PRMT_sEMPTY; // create element only if use & display are NOT both empty var v_sUse = this.f_getUse(); var v_sDisplay = this.f_getDisplay( true ); if ( this.f_isNull() ) { v_sXML = ' nullUse="1"'; if ( this.display ) { v_sXML += ' displayValue="' + v_sDisplay.f_xmlSafe() + '"'; } else { v_sXML += ' nullDisplay="1"'; } } else { //Set the use value if it is not undefined if ( (typeof v_sUse) !== K_PRMT_sUNDEFINED ) { if( v_sUse || v_sUse == K_PRMT_sEMPTY ) { v_sXML += ' useValue="' + v_sUse.f_xmlSafe() + '"'; } } //Set the display value if it exists, or set it equal to the use value if it doesn't if ( v_sDisplay || v_sDisplay == K_PRMT_sEMPTY ) { v_sXML += ' displayValue="' + v_sDisplay.f_xmlSafe() + '"'; } } if ( v_sXML !== K_PRMT_sEMPTY ) { v_sXML = K_PRMT_sLT + v_sTag + v_sXML + K_PRMT_sSL + K_PRMT_sGT; } return v_sXML; }; /** @private @return {String} */ cognos.Value.prototype.getUseValue = function() { return (this.f_getUse()); }; /** @private @return {String} */ cognos.Value.prototype.f_getUse = function() { var v_sUse = null; if ( this['use'] || this['use'] == K_PRMT_sEMPTY) { v_sUse = (K_PRMT_sEMPTY + this['use']); } else { var v_pvStart = this.f_getStart(); var v_pvEnd = this.f_getEnd(); if ( v_pvStart || v_pvEnd ) { if ( v_pvStart ) { v_sUse = v_pvStart.f_getUse(); } if ( !v_pvStart || !v_pvStart.f_equals(v_pvEnd)) { v_sUse += K_PRMT_sCOLON; if ( v_pvEnd ) { v_sUse += v_pvEnd.f_getUse(); } } } } if ( v_sUse !== K_PRMT_sEMPTY ) { this['use'] = v_sUse; } return v_sUse; }; /** @private @return {cognos.Value} */ cognos.Value.prototype.f_getEnd = function() { return cognos.Value.getValue( this['end'] ); }; /** @private @return {cognos.Value} */ cognos.Value.prototype.f_getStart = function() { return cognos.Value.getValue( this['start'] ); }; /** @private @return {boolean} */ cognos.Value.prototype.f_isNull = function() { return ( this['nil'] === true ); }; /** @private @return {boolean} */ cognos.Value.prototype.f_isRange = function() { return ( this['start'] || this['end'] ? true : false); }; /** Transform an object to a JSON string. Used by C_Choices to keep the original value as a string in