Interval.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2011
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. The Interval control is using a combination of Text controls to render itself.
  14. @class
  15. @private
  16. */
  17. cognos.Prompt.Control.Interval = cognos.Prompt.Control.f_extend({
  18. f_initialize: function( v_oProps, v_oPM ) {
  19. this[K_PRMT_LABEL_RANGE_LOWEST] = PMT_RNG_LOWEST_INTERVAL;
  20. this[K_PRMT_LABEL_RANGE_HIGHEST] = PMT_RNG_HIGHEST_INTERVAL;
  21. this._type_ = "cognos.Prompt.Control.Interval";
  22. this.f_parent( v_oProps ); // call parent's initialize()
  23. this.m_oPM = v_oPM;
  24. // by default, we allow negative values (if property isn't explicitly set to false)
  25. if ( this["@allowNegative"] !== false )
  26. {
  27. this["@allowNegative"] = true;
  28. }
  29. if ( this["@showMilliseconds"] )
  30. {
  31. this["@showSeconds"] = true;
  32. }
  33. var v_oInputProps = Object.f_extend( {}, v_oProps );
  34. v_oInputProps["n"] = "textBox";
  35. v_oInputProps["@dataType"] = "integer";
  36. v_oInputProps["@defaultValue"] = ( this.isRequired() && !this.isMulti() ? "0" : K_PRMT_sEMPTY );
  37. v_oInputProps["@hideAdornments"] = true;
  38. v_oInputProps["@size"] = 4;
  39. v_oInputProps.m_bIsAComponent = true;
  40. v_oInputProps.m_oOwner = this;
  41. this.m_pDays = this.f_initComponent( v_oInputProps, "[D]" );
  42. this.m_pHours = this.f_initComponent( v_oInputProps, "[H]" );
  43. v_oInputProps["@maxLength"] = "2";
  44. this.m_pMinutes = this.f_initComponent( v_oInputProps, "[M]" );
  45. v_oInputProps["@maxLength"] = "2";
  46. this.m_pSeconds = ( this["@showSeconds"] ? this.f_initComponent( v_oInputProps, "[S]" ) : null );
  47. v_oInputProps["@maxLength"] = "3";
  48. this.m_pMillis = ( this["@showMilliseconds"] ? this.f_initComponent( v_oInputProps, "[MS]" ) : null );
  49. this.m_bSkipAdornments = true;
  50. this.m_bHasLabel = true;
  51. this.f_initCompleted();
  52. },
  53. checkData: function() {
  54. // We keep a reference to the parent function
  55. // Calling this.m_oFrom functions seems to have a side effect on this.f_parent().
  56. var v_fnParent = this.f_parent;
  57. var v_bValid =
  58. this.m_pDays.getValid() &&
  59. this.m_pHours.getValid() &&
  60. this.m_pMinutes.getValid() &&
  61. ( !this.m_pSeconds || this.m_pSeconds.getValid() ) &&
  62. ( !this.m_pMillis || this.m_pMillis.getValid() );
  63. this.m_bValid = ( v_bValid ? true : false );
  64. this.f_parent = v_fnParent; // call parent's checkData using saved reference.
  65. this.f_parent(); // call parent's checkData using saved reference.
  66. return this.m_bValid;
  67. },
  68. clearValues: function() {
  69. this.f_parent();
  70. this.f_clear();
  71. },
  72. f_drawCompleted: function() {
  73. // We keep a reference to the parent function
  74. // Calling this.m_oFrom.f_drawCompleted seems to have a side effect on this.f_parent().
  75. var v_fnParent = this.f_parent;
  76. this.m_pDays.f_drawCompleted();
  77. this.m_pHours.f_drawCompleted();
  78. this.m_pMinutes.f_drawCompleted();
  79. if ( this.m_pSeconds )
  80. {
  81. this.m_pSeconds.f_drawCompleted();
  82. }
  83. if ( this.m_pMillis )
  84. {
  85. this.m_pMillis.f_drawCompleted();
  86. }
  87. this.f_setValue( this["@defaultValue"] );
  88. this.f_parent = v_fnParent; // call parent's f_drawCompleted using saved reference.
  89. this.f_parent(); // call parent's f_drawCompleted using saved reference.
  90. }
  91. });
  92. /**
  93. Clear all values.
  94. @private
  95. @return {void}
  96. */
  97. cognos.Prompt.Control.Interval.prototype.f_clear = function()
  98. {
  99. this.m_pDays.m_oForm.value = K_PRMT_sEMPTY;
  100. this.m_pHours.m_oForm.value = K_PRMT_sEMPTY;
  101. this.m_pMinutes.m_oForm.value = K_PRMT_sEMPTY;
  102. if ( this.m_pSeconds )
  103. {
  104. this.m_pSeconds.m_oForm.value = K_PRMT_sEMPTY;
  105. }
  106. if ( this.m_pMillis )
  107. {
  108. this.m_pMillis.m_oForm.value = K_PRMT_sEMPTY;
  109. }
  110. };
  111. /**
  112. Compare values. See {@link cognos.Prompt.Control#f_compare} for details.
  113. @see cognos.Prompt.Control#f_compare
  114. @private
  115. @return {Integer}
  116. */
  117. cognos.Prompt.Control.Interval.prototype.f_compare = function( v_oValue )
  118. {
  119. var v_iRetval = 1;
  120. if ( v_oValue )
  121. {
  122. var v_iThis = this.f_getValue().f_getAsMillis();
  123. var v_iCompareTo = v_oValue.f_getValue().f_getAsMillis();
  124. if ( v_iCompareTo > v_iThis )
  125. {
  126. v_iRetval = -1;
  127. }
  128. else if ( v_iCompareTo == v_iThis)
  129. {
  130. v_iRetval = 0;
  131. }
  132. }
  133. return v_iRetval;
  134. };
  135. /**
  136. Sets the JavaScript references used by custom scripts based on generated code from Blaring and before.
  137. (Custom Scripts Workaround)
  138. @private
  139. @return {void}
  140. */
  141. cognos.Prompt.Control.Interval.prototype.f_CSW_init = function()
  142. {
  143. this.f_CSW_createJSObject( "intervalControl" );
  144. };
  145. /**
  146. @private
  147. @param {C_PromptElement} v_el Container.
  148. @return {void}
  149. */
  150. cognos.Prompt.Control.Interval.prototype.f_drawInput = function( v_el )
  151. {
  152. var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_el );
  153. var v_tbd = $CE( "tbody", {}, v_tbl );
  154. var v_trLabels = $CE( "tr", {}, v_tbd );
  155. var v_trControls = $CE( "tr", {}, v_tbd );
  156. var v_td = $CE( "td", {}, v_trLabels );
  157. if ( this["@hideAdornments"] )
  158. {
  159. // add spacer in lieu of adornments
  160. v_td = $CE( "td", {}, v_trControls );
  161. $CE( "img", { "src": this.m_sSkin + "/prompting/images/spacer.gif", "vAlign": "top", "height": 10, "width": 10, "border": 0, "alt": "" }, v_td);
  162. }
  163. else
  164. {
  165. this.f_drawAdornments( v_trControls, this.isMulti() );
  166. }
  167. this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_DAYS], K_PRMT_sTB_PREFIX + this.m_pDays["_id_"], false );
  168. this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_HOURS], K_PRMT_sTB_PREFIX + this.m_pHours["_id_"] );
  169. this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_MINUTES], K_PRMT_sTB_PREFIX + this.m_pMinutes["_id_"] );
  170. if ( this["@showSeconds"] || this["@showMilliseconds"] )
  171. {
  172. this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_SECONDS], K_PRMT_sTB_PREFIX + this.m_pSeconds["_id_"] );
  173. }
  174. if ( this["@showMilliseconds"] )
  175. {
  176. this.f_drawLabel( v_trLabels, this[K_PRMT_LABEL_INTERVAL_MILLISECONDS], K_PRMT_sTB_PREFIX + this.m_pMillis["_id_"] );
  177. }
  178. this.f_drawControl( v_trControls, this.m_pDays, false );
  179. this.f_drawControl( v_trControls, this.m_pHours );
  180. this.f_drawControl( v_trControls, this.m_pMinutes );
  181. this.f_drawControl( v_trControls, this.m_pSeconds );
  182. this.f_drawControl( v_trControls, this.m_pMillis );
  183. };
  184. /**
  185. @private
  186. @param {C_PromptElement} v_tr Container (a TR row).
  187. @param {cognos.Prompt.Control} v_oControl
  188. @return {void}
  189. */
  190. cognos.Prompt.Control.Interval.prototype.f_drawControl = function( v_tr, v_oControl )
  191. {
  192. if ( v_oControl )
  193. {
  194. var v_td = $CE( "td", {"style": "margin-right: 3px"}, v_tr );
  195. v_oControl.f_drawInput( v_td );
  196. }
  197. };
  198. /**
  199. @private
  200. @param {C_PromptElement} v_tr Container (a TR row).
  201. @param {String} v_sLabel
  202. @param {boolean} [v_bAddSpacer] default = true
  203. @return {void}
  204. */
  205. cognos.Prompt.Control.Interval.prototype.f_drawLabel = function( v_tr, v_sLabel, v_sControlId, v_bAddSpacer )
  206. {
  207. var v_td = null;
  208. if ( v_bAddSpacer !== false )
  209. {
  210. v_td = $CE( "td", { "width": 3, "rowSpan": 2 }, v_tr );
  211. $CE("img", {"src": this.m_sSkin + "/prompting/images/spacer.gif", "width": 3, "height": 1, "border": 0, "alt": ""}, v_td);
  212. }
  213. v_td = $CE( "td", { "class": "clsControlLabel pc" }, v_tr );
  214. var v_captionLabel = $CE( "label", { "for": v_sControlId }, v_td );
  215. v_captionLabel.f_appendText( v_sLabel );
  216. };
  217. /**
  218. @private
  219. @return {cognos.Value} null if no value.
  220. */
  221. cognos.Prompt.Control.Interval.prototype.f_getPV = function()
  222. {
  223. var v_oPV = null;
  224. if (!this.m_bisGetValuesCall) {
  225. this.checkData();
  226. }
  227. var v_oIV = this.f_getValue();
  228. if ( this.hasValue() )
  229. {
  230. v_oPV = { "use": v_oIV.f_getUseValue(), "display": v_oIV.f_getDisplayValue() };
  231. }
  232. return v_oPV;
  233. };
  234. /**
  235. @private
  236. @return {cognos.Prompt.Control.IntervalValue}
  237. */
  238. cognos.Prompt.Control.Interval.prototype.f_getValue = function()
  239. {
  240. return ( new cognos.Prompt.Control.IntervalValue(
  241. this.f_getValueFor( this.m_pDays ),
  242. this.f_getValueFor( this.m_pHours ),
  243. this.f_getValueFor( this.m_pMinutes ),
  244. this.f_getValueFor( this.m_pSeconds ),
  245. this.f_getValueFor( this.m_pMillis )
  246. ) );
  247. };
  248. /**
  249. @private
  250. @param {cognos.Prompt.Control.Text} v_oP Component to get the value for (Days, Hours, Minutes, Seconds and MilliSeconds).
  251. @return {void}
  252. */
  253. cognos.Prompt.Control.Interval.prototype.f_getValueFor = function( v_oP )
  254. {
  255. return ( v_oP && v_oP.getValue ? v_oP.getValue() : null );
  256. };
  257. /**
  258. Creates a textbox control to deal with one component of the Intervas (Days, Hours, Minutes, Seconds and MilliSeconds).
  259. @private
  260. @param {object} v_oProps Properties for a component of an Interval control (a textbox control).
  261. @param {String} v_sSuffix Suffix to use to make this component unique.
  262. @return {cognos.Prompt.Control.Text}
  263. */
  264. cognos.Prompt.Control.Interval.prototype.f_initComponent = function( v_oProps, v_sSuffix )
  265. {
  266. return (
  267. this.m_oPM.f_create(
  268. Object.f_extend(
  269. v_oProps,
  270. { "_id_": this["_id_"] + v_sSuffix }
  271. )
  272. )
  273. );
  274. };
  275. /**
  276. @private
  277. @return {void}
  278. */
  279. cognos.Prompt.Control.Interval.prototype.f_setControlValue = function( v_oControl, v_sValue )
  280. {
  281. if ( v_oControl && v_oControl.m_oForm )
  282. {
  283. v_sValue = ( v_sValue === null && this.isRequired() ? "0" : v_sValue );
  284. v_oControl.m_oForm.value = ( v_sValue === null ? K_PRMT_sEMPTY : v_sValue );
  285. v_oControl.checkData();
  286. }
  287. };
  288. /**
  289. @private
  290. @param {cognos.Value} v_oPV
  291. @return {void}
  292. */
  293. cognos.Prompt.Control.Interval.prototype.f_setPV = function( v_oPV )
  294. {
  295. var v_sValue = v_oPV["use"];
  296. if ( v_sValue )
  297. {
  298. this.f_setValue( v_sValue );
  299. }
  300. };
  301. /**
  302. Parse and set value in the Interval control.
  303. @private
  304. @param {String} v_sValue
  305. @return {void}
  306. */
  307. cognos.Prompt.Control.Interval.prototype.f_setValue = function( v_sValue )
  308. {
  309. if ( !v_sValue )
  310. {
  311. return;
  312. }
  313. var v_oValue = new cognos.Prompt.Control.IntervalValue( v_sValue );
  314. this.f_setControlValue( this.m_pDays, v_oValue[ K_PRMT_sINTERVAL_DAYS ] * (v_oValue[ K_PRMT_sINTERVAL_NEGATIVE ] ? -1 : 1) );
  315. this.f_setControlValue( this.m_pHours, v_oValue[ K_PRMT_sINTERVAL_HOURS ] );
  316. this.f_setControlValue( this.m_pMinutes, v_oValue[ K_PRMT_sINTERVAL_MINUTES ] );
  317. this.f_setControlValue( this.m_pSeconds, v_oValue[ K_PRMT_sINTERVAL_SECONDS ] );
  318. this.f_setControlValue( this.m_pMillis, v_oValue[ K_PRMT_sINTERVAL_MILLIS ]);
  319. };
  320. /**
  321. * By default, returns true if the control does not return any value.
  322. *
  323. * @private
  324. * @return {boolean}
  325. */cognos.Prompt.Control.Interval.prototype.isEmpty = function()
  326. {
  327. var v_bHasValue =
  328. this.m_pDays.hasValue() ||
  329. this.m_pHours.hasValue() ||
  330. this.m_pMinutes.hasValue() ||
  331. ( this.m_pSeconds && this.m_pSeconds.hasValue() ) ||
  332. ( this.m_pMillis && this.m_pMillis.hasValue() );
  333. return ( v_bHasValue ? false : true );
  334. };
  335. /**
  336. * Return true if the field is not empty and is valid.
  337. *
  338. * @private
  339. * @return {boolean}
  340. */
  341. cognos.Prompt.Control.Interval.prototype.hasValue = function()
  342. {
  343. var v_bHasValue = !this.isEmpty();
  344. return ( v_bHasValue && this.m_bValid ? true : false );
  345. };
  346. /**
  347. Used to deal with interval values.
  348. @class
  349. @private
  350. */
  351. cognos.Prompt.Control.IntervalValue = function()
  352. {
  353. this[ K_PRMT_sINTERVAL_NEGATIVE ] = false;
  354. this[ K_PRMT_sINTERVAL_DAYS ] = null;
  355. this[ K_PRMT_sINTERVAL_HOURS ] = null;
  356. this[ K_PRMT_sINTERVAL_MINUTES ] = null;
  357. this[ K_PRMT_sINTERVAL_SECONDS ] = null;
  358. this[ K_PRMT_sINTERVAL_MILLIS ] = null;
  359. if ( arguments.length > 0 )
  360. {
  361. if ( typeof arguments[0] == K_PRMT_sSTRING && arguments.length == 1 )
  362. {
  363. Object.f_extend( this, this.f_parse( arguments[0] ) );
  364. }
  365. else if ( typeof arguments[0] == K_PRMT_sOBJECT && arguments[0] !== null )
  366. {
  367. Object.f_extend( this, arguments[0] );
  368. }
  369. else
  370. {
  371. this.f_init.apply( this, arguments );
  372. }
  373. }
  374. var v_aKeys = [ K_PRMT_sINTERVAL_MILLIS, K_PRMT_sINTERVAL_SECONDS, K_PRMT_sINTERVAL_MINUTES, K_PRMT_sINTERVAL_HOURS, K_PRMT_sINTERVAL_DAYS ];
  375. var v_bSetToZero = false;
  376. // make sure previous values (hours, minutes) are not nulls when we have seconds and milliseconds
  377. for (var v_iKey = 0; v_iKey < v_aKeys.length; v_iKey++)
  378. {
  379. if ( this[ v_aKeys[v_iKey] ] !== null )
  380. {
  381. v_bSetToZero = true;
  382. }
  383. if ( v_bSetToZero && this[ v_aKeys[v_iKey] ] === null )
  384. {
  385. this[ v_aKeys[v_iKey] ] = 0;
  386. }
  387. }
  388. this.f_fixExcedent( K_PRMT_sINTERVAL_MILLIS, K_PRMT_sINTERVAL_SECONDS, 1000);
  389. this.f_fixExcedent( K_PRMT_sINTERVAL_SECONDS, K_PRMT_sINTERVAL_MINUTES, 60);
  390. this.f_fixExcedent( K_PRMT_sINTERVAL_MINUTES, K_PRMT_sINTERVAL_HOURS, 60);
  391. this.f_fixExcedent( K_PRMT_sINTERVAL_HOURS, K_PRMT_sINTERVAL_DAYS, 24);
  392. return (this);
  393. }
  394. /**
  395. Compare the current value with v_oInterval.
  396. @private
  397. @param {cognos.Prompt.Control.IntervalValue} v_oInteval
  398. @return {boolean}
  399. */
  400. cognos.Prompt.Control.IntervalValue.prototype.f_equals = function( v_oInterval )
  401. {
  402. var v_bResult = false;
  403. if ( !(v_oInterval instanceof cognos.Prompt.Control.IntervalValue) )
  404. {
  405. v_oInterval = new cognos.Prompt.Control.IntervalValue( v_oInterval );
  406. }
  407. v_bResult = (
  408. this[ K_PRMT_sINTERVAL_NEGATIVE ] === v_oInterval[ K_PRMT_sINTERVAL_NEGATIVE ] &&
  409. this[ K_PRMT_sINTERVAL_DAYS ] === v_oInterval[ K_PRMT_sINTERVAL_DAYS ] &&
  410. this[ K_PRMT_sINTERVAL_HOURS ] === v_oInterval[ K_PRMT_sINTERVAL_HOURS ] &&
  411. this[ K_PRMT_sINTERVAL_MINUTES ] === v_oInterval[ K_PRMT_sINTERVAL_MINUTES ] &&
  412. this[ K_PRMT_sINTERVAL_SECONDS ] === v_oInterval[ K_PRMT_sINTERVAL_SECONDS ] &&
  413. this[ K_PRMT_sINTERVAL_MILLIS ] === v_oInterval[ K_PRMT_sINTERVAL_MILLIS ]
  414. );
  415. return v_bResult;
  416. };
  417. /**
  418. Fix limits for component of a Interval control.
  419. @private
  420. @param {String} v_sSource Source object.
  421. @param {String} v_sTarget Target object.
  422. @param {Integer} v_iLimit Limit for Source object.
  423. @return {void}
  424. @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>
  425. */
  426. cognos.Prompt.Control.IntervalValue.prototype.f_fixExcedent = function( v_sSource, v_sTarget, v_iLimit )
  427. {
  428. var v_iSource = this[ v_sSource ];
  429. var v_iTarget = this[ v_sTarget ];
  430. if ( v_iSource === null )
  431. {
  432. return;
  433. }
  434. if ( v_iSource < 0 || v_iTarget < 0 )
  435. {
  436. this[ K_PRMT_sINTERVAL_NEGATIVE ] = true;
  437. }
  438. v_iSource = Math.abs( v_iSource );
  439. v_iTarget = Math.abs( v_iTarget );
  440. if ( v_iSource >= v_iLimit )
  441. {
  442. var v_iExcedent = Math.floor( v_iSource / v_iLimit );
  443. v_iTarget += v_iExcedent;
  444. v_iSource = v_iSource - ( v_iExcedent * v_iLimit );
  445. }
  446. this[ v_sSource ] = v_iSource;
  447. this[ v_sTarget ] = v_iTarget;
  448. };
  449. /**
  450. Return the value of this interval as Milliseconds only, useful to simplify comparing value.
  451. @private
  452. @return {Integer}
  453. */
  454. cognos.Prompt.Control.IntervalValue.prototype.f_getAsMillis = function()
  455. {
  456. var v_iRetval = 0;
  457. var v_iMultiplier = 1;
  458. if ( this[ K_PRMT_sINTERVAL_MILLIS ] !== null ) {
  459. v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_MILLIS ];
  460. }
  461. v_iMultiplier *= 1000;
  462. if ( this[ K_PRMT_sINTERVAL_SECONDS ] !== null ) {
  463. v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_SECONDS ];
  464. }
  465. v_iMultiplier *= 60;
  466. if ( this[ K_PRMT_sINTERVAL_MINUTES ] !== null ) {
  467. v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_MINUTES ];
  468. }
  469. v_iMultiplier *= 60;
  470. if ( this[ K_PRMT_sINTERVAL_HOURS ] !== null ) {
  471. v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_HOURS ];
  472. }
  473. v_iMultiplier *= 24;
  474. if ( this[ K_PRMT_sINTERVAL_DAYS ] !== null ) {
  475. v_iRetval += v_iMultiplier * this[ K_PRMT_sINTERVAL_DAYS ];
  476. }
  477. return ( this.f_isNegative() ? -1*v_iRetval : v_iRetval);
  478. };
  479. /**
  480. @private
  481. @return {String}
  482. */
  483. cognos.Prompt.Control.IntervalValue.prototype.f_getDisplayValue = function()
  484. {
  485. var v_sValue = (this.f_isNegative() ? g_minusSign : K_PRMT_sEMPTY);
  486. var v_sDays = this.f_getNumber( K_PRMT_sINTERVAL_DAYS, 1 );
  487. var v_sHours = this.f_getNumber( K_PRMT_sINTERVAL_HOURS, 1 );
  488. var v_sMinutes = this.f_getNumber( K_PRMT_sINTERVAL_MINUTES, 2 );
  489. var v_sSeconds = this.f_getNumber( K_PRMT_sINTERVAL_SECONDS, 2 );
  490. var v_sMillis = this.f_getNumber( K_PRMT_sINTERVAL_MILLIS, 3 );
  491. if ( v_sDays )
  492. {
  493. v_sValue += v_sDays;
  494. }
  495. if ( v_sHours )
  496. {
  497. if ( v_sDays )
  498. {
  499. v_sValue += K_PRMT_sSP;
  500. }
  501. v_sValue += v_sHours;
  502. }
  503. if ( v_sMinutes )
  504. {
  505. v_sValue += K_PRMT_sCOLON + v_sMinutes;
  506. }
  507. if ( v_sSeconds )
  508. {
  509. v_sValue += K_PRMT_sCOLON + v_sSeconds;
  510. }
  511. if ( v_sMillis )
  512. {
  513. v_sValue += K_PRMT_sDOT + v_sMillis;
  514. }
  515. return v_sValue;
  516. };
  517. /**
  518. Format number properly with the right number of digits. Add '0' in front if required.
  519. @private
  520. @param {String} v_sKey
  521. @param {Integer} v_iMinNumberOfDigits
  522. @return {void}
  523. */
  524. cognos.Prompt.Control.IntervalValue.prototype.f_getNumber = function( v_sKey, v_iMinNumberOfDigits )
  525. {
  526. var v_sValue = this[ v_sKey ];
  527. if ( v_sValue !== null )
  528. {
  529. v_sValue = K_PRMT_sEMPTY + v_sValue;
  530. while ( v_sValue.length < v_iMinNumberOfDigits )
  531. {
  532. v_sValue = "0" + v_sValue;
  533. }
  534. }
  535. return v_sValue;
  536. };
  537. /**
  538. @private
  539. @param {Integer} v_ivalue
  540. @param {String} [v_sFormat]
  541. @return {String}
  542. */
  543. cognos.Prompt.Control.IntervalValue.prototype.f_getValueFor = function( v_iValue, v_sFormat )
  544. {
  545. if ( v_iValue < 0 )
  546. {
  547. this.m_bNegative = true;
  548. }
  549. var v_iValue = Math.abs( v_iValue );
  550. if ( v_sValue && typeof v_sFormat == K_PRMT_sSTRING )
  551. {
  552. v_sValue = v_sFormat.replace("*", v_sValue);
  553. }
  554. return ( v_sValue );
  555. };
  556. /**
  557. Format value as <tt>(-)P</tt>99<tt>D</tt>99<tt>H</tt>99<tt>M</tt>99.999<tt>S</tt>.
  558. @private
  559. @return {String}
  560. */
  561. cognos.Prompt.Control.IntervalValue.prototype.f_getUseValue = function()
  562. {
  563. var v_sValue = K_PRMT_sEMPTY;
  564. if ( this[ K_PRMT_sINTERVAL_DAYS ] !== null ) {
  565. v_sValue += this[ K_PRMT_sINTERVAL_DAYS ] + "D";
  566. }
  567. //add the time designator
  568. 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 )
  569. {
  570. v_sValue += "T";
  571. if ( this[ K_PRMT_sINTERVAL_HOURS ] !== null ) {
  572. v_sValue += this[ K_PRMT_sINTERVAL_HOURS ] + "H";
  573. }
  574. if ( this[ K_PRMT_sINTERVAL_MINUTES ] !== null ) {
  575. v_sValue += this[ K_PRMT_sINTERVAL_MINUTES ] + "M";
  576. }
  577. if ( this[ K_PRMT_sINTERVAL_SECONDS ] !== null ) {
  578. v_sValue += this[ K_PRMT_sINTERVAL_SECONDS ];
  579. }
  580. if ( this[ K_PRMT_sINTERVAL_MILLIS ] !== null ) {
  581. v_sValue += K_PRMT_sDOT + this.f_getNumber( K_PRMT_sINTERVAL_MILLIS, 3 ) + "S";
  582. }
  583. }
  584. //has the user specified an interval?
  585. if ( v_sValue !== K_PRMT_sEMPTY)
  586. {
  587. v_sValue = "P" + v_sValue;
  588. //if the interval is negative, prepend with the minus sign
  589. if ( this[ K_PRMT_sINTERVAL_NEGATIVE ] )
  590. {
  591. v_sValue = g_minusSign + v_sValue;
  592. }
  593. }
  594. return v_sValue;
  595. };
  596. /**
  597. Initialize a cognos.Prompt.Control.IntervalValue object.
  598. @private
  599. @param {String} v_sDays
  600. @param {String} v_sHours
  601. @param {String} v_sMinutes
  602. @param {String} v_sSeconds
  603. @param {String} v_sMillis
  604. @return {void}
  605. */
  606. cognos.Prompt.Control.IntervalValue.prototype.f_init = function( v_sDays, v_sHours, v_sMinutes, v_sSeconds, v_sMillis )
  607. {
  608. var v_aArgs = [];
  609. var v_oResult = {};
  610. var v_sValue = null;
  611. // make sure we got strings
  612. for (var i = 0; i < 5; i++) {
  613. v_sValue = (arguments[i] === null || typeof arguments[i]==K_PRMT_sUNDEFINED ? null : K_PRMT_sEMPTY + arguments[i] );
  614. if ( typeof v_sValue == K_PRMT_sSTRING && v_sValue.match(K_PRMT_reBLANK_STRING) )
  615. {
  616. // if empty string, make it Zero.
  617. v_sValue = "0";
  618. }
  619. v_aArgs.push( v_sValue );
  620. }
  621. // Now, make sure we got numbers
  622. for (var i=0; i < v_aArgs.length; i++) {
  623. v_aArgs[i] = ( v_aArgs[i]!==null ? parseInt( v_aArgs[i], 10 ) : null );
  624. }
  625. v_oResult[ K_PRMT_sINTERVAL_DAYS ] = v_aArgs[0];
  626. v_oResult[ K_PRMT_sINTERVAL_HOURS ] = v_aArgs[1];
  627. v_oResult[ K_PRMT_sINTERVAL_MINUTES ] = v_aArgs[2];
  628. v_oResult[ K_PRMT_sINTERVAL_SECONDS ] = v_aArgs[3];
  629. v_oResult[ K_PRMT_sINTERVAL_MILLIS ] = v_aArgs[4];
  630. Object.f_extend( this, v_oResult );
  631. return (v_oResult);
  632. };
  633. /**
  634. @private
  635. @return {boolean}
  636. */
  637. cognos.Prompt.Control.IntervalValue.prototype.f_isNegative = function()
  638. {
  639. return ( this[ K_PRMT_sINTERVAL_NEGATIVE ] === true );
  640. };
  641. /**
  642. Itialize this value from a string.
  643. @private
  644. @param {String} v_sValue Can use one of these two formats: <ul>
  645. <li>(-)P999DT99H99M99.999</li>
  646. <li>(-)999 99:99:99.999</li></ul>
  647. @return {void}
  648. */
  649. cognos.Prompt.Control.IntervalValue.prototype.f_parse = function( v_sValue )
  650. {
  651. var v_oResult = {};
  652. var v_aMatch = null;
  653. if ( v_aMatch = v_sValue.match( K_PRMT_reXSD_FORMAT ) )
  654. {
  655. v_oResult[ K_PRMT_sINTERVAL_NEGATIVE ] = ( v_aMatch[1] ? true : false );
  656. v_oResult[ K_PRMT_sINTERVAL_DAYS ] = this.f_parseNumber( v_aMatch[2] );
  657. v_oResult[ K_PRMT_sINTERVAL_HOURS ] = this.f_parseNumber( v_aMatch[3] );
  658. v_oResult[ K_PRMT_sINTERVAL_MINUTES ] = this.f_parseNumber( v_aMatch[4] );
  659. v_oResult[ K_PRMT_sINTERVAL_SECONDS ] = this.f_parseNumber( v_aMatch[5] );
  660. v_oResult[ K_PRMT_sINTERVAL_MILLIS ] = this.f_parseNumber( v_aMatch[6] );
  661. }
  662. else if ( v_aMatch = v_sValue.match( K_PRMT_reINTERVAL_FORMAT ) )
  663. {
  664. v_oResult[ K_PRMT_sINTERVAL_NEGATIVE ] = ( v_aMatch[1] ? true : false );
  665. v_oResult[ K_PRMT_sINTERVAL_DAYS ] = this.f_parseNumber( v_aMatch[2] );
  666. v_oResult[ K_PRMT_sINTERVAL_HOURS ] = this.f_parseNumber( v_aMatch[3] );
  667. v_oResult[ K_PRMT_sINTERVAL_MINUTES ] = this.f_parseNumber( v_aMatch[4] );
  668. v_oResult[ K_PRMT_sINTERVAL_SECONDS ] = this.f_parseNumber( v_aMatch[5] );
  669. v_oResult[ K_PRMT_sINTERVAL_MILLIS ] = this.f_parseNumber( v_aMatch[6] );
  670. }
  671. return v_oResult;
  672. };
  673. /**
  674. @private
  675. @param {String} v_sValue String should be a number.
  676. @return {Integer}
  677. */
  678. cognos.Prompt.Control.IntervalValue.prototype.f_parseNumber = function( v_sValue )
  679. {
  680. return ( v_sValue ? parseInt(v_sValue.replace(K_PRMT_reINTERVAL_NODIGITS, K_PRMT_sEMPTY), 10) : null );
  681. };
  682. /**
  683. @private
  684. @param {boolean} v_bFlag Is negative?
  685. @return {void}
  686. */
  687. cognos.Prompt.Control.IntervalValue.prototype.f_setNegative = function( v_bFlag )
  688. {
  689. this[ K_PRMT_sINTERVAL_NEGATIVE ] = ( v_bFlag !== false );
  690. };
  691. var C_Interval = cognos.Prompt.Control.Interval; // Keep old reference for backward compatibility with custom scripts.
  692. var C_IntervalValue = cognos.Prompt.Control.IntervalValue; // Keep old reference for backward compatibility with custom scripts.