| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 | /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| BI and PM: prmt *| (C) Copyright IBM Corp. 2002, 2022 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+*//**	This script is used to provide interactivity for the textBox prompt control	@private	@class*/cognos.Prompt.Control.Text = cognos.Prompt.Control.f_extend({	f_initialize: function( v_oProps ) {		this._type_ = "cognos.Prompt.Control.Text";		this.f_parent( v_oProps ); // call parent's initialize()		this.m_reMultiLineDelimiters = new RegExp("[\\n\\f\\r\\t]");		this.m_bIsCurrency = false;		// by default we allow zeros in the text areas		if ( this["@allowZero"] !== false )		{			this["@allowZero"] = true;		}		if ( !this["@dataType"] && this["@numbersOnly"] )		{			this["@dataType"] = "number";		}		if ( this["@showThousandSeparator"] && this["@showThousandSeparator"] !== false )		{			this["@showThousandSeparator"] = true;		}		this.m_sCurrentValue = ( this["@defaultValue"] ? sDecodeU003( this["@defaultValue"] ) : K_PRMT_sEMPTY );		//create regular expressions for parsing with current locale		initParsingRegularExpressions();		this.f_initCompleted();	},	//validate the input into the control	checkData: function()	{		// We keep a reference to the parent function		// Calling this.m_oFrom functions seems to have a side effect on this.f_parent().		var v_fnParent = this.f_parent;		this.checkRequired();		if ( this.isRequired() && !this.isMulti() && !(this.getValue()) )		{			this.m_bValid = false;		}		else		{			//determine whether this is a single value or multiple values			var v_aInsertText = this.m_oForm.value.split( this.m_reMultiLineDelimiters );			if (v_aInsertText.length > 1)			{				var bParseValid = true;				for (var i=0; i < v_aInsertText.length; i++)				{					var bTest = sParseByDataType( v_aInsertText[i], this["@dataType"] );					if (bTest === false)					{						bParseValid = false;					}				}				if (bParseValid == false)				{					this.m_bValid = false;				}				else				{					this.m_bValid = true;					this.m_sCurrentValue = this.m_oForm.value;					//set the form value for non-xml prompts					if (this["@submitType"] != K_PRMT_sXML && this.m_oSubmit)					{						this.m_oSubmit.value = this.m_sCurrentValue;					}				}			}			else			{				var sValue = this.bParse(this.m_oForm.value, this["@dataType"]);				if ( sValue === false && this.m_oForm.value != K_PRMT_sEMPTY )				{					this.m_bValid = false;				}				else				{					this.m_bValid = true;					//set the form value for non-xml prompts					if (this["@submitType"] != K_PRMT_sXML && this.m_oSubmit)					{						this.m_oSubmit.value = this.m_sCurrentValue;					}				}			}		}		this.f_parent = v_fnParent; // call parent's checkData using saved reference.		this.f_parent(); // call parent's checkData using saved reference.		return this.m_bValid;	},	clearValues: function() {		this.f_parent();		this.f_clear();	},	f_drawCompleted: function()	{		v_InputId = this.f_getId(K_PRMT_sTB_PREFIX);		var v_oInput = $( v_InputId );		v_oInput.m_oPrompt = this;		// link a11y label if it exists using FOR		var v_a11yLabel = $( this.f_getId("PRMT_LBL_") );		if ( v_a11yLabel && !v_a11yLabel.getAttribute("for")) {			v_a11yLabel.setAttribute("for", v_InputId);		}		PRMTUtils.f_addEvent( v_oInput, "keyup", this.f_keyUp.bind(this) );		PRMTUtils.f_addEvent( v_oInput, "keypress", this.f_keyPress.bind(this) );		PRMTUtils.f_addEvent( v_oInput, "blur", this.f_endCheckDataInterval.bind(this) );		PRMTUtils.f_addEvent( v_oInput, "contextmenu", this.f_startCheckDataInterval.bind(this) );		this.m_elPrompt = this.m_oForm = v_oInput;		this.f_parent(); // call parent's f_drawCompleted		this.f_lostFocus();		// Bidi text style		if ( G_IsBidiEnabled && this["@contentTextDirection"] && !this["@hideText"]) {			this.m_oForm.style.direction = PRMT_BidiUtils.getTextDirection(this.m_oForm.value, this["@contentTextDirection"]);		}	}});/**	Parse the current input and validate the data.	@private	@param {String} sValue	@param {String} sDataType	@return {boolean}*/cognos.Prompt.Control.Text.prototype.bParse = function(sValue, sDataType){	var sTestString = sParseByDataType(sValue, sDataType, this["@allowZero"]);	var v_bRetVal = true;	if (sTestString === false)	{		this.m_bIsCurrency = false;		v_bRetVal = false;	}	else	{		sTestString = sTestString.toString();		//persist currency character?		var z = sTestString.search(rCurrencySymbol);		this.m_bIsCurrency = (z != -1);		this.m_sCurrentValue = sTestString;	}	return v_bRetVal;};/**	Check if value has changed.	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.checkValueChange = function(){	if (this.m_oForm.value != this.m_sCurrentValue)	{		this.f_endCheckDataInterval();	}};/**	Remove all values from the prompt control.	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.f_clear = function(){	this.f_clearMemberValue("m_oSubmit");	this.m_oForm.value = K_PRMT_sEMPTY;	this.m_sCurrentValue = K_PRMT_sEMPTY;};cognos.Prompt.Control.Text.prototype.f_clearMemberValue = function(v_member){	if (!this[v_member]) {		this[v_member] = {};	}	this[v_member]["value"] = K_PRMT_sEMPTY;};/**	Compare values. See {@link cognos.Prompt.Control#f_compare} for details.	@see cognos.Prompt.Control#f_compare	@private	@return {Integer}*/cognos.Prompt.Control.Text.prototype.f_compare = function( v_oValue ){	var v_iRetval = 1;	if ( SYSTEMPROPERTY_REORDER_TEXT_VALUES_IN_RANGES === true && v_oValue )	{		var v_thisValue = null;		var v_compareTo = null;		if (this["@dataType"] == "number") 		{			v_thisValue = parseFloat(this.m_sCurrentValue);			v_compareTo = parseFloat(v_oValue.m_sCurrentValue);		}		else		{			v_thisValue = this.m_sCurrentValue;			v_compareTo = v_oValue.m_sCurrentValue;		}		if ( v_compareTo > v_thisValue )		{			v_iRetval = -1;		}		else if (v_compareTo == v_thisValue)		{			v_iRetval = 0;		}	}	return v_iRetval;};/**	Sets the JavaScript references used by custom scripts based on generated code from Blaring and before.	(Custom Scripts Workaround)	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.f_CSW_init = function(){	this.f_CSW_SetFormElement("_textEditBox");};/**	@private	@param {C_PromptElement} v_el Container.	@return {void}*/cognos.Prompt.Control.Text.prototype.f_drawInput = function( v_el ){	var v_oInput = null;	var v_oP = {		"style": cssParser(this["@style"], 'color,font,text'),		"class": "clsTextWidget pt"	};		if ( this["@maxLength"] !== K_PRMT_sEMPTY && !isNaN(this["@maxLength"]) )	{		v_oP.maxLength = this["@maxLength"];	}	if ( this["@readOnly"] )	{		v_oP.readOnly = true;	}	// With display:inline-table, width:100% work in IE too	if ( cssParser( this["@style"], "width" ) )	{		v_oP.style += ";width:100%";	}	if ( this["@size"] )	{		v_oP.size = this["@size"];	}	if ( this[K_PRMT_sATTR_DISABLED] )	{		v_oP.disabled = true;	}	// title for WCAG 2.0	if ( this["@title"] )	{		v_oP.title = this["@title"];	}	if ( this.isRequired() )	{		v_oP["aria-required"] = "true";	}				// Password field	if (this["@hideText"])	{		v_oP.type = "password";		v_oP.autocomplete = "off";		v_oP.value = this.m_sCurrentValue;		v_oInput = $CE( "input", v_oP );	}	// Single line edit box	else if (!this["@multiLine"])	{		var v_customHeight = cssParser( this["@style"], "height", true );		if ( !(/\d%/).test(v_customHeight) )		{			v_oP.style += ";height:" + v_customHeight;		}		v_oP.type = "text";		v_oP.value = this.m_sCurrentValue;		v_oInput = $CE( "input", v_oP );							}	// Multi line edit box	else	{		var v_customHeight = cssParser( this["@style"], "height", true );		if ( !(/\d%/).test(v_customHeight) )		{			v_oP.style += ";height:" + v_customHeight;		}		v_oP.rows = 7;		v_oP.cols = 20;		v_oInput = $CE( "textarea", v_oP );		v_oInput.f_appendText( this.m_sCurrentValue );					}	var sId = this.f_getId(K_PRMT_sTB_PREFIX);	v_oInput.f_setProperty( "id", this.f_getId(K_PRMT_sTB_PREFIX) );	v_el.f_appendChild( v_oInput );	//set the default parameter values	if (this.m_sCurrentValue)	{		//convert the default value to the locale		var sLocaleDefaultValue = convertSQLToLocale(this.m_sCurrentValue, this["@dataType"]);		var sText = sLocaleDefaultValue;		if (this.bParse(sLocaleDefaultValue, this["@dataType"]) == true)		{			sText = this.m_sCurrentValue;		}		v_oInput.value = getFormatByDataType( sText, this["@dataType"], this.m_bIsCurrency, this.f_getShowThousandSeparator() );	}	else	{		this.m_sCurrentValue = K_PRMT_sEMPTY;	}					return v_oInput;};/** * Getter for range inputId * rangeInputId used by range label to associate the label (From/To) to the input when there are not radio buttons *  */cognos.Prompt.Control.Text.prototype.f_getRangeInputId = function() { 	return (this.f_getId(K_PRMT_sTB_PREFIX));}/**	Stop the control from checking for changed/valid data.	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.f_endCheckDataInterval = function(){	if (typeof this.m_intervalId != K_PRMT_sUNDEFINED)	{		clearInterval(this.m_intervalId);	}	this.f_lostFocus();	this.checkData();};/**	@private	@return {cognos.Value[]}*/cognos.Prompt.Control.Text.prototype.f_getPV = function(){	var v_oPV = null;	if ( this.hasValue() )	{		if ( this["@multiLine"] && this.m_oChoices )		{			var v_sText = this.sGetValue();			var v_bAllowEmptyStrings = window.isAllowEmptyStrings ? window.isAllowEmptyStrings() : true;			var v_aInsertText = v_sText.split( this.m_reMultiLineDelimiters );			v_oPV = [];			for (var i=0; i < v_aInsertText.length; i++)			{				if (v_aInsertText[i].length == 0 && v_bAllowEmptyStrings == false)				{					continue;				}								var v_sFormatValue = getFormatByDataType( v_aInsertText[i], this["@dataType"], this.m_bIsCurrency );				v_oPV.push( {"use": v_aInsertText[i], "display": v_sFormatValue } );			}		}		else		{			v_oPV = {"use": this.sGetValue(), "display": this.sGetFormatValue()};		}	}	return v_oPV;};/**	@private	@return {boolean}*/cognos.Prompt.Control.Text.prototype.f_getShowThousandSeparator = function(){	return ( this["@showThousandSeparator"] ? true : false );};/**	Catch the backspace key. Some browsers (IE5.5) don't capture this event.	@private	@return {boolean}*/cognos.Prompt.Control.Text.prototype.f_keyPress = function (evt){	var evt = ( arguments && arguments.length ? arguments[arguments.length-1] : null );	var v_oEvt = (evt ? evt : (typeof event != K_PRMT_sUNDEFINED ? event : null ));	if ( v_oEvt )	{		var keyCode = (v_oEvt.keyCode) ? v_oEvt.keyCode : v_oEvt.which;		if (keyCode == '8')		{			//check the data that has been typed in			this.checkData();		}		else if (keyCode=='13' && !this["@multiLine"])		{			var oCV = this.f_getCV();			if ( this.m_oChoices )			{				if ( this.m_bValid )				{					this.m_oChoices.F_Insert();				}			}			else if ( oCV && (typeof oCV.canSubmitPrompt == K_PRMT_sFUNCTION) && oCV.canSubmitPrompt() && (typeof oCV.promptAction == K_PRMT_sFUNCTION))			{				// submits the form				oCV.promptAction(K_ACTION_NEXT);			}			return PRMTUtils.F_StopEvent( v_oEvt );		}	}	return true;};/**	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.f_keyUp = function(evt){	var evt = ( arguments && arguments.length ? arguments[arguments.length-1] : null );	this.checkData();	if ( !this["@multiLine"] )	{		PRMTUtils.F_PreventSubmit(evt);	}	if ( G_IsBidiEnabled && this["@contentTextDirection"] && !this["@hideText"] )	{					PRMT_BidiUtils.fixInputDirection(evt.target ? evt.target : evt.srcElement, this["@contentTextDirection"], 'true'); 	}};/**	Update UI when control is losing the focus.	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.f_lostFocus = function(){	//dynamically format values in the text box	if ( this.bParse(this.m_oForm.value, this["@dataType"]) !== false)	{		var v_sFormatValue = this.sGetFormatValue();		if ( v_sFormatValue !== false)		{			this.m_oForm.value = v_sFormatValue;		}	}	if ( this["@multiLine"] )	{		this.checkData();	}};/**	@private	@param {cognos.Value} v_oPV	@return {void}*/cognos.Prompt.Control.Text.prototype.f_setPV = function( v_oPV ){	var v_sValue = v_oPV[K_PRMT_sUSE];	if ( this["@dataType"] == "percentage" )	{		v_sValue = sParseOutCommon(v_sValue);		v_sValue = sMultiplyBy100(v_sValue);	}	v_sValue = convertSQLToLocale(v_sValue, this["@dataType"]);	this.m_oForm.value = v_sValue;	this.f_lostFocus();};/**	Set an interval in which the control will check for changed/valid data.	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.f_startCheckDataInterval = function( v_iInterval ){	if ( typeof v_iInterval != "number" )	{		v_iInterval = 100;	}	this.m_sCurrentValue = this.m_oForm.value;	this.m_intervalId = setInterval( this.checkValueChange.bind(this), v_iInterval );};/**	@private	@return {Integer}*/cognos.Prompt.Control.Text.prototype.getDecimalSize = function(){	var sTest = this.sGetValue();	// we are testing against the use value which will always have a value of "." no matter which locale we're in	var iDecimalPos = -1;	if (sTest !== false)	{		iDecimalPos = sTest.lastIndexOf(K_PRMT_sDOT);	}	//test for a decimal place	if (iDecimalPos != -1)	{		//strip the leading characters		sTest= sTest.substring (iDecimalPos +1);		//strip any non numerics		var iLastNumber = sTest.search(/\D/);		if (iLastNumber != -1)		{			sTest = sTest.substring (0, iLastNumber);		}		return sTest.length;	}	return 0;};/**	Return the value from the textbox.	@private	@return {String}*/cognos.Prompt.Control.Text.prototype.getValue = function(){	return this.m_oForm.value;};/**	@private	@return {boolean}*/cognos.Prompt.Control.Text.prototype.hasValue = function(){	return ( this.m_bValid && !this.isEmpty() ? true: false );};/** *	By default, returns true if the control does not return any value. * *	@private *	@return {boolean}*/cognos.Prompt.Control.Text.prototype.isEmpty = function(){	return (this.m_oForm && this.m_oForm.value && this.m_oForm.value.length > 0? false : true);};/**Check if this control is valid, i.e. ready to submit.@private@return {boolean} <i>true</i> if this control has a valid selection.*/cognos.Prompt.Control.Text.prototype.isValid = function(){	result = false;	if ( this.isRequired() && this.isMulti() && this.m_oChoices ) {		result = this.m_oChoices.f_getValid(); 	} else {		this.checkData();		result = (this.m_bValid===true);	}	return result;};/**	Hndle focus given to the control.	@private	@param {HTMLelement} obj Element to give the focus to.	@return {void}*/cognos.Prompt.Control.Text.prototype.setCurrentFocus = function(obj){	this.m_oCurrentFocus = obj;	this.m_oCurrentFocus.select();};/**	@private	@return {void}*/cognos.Prompt.Control.Text.prototype.setCurrentValue = function(){	this.m_oForm.value = this.m_sCurrentValue;};/**	Return a formatted value.	@private	@return {String} Returns false (boolean) if invalid.*/cognos.Prompt.Control.Text.prototype.sGetFormatValue = function(){	if (!this.m_bisGetValuesCall) {		this.checkData();	}	if (this.m_bValid == true)	{		return getFormatByDataType(this.sGetValue(), this["@dataType"], this.m_bIsCurrency, this.f_getShowThousandSeparator());	}	else	{		return false;	}};/**	Return a valid value.	@private	@return {String} The value or false if invalid.*/cognos.Prompt.Control.Text.prototype.sGetValue = function(){	if (!this.m_bisGetValuesCall) {		this.checkData();	}	if (this.m_bValid == true)	{		return (K_PRMT_sEMPTY + this.m_sCurrentValue);	}	return false;};var C_Text = cognos.Prompt.Control.Text; // Keep old reference for backward compatibility with custom scripts.
 |