/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| BI and PM: prmt *| (C) Copyright IBM Corp. 2002, 2016 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ /** @class @private */ cognos.Prompt.Control.DateTime = cognos.Prompt.Control.f_extend({ f_initialize: function( v_oProps ) { this[K_PRMT_LABEL_RANGE_LOWEST] = PMT_RNG_EARLIEST_DATE; this[K_PRMT_LABEL_RANGE_HIGHEST] = PMT_RNG_LATEST_DATE; this._type_ = "cognos.Prompt.Control.DateTime"; this.f_parent( v_oProps ); // call parent's initialize() if ( this["@selectDateTimeUI"] ) { this["@selectUI"] = this["@selectDateTimeUI"]; } var v_oPropsComponent = Object.f_extend( {}, v_oProps ); if ( this["@selectUI"] == "editBox" ) { v_oPropsComponent["@selectUI"] = "editBox"; } v_oPropsComponent["@required"] = true; v_oPropsComponent["@hideAdornments"] = true; v_oPropsComponent.m_bIsAComponent = true; v_oPropsComponent.m_oOwner = this; this.m_oDate = new cognos.Prompt.Control.Date( v_oPropsComponent ); this.m_oTime = new cognos.Prompt.Control.Time( v_oPropsComponent ); this.m_bSkipAdornments = true; this.m_bDisabled = false; this.f_initCompleted(); if (SYSTEMPROPERTY_TREE_CACHE_ENABLED) { this.cacheDateTimeControlName(this.getTracking()); } }, 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; this.m_bValid = (this.m_oDate.m_bValid && this.m_oTime.m_bValid); 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.m_oDate.clearValues(); this.m_oTime.clearValues(); }, 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; var v_chk = $(this.f_getId( "chkAnyValue" )); if ( v_chk ) { PRMTUtils.f_addEvent( v_chk, "click", this.f_toggleDisable.bind(this) ); } this.m_oDate.f_drawCompleted(); this.m_oTime.f_drawCompleted(); this.f_parent = v_fnParent; // call parent's f_drawCompleted using saved reference. this.f_parent(); // call parent's f_drawCompleted using saved reference. if ( this[K_PRMT_sATTR_DISABLED] ) { this.m_oDate.f_setEnabled( false ); this.m_oTime.f_setEnabled( false ); } } }); /** Compare values. See {@link cognos.Prompt.Control#f_compare} for details. @see cognos.Prompt.Control#f_compare @private @return {Integer} */ cognos.Prompt.Control.DateTime.prototype.f_compare = function( v_oValue ) { var v_iRetval = 1; if ( v_oValue ) { v_iRetval = this.m_oDate.f_compare( v_oValue.m_oDate ); if ( v_iRetval === 0 ) { v_iRetval = this.m_oTime.f_compare( v_oValue.m_oTime ); } } 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.DateTime.prototype.f_CSW_init = function() { var v_oDT = this.f_CSW_createJSObject( "selectDateTime", this.m_oControl ); if (v_oDT) { if (!v_oDT.m_oDateControl) { v_oDT.m_oDateControl = ( this.m_oDate && this.m_oDate.m_oControl ? this.m_oDate.m_oControl : null ); } if (!v_oDT.m_oTimeControl) { v_oDT.m_oTimeControl = ( this.m_oTime && this.m_oTime.m_oControl ? this.m_oTime.m_oControl : null ); } } }; /** @private @param {C_PromptElement} v_el Container. @return {void} */ cognos.Prompt.Control.DateTime.prototype.f_drawInput = function( v_el ) { var v_tbl = $CE( "table", { "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 0, "cellSpacing": 0, "class": "clsPromptComponent", "style": cssParser( this["@style"], "visibility") }, v_el ); var v_tbd = $CE( "tbody", {}, v_tbl ); var v_tr = $CE( "tr", {}, v_tbd ); var v_td = null; if ( !this.isRequired() && !this["@suppressDisabled"] && !(this.m_bIsAComponent || this["@multiSelect"]) ) { var v_bDisabled = ( this[K_PRMT_sATTR_DISABLED] === true ); v_td = $CE( "td", {"vAlign": "top"}, v_tr ); $CE( "input", { "type": "checkbox", "value": "anyValue", "id": this.f_getId( "chkAnyValue" ), "name": this.f_getId( "chkAnyValue" ), "checked": (v_bDisabled ? K_PRMT_sEMPTY : "checked") }, v_td ); this.m_bDisabled = v_bDisabled; } v_td = $CE( "td", {"vAlign": "top"}, v_tr ); v_tbl = $CE( "table", { "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 5, "cellSpacing": 0, "class": "clsBoundingBox pdt" , "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_td ); if ( this.m_bIsAComponent ) { v_tbl.f_setProperty( "style", "margin-left:0px" ); } v_tbd = $CE( "tbody", {}, v_tbl ); v_tr = $CE( "tr", {}, v_tbd ); v_td = $CE( "td", {"id": this.f_getId("selectDate"), "vAlign": "top"}, v_tr ); this.m_oDate.f_drawInput( v_td ); if ( this["@selectUI"] == "editBox" ) { // if 'editBox', calendar goes on top of time, otherwise, they are side by side. v_tr = $CE( "tr", {}, v_tbd ); } v_td = $CE( "td", {"id": this.f_getId("selectDate"), "vAlign": "top"}, v_tr ); this.m_oTime.f_drawInput( v_td ); }; /** @private @return {void} */ cognos.Prompt.Control.DateTime.prototype.f_getDisplayValue = function() { var v_oDate = this.m_oDate.m_oControl; var v_oTime = this.m_oTime.m_oControl; return ( getFormatDate(v_oDate.m_dDate, v_oDate.m_iType, v_oDate.m_sInputOrder) + K_PRMT_sSP + v_oTime.sGetFormatTime() ); }; /** @private @return {void} */ cognos.Prompt.Control.DateTime.prototype.f_getPV = function() { return ( this.m_bDisabled ? null : { "use": this.f_getUseValue(), "display": this.f_getDisplayValue() } ); }; /** @private @return {String} */ cognos.Prompt.Control.DateTime.prototype.f_getUseValue = function() { return ( this.m_oDate.m_oControl.sGetValue() + "T" + this.m_oTime.m_oControl.sGetSQLTime() ); }; /** @private @return {void} */ cognos.Prompt.Control.DateTime.prototype.f_setPV = function( v_oPV ) { var v_sValue = v_oPV["use"]; if ( v_sValue ) { var v_oDate = this.m_oDate.m_oControl; var v_oTime = this.m_oTime.m_oControl; var v_aValues = v_sValue.split(new RegExp("[T\\s]")); if ( v_aValues.length > 2 ) { for ( var v_idx = 1; v_idx < v_aValues.length - 1; v_idx++ ) { // add all Date parts to the first element. v_aValues[0] += K_PRMT_sSP + (v_aValues[v_idx]).f_trim(); } v_aValues[0] = v_aValues[0].f_trim(); // move Time part (last value) in slot 1 v_aValues[1] = v_aValues[ v_aValues.length - 1]; } if ( v_aValues.length >= 1 ) { v_oDate.setValue( v_aValues[0] ); if ( v_aValues.length >= 2 ) { v_oTime.setValue( v_aValues[1] ); } } } }; /** @private @return {void} */ cognos.Prompt.Control.DateTime.prototype.f_toggleDisable = function() { if ( !this.isRequired() ) { var v_bState = this.m_bDisabled; this.m_oDate.f_setEnabled( v_bState ); this.m_oTime.f_setEnabled( v_bState ); this.m_bDisabled = !v_bState; } this.checkData(); }; /** @private @return {boolean} */ cognos.Prompt.Control.DateTime.prototype.hasValue = function() { return (this.m_bValid); }; C_DateTime = cognos.Prompt.Control.DateTime; // Keep old reference for backward compatibility with custom scripts.