/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| BI and PM: prmt *| (C) Copyright IBM Corp. 2002, 2013 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ /** @private @class */ cognos.Prompt.Control.SelectHTML5Time = cognos.Prompt.Control.f_extend({ f_initialize: function( v_oProps ) { this[K_PRMT_LABEL_RANGE_LOWEST] = PMT_RNG_EARLIEST_TIME; this[K_PRMT_LABEL_RANGE_HIGHEST] = PMT_RNG_LATEST_TIME; this._type_ = "cognos.Prompt.Control.SelectHTML5Time"; this.f_parent( v_oProps ); // call parent's initialize() //@display indicates which time parts are used for display; secs and millisecs are optional if ( typeof this["@display"] == K_PRMT_sSTRING ) { this["@display"] = parseInt( this["@display"], 10 ); } if ( typeof this["@display"] != "number" || isNaN(this["@display"]) ) { this["@display"] = ( this["@showMilliseconds"] ? 0 : (this["@showSeconds"] ? 1 : 2) ); } //@type is used for formatting the time display value if ( typeof this["@type"] == K_PRMT_sSTRING ) { this["@type"] = parseInt( this["@type"], 10 ); } if ( typeof this["@type"] != "number" || isNaN(this["@type"]) ) { if (typeof g_24HourClock != K_PRMT_sUNDEFINED && g_24HourClock.toString().toLowerCase() == "true") { this["@type"] = 2; } else { this["@type"] = (typeof g_AMPMLocation != K_PRMT_sUNDEFINED && g_AMPMLocation == 'left' ? 1 : 0); } } //@clockMode indicates if the clock is to display live time of static time if ( this["@clockMode"] == "static" ) { this["@clockMode"] = 0; } else if ( this["@clockMode"] == "live" ) { this["@clockMode"] = 1; } else if ( typeof this["@clockMode"] == K_PRMT_sSTRING ) { this["@clockMode"] = parseInt( this["@clockMode"], 10 ); } if ( typeof this["@clockMode"] != "number" || isNaN(this["@clockMode"]) ) { this["@clockMode"] = 0; } this.m_bSkipAdornments = true; this.m_bDisabled = false; this.m_bValid = false; 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; //Value in the time form input field var v_sValue = this.m_elPrompt.value; if ( ( this.isRequired() || !(this.m_bDisabled) ) && !(this.m_oTimeHelper.bCheckTime(v_sValue, this.m_iDisplay)) ) { this.m_bValid = false; } else { this.m_bValid = true; } 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; if (!this["@timeZone"]) { this["@timeZone"] = "GMT"; } if (!this["@hourFormat"]) { this["@hourFormat"] = "hh"; } if (!this["@minuteFormat"]) { this["@minuteFormat"] = "mm"; } if (!this["@secondFormat"]) { this["@secondFormat"] = "ss"; } this.m_oTimeHelper = new PRMT_TimeHelper(this.isRequired()); this.m_oForm = $(this.f_getId("_Time")); this.m_elPrompt = $(this.f_getId("selectMobileTime_")); //Clock Mode //0 = static //1 = live this.m_iLiveClockMode = this["@clockMode"]; if (this.m_iLiveClockMode==1){ this.funcInt = setInterval( this.f_drawLiveTime.bind(this), 1000 ); } //what is being displayed //0 = h:m:s:ms //1 = h:m:s //2 = h:m this.m_iDisplay = this["@display"]; this.f_setInputEvents(); if(this["@defaultValue"]){ this.f_setTime(this["@defaultValue"]); } else { this.f_setTime("00:00:00.000"); } this.f_refreshTime(); this.f_parent = v_fnParent; // call parent's f_drawCompleted using saved reference. this.f_parent(); // call parent's f_drawCompleted using saved reference. } }); /** @private @param {C_PromptElement} v_el Container. @return {void} */ cognos.Prompt.Control.SelectHTML5Time.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_tr = $CE( "tr", {}, v_tbd ); if ( this["@required"] && !this.isMulti() && !this["@hideAdornments"]) { this.f_drawAdornments(v_tr); } var v_td = $CE( "td", {"id": this.f_getId("timeEditBox"), "noWrap": "noWrap"}, v_tr ); var v_sClass = "clsHTML5Input"; var v_sCustomDir = cssParser( this["@style"], "direction", true ); var v_Container = (this.m_elRangeContainer ? this.m_elRangeContainer : $( this.f_getId(this.m_sDivPrefix) )); var v_FinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection(v_Container)); v_sStyle = "direction:ltr"; if (v_FinalDir == "rtl") { v_sStyle += ";text-align:right"; v_sClass += "RTL"; } var v_oControl = null; //v_fStep is a floating point value representing the number of seconds per increment or "step" in the time control var v_fStep = 60.0; if ( this["@display"] == 1) { v_fStep = 1.0; }else if ( this["@display"] === 0) { v_fStep = 0.001; } $CE( "input", {"id": this.f_getId("selectMobileTime_"), "type": "time", "step": v_fStep, "class": v_sClass, "style": v_sStyle}, v_td ); $CE("input", {"type": "hidden", "id": this.f_getId("_Time"), "value":"00:00:00.000"}, v_el ); v_oControl = $(this.f_getId("selectMobileTime_")); return v_oControl; }; /** @private @return {void} */ cognos.Prompt.Control.SelectHTML5Time.prototype.f_clear = function( ) { this.m_dTime = null; this.m_oForm.value = K_PRMT_sEMPTY; this.m_elPrompt.value = K_PRMT_sEMPTY; }; /** @private @param {String} sTime @return {void} */ cognos.Prompt.Control.SelectHTML5Time.prototype.f_setTime = function( sTime ) { this.m_dTime = this.m_oTimeHelper.dParseTime (sTime); this.m_oForm.value = this.m_oTimeHelper.getTimeFormatForSubmit(this.m_dTime); this.m_elPrompt.value = this.m_oTimeHelper.getTimeFormatForInput(this.m_dTime, this.m_iDisplay); }; /** @private @return {cognos.Value} */ cognos.Prompt.Control.SelectHTML5Time.prototype.f_getPV = function() { var v_bHasValue = this.hasValue(); return ( (v_bHasValue)? { "use": this.m_oForm.value, "display": this.m_oTimeHelper.getTimeFormatForDisplay(this.m_dTime, this.m_iDisplay) } : null); }; cognos.Prompt.Control.SelectHTML5Time.prototype.getTimeFormatForDisplay = function() { return this.m_oTimeHelper.getTimeFormatForDisplay(this.m_dTime, this.m_iDisplay); } cognos.Prompt.Control.SelectHTML5Time.prototype.getTimeInputValue = function() { return this.m_oForm.value; } /** @private @param {cognos.Value} v_oPV @return {void} */ cognos.Prompt.Control.SelectHTML5Time.prototype.f_setPV = function( v_oPV ) { var v_sValue = v_oPV["use"]; if ( v_sValue ) { var v_aValues = v_sValue.split(new RegExp("[T\\s]")); if ( v_aValues.length >= 0 ) { this.f_setTime( v_aValues[ v_aValues.length-1 ] ); } } }; /** Compare values. See {@link cognos.Prompt.Control#f_compare} for details. @see cognos.Prompt.Control#f_compare @private @return {Integer} */ cognos.Prompt.Control.SelectHTML5Time.prototype.f_compare = function( v_oValue ) { var v_iRetval = 1; if ( v_oValue ) { var v_dThis = this.m_oTimeHelper.dParseTime( this.m_oForm.value ); var v_dCompareTo = v_oValue.m_oTimeHelper.dParseTime( v_oValue.m_oForm.value ); var v_iThis = v_dThis.getTime(); var v_iCompareTo = v_dCompareTo.getTime(); if ( v_iCompareTo > v_iThis ) { v_iRetval = -1; } else if ( v_iCompareTo == v_iThis ) { v_iRetval = 0; } } return v_iRetval; }; /** Set up event handlers for time input @return {void} */ cognos.Prompt.Control.SelectHTML5Time.prototype.f_setInputEvents = function() { //Update the prompt values when user leave the control PRMTUtils.f_addEvent( this.m_elPrompt, "blur", this.f_updateControl.bind(this) ); //PRMTUtils.f_addEvent( this.m_elPrompt, "input", this.f_updateControl.bind(this) ); if(PRMTUtils.f_isMobileDevice()){ //Stop the live clock when user gives focus to the control // Limitation of mobile Safari: only fires focus and blur events PRMTUtils.f_addEvent( this.m_elPrompt, "focus", this.f_stopLiveTime.bind(this) ); }else{ //Stop the live clock on change of input in other browsers PRMTUtils.f_addEvent( this.m_elPrompt, "change", this.f_stopLiveTime.bind(this) ); PRMTUtils.f_addEvent( this.m_elPrompt, "input", this.f_stopLiveTime.bind(this) ); } }; cognos.Prompt.Control.SelectHTML5Time.prototype.f_updateControl = function() { this.f_setTime(this.m_elPrompt.value); this.f_refreshTime(); }; /** @private @return {boolean} */ cognos.Prompt.Control.SelectHTML5Time.prototype.hasValue = function() { return !(this.m_oForm.value == K_PRMT_sEMPTY); }; //render live time cognos.Prompt.Control.SelectHTML5Time.prototype.f_drawLiveTime = function() { this.m_dTime = new Date(); this.m_oForm.value = this.m_oTimeHelper.getTimeFormatForSubmit(this.m_dTime); this.m_elPrompt.value = this.m_oTimeHelper.getTimeFormatForInput(this.m_dTime, this.m_iDisplay); }; //stop live time cognos.Prompt.Control.SelectHTML5Time.prototype.f_stopLiveTime = function() { if (this.m_iLiveClockMode==1) { if ( this.m_iDisplay > 1 ) { // Can't change the seconds in the UI, so reset to 0. this.m_dTime.setSeconds(0); } if ( this.m_iDisplay > 0 ) { // Can't change the milliseconds in the UI, so reset to 0. this.m_dTime.setMilliseconds(0); } this.m_iLiveClockMode=0; clearInterval(this.funcInt); } }; //render the values for the control based on display settings cognos.Prompt.Control.SelectHTML5Time.prototype.f_refreshTime = function() { this.checkData(); if (this.m_bValid) { this.m_oForm.value = this.m_oTimeHelper.getTimeFormatForSubmit(this.m_dTime); this.m_elPrompt.value = this.m_oTimeHelper.getTimeFormatForInput(this.m_dTime, this.m_iDisplay); } else { this.f_clear(); } }; /** @private @return {void} */ cognos.Prompt.Control.SelectHTML5Time.prototype.f_setEnabled = function( v_bState ) { this.m_bDisabled = !v_bState; if (v_bState) { this.m_elPrompt.removeAttribute("disabled"); } else { this.m_elPrompt.setAttribute("disabled",true); } };