123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| BI and PM: prmt
- *| (C) Copyright IBM Corp. 2002, 2011
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- /**
- The Interval control is using a combination of Text controls to render itself.
- @class
- @private
- */
- cognos.Prompt.Control.Interval = cognos.Prompt.Control.f_extend({
- f_initialize: function( v_oProps, v_oPM ) {
- this[K_PRMT_LABEL_RANGE_LOWEST] = PMT_RNG_LOWEST_INTERVAL;
- this[K_PRMT_LABEL_RANGE_HIGHEST] = PMT_RNG_HIGHEST_INTERVAL;
- this._type_ = "cognos.Prompt.Control.Interval";
- this.f_parent( v_oProps ); // call parent's initialize()
- this.m_oPM = v_oPM;
- // by default, we allow negative values (if property isn't explicitly set to false)
- if ( this["@allowNegative"] !== false )
- {
- this["@allowNegative"] = true;
- }
- if ( this["@showMilliseconds"] )
- {
- this["@showSeconds"] = true;
- }
- var v_oInputProps = Object.f_extend( {}, v_oProps );
- v_oInputProps["n"] = "textBox";
- v_oInputProps["@dataType"] = "integer";
- v_oInputProps["@defaultValue"] = ( this.isRequired() && !this.isMulti() ? "0" : K_PRMT_sEMPTY );
- v_oInputProps["@hideAdornments"] = true;
- v_oInputProps["@size"] = 4;
- v_oInputProps.m_bIsAComponent = true;
- v_oInputProps.m_oOwner = this;
- this.m_pDays = this.f_initComponent( v_oInputProps, "[D]" );
- this.m_pHours = this.f_initComponent( v_oInputProps, "[H]" );
- v_oInputProps["@maxLength"] = "2";
- this.m_pMinutes = this.f_initComponent( v_oInputProps, "[M]" );
- v_oInputProps["@maxLength"] = "2";
- this.m_pSeconds = ( this["@showSeconds"] ? this.f_initComponent( v_oInputProps, "[S]" ) : null );
- v_oInputProps["@maxLength"] = "3";
- this.m_pMillis = ( this["@showMilliseconds"] ? this.f_initComponent( v_oInputProps, "[MS]" ) : null );
- this.m_bSkipAdornments = true;
- this.m_bHasLabel = true;
- this.f_initCompleted();
- },
- 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;
- var v_bValid =
- this.m_pDays.getValid() &&
- this.m_pHours.getValid() &&
- this.m_pMinutes.getValid() &&
- ( !this.m_pSeconds || this.m_pSeconds.getValid() ) &&
- ( !this.m_pMillis || this.m_pMillis.getValid() );
- this.m_bValid = ( v_bValid ? true : false );
- 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() {
- // We keep a reference to the parent function
- // Calling this.m_oFrom.f_drawCompleted seems to have a side effect on this.f_parent().
- var v_fnParent = this.f_parent;
- this.m_pDays.f_drawCompleted();
- this.m_pHours.f_drawCompleted();
- this.m_pMinutes.f_drawCompleted();
- if ( this.m_pSeconds )
- {
- this.m_pSeconds.f_drawCompleted();
- }
- if ( this.m_pMillis )
- {
- this.m_pMillis.f_drawCompleted();
- }
- this.f_setValue( this["@defaultValue"] );
- this.f_parent = v_fnParent; // call parent's f_drawCompleted using saved reference.
- this.f_parent(); // call parent's f_drawCompleted using saved reference.
- }
- });
- /**
- Clear all values.
- @private
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_clear = function()
- {
- this.m_pDays.m_oForm.value = K_PRMT_sEMPTY;
- this.m_pHours.m_oForm.value = K_PRMT_sEMPTY;
- this.m_pMinutes.m_oForm.value = K_PRMT_sEMPTY;
- if ( this.m_pSeconds )
- {
- this.m_pSeconds.m_oForm.value = K_PRMT_sEMPTY;
- }
- if ( this.m_pMillis )
- {
- this.m_pMillis.m_oForm.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.Interval.prototype.f_compare = function( v_oValue )
- {
- var v_iRetval = 1;
- if ( v_oValue )
- {
- var v_iThis = this.f_getValue().f_getAsMillis();
- var v_iCompareTo = v_oValue.f_getValue().f_getAsMillis();
- if ( v_iCompareTo > v_iThis )
- {
- v_iRetval = -1;
- }
- else if ( v_iCompareTo == v_iThis)
- {
- 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.Interval.prototype.f_CSW_init = function()
- {
- this.f_CSW_createJSObject( "intervalControl" );
- };
- /**
- @private
- @param {C_PromptElement} v_el Container.
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_drawInput = function( v_el )
- {
- var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_el );
- var v_tbd = $CE( "tbody", {}, v_tbl );
- var v_trLabels = $CE( "tr", {}, v_tbd );
- var v_trControls = $CE( "tr", {}, v_tbd );
- var v_td = $CE( "td", {}, v_trLabels );
- if ( this["@hideAdornments"] )
- {
- // add spacer in lieu of adornments
- v_td = $CE( "td", {}, v_trControls );
- $CE( "img", { "src": this.m_sSkin + "/prompting/images/spacer.gif", "vAlign": "top", "height": 10, "width": 10, "border": 0, "alt": "" }, v_td);
- }
- else
- {
- this.f_drawAdornments( v_trControls, this.isMulti() );
- }
- this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_DAYS], K_PRMT_sTB_PREFIX + this.m_pDays["_id_"], false );
- this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_HOURS], K_PRMT_sTB_PREFIX + this.m_pHours["_id_"] );
- this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_MINUTES], K_PRMT_sTB_PREFIX + this.m_pMinutes["_id_"] );
- if ( this["@showSeconds"] || this["@showMilliseconds"] )
- {
- this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_SECONDS], K_PRMT_sTB_PREFIX + this.m_pSeconds["_id_"] );
- }
- if ( this["@showMilliseconds"] )
- {
- this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_MILLISECONDS], K_PRMT_sTB_PREFIX + this.m_pMillis["_id_"] );
- }
- this.f_drawControl( v_trControls, this.m_pDays, false );
- this.f_drawControl( v_trControls, this.m_pHours );
- this.f_drawControl( v_trControls, this.m_pMinutes );
- this.f_drawControl( v_trControls, this.m_pSeconds );
- this.f_drawControl( v_trControls, this.m_pMillis );
- };
- /**
- @private
- @param {C_PromptElement} v_tr Container (a TR row).
- @param {cognos.Prompt.Control} v_oControl
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_drawControl = function( v_tr, v_oControl )
- {
- if ( v_oControl )
- {
- var v_td = $CE( "td", {"style": "margin-right: 3px"}, v_tr );
- v_oControl.f_drawInput( v_td );
- }
- };
- /**
- @private
- @param {C_PromptElement} v_tr Container (a TR row).
- @param {String} v_sLabel
- @param {boolean} [v_bAddSpacer] default = true
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_drawLabel = function( v_tr, v_sLabel, v_sControlId, v_bAddSpacer )
- {
- var v_td = null;
- if ( v_bAddSpacer !== false )
- {
- v_td = $CE( "td", { "width": 3, "rowSpan": 2 }, v_tr );
- $CE("img", {"src": this.m_sSkin + "/prompting/images/spacer.gif", "width": 3, "height": 1, "border": 0, "alt": ""}, v_td);
- }
- v_td = $CE( "td", { "class": "clsControlLabel pc" }, v_tr );
- var v_captionLabel = $CE( "label", { "for": v_sControlId }, v_td );
- v_captionLabel.f_appendText( v_sLabel );
- };
- /**
- @private
- @return {cognos.Value} null if no value.
- */
- cognos.Prompt.Control.Interval.prototype.f_getPV = function()
- {
- var v_oPV = null;
- if (!this.m_bisGetValuesCall) {
- this.checkData();
- }
- var v_oIV = this.f_getValue();
- if ( this.hasValue() )
- {
- v_oPV = { "use": v_oIV.f_getUseValue(), "display": v_oIV.f_getDisplayValue() };
- }
- return v_oPV;
- };
- /**
- @private
- @return {cognos.Prompt.Control.IntervalValue}
- */
- cognos.Prompt.Control.Interval.prototype.f_getValue = function()
- {
- return ( new cognos.Prompt.Control.IntervalValue(
- this.f_getValueFor( this.m_pDays ),
- this.f_getValueFor( this.m_pHours ),
- this.f_getValueFor( this.m_pMinutes ),
- this.f_getValueFor( this.m_pSeconds ),
- this.f_getValueFor( this.m_pMillis )
- ) );
- };
- /**
- @private
- @param {cognos.Prompt.Control.Text} v_oP Component to get the value for (Days, Hours, Minutes, Seconds and MilliSeconds).
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_getValueFor = function( v_oP )
- {
- return ( v_oP && v_oP.getValue ? v_oP.getValue() : null );
- };
- /**
- Creates a textbox control to deal with one component of the Intervas (Days, Hours, Minutes, Seconds and MilliSeconds).
- @private
- @param {object} v_oProps Properties for a component of an Interval control (a textbox control).
- @param {String} v_sSuffix Suffix to use to make this component unique.
- @return {cognos.Prompt.Control.Text}
- */
- cognos.Prompt.Control.Interval.prototype.f_initComponent = function( v_oProps, v_sSuffix )
- {
- return (
- this.m_oPM.f_create(
- Object.f_extend(
- v_oProps,
- { "_id_": this["_id_"] + v_sSuffix }
- )
- )
- );
- };
- /**
- @private
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_setControlValue = function( v_oControl, v_sValue )
- {
- if ( v_oControl && v_oControl.m_oForm )
- {
- v_sValue = ( v_sValue === null && this.isRequired() ? "0" : v_sValue );
- v_oControl.m_oForm.value = ( v_sValue === null ? K_PRMT_sEMPTY : v_sValue );
- v_oControl.checkData();
- }
- };
- /**
- @private
- @param {cognos.Value} v_oPV
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_setPV = function( v_oPV )
- {
- var v_sValue = v_oPV["use"];
- if ( v_sValue )
- {
- this.f_setValue( v_sValue );
- }
- };
- /**
- Parse and set value in the Interval control.
- @private
- @param {String} v_sValue
- @return {void}
- */
- cognos.Prompt.Control.Interval.prototype.f_setValue = function( v_sValue )
- {
- if ( !v_sValue )
- {
- return;
- }
- var v_oValue = new cognos.Prompt.Control.IntervalValue( v_sValue );
- this.f_setControlValue( this.m_pDays, v_oValue[ K_PRMT_sINTERVAL_DAYS ] * (v_oValue[ K_PRMT_sINTERVAL_NEGATIVE ] ? -1 : 1) );
- this.f_setControlValue( this.m_pHours, v_oValue[ K_PRMT_sINTERVAL_HOURS ] );
- this.f_setControlValue( this.m_pMinutes, v_oValue[ K_PRMT_sINTERVAL_MINUTES ] );
- this.f_setControlValue( this.m_pSeconds, v_oValue[ K_PRMT_sINTERVAL_SECONDS ] );
- this.f_setControlValue( this.m_pMillis, v_oValue[ K_PRMT_sINTERVAL_MILLIS ]);
- };
- /**
- * By default, returns true if the control does not return any value.
- *
- * @private
- * @return {boolean}
- */cognos.Prompt.Control.Interval.prototype.isEmpty = function()
- {
- var v_bHasValue =
- this.m_pDays.hasValue() ||
- this.m_pHours.hasValue() ||
- this.m_pMinutes.hasValue() ||
- ( this.m_pSeconds && this.m_pSeconds.hasValue() ) ||
- ( this.m_pMillis && this.m_pMillis.hasValue() );
- return ( v_bHasValue ? false : true );
- };
- /**
- * Return true if the field is not empty and is valid.
- *
- * @private
- * @return {boolean}
- */
- cognos.Prompt.Control.Interval.prototype.hasValue = function()
- {
- var v_bHasValue = !this.isEmpty();
- return ( v_bHasValue && this.m_bValid ? true : false );
- };
- /**
- Used to deal with interval values.
- @class
- @private
- */
- cognos.Prompt.Control.IntervalValue = function()
- {
- this[ K_PRMT_sINTERVAL_NEGATIVE ] = false;
- this[ K_PRMT_sINTERVAL_DAYS ] = null;
- this[ K_PRMT_sINTERVAL_HOURS ] = null;
- this[ K_PRMT_sINTERVAL_MINUTES ] = null;
- this[ K_PRMT_sINTERVAL_SECONDS ] = null;
- this[ K_PRMT_sINTERVAL_MILLIS ] = null;
- if ( arguments.length > 0 )
- {
- if ( typeof arguments[0] == K_PRMT_sSTRING && arguments.length == 1 )
- {
- Object.f_extend( this, this.f_parse( arguments[0] ) );
- }
- else if ( typeof arguments[0] == K_PRMT_sOBJECT && arguments[0] !== null )
- {
- Object.f_extend( this, arguments[0] );
- }
- else
- {
- this.f_init.apply( this, arguments );
- }
- }
- var v_aKeys = [ K_PRMT_sINTERVAL_MILLIS, K_PRMT_sINTERVAL_SECONDS, K_PRMT_sINTERVAL_MINUTES, K_PRMT_sINTERVAL_HOURS, K_PRMT_sINTERVAL_DAYS ];
- var v_bSetToZero = false;
- // make sure previous values (hours, minutes) are not nulls when we have seconds and milliseconds
- for (var v_iKey = 0; v_iKey < v_aKeys.length; v_iKey++)
- {
- if ( this[ v_aKeys[v_iKey] ] !== null )
- {
- v_bSetToZero = true;
- }
- if ( v_bSetToZero && this[ v_aKeys[v_iKey] ] === null )
- {
- this[ v_aKeys[v_iKey] ] = 0;
- }
- }
- this.f_fixExcedent( K_PRMT_sINTERVAL_MILLIS, K_PRMT_sINTERVAL_SECONDS, 1000);
- this.f_fixExcedent( K_PRMT_sINTERVAL_SECONDS, K_PRMT_sINTERVAL_MINUTES, 60);
- this.f_fixExcedent( K_PRMT_sINTERVAL_MINUTES, K_PRMT_sINTERVAL_HOURS, 60);
- this.f_fixExcedent( K_PRMT_sINTERVAL_HOURS, K_PRMT_sINTERVAL_DAYS, 24);
- return (this);
- }
- /**
- Compare the current value with v_oInterval.
- @private
- @param {cognos.Prompt.Control.IntervalValue} v_oInteval
- @return {boolean}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_equals = function( v_oInterval )
- {
- var v_bResult = false;
- if ( !(v_oInterval instanceof cognos.Prompt.Control.IntervalValue) )
- {
- v_oInterval = new cognos.Prompt.Control.IntervalValue( v_oInterval );
- }
- v_bResult = (
- this[ K_PRMT_sINTERVAL_NEGATIVE ] === v_oInterval[ K_PRMT_sINTERVAL_NEGATIVE ] &&
- this[ K_PRMT_sINTERVAL_DAYS ] === v_oInterval[ K_PRMT_sINTERVAL_DAYS ] &&
- this[ K_PRMT_sINTERVAL_HOURS ] === v_oInterval[ K_PRMT_sINTERVAL_HOURS ] &&
- this[ K_PRMT_sINTERVAL_MINUTES ] === v_oInterval[ K_PRMT_sINTERVAL_MINUTES ] &&
- this[ K_PRMT_sINTERVAL_SECONDS ] === v_oInterval[ K_PRMT_sINTERVAL_SECONDS ] &&
- this[ K_PRMT_sINTERVAL_MILLIS ] === v_oInterval[ K_PRMT_sINTERVAL_MILLIS ]
- );
- return v_bResult;
- };
- /**
- Fix limits for component of a Interval control.
- @private
- @param {String} v_sSource Source object.
- @param {String} v_sTarget Target object.
- @param {Integer} v_iLimit Limit for Source object.
- @return {void}
- @example <div><tt>f_fixExcedent( v_oSeconds, v_oMinutes, 60)</tt> will move convert any value higher than 60 in v_oSeconds and move it to v_oMinutes.<br/>A value of <tt>124 seconds</tt> will become <tt>2 minutes and 4 seconds</tt>.</div>
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_fixExcedent = function( v_sSource, v_sTarget, v_iLimit )
- {
- var v_iSource = this[ v_sSource ];
- var v_iTarget = this[ v_sTarget ];
- if ( v_iSource === null )
- {
- return;
- }
- if ( v_iSource < 0 || v_iTarget < 0 )
- {
- this[ K_PRMT_sINTERVAL_NEGATIVE ] = true;
- }
- v_iSource = Math.abs( v_iSource );
- v_iTarget = Math.abs( v_iTarget );
- if ( v_iSource >= v_iLimit )
- {
- var v_iExcedent = Math.floor( v_iSource / v_iLimit );
- v_iTarget += v_iExcedent;
- v_iSource = v_iSource - ( v_iExcedent * v_iLimit );
- }
- this[ v_sSource ] = v_iSource;
- this[ v_sTarget ] = v_iTarget;
- };
- /**
- Return the value of this interval as Milliseconds only, useful to simplify comparing value.
- @private
- @return {Integer}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_getAsMillis = function()
- {
- var v_iRetval = 0;
- var v_iMultiplier = 1;
- if ( this[ K_PRMT_sINTERVAL_MILLIS ] !== null ) {
- v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_MILLIS ];
- }
- v_iMultiplier *= 1000;
- if ( this[ K_PRMT_sINTERVAL_SECONDS ] !== null ) {
- v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_SECONDS ];
- }
- v_iMultiplier *= 60;
- if ( this[ K_PRMT_sINTERVAL_MINUTES ] !== null ) {
- v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_MINUTES ];
- }
- v_iMultiplier *= 60;
- if ( this[ K_PRMT_sINTERVAL_HOURS ] !== null ) {
- v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_HOURS ];
- }
- v_iMultiplier *= 24;
- if ( this[ K_PRMT_sINTERVAL_DAYS ] !== null ) {
- v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_DAYS ];
- }
- return ( this.f_isNegative() ? -1*v_iRetval : v_iRetval);
- };
- /**
- @private
- @return {String}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_getDisplayValue = function()
- {
- var v_sValue = (this.f_isNegative() ? g_minusSign : K_PRMT_sEMPTY);
- var v_sDays = this.f_getNumber( K_PRMT_sINTERVAL_DAYS, 1 );
- var v_sHours = this.f_getNumber( K_PRMT_sINTERVAL_HOURS, 1 );
- var v_sMinutes = this.f_getNumber( K_PRMT_sINTERVAL_MINUTES, 2 );
- var v_sSeconds = this.f_getNumber( K_PRMT_sINTERVAL_SECONDS, 2 );
- var v_sMillis = this.f_getNumber( K_PRMT_sINTERVAL_MILLIS, 3 );
- if ( v_sDays )
- {
- v_sValue += v_sDays;
- }
- if ( v_sHours )
- {
- if ( v_sDays )
- {
- v_sValue += K_PRMT_sSP;
- }
- v_sValue += v_sHours;
- }
- if ( v_sMinutes )
- {
- v_sValue += K_PRMT_sCOLON + v_sMinutes;
- }
- if ( v_sSeconds )
- {
- v_sValue += K_PRMT_sCOLON + v_sSeconds;
- }
- if ( v_sMillis )
- {
- v_sValue += K_PRMT_sDOT + v_sMillis;
- }
- return v_sValue;
- };
- /**
- Format number properly with the right number of digits. Add '0' in front if required.
- @private
- @param {String} v_sKey
- @param {Integer} v_iMinNumberOfDigits
- @return {void}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_getNumber = function( v_sKey, v_iMinNumberOfDigits )
- {
- var v_sValue = this[ v_sKey ];
- if ( v_sValue !== null )
- {
- v_sValue = K_PRMT_sEMPTY + v_sValue;
- while ( v_sValue.length < v_iMinNumberOfDigits )
- {
- v_sValue = "0" + v_sValue;
- }
- }
- return v_sValue;
- };
- /**
- @private
- @param {Integer} v_ivalue
- @param {String} [v_sFormat]
- @return {String}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_getValueFor = function( v_iValue, v_sFormat )
- {
- if ( v_iValue < 0 )
- {
- this.m_bNegative = true;
- }
- var v_iValue = Math.abs( v_iValue );
- if ( v_sValue && typeof v_sFormat == K_PRMT_sSTRING )
- {
- v_sValue = v_sFormat.replace("*", v_sValue);
- }
- return ( v_sValue );
- };
- /**
- Format value as <tt>(-)P</tt>99<tt>D</tt>99<tt>H</tt>99<tt>M</tt>99.999<tt>S</tt>.
- @private
- @return {String}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_getUseValue = function()
- {
- var v_sValue = K_PRMT_sEMPTY;
- if ( this[ K_PRMT_sINTERVAL_DAYS ] !== null ) {
- v_sValue += this[ K_PRMT_sINTERVAL_DAYS ] + "D";
- }
- //add the time designator
- if ( this[ K_PRMT_sINTERVAL_HOURS ] !== null || this[ K_PRMT_sINTERVAL_MINUTES ] !== null || this[ K_PRMT_sINTERVAL_SECONDS ] !== null || this[ K_PRMT_sINTERVAL_MILLIS ] !== null )
- {
- v_sValue += "T";
- if ( this[ K_PRMT_sINTERVAL_HOURS ] !== null ) {
- v_sValue += this[ K_PRMT_sINTERVAL_HOURS ] + "H";
- }
- if ( this[ K_PRMT_sINTERVAL_MINUTES ] !== null ) {
- v_sValue += this[ K_PRMT_sINTERVAL_MINUTES ] + "M";
- }
- if ( this[ K_PRMT_sINTERVAL_SECONDS ] !== null ) {
- v_sValue += this[ K_PRMT_sINTERVAL_SECONDS ];
- }
- if ( this[ K_PRMT_sINTERVAL_MILLIS ] !== null ) {
- v_sValue += K_PRMT_sDOT + this.f_getNumber( K_PRMT_sINTERVAL_MILLIS, 3 ) + "S";
- }
- }
- //has the user specified an interval?
- if ( v_sValue !== K_PRMT_sEMPTY)
- {
- v_sValue = "P" + v_sValue;
- //if the interval is negative, prepend with the minus sign
- if ( this[ K_PRMT_sINTERVAL_NEGATIVE ] )
- {
- v_sValue = g_minusSign + v_sValue;
- }
- }
- return v_sValue;
- };
- /**
- Initialize a cognos.Prompt.Control.IntervalValue object.
- @private
- @param {String} v_sDays
- @param {String} v_sHours
- @param {String} v_sMinutes
- @param {String} v_sSeconds
- @param {String} v_sMillis
- @return {void}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_init = function( v_sDays, v_sHours, v_sMinutes, v_sSeconds, v_sMillis )
- {
- var v_aArgs = [];
- var v_oResult = {};
- var v_sValue = null;
- // make sure we got strings
- for (var i = 0; i < 5; i++) {
- v_sValue = (arguments[i] === null || typeof arguments[i]==K_PRMT_sUNDEFINED ? null : K_PRMT_sEMPTY + arguments[i] );
- if ( typeof v_sValue == K_PRMT_sSTRING && v_sValue.match(K_PRMT_reBLANK_STRING) )
- {
- // if empty string, make it Zero.
- v_sValue = "0";
- }
- v_aArgs.push( v_sValue );
- }
- // Now, make sure we got numbers
- for (var i=0; i < v_aArgs.length; i++) {
- v_aArgs[i] = ( v_aArgs[i]!==null ? parseInt( v_aArgs[i], 10 ) : null );
- }
- v_oResult[ K_PRMT_sINTERVAL_DAYS ] = v_aArgs[0];
- v_oResult[ K_PRMT_sINTERVAL_HOURS ] = v_aArgs[1];
- v_oResult[ K_PRMT_sINTERVAL_MINUTES ] = v_aArgs[2];
- v_oResult[ K_PRMT_sINTERVAL_SECONDS ] = v_aArgs[3];
- v_oResult[ K_PRMT_sINTERVAL_MILLIS ] = v_aArgs[4];
- Object.f_extend( this, v_oResult );
- return (v_oResult);
- };
- /**
- @private
- @return {boolean}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_isNegative = function()
- {
- return ( this[ K_PRMT_sINTERVAL_NEGATIVE ] === true );
- };
- /**
- Itialize this value from a string.
- @private
- @param {String} v_sValue Can use one of these two formats: <ul>
- <li>(-)P999DT99H99M99.999</li>
- <li>(-)999 99:99:99.999</li></ul>
- @return {void}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_parse = function( v_sValue )
- {
- var v_oResult = {};
- var v_aMatch = null;
- if ( v_aMatch = v_sValue.match( K_PRMT_reXSD_FORMAT ) )
- {
- v_oResult[ K_PRMT_sINTERVAL_NEGATIVE ] = ( v_aMatch[1] ? true : false );
- v_oResult[ K_PRMT_sINTERVAL_DAYS ] = this.f_parseNumber( v_aMatch[2] );
- v_oResult[ K_PRMT_sINTERVAL_HOURS ] = this.f_parseNumber( v_aMatch[3] );
- v_oResult[ K_PRMT_sINTERVAL_MINUTES ] = this.f_parseNumber( v_aMatch[4] );
- v_oResult[ K_PRMT_sINTERVAL_SECONDS ] = this.f_parseNumber( v_aMatch[5] );
- v_oResult[ K_PRMT_sINTERVAL_MILLIS ] = this.f_parseNumber( v_aMatch[6] );
- }
- else if ( v_aMatch = v_sValue.match( K_PRMT_reINTERVAL_FORMAT ) )
- {
- v_oResult[ K_PRMT_sINTERVAL_NEGATIVE ] = ( v_aMatch[1] ? true : false );
- v_oResult[ K_PRMT_sINTERVAL_DAYS ] = this.f_parseNumber( v_aMatch[2] );
- v_oResult[ K_PRMT_sINTERVAL_HOURS ] = this.f_parseNumber( v_aMatch[3] );
- v_oResult[ K_PRMT_sINTERVAL_MINUTES ] = this.f_parseNumber( v_aMatch[4] );
- v_oResult[ K_PRMT_sINTERVAL_SECONDS ] = this.f_parseNumber( v_aMatch[5] );
- v_oResult[ K_PRMT_sINTERVAL_MILLIS ] = this.f_parseNumber( v_aMatch[6] );
- }
- return v_oResult;
- };
- /**
- @private
- @param {String} v_sValue String should be a number.
- @return {Integer}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_parseNumber = function( v_sValue )
- {
- return ( v_sValue ? parseInt(v_sValue.replace(K_PRMT_reINTERVAL_NODIGITS, K_PRMT_sEMPTY), 10) : null );
- };
- /**
- @private
- @param {boolean} v_bFlag Is negative?
- @return {void}
- */
- cognos.Prompt.Control.IntervalValue.prototype.f_setNegative = function( v_bFlag )
- {
- this[ K_PRMT_sINTERVAL_NEGATIVE ] = ( v_bFlag !== false );
- };
- var C_Interval = cognos.Prompt.Control.Interval; // Keep old reference for backward compatibility with custom scripts.
- var C_IntervalValue = cognos.Prompt.Control.IntervalValue; // Keep old reference for backward compatibility with custom scripts.
|