/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| BI and PM: prmt *| (C) Copyright IBM Corp. 2002, 2020 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ /** @private @class */ cognos.Prompt.Control.Time = 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.Time"; this.f_parent( v_oProps ); // call parent's initialize() if ( this["@selectTimeUI"] ) { this["@selectUI"] = this["@selectTimeUI"]; } if ( !this["@selectUI"] ) { this["@selectUI"] = "clock"; } 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) ); } 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); } } 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.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; this.m_bValid = ( this.m_oControl.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.f_setTime( "00:00:00.000" ); }, 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_divClock = $( this.f_getId("clock") ); if ( v_divClock ) { this.m_clockDisplay = new CClock( v_divClock, null, this.f_getId("clockDisplay"), this["@clockMode"], this["@showSeconds"] ); } if (!this["@timeZone"]) { this["@timeZone"] = "GMT"; } if (!this["@hourFormat"]) { this["@hourFormat"] = "hh"; } if (!this["@minuteFormat"]) { this["@minuteFormat"] = "mm"; } if (!this["@secondFormat"]) { this["@secondFormat"] = "ss"; } var v_oControl = new CTimePicker( null, //oSubmit, $(this.f_getId("_Time")), //oForm, $(this.f_getId("hours")), //oHours, $(this.f_getId("minutes")), //oMinutes, $(this.f_getId("seconds")), //oSeconds, $(this.f_getId("milliseconds")), //oMilliseconds, $(this.f_getId("AMPM")), //oAMPM, null, //oImgTest, $(this.f_getId("clock")), //oClockBox, $(this.f_getId("editBox")), //oEditBox, this.f_getId(), //sRef, this["@type"], //iType, this["@display"], //iDisplay, (this["@selectUI"] != "editBox"), //bInline, this["@timeZone"], //sTimeZone, this["@hourFormat"], //sHourFormat, this["@minuteFormat"], //sMinuteFormat, this["@secondFormat"], //sSecondFormat, this["@clockMode"], //iMode, this.m_clockDisplay, //sClock, this["@defaultValue"], //sTime, this["@required"], //bRequired, null, //sSubmitType, this["CVId"], // sCVId this.f_getControlId(), // sbaseId this ); v_oControl.m_oParent = this; var v_td = $(this.f_getId("btnTimeUp")); if ( v_td ) { PRMTUtils.f_addEvent( v_td, "click", v_oControl.timeUp.bind(v_oControl) ); if (window.ie) { PRMTUtils.f_addEvent( v_td, "dblclick", v_oControl.timeUp.bind(v_oControl) ); } } v_td = $(this.f_getId("btnTimeDown")); if ( v_td ) { PRMTUtils.f_addEvent( v_td, "click", v_oControl.timeDown.bind(v_oControl) ); if (window.ie) { PRMTUtils.f_addEvent( v_td, "dblclick", v_oControl.timeDown.bind(v_oControl) ); } } var v_cb = $( this.f_getId( "chkAnyValue" ) ); if ( v_cb ) { PRMTUtils.f_addEvent( v_cb, "click", this.f_toggleDisable.bind(this) ); } this.m_oControl = v_oControl; this.f_setFocusEvents( v_oControl.m_oHours ? v_oControl.m_oHours.id : this.f_getId("hours"), v_oControl.bCheckHour ); this.f_setFocusEvents( v_oControl.m_oMinutes ? v_oControl.m_oMinutes.id : this.f_getId("minutes"), v_oControl.bCheckMinute ); this.f_setFocusEvents( v_oControl.m_oSeconds ? v_oControl.m_oSeconds.id : this.f_getId("seconds"), v_oControl.bCheckSecond ); this.f_setFocusEvents( v_oControl.m_oMilliseconds ? v_oControl.m_oMilliseconds.id : this.f_getId("milliseconds"), v_oControl.bCheckMillisecond ); this.f_setFocusEvents( v_oControl.m_oAMPM ? v_oControl.m_oAMPM.id : this.f_getId("AMPM"), v_oControl.bCheckAMPM ); // link a11y label if it exists using FOR var v_a11yLabel = $( this.f_getId("PRMT_LBL_") ); if ( v_a11yLabel && !v_a11yLabel.getAttribute("for")) { v_a11yLabel.setAttribute("for", this.f_getId("hours")); } this.f_parent = v_fnParent; // call parent's f_drawCompleted using saved reference. this.f_parent(); // call parent's f_drawCompleted using saved reference. } }); /** Compare values. See {@link cognos.Prompt.Control#f_compare} for details. @see cognos.Prompt.Control#f_compare @private @return {Integer} */ cognos.Prompt.Control.Time.prototype.f_compare = function( v_oValue ) { var v_iRetval = 1; if ( v_oValue ) { var v_dThis = dParseTime( this.m_oControl.sGetValue() ); var v_dCompareTo = dParseTime( v_oValue.m_oControl.sGetValue() ); 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; }; /** 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.Time.prototype.f_CSW_init = function() { this.f_CSW_createJSObject( "timePicker", this.m_oControl ); if (this["@selectUI"] == "clock") { this.f_CSW_createJSObject( "clockDisplay", this.m_clockDisplay ); } }; /** @private @param {C_PromptElement} v_el Container. @param {String} v_sId @param {String} v_sValue @param {String} v_sSeparator @param {Integer} v_iSize @return {void} */ cognos.Prompt.Control.Time.prototype.f_drawField = function( v_el, v_sId, v_sValue, v_sSeparator, v_iSize, inputLabel ) { if ( v_sSeparator ) { $CE( "span", {"class": "clsColon pcl"}, v_el ).f_appendText( v_sSeparator ); } var newInput = $CE( "input", { "id": this.f_getId( v_sId ), "name": this.f_getId( v_sId ), "class": "clsSelectTimeControl", "style": "border:none;", "value": v_sValue, "size": ( v_iSize ? v_iSize : 2 ), "maxLength": ( v_iSize ? v_iSize : 2 ) }, $CE( "span", {}, v_el ) ); if (inputLabel != null){ newInput.f_setProperty("aria-label", inputLabel); } if (this.isRequired()) { newInput.f_setProperty("aria-required", "true"); } }; /** @private @param {C_PromptElement} v_el Container. @return {void} */ cognos.Prompt.Control.Time.prototype.f_drawInput = function( v_el ) { var v_oInput = null; 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 ); var v_td = null; var v_ipt = null; if ( this["@required"] == false && !this["@suppressDisabled"] && !this.m_bIsAComponent ) { v_td = $CE( "td", {"vAlign": "top"}, v_tr ); v_ipt = $CE( "input", { "type": "checkbox", "value": "anyValue", "id": this.f_getId( "chkAnyValue" ), "checked": "checked" }, v_td ); } v_td = $CE( "td", {"vAlign": "top"}, v_tr ); v_tbl = $CE( "table", { "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 0, "cellSpacing": 0, "class": "clsSelectTime", "role":K_PRMT_ARIA_ROLE_PRESENTATION }, v_td ); v_tbd = $CE( "tbody", {}, v_tbl ); var v_div = null; if ( this["@selectUI"] == "clock" ) { v_tr = $CE( "tr", {"class": "clsClockPosition"}, v_tbd ); v_td = $CE( "td", { "height": "100%", "colSpan": 3 }, v_tr ); v_div = $CE( "div", {"class": "clsClockBlock", "align": "center"}, v_td ); v_div = $CE( "div", {"id": this.f_getId("clock"), "class": "clsClock"}, v_div ); v_div.f_appendText(K_PRMT_sEMPTY); } v_tr = $CE( "tr", {}, v_tbd ); if ( this["@required"] && !this.isMulti() && !this["@hideAdornments"]) { this.f_drawAdornments(v_tr); } v_td = $CE( "td", {"id": this.f_getId("timeEditBox"), "noWrap": "noWrap"}, v_tr ); var v_sClass = "clsSelectTimeEditBox" + ( this["@display"] === 0 && (this["@type"] === 0 || this["@type"] == 1) ? "Extend" : K_PRMT_sEMPTY ); 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"; } v_div = $CE( "div", {"id": this.f_getId("editBox"), "class": v_sClass, "style": v_sStyle}, v_td ); if ( this["@type"] == 1) { this.f_drawField( v_div, "AMPM", "PM", null, null, PMT_DTP_TIME_AMPM_ENTRY_FIELD ); } this.f_drawField( v_div, "hours", 12, null, null, PMT_DTP_TIME_HOURS_ENTRY_FIELD ); this.f_drawField( v_div, "minutes", 10, K_PRMT_sCOLON , null, PMT_DTP_TIME_MINUTES_ENTRY_FIELD); if ( this["@display"] == 1 || this["@display"] === 0) { this.f_drawField( v_div, "seconds", 59, K_PRMT_sCOLON, null, PMT_DTP_TIME_SECONDS_ENTRY_FIELD ); } if ( this["@display"] === 0) { this.f_drawField( v_div, "milliseconds", "000", K_PRMT_sDOT, 3, PMT_DTP_TIME_MILLISECONDS_ENTRY_FIELD ); } if ( this["@type"] === 0 ) { this.f_drawField( v_div, "AMPM", "PM" , null, null, PMT_DTP_TIME_AMPM_ENTRY_FIELD); } v_td = $CE( "td", {}, v_tr ); v_tbl = $CE( "table", { "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 0, "cellSpacing": 0, "role":K_PRMT_ARIA_ROLE_PRESENTATION }, v_td ); v_tbd = $CE( "tbody", {}, v_tbl ); v_tr = $CE( "tr", {}, v_tbd ); v_td = $CE( "td", { "id": this.f_getId("btnTimeUp"), "width": 15, "align": "right", "class": "clsToolbarButton", "onmouseover": "buttonOver(this)", "onmouseout": "buttonOut(this)", "onmousedown": "buttonOver(this)", "aria-label": PMT_DTP_TIME_BUTTON_INCREMENT, "role":K_PRMT_TREE_ROLE_BUTTON}, v_tr ); var v_img = $CE( "div", { "class" : "clsBtnTimeUp", "border": 0, "align": "top", "alt": ""}, v_td ); v_tr = $CE( "tr", {}, v_tbd ); v_td = $CE( "td", { "id": this.f_getId("btnTimeDown"), "width": 15, "align": "right", "class": "clsToolbarButton", "onmouseover": "buttonOver(this)", "onmouseout": "buttonOut(this)", "onmousedown": "buttonOver(this)", "aria-label": PMT_DTP_TIME_BUTTON_DECREMENT, "role":K_PRMT_TREE_ROLE_BUTTON}, v_tr ); var v_img = $CE( "div", { "class" : "clsBtnTimeDown", "border": 0, "align": "top", "alt": ""}, v_td ); $CE("input", {"type": "hidden", "id": this.f_getId("_Time"), "value":"00:00:00.000"}, v_el ); return v_oInput; }; /** @private @return {cognos.Value} */ cognos.Prompt.Control.Time.prototype.f_getPV = function() { var v_cb = $( this.f_getId( "chkAnyValue" ) ); var v_bEnabled = ( v_cb && !v_cb.checked ? false : true); return (v_bEnabled? { "use": this.m_oControl.sGetSQLTime(), "display": this.m_oControl.sGetFormatTime() }: null); }; /** Event handler for a keypress event which actually will be keyup for IE and keydown for FF @private @return {void} */ cognos.Prompt.Control.Time.prototype.f_keyPress = function(event) { /* Hack to fix RTC 11990: Time prompt does not retain typed in value in FireFox. extensions.js overrides Function.prototype.bind; the implementation of which preserves function arguments from previous calls to the same function...that behaviour cannot be fixed without affecting other prompt controls. */ var eventArg = event; if(arguments.length != 0) { eventArg = arguments[arguments.length - 1]; } this.m_oControl.keyPress(eventArg, this); this.m_fctKeyUp(); }; /** @private @return {void} */ cognos.Prompt.Control.Time.prototype.f_setCurrentFocus = function() { this.m_oControl.setCurrentFocus(this); }; /** Change control state. @private @param {boolean} v_bState @return {void} */ cognos.Prompt.Control.Time.prototype.f_setEnabled = function( v_bState ) { if ( v_bState ) { this.m_oControl.enable(); } else { this.m_oControl.disable(); } }; /** Map a KeyUp/Keydown(IE/FF) event handler. @private @param {String} v_sId @param {String} v_fKeyUpHandler @return {void} */ cognos.Prompt.Control.Time.prototype.f_setFocusEvents = function( v_sId, v_fKeyUpHandler ) { var v_el = $( v_sId ); if ( v_el ) { v_el.m_oControl = this.m_oControl; if ( v_fKeyUpHandler ) { v_el.m_fctKeyUp = v_fKeyUpHandler.bind(this.m_oControl); } PRMTUtils.f_addEvent( v_el, "keyup", this.f_keyPress.bind(v_el) ); PRMTUtils.f_addEvent( v_el, "blur", this.m_oControl.refreshTime.bind(this.m_oControl) ); PRMTUtils.f_addEvent( v_el, "focus", this.f_setCurrentFocus.bind(v_el) ); } }; /** @private @param {cognos.Value} v_oPV @return {void} */ cognos.Prompt.Control.Time.prototype.f_setPV = function( v_oPV ) { var v_sValue = v_oPV["use"]; if ( v_sValue ) { var v_oTime = this.m_oControl; var v_aValues = v_sValue.split(new RegExp("[T\\s]")); if ( v_aValues.length >= 0 ) { this.f_setTime( v_aValues[ v_aValues.length-1 ] ); } } }; /** @private @param {String} v_sTime @return {void} */ cognos.Prompt.Control.Time.prototype.f_setTime = function( v_sTime ) { this.m_oControl.setValue( v_sTime ); }; /** @private @return {void} */ cognos.Prompt.Control.Time.prototype.f_toggleDisable = function() { var v_cb = $( this.f_getId( "chkAnyValue" ) ); if ( v_cb ) { this.m_oControl.toggleDisable( v_cb.checked ); } }; /** @private @return {boolean} */ cognos.Prompt.Control.Time.prototype.hasValue = function() { return (this.m_bValid); }; var C_Time = cognos.Prompt.Control.Time; // Keep old reference for backward compatibility with custom scripts.