SelectHTML5DateTime.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.SelectHTML5DateTime = 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.SelectHTML5DateTime";
  22. this.f_parent( v_oProps ); // call parent's initialize()
  23. var v_oPropsComponent = Object.f_extend( {}, v_oProps );
  24. v_oPropsComponent["@required"] = true;
  25. v_oPropsComponent["@hideAdornments"] = true;
  26. v_oPropsComponent.m_bIsAComponent = true;
  27. this.m_oDate = new cognos.Prompt.Control.SelectHTML5Date( v_oPropsComponent );
  28. this.m_oTime = new cognos.Prompt.Control.SelectHTML5Time( v_oPropsComponent );
  29. this.m_oDate.m_oOwner = this;
  30. this.m_oTime.m_oOwner = this;
  31. this.m_bSkipAdornments = true;
  32. this.m_bDisabled = false;
  33. this.f_initCompleted();
  34. if (SYSTEMPROPERTY_TREE_CACHE_ENABLED)
  35. {
  36. this.cacheDateTimeControlName(this.getTracking());
  37. }
  38. },
  39. checkData: function()
  40. {
  41. // We keep a reference to the parent function
  42. // Calling this.m_oFrom functions seems to have a side effect on this.f_parent().
  43. var v_fnParent = this.f_parent;
  44. if ( ( this.isRequired() || !(this.m_bDisabled) ) && !(this.m_oDate.m_bValid && this.m_oTime.m_bValid) ) {
  45. this.m_bValid = false;
  46. } else {
  47. this.m_bValid = true;
  48. }
  49. this.f_parent = v_fnParent; // call parent's checkData using saved reference.
  50. this.f_parent(); // call parent's checkData using saved reference.
  51. return this.m_bValid;
  52. },
  53. clearValues: function()
  54. {
  55. this.f_parent();
  56. this.m_oDate.clearValues();
  57. this.m_oTime.clearValues();
  58. },
  59. f_drawCompleted: function()
  60. {
  61. // We keep a reference to the parent function
  62. // Calling this.m_oFrom.f_drawCompleted seems to have a side effect on this.f_parent().
  63. var v_fnParent = this.f_parent;
  64. var v_chk = $(this.f_getId( "chkAnyValue" ));
  65. if ( v_chk ) {
  66. PRMTUtils.f_addEvent( v_chk, "click", this.f_toggleDisable.bind(this) );
  67. }
  68. this.m_oDate.f_drawCompleted();
  69. this.m_oTime.f_drawCompleted();
  70. this.f_parent = v_fnParent; // call parent's f_drawCompleted using saved reference.
  71. this.f_parent(); // call parent's f_drawCompleted using saved reference.
  72. if ( this[K_PRMT_sATTR_DISABLED] ) {
  73. this.m_oDate.f_setEnabled( false );
  74. this.m_oTime.f_setEnabled( false );
  75. }
  76. }
  77. });
  78. /**
  79. Compare values. See {@link cognos.Prompt.Control#f_compare} for details.
  80. @see cognos.Prompt.Control#f_compare
  81. @private
  82. @return {Integer}
  83. */
  84. cognos.Prompt.Control.SelectHTML5DateTime.prototype.f_compare = function( v_oValue )
  85. {
  86. var v_iRetval = 1;
  87. if ( v_oValue ) {
  88. v_iRetval = this.m_oDate.f_compare( v_oValue.m_oDate );
  89. if ( v_iRetval === 0 ) {
  90. v_iRetval = this.m_oTime.f_compare( v_oValue.m_oTime );
  91. }
  92. }
  93. return v_iRetval;
  94. };
  95. /**
  96. @private
  97. @param {C_PromptElement} v_el Container.
  98. @return {void}
  99. */
  100. cognos.Prompt.Control.SelectHTML5DateTime.prototype.f_drawInput = function( v_el )
  101. {
  102. var v_tbl = $CE( "table", {
  103. "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 0, "cellSpacing": 0,
  104. "class": "clsPromptComponent",
  105. "style": cssParser( this["@style"], "visibility") }, v_el );
  106. var v_tbd = $CE( "tbody", {}, v_tbl );
  107. var v_tr = $CE( "tr", {}, v_tbd );
  108. var v_td = null;
  109. if ( !this.isRequired() && !this["@suppressDisabled"] && !(this.m_bIsAComponent || this["@multiSelect"]) ) {
  110. var v_bDisabled = ( this[K_PRMT_sATTR_DISABLED] === true );
  111. v_td = $CE( "td", {"vAlign": "top"}, v_tr );
  112. $CE( "input", {
  113. "type": "checkbox",
  114. "value": "anyValue",
  115. "id": this.f_getId( "chkAnyValue" ),
  116. "name": this.f_getId( "chkAnyValue" ),
  117. "checked": (v_bDisabled ? K_PRMT_sEMPTY : "checked") }, v_td );
  118. this.m_bDisabled = v_bDisabled;
  119. }
  120. v_td = $CE( "td", {"vAlign": "top"}, v_tr );
  121. v_tbl = $CE( "table", { "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 5, "cellSpacing": 0, "class": "clsBoundingBox pdt" }, v_td );
  122. if ( this.m_bIsAComponent ) {
  123. v_tbl.f_setProperty( "style", "margin-left:0px" );
  124. }
  125. v_tbd = $CE( "tbody", {}, v_tbl );
  126. v_tr = $CE( "tr", {}, v_tbd );
  127. v_td = $CE( "td", {"id": this.f_getId("selectDate"), "vAlign": "top"}, v_tr );
  128. this.m_oDate.f_drawInput( v_td );
  129. v_tr = $CE( "tr", {}, v_tbd );
  130. v_td = $CE( "td", {"id": this.f_getId("selectDate"), "vAlign": "top"}, v_tr );
  131. this.m_oTime.f_drawInput( v_td );
  132. };
  133. /**
  134. @private
  135. @return {void}
  136. */
  137. cognos.Prompt.Control.SelectHTML5DateTime.prototype.f_getDisplayValue = function()
  138. {
  139. return ( this.m_oDate.f_getDisplayValue() + K_PRMT_sSP + this.m_oTime.getTimeFormatForDisplay() );
  140. };
  141. /**
  142. @private
  143. @return {void}
  144. */
  145. cognos.Prompt.Control.SelectHTML5DateTime.prototype.f_getPV = function()
  146. {
  147. return (
  148. this.m_bDisabled ? null : { "use": this.f_getUseValue(), "display": this.f_getDisplayValue() }
  149. );
  150. };
  151. /**
  152. @private
  153. @return {String}
  154. */
  155. cognos.Prompt.Control.SelectHTML5DateTime.prototype.f_getUseValue = function() {
  156. return ( this.m_oDate.f_getUseValue() + "T" + this.m_oTime.getTimeInputValue() );
  157. };
  158. /**
  159. @private
  160. @return {void}
  161. */
  162. cognos.Prompt.Control.SelectHTML5DateTime.prototype.f_setPV = function( v_oPV )
  163. {
  164. var v_sValue = v_oPV["use"];
  165. if ( v_sValue ) {
  166. var v_aValues = v_sValue.split(new RegExp("[T\\s]"));
  167. if ( v_aValues.length > 2 ) {
  168. for ( var v_idx = 1; v_idx < v_aValues.length - 1; v_idx++ ) {
  169. // add all Date parts to the first element.
  170. v_aValues[0] += K_PRMT_sSP + (v_aValues[v_idx]).f_trim();
  171. }
  172. v_aValues[0] = v_aValues[0].f_trim();
  173. // move Time part (last value) in slot 1
  174. v_aValues[1] = v_aValues[ v_aValues.length - 1];
  175. }
  176. if ( v_aValues.length >= 1 ) {
  177. this.m_oDate.f_setDate( v_aValues[0] );
  178. if ( v_aValues.length >= 2 ) {
  179. this.m_oTime.f_setTime( v_aValues[1] );
  180. }
  181. }
  182. }
  183. };
  184. /**
  185. @private
  186. @return {void}
  187. */
  188. cognos.Prompt.Control.SelectHTML5DateTime.prototype.f_toggleDisable = function()
  189. {
  190. if ( !this.isRequired() ) {
  191. var v_bState = this.m_bDisabled;
  192. this.m_oDate.f_setEnabled( v_bState );
  193. this.m_oTime.f_setEnabled( v_bState );
  194. this.m_bDisabled = !v_bState;
  195. }
  196. this.checkData();
  197. };
  198. /**
  199. @private
  200. @return {boolean}
  201. */
  202. cognos.Prompt.Control.SelectHTML5DateTime.prototype.hasValue = function()
  203. {
  204. return (this.m_bValid);
  205. };