123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- 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 );
- this.m_reMultiLineDelimiters = new RegExp("[\\n\\f\\r\\t]");
- this.m_bIsCurrency = false;
-
- 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 );
-
- initParsingRegularExpressions();
- this.f_initCompleted();
- },
-
- checkData: function()
- {
-
-
- var v_fnParent = this.f_parent;
- this.checkRequired();
- if ( this.isRequired() && !this.isMulti() && !(this.getValue()) )
- {
- this.m_bValid = false;
- }
- else
- {
-
- 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;
-
- 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;
-
- if (this["@submitType"] != K_PRMT_sXML && this.m_oSubmit)
- {
- this.m_oSubmit.value = this.m_sCurrentValue;
- }
- }
- }
- }
- this.f_parent = v_fnParent;
- this.f_parent();
- 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;
-
- 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();
- this.f_lostFocus();
-
- if ( G_IsBidiEnabled && this["@contentTextDirection"] && !this["@hideText"]) {
- this.m_oForm.style.direction = PRMT_BidiUtils.getTextDirection(this.m_oForm.value, this["@contentTextDirection"]);
- }
- }
- });
- 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();
-
- var z = sTestString.search(rCurrencySymbol);
- this.m_bIsCurrency = (z != -1);
- this.m_sCurrentValue = sTestString;
- }
- return v_bRetVal;
- };
- cognos.Prompt.Control.Text.prototype.checkValueChange = function()
- {
- if (this.m_oForm.value != this.m_sCurrentValue)
- {
- this.f_endCheckDataInterval();
- }
- };
- 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;
- };
- 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;
- };
- cognos.Prompt.Control.Text.prototype.f_CSW_init = function()
- {
- this.f_CSW_SetFormElement("_textEditBox");
- };
- 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;
- }
-
- 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;
- }
-
- if ( this["@title"] )
- {
- v_oP.title = this["@title"];
- }
- if ( this.isRequired() )
- {
- v_oP["aria-required"] = "true";
- }
-
-
- if (this["@hideText"])
- {
- v_oP.type = "password";
- v_oP.autocomplete = "off";
- v_oP.value = this.m_sCurrentValue;
- v_oInput = $CE( "input", v_oP );
- }
-
- 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 );
- }
-
- 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 );
-
- if (this.m_sCurrentValue)
- {
-
- 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;
- };
- cognos.Prompt.Control.Text.prototype.f_getRangeInputId = function() {
- return (this.f_getId(K_PRMT_sTB_PREFIX));
- }
- 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();
- };
- 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;
- };
- cognos.Prompt.Control.Text.prototype.f_getShowThousandSeparator = function()
- {
- return ( this["@showThousandSeparator"] ? true : false );
- };
- 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')
- {
-
- 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))
- {
-
- oCV.promptAction(K_ACTION_NEXT);
- }
- return PRMTUtils.F_StopEvent( v_oEvt );
- }
- }
- return true;
- };
- 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');
- }
- };
- cognos.Prompt.Control.Text.prototype.f_lostFocus = function()
- {
-
- 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();
- }
- };
- 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();
- };
- 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 );
- };
- cognos.Prompt.Control.Text.prototype.getDecimalSize = function()
- {
- var sTest = this.sGetValue();
-
- var iDecimalPos = -1;
- if (sTest !== false)
- {
- iDecimalPos = sTest.lastIndexOf(K_PRMT_sDOT);
- }
-
- if (iDecimalPos != -1)
- {
-
- sTest= sTest.substring (iDecimalPos +1);
-
- var iLastNumber = sTest.search(/\D/);
- if (iLastNumber != -1)
- {
- sTest = sTest.substring (0, iLastNumber);
- }
- return sTest.length;
- }
- return 0;
- };
- cognos.Prompt.Control.Text.prototype.getValue = function()
- {
- return this.m_oForm.value;
- };
- cognos.Prompt.Control.Text.prototype.hasValue = function()
- {
- return ( this.m_bValid && !this.isEmpty() ? true: false );
- };
- cognos.Prompt.Control.Text.prototype.isEmpty = function()
- {
- return (this.m_oForm && this.m_oForm.value && this.m_oForm.value.length > 0? false : true);
- };
- 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;
- };
- cognos.Prompt.Control.Text.prototype.setCurrentFocus = function(obj)
- {
- this.m_oCurrentFocus = obj;
- this.m_oCurrentFocus.select();
- };
- cognos.Prompt.Control.Text.prototype.setCurrentValue = function()
- {
- this.m_oForm.value = this.m_sCurrentValue;
- };
- 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;
- }
- };
- 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;
|