DateTime.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2016
  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. @class
  14. @private
  15. */
  16. cognos.Prompt.Control.DateTime = cognos.Prompt.Control.f_extend({
  17. f_initialize: function( v_oProps )
  18. {
  19. this[K_PRMT_LABEL_RANGE_LOWEST] = PMT_RNG_EARLIEST_DATE;
  20. this[K_PRMT_LABEL_RANGE_HIGHEST] = PMT_RNG_LATEST_DATE;
  21. this._type_ = "cognos.Prompt.Control.DateTime";
  22. this.f_parent( v_oProps ); // call parent's initialize()
  23. if ( this["@selectDateTimeUI"] )
  24. {
  25. this["@selectUI"] = this["@selectDateTimeUI"];
  26. }
  27. var v_oPropsComponent = Object.f_extend( {}, v_oProps );
  28. if ( this["@selectUI"] == "editBox" )
  29. {
  30. v_oPropsComponent["@selectUI"] = "editBox";
  31. }
  32. v_oPropsComponent["@required"] = true;
  33. v_oPropsComponent["@hideAdornments"] = true;
  34. v_oPropsComponent.m_bIsAComponent = true;
  35. v_oPropsComponent.m_oOwner = this;
  36. this.m_oDate = new cognos.Prompt.Control.Date( v_oPropsComponent );
  37. this.m_oTime = new cognos.Prompt.Control.Time( v_oPropsComponent );
  38. this.m_bSkipAdornments = true;
  39. this.m_bDisabled = false;
  40. this.f_initCompleted();
  41. if (SYSTEMPROPERTY_TREE_CACHE_ENABLED)
  42. {
  43. this.cacheDateTimeControlName(this.getTracking());
  44. }
  45. },
  46. checkData: function()
  47. {
  48. // We keep a reference to the parent function
  49. // Calling this.m_oFrom functions seems to have a side effect on this.f_parent().
  50. var v_fnParent = this.f_parent;
  51. this.m_bValid = (this.m_oDate.m_bValid && this.m_oTime.m_bValid);
  52. this.f_parent = v_fnParent; // call parent's checkData using saved reference.
  53. this.f_parent(); // call parent's checkData using saved reference.
  54. return this.m_bValid;
  55. },
  56. clearValues: function()
  57. {
  58. this.f_parent();
  59. this.m_oDate.clearValues();
  60. this.m_oTime.clearValues();
  61. },
  62. f_drawCompleted: function()
  63. {
  64. // We keep a reference to the parent function
  65. // Calling this.m_oFrom.f_drawCompleted seems to have a side effect on this.f_parent().
  66. var v_fnParent = this.f_parent;
  67. var v_chk = $(this.f_getId( "chkAnyValue" ));
  68. if ( v_chk )
  69. {
  70. PRMTUtils.f_addEvent( v_chk, "click", this.f_toggleDisable.bind(this) );
  71. }
  72. this.m_oDate.f_drawCompleted();
  73. this.m_oTime.f_drawCompleted();
  74. this.f_parent = v_fnParent; // call parent's f_drawCompleted using saved reference.
  75. this.f_parent(); // call parent's f_drawCompleted using saved reference.
  76. if ( this[K_PRMT_sATTR_DISABLED] )
  77. {
  78. this.m_oDate.f_setEnabled( false );
  79. this.m_oTime.f_setEnabled( false );
  80. }
  81. }
  82. });
  83. /**
  84. Compare values. See {@link cognos.Prompt.Control#f_compare} for details.
  85. @see cognos.Prompt.Control#f_compare
  86. @private
  87. @return {Integer}
  88. */
  89. cognos.Prompt.Control.DateTime.prototype.f_compare = function( v_oValue )
  90. {
  91. var v_iRetval = 1;
  92. if ( v_oValue )
  93. {
  94. v_iRetval = this.m_oDate.f_compare( v_oValue.m_oDate );
  95. if ( v_iRetval === 0 )
  96. {
  97. v_iRetval = this.m_oTime.f_compare( v_oValue.m_oTime );
  98. }
  99. }
  100. return v_iRetval;
  101. };
  102. /**
  103. Sets the JavaScript references used by custom scripts based on generated code from Blaring and before.
  104. (Custom Scripts Workaround)
  105. @private
  106. @return {void}
  107. */
  108. cognos.Prompt.Control.DateTime.prototype.f_CSW_init = function()
  109. {
  110. var v_oDT = this.f_CSW_createJSObject( "selectDateTime", this.m_oControl );
  111. if (v_oDT)
  112. {
  113. if (!v_oDT.m_oDateControl) { v_oDT.m_oDateControl = ( this.m_oDate && this.m_oDate.m_oControl ? this.m_oDate.m_oControl : null ); }
  114. if (!v_oDT.m_oTimeControl) { v_oDT.m_oTimeControl = ( this.m_oTime && this.m_oTime.m_oControl ? this.m_oTime.m_oControl : null ); }
  115. }
  116. };
  117. /**
  118. @private
  119. @param {C_PromptElement} v_el Container.
  120. @return {void}
  121. */
  122. cognos.Prompt.Control.DateTime.prototype.f_drawInput = function( v_el )
  123. {
  124. var v_tbl = $CE( "table", {
  125. "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 0, "cellSpacing": 0,
  126. "class": "clsPromptComponent",
  127. "style": cssParser( this["@style"], "visibility") }, v_el );
  128. var v_tbd = $CE( "tbody", {}, v_tbl );
  129. var v_tr = $CE( "tr", {}, v_tbd );
  130. var v_td = null;
  131. if ( !this.isRequired() && !this["@suppressDisabled"] && !(this.m_bIsAComponent || this["@multiSelect"]) )
  132. {
  133. var v_bDisabled = ( this[K_PRMT_sATTR_DISABLED] === true );
  134. v_td = $CE( "td", {"vAlign": "top"}, v_tr );
  135. $CE( "input", {
  136. "type": "checkbox",
  137. "value": "anyValue",
  138. "id": this.f_getId( "chkAnyValue" ),
  139. "name": this.f_getId( "chkAnyValue" ),
  140. "checked": (v_bDisabled ? K_PRMT_sEMPTY : "checked") }, v_td );
  141. this.m_bDisabled = v_bDisabled;
  142. }
  143. v_td = $CE( "td", {"vAlign": "top"}, v_tr );
  144. v_tbl = $CE( "table", { "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 5, "cellSpacing": 0, "class": "clsBoundingBox pdt" , "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_td );
  145. if ( this.m_bIsAComponent )
  146. {
  147. v_tbl.f_setProperty( "style", "margin-left:0px" );
  148. }
  149. v_tbd = $CE( "tbody", {}, v_tbl );
  150. v_tr = $CE( "tr", {}, v_tbd );
  151. v_td = $CE( "td", {"id": this.f_getId("selectDate"), "vAlign": "top"}, v_tr );
  152. this.m_oDate.f_drawInput( v_td );
  153. if ( this["@selectUI"] == "editBox" )
  154. {
  155. // if 'editBox', calendar goes on top of time, otherwise, they are side by side.
  156. v_tr = $CE( "tr", {}, v_tbd );
  157. }
  158. v_td = $CE( "td", {"id": this.f_getId("selectDate"), "vAlign": "top"}, v_tr );
  159. this.m_oTime.f_drawInput( v_td );
  160. };
  161. /**
  162. @private
  163. @return {void}
  164. */
  165. cognos.Prompt.Control.DateTime.prototype.f_getDisplayValue = function()
  166. {
  167. var v_oDate = this.m_oDate.m_oControl;
  168. var v_oTime = this.m_oTime.m_oControl;
  169. return ( getFormatDate(v_oDate.m_dDate, v_oDate.m_iType, v_oDate.m_sInputOrder) + K_PRMT_sSP + v_oTime.sGetFormatTime() );
  170. };
  171. /**
  172. @private
  173. @return {void}
  174. */
  175. cognos.Prompt.Control.DateTime.prototype.f_getPV = function()
  176. {
  177. return (
  178. this.m_bDisabled ? null : { "use": this.f_getUseValue(), "display": this.f_getDisplayValue() }
  179. );
  180. };
  181. /**
  182. @private
  183. @return {String}
  184. */
  185. cognos.Prompt.Control.DateTime.prototype.f_getUseValue = function()
  186. {
  187. return ( this.m_oDate.m_oControl.sGetValue() + "T" + this.m_oTime.m_oControl.sGetSQLTime() );
  188. };
  189. /**
  190. @private
  191. @return {void}
  192. */
  193. cognos.Prompt.Control.DateTime.prototype.f_setPV = function( v_oPV )
  194. {
  195. var v_sValue = v_oPV["use"];
  196. if ( v_sValue )
  197. {
  198. var v_oDate = this.m_oDate.m_oControl;
  199. var v_oTime = this.m_oTime.m_oControl;
  200. var v_aValues = v_sValue.split(new RegExp("[T\\s]"));
  201. if ( v_aValues.length > 2 )
  202. {
  203. for ( var v_idx = 1; v_idx < v_aValues.length - 1; v_idx++ )
  204. {
  205. // add all Date parts to the first element.
  206. v_aValues[0] += K_PRMT_sSP + (v_aValues[v_idx]).f_trim();
  207. }
  208. v_aValues[0] = v_aValues[0].f_trim();
  209. // move Time part (last value) in slot 1
  210. v_aValues[1] = v_aValues[ v_aValues.length - 1];
  211. }
  212. if ( v_aValues.length >= 1 )
  213. {
  214. v_oDate.setValue( v_aValues[0] );
  215. if ( v_aValues.length >= 2 )
  216. {
  217. v_oTime.setValue( v_aValues[1] );
  218. }
  219. }
  220. }
  221. };
  222. /**
  223. @private
  224. @return {void}
  225. */
  226. cognos.Prompt.Control.DateTime.prototype.f_toggleDisable = function()
  227. {
  228. if ( !this.isRequired() )
  229. {
  230. var v_bState = this.m_bDisabled;
  231. this.m_oDate.f_setEnabled( v_bState );
  232. this.m_oTime.f_setEnabled( v_bState );
  233. this.m_bDisabled = !v_bState;
  234. }
  235. this.checkData();
  236. };
  237. /**
  238. @private
  239. @return {boolean}
  240. */
  241. cognos.Prompt.Control.DateTime.prototype.hasValue = function()
  242. {
  243. return (this.m_bValid);
  244. };
  245. C_DateTime = cognos.Prompt.Control.DateTime; // Keep old reference for backward compatibility with custom scripts.