/* *+------------------------------------------------------------------------+ *| 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. *| *+------------------------------------------------------------------------+ */ /** @fileOverview Managing Prompts. @namespace cognos.Prompt */ /** @class Prompting Control. Refers to elements in the User Interface used to manipulate values associated to a parameter. There can be one or many controls associated to a parameter. */ cognos.Prompt.Control = new Class({}); cognos.Prompt.Control.isElementInList = function(elem,list) { var aElements = list.split(K_PRMT_TREE_CACHE_LIST_SEP); var bIsInList = false; for (var i = 0; i < aElements.length; i++) { if (aElements[i] == elem) { bIsInList = true; break; } } return bIsInList; }; /** @private @return {void} */ cognos.Prompt.Control.prototype.f_initialize = function( v_oProps ) { // set the default for the customizable labels // C_Choices labels this[K_PRMT_LABEL_CHOICES] = (this._type_ == "cognos.Prompt.Control.Search" && !this.isMulti()? PMT_UIM_CHOICE : PMT_UIM_CHOICES); this[K_PRMT_LABEL_INSERT] = PMT_UIM_INSERT; this[K_PRMT_LABEL_REMOVE] = PMT_UIM_REMOVE; this[K_PRMT_LABEL_CHOICES_SELECT_ALL] = PMT_UIM_SELECTALL; this[K_PRMT_LABEL_CHOICES_DESELECT_ALL] = PMT_UIM_DESELECTALL; this[K_PRMT_LABEL_RESULTS_SELECT_ALL] = PMT_UIM_SELECTALL; this[K_PRMT_LABEL_RESULTS_DESELECT_ALL] = PMT_UIM_DESELECTALL; //range this[K_PRMT_LABEL_RANGE_FROM] = PMT_RNG_FROM; this[K_PRMT_LABEL_RANGE_TO] = PMT_RNG_TO; // the following attr can be overriden by the subclass this[K_PRMT_LABEL_RANGE_LOWEST] = this[K_PRMT_LABEL_RANGE_LOWEST] ? this[K_PRMT_LABEL_RANGE_LOWEST] : PMT_RNG_LOWEST_VALUE; this[K_PRMT_LABEL_RANGE_HIGHEST] = this[K_PRMT_LABEL_RANGE_HIGHEST] ? this[K_PRMT_LABEL_RANGE_HIGHEST] : PMT_RNG_HIGHEST_VALUE; // search this[K_PRMT_LABEL_SEARCH_KEYWORDS] = PMT_SSM_KEYWORDSLABEL; this[K_PRMT_LABEL_SEARCH_INSTRUCTIONS_TEXT] = PMT_SSM_KEYWORDTIP; this[K_PRMT_LABEL_SEARCH_BTN_LABEL] = PMT_SSM_SEARCH; this[K_PRMT_LABEL_SEARCH_OPTIONS_TEXT] = PMT_SSM_OPTIONS; this[K_PRMT_LABEL_SEARCH_RESULTS_TEXT] = PMT_SSM_SEARCHRESULTS; // selectValue this[K_PRMT_LABEL_DESELECT] = PMT_UIM_DESELECT; // interval this[K_PRMT_LABEL_INTERVAL_DAYS] = PMT_SIC_DAYS; this[K_PRMT_LABEL_INTERVAL_HOURS] = PMT_SIC_HOURS; this[K_PRMT_LABEL_INTERVAL_MINUTES] = PMT_SIC_MINUTES; this[K_PRMT_LABEL_INTERVAL_SECONDS] = PMT_SIC_SECONDS; this[K_PRMT_LABEL_INTERVAL_MILLISECONDS] = PMT_SIC_MILLISECONDS; if ( v_oProps ) { Object.f_extend( this, v_oProps ); } this.f_decodeProperty("@parameter"); this.f_decodeProperty("@name"); // this.m_oSubmit is the hidden used to submit (POST) prompt values () this.m_oSubmit = null; this.m_sDivPrefix = "PRMT_"; this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN); this.m_elPrompt = null; this.m_imgError = null; this.m_oChoices = null; this.m_fValidator = null; this.m_bisValidationON = false; this.m_bisGetValuesCall = false; this.m_sImgErrorOn = this.m_sSkin + "/prompting/images/error_timed_small.gif"; this.m_sImgErrorOnRTL = this.m_sSkin + "/prompting/images/error_timed_small_rtl.gif"; this.m_sImgErrorOff = this.m_sSkin + "/prompting/images/error_timed_small_off.gif"; if ( !this["@submitType"] ) { this["@submitType"] = K_PRMT_sXML; } this.m_bValid = false; this.m_dicStrings = { 'lowest': PMT_RNG_LOWEST_VALUE, 'highest': PMT_RNG_HIGHEST_VALUE }; }; cognos.Prompt.Control.prototype.clearSubmit = function() { this.m_oSubmit.value = K_PRMT_sEMPTY; }; /** Triggers verification routine. Used after modifying a selection for example. @private @return {boolean} true if verification passed. false otherwise. */ cognos.Prompt.Control.prototype.checkData = function() { if ( this.m_oRangeControl ) { this.m_oRangeControl.checkData(); } // custom validation through the JS API if (this.m_fValidator && (typeof this.m_fValidator == K_PRMT_sFUNCTION) && !this.m_bisValidationON) { this.m_bisValidationON = true; this.m_bValid = this.m_fValidator(this.getValues()); this.m_bisValidationON = false; } var v_bPass = this.m_bValid; if ( v_bPass ) { this.checkPass(); } else { this.checkFail(); } if ( this.m_oOwner ) { this.m_oOwner.checkData(); } if (v_bPass && (this._type_ != "cognos.Prompt.Control.Search") && (this._type_ != "cognos.Prompt.Control.Time")) { this.cacheControlValue(this._type_); } return v_bPass; }; /** Update UI to show this control as invalid. @private @return {void} */ cognos.Prompt.Control.prototype.checkFail = function() { var v_elWidget = this.f_getErrorWidget(); if ( v_elWidget ) { PRMTUtils.f_addClass( v_elWidget, "clsTextWidgetParseError" ); // Date control is made in CDatePickerIE5 CDatePicker_checkDateFail if ( !(this._type_ == "cognos.Prompt.Control.Date") ) { var v_errorMsg = (this.isEmpty() ? PMT_UIM_MISSING_VALUE : PMT_UIM_INVALID_INPUT ); var v_oPrompt = this.m_elPrompt; var v_sPromptId = this.f_getId(); var v_sPromptSkin = this.m_sSkin; window.setTimeout(function () { PRMTUtils.f_showARIAFail(v_oPrompt, v_sPromptId,v_sPromptSkin, v_errorMsg); },0); } } if ( !this["@hideAdornments"] && this.m_imgError && this.m_imgError.getAttribute("src") != this.m_sImgErrorOn && this.m_imgError.getAttribute("src") != this.m_sImgErrorOnRTL) { var v_el = (this.m_elRangeContainer ? this.m_elRangeContainer : $( this.f_getId(this.m_sDivPrefix) )); var v_sCustomDir = cssParser( this["@style"], "direction", true ); var v_sFinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection(v_el)); this.m_imgError.setAttribute( "src", ( v_sFinalDir == "rtl" ) ? this.m_sImgErrorOnRTL : this.m_sImgErrorOn); } this.notify(gFAIL, this); }; /** Update UI to show this control as valid. @private @return {void} */ cognos.Prompt.Control.prototype.checkPass = function() { var v_elWidget = this.f_getErrorWidget(); if ( v_elWidget ) { PRMTUtils.f_removeClass( v_elWidget, "clsTextWidgetParseError" ); // Date control is made in CDatePickerIE5 CDatePicker_checkDatePass if ( !(this._type_ == "cognos.Prompt.Control.Date") ) { PRMTUtils.f_showARIAPass(this.m_elPrompt, this.f_getId()); } } if ( this.m_oErrorFeedback ) { PRMTUtils.f_removeClass( this.m_oErrorFeedback, this.m_sErrorFeedbackClass ? this.m_sErrorFeedbackClass : "clsFeedbackWidgetParseError" ); } if ( !this["@hideAdornments"] && this.m_imgError && this.m_imgError.getAttribute("src") != this.m_sImgErrorOff ) { this.m_imgError.setAttribute( "src", this.m_sImgErrorOff ); } this.notify(gPASS, this); }; /** Update UI to show this control as required. @private @return {void} */ cognos.Prompt.Control.prototype.checkRequired = function() { if ( this.isRequired() ) { if ( this.m_oChoices && this.m_oChoices.m_elRequired ) { if ( this.m_oChoices.F_IsEmpty() ) { PRMTUtils.f_addClass( this.m_oChoices.m_elRequired, this.m_sErrorFeedbackClass ? this.m_sErrorFeedbackClass : "clsTextWidgetParseError" ); } else { PRMTUtils.f_removeClass( this.m_oChoices.m_elRequired, this.m_sErrorFeedbackClass ); PRMTUtils.f_removeClass( this.m_oChoices.m_elRequired, "clsTextWidgetParseError" ); } } } }; /** Set the aria-required tag to an element. @private @return {void} */ cognos.Prompt.Control.prototype.setAriaRequired = function(v_inputEl) { if (this.isRequired() && v_inputEl) { v_inputEl.setAttribute("aria-required", true); } }; cognos.Prompt.Control.prototype.getWebContentRoot = function() { var v_sWebContentRoot = ".."; var v_oCV = (this.f_getCV ? this.f_getCV() : null); if (v_oCV && v_oCV.getWebContentRoot) { v_sWebContentRoot = v_oCV.getWebContentRoot(); } return v_sWebContentRoot; }; /** [Abstract] This function should be overriden by any sub-classes of cognos.Prompt.Control. Return values: @private @return {Integer} Always returns 1. */ cognos.Prompt.Control.prototype.f_compare = function( v_oValue ) { PRMTUtils.f_error( "PRMT_0006", "f_compare() not implemented! [" + this._type_ + "]"); return 1; }; /** Kicks off the control UI rendering in the container. @private @return {void} */ cognos.Prompt.Control.prototype.f_draw = function() { var v_el = $( this.f_getId(this.m_sDivPrefix) ); if ( !v_el ) { PRMTUtils.f_error( "PRMT_0000", "f_draw():: Can't find " + this.f_getId(this.m_sDivPrefix) ); return; } if (PRMTUtils.f_isHighContrast()) { v_el.className = v_el.className + " clsPrompt_a11y"; } var v_customVAlign = cssParser( this["@style"], "vertical-align", true ); if ( v_customVAlign ) { v_el.style.verticalAlign = v_customVAlign; } var v_sCustomDir = cssParser( this["@style"], "direction", true ); var v_sFinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection(v_el)); if ( v_sFinalDir == "rtl" ) { v_el.style.textAlign = "right"; } else { v_el.style.textAlign = "left"; } var v_tblLayout = $CE( "table", { "border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding": 0, "cellSpacing": 0, "role":K_PRMT_ARIA_ROLE_PRESENTATION, "style": (window.ie?"display:inline-table;vertical-align:top;":"") + cssParser( this["@style"], gsCSS_DEFAULT_STYLE ) }); if ( cssParser( this["@style"], "width" ) && this.n != "selectValue" ) { v_tblLayout.f_setProperty( "width", "100%" ); } if ( this[K_PRMT_sATTR_DISABLED] ) { v_tblLayout.f_appendClass( K_PRMT_sCLS_DISABLED ); } var v_tbdLayout = $CE( "tbody", {}, v_tblLayout ); var v_trLayout = $CE( "tr", {}, v_tbdLayout ); this.f_drawLayout( v_trLayout ); var v_sCSSFloat = cssParser( this["@style"], "float", true ); if ( v_sCSSFloat ) { v_el.style.styleFloat = v_sCSSFloat; //IE v_el.style.cssFloat = v_sCSSFloat; // Firefox } var v_sHTML = this.f_drawParameterValueHolder() + v_tblLayout.f_getHTML(); v_el.innerHTML = ( v_sHTML ); if ( !this.m_oSubmit ) { this.f_setFormSubmit(); } if ( this.m_elPrompt && this.disabled ) { this.m_elPrompt.f_setProperty( "disabled", "disabled" ); } this.f_drawCompleted(); }; /** Renders the adornments for errors and required. @private @param {HTMLelement} v_el Container for this control. @param {boolean} [v_bSkipRequired] Skips rendering of the required flag. Used when controls are set as children of another control (like in ranges). The parent control will handle the 'Required' UI. @return {C_PromptElement} */ cognos.Prompt.Control.prototype.f_drawAdornments = function( v_el, v_bSkipRequired ) { var v_td0 = $CE( "td", {"vAlign": "top", "width": "10px"}, v_el ); if ( this["@hideAdornments"] ) { // This function shouldn't be called when @hideAdornments is set to true, but to preserve some // layout formatting (like in ranges), we are using blank image as spacers. var v_img = $CE( "img", { "src": this.m_sSkin + "/prompting/images/spacer.gif", "height": 10, "width": 10, "border": 0 }, v_td0); if ( !this.m_bIsAComponent ) { // class clsErrorRequired adds padding, which we don't want when the control is a component of an other control. // (ie. Time in a DateTime, text box in a range control...) v_img.f_setProperty( "class", "clsErrorRequired" ); } } else { var v_tblReq = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "width":10, "height":20, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_td0 ); var v_tbdReq = $CE( "tbody", {}, v_tblReq ); if ( this.isRequired() && !v_bSkipRequired ) { var v_trReq = $CE( "tr", {}, v_tbdReq); var v_tdReq = $CE( "td", {"vAlign":"top"}, v_trReq); var v_imgReq = $CE( "img", { "src": this.m_sSkin + "/prompting/images/icon_required.gif", "class": "clsErrorRequired", "vAlign": "top", "height": 10, "width": 10, "border": 0, "alt": "" }, v_tdReq); } var v_trError = $CE( "tr", {}, v_tbdReq ); var v_tdError = $CE( "td", {"vAlign":"top"}, v_trError ); $CE( "img", { "id": this.f_getId( K_PRMT_sIMG_ERROR_PREFIX ), "src": this.m_sSkin + "/prompting/images/error_timed_small_off.gif", "class": "clsErrorRequired", "vAlign": "top", "height": 10, "width": 10, "border": 0, "alt": "" }, v_tdError); } return v_td0; }; /** [Abstract] This function should be overriden by any sub-classes of cognos.Prompt.Control. @private @param {C_PromptElement} v_el Container. @return {void} */ cognos.Prompt.Control.prototype.f_drawInput = function( v_el ) { alert( "cognos.Prompt.Control::f_drawInput" ); }; /** Renders the layout of the control: position lists, adornments and control inputs. @private @param {C_PromptElement} v_trLayout Container for this control. @return {C_PromptElement} */ cognos.Prompt.Control.prototype.f_drawLayout = function( v_trLayout ) { var v_oPrompt = null; if ( this.isMulti() ) { var v_td1 = $CE( "td", {"vAlign":"top", "class": "clsControlLabel pc"}, v_trLayout ); if ( !this.f_isRange() && !this.m_bHasLabel ) { v_td1.f_appendChild( " 
" ); if ( this["@showCondition"]) { // Add a empty (invisible) select, to fix alignment. var v_sel = $CE( "select", {"style":"margin-bottom:5px;visibility:hidden;"}, v_td1 ); var v_opt = $CE( "option", {"value":"null"}, v_sel); v_opt.f_appendText( "x" ); } } var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0}, v_td1 ); var v_tbd = $CE( "tbody", {}, v_tbl ); var v_tr = $CE( "tr", {}, v_tbd ); if ( !(this["@hideAdornments"] || this.m_bSkipAdornments) ) { this.f_drawAdornments( v_tr, true ); } var v_td = $CE( "td", {}, v_tr ); if ( cssParser( this["@style"], "width" ) ) { v_td1.f_setProperty( "width", "100%" ); v_tbl.f_setProperty( "width", "100%" ); v_td.f_setProperty( "width", "100%" ); } v_oPrompt = this.f_drawInput( v_td ); this.setAriaRequired(); this.m_oChoices = new C_Choices( this ); var v_aMO = this.f_getCV().multipleObserverArray; if (v_aMO) { v_aMO.push( this.m_oChoices ); } this.m_oChoices.F_Draw( v_trLayout ); } else { if ( !(this["@hideAdornments"] || this.m_bSkipAdornments) ) { this.f_drawAdornments( v_trLayout ); } v_oPrompt = this.f_drawInput( $CE( "td", {}, v_trLayout ) ); } this.m_elPrompt = v_oPrompt; return (v_oPrompt); }; /** [Abstract] This function should be overriden by any sub-classes of cognos.Prompt.Control. @private @return {void} */ cognos.Prompt.Control.prototype.f_getPV = function() { PRMTUtils.f_error( "PRMT_0004", "f_getPV() not implemented! [" + this._type_ + "]"); }; /** Return a localized string. @private @param {String} v_sKey Key for the localized string. @return {String} Returns the value associated with the key. If no value, return the key. */ cognos.Prompt.Control.prototype.f_getString = function( v_sKey ) { var v_s = this.m_dicStrings[v_sKey]; if ( typeof v_s == K_PRMT_sUNDEFINED ) { v_s = v_sKey; } return v_s; }; /** Returns the last validity state. It doesn't check the data first. Call checkData() before if required. @private @return {boolean} */ cognos.Prompt.Control.prototype.getValid = function() { return ( this.m_oChoices ? this.m_oChoices.f_getValid() : this.m_bValid ); }; /** Return the first element matching the tag name in the control. @private @param {String} v_sTag Tag name. @return {HTMLelement[]} Null if not found. */ cognos.Prompt.Control.prototype.f_getChildByTagName = function( v_sTag ) { var v_oPrompt = this; var v_oChild = null; if ( v_oPrompt.c && v_oPrompt.c.length ) { for ( var v_idx = 0; v_idx < v_oPrompt.c.length; v_idx++ ) { if ( v_oPrompt.c[ v_idx ].n == v_sTag ) { v_oChild = v_oPrompt.c[ v_idx ]; if ( !(v_oChild && v_oChild.c && v_oChild.c.length > 0) ) { // clear v_oChild, is empty v_oChild = null; } // Stop after the first find, we should have only one node called 'selectChoices'. break; } } } return v_oChild; }; /** Return the <selectChoices> node. @private @return {HTMLelement} Null if not found. */ cognos.Prompt.Control.prototype.getSelectChoices = function() { return ( this.f_getChildByTagName( "selectChoices" ) ); }; /** By default, returns true if one or more value are returned by the control. @private @return {boolean} Always false. */ cognos.Prompt.Control.prototype.hasValue = function() { var v_aPV = this.f_getPV(); return ( v_aPV && v_aPV.length > 0 ); }; /** * By default, returns true if the control does not return any value. * * @private * @return {boolean} */ cognos.Prompt.Control.prototype.isEmpty = function() { return !this.hasValue(); }; /** Query Studio feature only. @private @return {boolean} */ cognos.Prompt.Control.prototype.isExclusive = function() { var v_sel = $( this.f_getId("oExcludeSelectedValues") ); return ( v_sel && v_sel.options && v_sel.options[1] && v_sel.options[1].selected ? true : false ); }; /** Check if multi-selection if enabled. @private @return {boolean} true if this control accepts multiple selections. */ cognos.Prompt.Control.prototype.isMulti = function() { return ( this["@multiSelect"] === true ); }; /** Check if this is a range control. @private @return {boolean} */ cognos.Prompt.Control.prototype.f_isRange = function() { return ( this["@range"] === true ); }; /** Check if this control needs to have a selection to be valid. @private @return {boolean} true if this control is satisfied. */ cognos.Prompt.Control.prototype.isRequired = function() { return ( this["@required"] === true ); }; /** Check if this control is valid, i.e. ready to submit. @private @return {boolean} true if this control has a valid selection. */ cognos.Prompt.Control.prototype.isValid = function() { this.checkData(); return (this.m_bValid===true); }; /** @private @param {integer} iState @param {object} oNotifier @return {void} */ cognos.Prompt.Control.prototype.notify = function(iState, oNotifier) { var v_oCV = this.f_getCV(); if (v_oCV && typeof v_oCV.notify == K_PRMT_sFUNCTION) { v_oCV.notify(iState, oNotifier); } }; /** @private @return {String} XML */ cognos.Prompt.Control.prototype.preProcess = function() { if ( !this.m_oSubmit ) { PRMTUtils.f_error( "PRMT_0005", "preProcess():: No m_oSubmit defined. [" + this._type_ + "]"); return; } var v_aPV = ( this.m_oChoices ? this.m_oChoices.f_getPV() : this.f_getPV() ); var v_sXML = null; if ( v_aPV && typeof v_aPV == K_PRMT_sOBJECT ) { v_sXML = cognos.Value.toXML(v_aPV); } else if ( typeof v_aPV == K_PRMT_sSTRING ) { v_sXML = v_aPV; } if ( v_sXML === null ) { v_sXML = K_PRMT_sEMPTY; } addSelectChoices( this.m_oSubmit, v_sXML ); return (v_sXML); }; /** @private @return {void} */ cognos.Prompt.Control.prototype.removeSelectedChoices = function() { var iFirstSelection = null; if (typeof this.m_oLstChoices == K_PRMT_sOBJECT) { iFirstSelection = this.m_oLstChoices.selectedIndex; } if (typeof iFirstSelection != "number") { return; } if (iFirstSelection != -1) { for (var idxSelection = this.m_oLstChoices.options.length-1; idxSelection > -1 ; idxSelection--) { if (this.m_oLstChoices.options[idxSelection].selected) { this.m_oLstChoices.options[idxSelection] = null; } } } else { var sPrompt_Select_Item_First = "sPrompt_Select_Item_First"; if (typeof PMT_UIM_sPrompt_Select_Item_First == K_PRMT_sSTRING) { sPrompt_Select_Item_First = PMT_UIM_sPrompt_Select_Item_First; } PRMTUtils.f_error("PRMT_0001", sPrompt_Select_Item_First); } this.checkData(); }; /** @private @param {String} sId New Id. @return {void} */ cognos.Prompt.Control.prototype.setCVId = function(sId) { if (typeof sId == K_PRMT_sSTRING && sId !== K_PRMT_sEMPTY & sId != K_PRMT_sUNDEFINED) { this.m_sCVId = sId; } }; /** Query Studio feature only. @private @param {boolean} v_bExclusive @return {void} */ cognos.Prompt.Control.prototype.setExclusive = function( v_bExclusive ) { var v_sel = $( this.f_getId("oExcludeSelectedValues") ); if ( v_sel && v_sel.options ) { var v_idx = ( v_bExclusive ? 1 : 0 ); if ( v_sel.options[v_idx] ) { v_sel.options[v_idx].selected = true; } } }; /** @private @return {void} */ cognos.Prompt.Control.prototype.f_setFormSubmit = function() { var v_frm = this.f_CSW_GetForm(); var sParamName = this.getParameterName(); if (v_frm) { this.m_oSubmit = v_frm.elements[ sParamName ]; } if (this.m_oSubmit) { this.m_oSubmit.value = K_PRMT_sEMPTY; } else { if ( document.readyState && document.readyState != "complete" ) { // Need DOM ready for IE. setTimeout( this.f_setFormSubmit.bind(this), 100 ); return; } this.m_oSubmit = PRMTUtils.f_createElement( "input", {"name": sParamName, "type":"hidden", "value":K_PRMT_sEMPTY}, v_frm ); } }; /** Modifies the selection of the control. @private @param {ParameterValues[]} Array of parameter values (cognos.SingleValue or cognos.RangeValue). If the control doesn't accept multiple selections, only the first value will be considered. @return {void} */ cognos.Prompt.Control.prototype.setParameterValues = function( v_aParmValueItems ) { var v_oChoiceControl = this.m_oChoices; if ( v_oChoiceControl ) { v_oChoiceControl.F_SelectAll(); v_oChoiceControl.F_Remove(); for ( var v_idx = 0; v_idx < v_aParmValueItems.length; v_idx++ ) { v_oChoiceControl.F_AddPV( v_aParmValueItems[ v_idx ] ); } v_oChoiceControl.checkData(); } else if (v_aParmValueItems.length) { this.f_setPV( v_aParmValueItems[0] ); } }; /** Finish drawing, set events. @private @return {void} */ cognos.Prompt.Control.prototype.f_drawCompleted = function() { if ( this.m_oChoices ) { this.m_oChoices.F_DrawCompleted(); } var img = $( this.f_getId(K_PRMT_sIMG_ERROR_PREFIX) ); if ( img ) { this.m_imgError = img; } if ( !this.m_oRangeControl ) { this.f_setSelectChoices(); } if (window.JsUnitException) { this.checkData(); } else { // 575695 - Need to call checkData() in a different thread. // We can't just call checkData() through setTimeout, JsUnit tests will fail. setTimeout( this.checkData.bind(this), 20 ); } if (typeof SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS != K_PRMT_sUNDEFINED && SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS && typeof this.f_CSW_init == K_PRMT_sFUNCTION) { this.f_CSW_init(); } }; /** Set up event callbacks for this control. Supported events: onChange, onFail, onValid, onLoad?. @param {String} evt Event type @param {function} fct The Javascript function used as callback. @return {void} @example Change the background to red when control's selection is invalid:
  ctrl.addEvent( "onFail", function() {
    var ctrl = cognos.Report.getReport().prompt.getControlByName('X');
    ctrl.setStyle("background-color:red;");
  }
); */ cognos.Prompt.Control.prototype.addEvent = function(evt, fct) {}; /** If the control doesn't support multiple values, only the first one will be considered. @param {cognos.Value[]} aValues New values to use for this control. @return {void} */ cognos.Prompt.Control.prototype.addValues = function( aValues ) { var v_iLimit = ( this.isMulti() ? aValues.length : 1); for (var v_idx = 0; v_idx < v_iLimit; v_idx++) { this.f_setPV( aValues[v_idx] ); if ( this.m_oChoices ) { this.m_oChoices.F_Insert(); } } this.checkData(); }; /** If the control doesn't support multiple values, only the first one will be considered. @param {cognos.Value[]} aValues New values to use for this control. @return {void} */ cognos.Prompt.Control.prototype.setValues = function( aValues ) { this.clearValues(); this.addValues(aValues); }; /** Change the validation function for controls. Returning false will update control's UI to indicate there is a validation error and will disable the Insert button when used in a multi-selection scenario. @param {function} oFct A function that would take the user input as parameter and must return a boolean value. @return {void} @example // Make sure we have a valid Postal Code (ie. A1A 1A1) textBox.setValidator( function (sInput) { var rePostalCodeFormat = new RegExp( "[a-z][0-9][a-z] [0-9][a-z][0-9]", "gi" ); if ( rePostalCodeFormat.test(sInput) ) { return true; } return false; } ); */ cognos.Prompt.Control.prototype.setValidator = function(oFct) { this.m_fValidator = oFct; }; /** Traps whether the user has pressed the delete key in the choices box. [IE specific] @private @param {Integer} iKeyCode @return {void} */ cognos.Prompt.Control.prototype.catchDeleteKey = function(iKeyCode) { //catch the Delete key code if (iKeyCode == 46 && typeof this.remove == K_PRMT_sFUNCTION) { this.remove(this.m_oLstChoices); } }; /** Clear (or deselect) all values for this control. @return {void} */ cognos.Prompt.Control.prototype.clearValues = function() { if ( this.m_oChoices ) { this.m_oChoices.F_SelectAll(); this.m_oChoices.F_Remove(); } }; /** Adds a javascript reference using 'prefix' and this control's name (Custom Scripts Workaround). @private @param {String} v_sPrefix Prefix of the 'input' control to use in the formWarpRequest @param {HTMLElement} v_obj HTML element to set to v_sName. If missing, using this.m_elPrompt. @return {object} The newly associated object, incidently 'this'. */ cognos.Prompt.Control.prototype.f_CSW_createJSObject = function( v_sPrefix, v_obj ) { if ( this["@name"] ) { var v_sName = v_sPrefix + this["@name"]; window[v_sName] = (v_obj ? v_obj : this); return (window[v_sName]); } return null; }; /** Set the value of an input in the FormWarpRequest form. Adds the reference if missing. (Custom Scripts Workaround) @private @return {HTMLelement} The 'FormWarpRequest' element. */ cognos.Prompt.Control.prototype.f_CSW_GetForm = function() { var v_doc = document; var v_sFWR = "formWarpRequest"; var v_f = v_doc[v_sFWR + this.f_getCVId()]; if ( !v_f && v_doc[v_sFWR] ) { v_f = v_doc[v_sFWR]; v_doc[v_sFWR].submit = f_CSW_tryCVPromptAction; } return v_f; }; /** Set the value of an input in the FormWarpRequest form. Adds the reference if missing (Custom Scripts Workaround). @private @param {String} v_sPrefix Prefix of the 'input' control to use in the formWarpRequest @param {HTMLElement} [v_el] HTML element to set to v_sName. If missing, using this.m_elPrompt. @return {void} */ cognos.Prompt.Control.prototype.f_CSW_SetFormElement = function(v_sPrefix, v_el) { if ( this["@name"] ) { var v_sName = v_sPrefix + this["@name"]; var v_f = this.f_CSW_GetForm(); if ( v_f ) { v_f[v_sName] = ( v_el ? v_el : this.m_elPrompt ); } if (this.m_sCSW_rangeSuffix) { // Used to fix references in ranges v_sName = v_sPrefix + this.m_sCSW_rangeSuffix + this["@name"]; window[v_sName] = ( v_el ? v_el : this.m_elPrompt ); if ( v_f ) { v_f[v_sName] = window[v_sName]; } } if ( this["@parameter"] ) { v_sName = "p_" + this["@parameter"]; if ( !v_f[v_sName] ) { v_f[v_sName] = this.m_oSubmit; } } } }; /** Checks and decodes a property if necessary (U003 encoding for < and >). @private @param {String} v_sPropertyName The property name we need to decode. @return {void} */ cognos.Prompt.Control.prototype.f_decodeProperty = function(v_sPropertyName) { if ( typeof this[v_sPropertyName] == K_PRMT_sSTRING ) { this[v_sPropertyName] = sDecodeU003( this[v_sPropertyName] ); } }; /** Generates a hidden input field to store parameter values in the UI. @private @return {C_PromptElement} */ cognos.Prompt.Control.prototype.f_drawParameterValueHolder = function() { var v_sHiddenInput = ""; var v_sCVID = this.f_getCVId(); var v_frm = $("formWarpRequest" + v_sCVID); if ( v_frm && v_frm.elements && !v_frm.elements[this.getParameterName()] ) { var v_hidden = $CE( "input", { "type": "hidden", "name": this.getParameterName() }); v_sHiddenInput = v_hidden.f_getHTML(); } return v_sHiddenInput; }; /** @private @return {CCognosViewer} */ cognos.Prompt.Control.prototype.f_getCV = function() { var oRetVal = window; if (typeof this.m_oCV == K_PRMT_sOBJECT) { oRetVal = this.m_oCV; } else { try { oRetVal = eval("oCV" + this.f_getCVId()); if (typeof oRetVal == K_PRMT_sOBJECT) { this.m_oCV = oRetVal; } } catch (e) { oRetVal = window; } } return oRetVal; }; /** @private @return {void} */ cognos.Prompt.Control.prototype.f_setPromptManager = function(oPromptManager) { this.m_oPromptManager = oPromptManager; } /** @private @return {PromptManager} */ cognos.Prompt.Control.prototype.f_getPromptManager = function() { return this.m_oPromptManager; } cognos.Prompt.Control.prototype.f_isBUX = function(){ var v_oCV = this.f_getCV(); return (typeof v_oCV == K_PRMT_sOBJECT && v_oCV.isBux? true :false); }; cognos.Prompt.Control.prototype.getGateway = function() { var v_sGateway = document.location.pathname; var v_oCV = (this.f_getCV ? this.f_getCV() : null); if (v_oCV && v_oCV.getGateway) { v_sGateway = v_oCV.getGateway(); } return v_sGateway; }; /** @private @return {String} */ cognos.Prompt.Control.prototype.f_getCVId = function() { return this.CVId; }; /** Retrieves the control's ID based on its id, name or parameter properties. @private @return {String} */ cognos.Prompt.Control.prototype.f_getControlId = function() { var v_sId = K_PRMT_sEMPTY; if ( this._id_ ) { v_sId = this._id_; } else if ( this.id ) { v_sId = this.id; } else if ( this["@parameter"] ) { v_sId = this["@parameter"]; } else if ( this.name ) { v_sId = this.name; } return v_sId; }; /** Return the error widget for this control. @private @return {HTMLelement} */ cognos.Prompt.Control.prototype.f_getErrorWidget = function() { var v_elWidget = this.m_elPrompt; // When control is a Text inside a Interval, use self for showing errors, otherwise use its parent. // It means the border will be under the control (as opposed to be the control's border in case of intervals). if ( !(this.m_oOwner && this.m_oOwner.n == "selectInterval") && v_elWidget && v_elWidget.parentNode ) { v_elWidget = v_elWidget.parentNode; } return v_elWidget; }; /** Returns the ID for this control. @private @param {String} [v_sPrefix] Prefix to add to the ID/name. @return {String} Prompt Control ID. */ cognos.Prompt.Control.prototype.f_getId = function( v_sPrefix ) { return ( (v_sPrefix ? v_sPrefix : K_PRMT_sEMPTY) + this.f_getControlId() ); }; /** Called after initialisation is completed and initiate the contol rendering. @private @return {void} */ cognos.Prompt.Control.prototype.f_initCompleted = function() { if ( !this.m_oRangeControl && !this.m_bIsAComponent ) { this.f_draw(); } }; /** @private @return {void} */ cognos.Prompt.Control.prototype.f_setPV = function() { PRMTUtils.f_log( "PRMT_0003", "f_setPV() is not implemented for this class. [" + this._type_ + "]"); }; /** @private @return {void} */ cognos.Prompt.Control.prototype.f_setSelectChoices = function() { var v_oSC = this.getSelectChoices(); var v_oPV = null; if ( v_oSC ) { if ( this.m_oChoices ) { if ( v_oSC.c && v_oSC.c.length > 0){ this.m_oChoices.f_setSelectChoices(v_oSC.c); } } else if ( !this.m_bIsAComponent ) { this.f_setPV( cognos.Value.getValue( v_oSC ) ); } } }; /** Finds a HTML element contained in this control. @private @param {String} v_sName Name of the HTML element. @return {HTMLelement} */ cognos.Prompt.Control.prototype.getChildByName = function( v_sName ) { var v_oChild = null; if ( this.c ) { for (var v_idxChild = 0; v_idxChild < this.c.length; v_idxChild++) { if ( this.c[v_idxChild].n == v_sName ) { v_oChild = this.c[v_idxChild]; break; } } } return v_oChild; }; /** Returns the control's name, set in Report Studio. @return {String} */ cognos.Prompt.Control.prototype.getName = function() { return ( typeof this["@name"] == K_PRMT_sUNDEFINED ? null : this["@name"] ); }; /** Returns the parameter associated to this control. @return {cognos.Prompt.Parameter} */ cognos.Prompt.Control.prototype.getParameter = function() {}; /** Returns the name of the parameter associated to this control. @private @return {String} Parameter name */ cognos.Prompt.Control.prototype.getParameterName = function() { var sParamName = "p_" + this["@parameter"]; if ( this.suppressExtraPromptNames ) { sParamName = sParamName.substring(1); } return sParamName; }; /** Returns the parameter values selected in this control. @private @return {ParameterValues[]} Array of parameter values (cognos.SingleValue or cognos.RangeValue). */ cognos.Prompt.Control.prototype.getParameterValues = function() { return ( this.m_oChoices ? this.m_oChoices.getParameterValues() : this.f_getPV() ); }; /** @private @return {HTMLelement[]} */ cognos.Prompt.Control.prototype.getSelectOptions = function() { if ( !this.m_aSO ) { this.m_aSO = this.getChildByName("selectOptions"); if (this.m_aSO && this.m_aSO.c) { this.m_aSO = this.m_aSO.c; } } return (this.m_aSO); }; /** Returns the current value for the control. Always returns an array for simplicity, even if single select and/or there is only one value selected. See {@link cognos.Value} for the format of the returned values. @return {cognos.Value[]} @example */ cognos.Prompt.Control.prototype.getValues = function(v_allOptions) { this.m_bisGetValuesCall = true; var v_aValues = ( this.m_oChoices ? this.m_oChoices.getValues() : this.f_getPV(true,v_allOptions) ); if ( !(v_aValues instanceof Array) ) { if (v_aValues) { v_aValues = [v_aValues]; } else { v_aValues = []; } } this.m_bisGetValuesCall = false; return v_aValues; }; /** Returns the name of the parameter associated to this control. @private @return {Object} cascadeOn Parameter */ cognos.Prompt.Control.prototype.getCascadeOnParameter = function() { var result = null; var v_promptManager = this.f_getPromptManager(); if(this["@cascadeOn"]){ var v_cascadeParamName = "p_" + this["@cascadeOn"]; result = v_promptManager.getParameterByName(v_cascadeParamName); } return result; }; cognos.Prompt.Control.prototype.getTracking = function() { var tracking_info = K_PRMT_sEMPTY; var oCV = this.f_getCV(); if (oCV && typeof oCV.getTracking == K_PRMT_sFUNCTION) { tracking_info = oCV.getTracking(); } else { // can't find tracking in CCognosViewer, trying with a form var oForm = document.getElementById("formWarpRequest" + this.f_getCVId()); if (!oForm) { oForm = document.getElementById("formWarpRequest"); } if (oForm) { if (typeof oForm.m_tracking != K_PRMT_sUNDEFINED) { tracking_info = oForm.m_tracking.value; } else if (typeof oForm.tracking != K_PRMT_sUNDEFINED) { tracking_info = oForm.tracking.value; } else if (typeof tracking != K_PRMT_sUNDEFINED) { tracking_info = tracking; } } } return tracking_info; }; cognos.Prompt.Control.prototype.cacheControlValue = function (sType) { if (SYSTEMPROPERTY_TREE_CACHE_ENABLED) { var sTracking = this.getTracking(); if (sTracking.length == 0) return; var selectDateTimeControl = this.getCachedDateTimePromptNames(sTracking); if (selectDateTimeControl != null) { if (cognos.Prompt.Control.isElementInList(this.getName(),selectDateTimeControl)) { // this is a DateTime control if (sType != "cognos.Prompt.Control.DateTime") { // getting a notification of a "has-a" control so ignore return; } } } // to avoid recursion DateTime control where attempt to get value calls checkData if ((typeof cognos.Prompt.Control.prototype.cacheControlValue.running != 'undefined') && cognos.Prompt.Control.prototype.cacheControlValue.running) { return; } else { cognos.Prompt.Control.prototype.cacheControlValue.running = true; } if (this.cacheUseValue(sTracking)) { this.cachePromptName(sTracking); } cognos.Prompt.Control.prototype.cacheControlValue.running = false; } }; cognos.Prompt.Control.prototype.getUseValues = function() { var sValues = ""; var v_aValues = this.getValues(); if (v_aValues) { for (var j = 0; j < v_aValues.length; j++) { var v_oValue = v_aValues[j]; sValues += v_oValue["use"]; } } return sValues }; cognos.Prompt.Control.prototype.cacheDateTimeControlName = function (sTracking) { var sCacheKey = this.generateUniqueDateTimeKey(sTracking); this.cacheControlName(sTracking,sCacheKey); }; cognos.Prompt.Control.prototype.cacheControlName = function (sTracking,sCacheKey) { var sPreviousValue = window.sessionStorage.getItem(sCacheKey); var bAddToList = true; if (sPreviousValue != null) { if (sPreviousValue.length != 0) { // only add if name is not already in list bAddToList = !cognos.Prompt.Control.isElementInList(this.getName(), sPreviousValue); if (bAddToList) { sPreviousValue += K_PRMT_TREE_CACHE_LIST_SEP; } } if (bAddToList) { sPreviousValue += this.getName(); } } else { sPreviousValue = this.getName(); } if (bAddToList) { this.saveToSessionStorage(sCacheKey,sPreviousValue,sTracking); } }; cognos.Prompt.Control.prototype.cacheUseValue = function (sTracking) { var bReturnValue = false; var sValues = this.getUseValues(); if (sValues && sValues.length > 0) { var sCacheKey = this.generateUniqueValueKey(sTracking); this.saveToSessionStorage(sCacheKey,sValues,sTracking); bReturnValue = true; } return bReturnValue; }; cognos.Prompt.Control.prototype.cachePromptName = function (sTracking) { var sCacheKey = this.generateUniquePromptKey(sTracking); this.cacheControlName(sTracking,sCacheKey); }; cognos.Prompt.Control.prototype.saveToSessionStorage = function(sCacheKey, sValue, sTrackingInfo) { // save tracking so we can clear our entries if (!sTrackingInfo) { sTrackingInfo = this.getTracking(); } var sPreviousValue = ""; sPreviousValue = window.sessionStorage.getItem(K_PRMT_TREE_CACHE_TRACKING); if (!sPreviousValue) { this.writeToSessionStorage(K_PRMT_TREE_CACHE_TRACKING,sTrackingInfo); } else { if (!cognos.Prompt.Control.isElementInList(sTrackingInfo, sPreviousValue)) { sPreviousValue += K_PRMT_TREE_CACHE_LIST_SEP; sPreviousValue += sTrackingInfo; // add tracking info this.writeToSessionStorage(K_PRMT_TREE_CACHE_TRACKING,sPreviousValue); } } this.writeToSessionStorage(sCacheKey, sValue); }; cognos.Prompt.Control.prototype.writeToSessionStorage = function(key, value, bNoRetryWhenFull) { if ((key == null) || (value == null)) return; if ((key == "") || (value == "")) return; try { window.sessionStorage.setItem(key,value); } catch(e) { if (!bNoRetryWhenFull) { this.cleanCacheValues(); this.saveToSessionStorage(key,value,true); } } }; cognos.Prompt.Control.prototype.cleanCacheValues = function() { if (SYSTEMPROPERTY_TREE_CACHE_ENABLED) { try { var sKnownTrackingIds = window.sessionStorage.getItem(K_PRMT_TREE_CACHE_TRACKING); var aTrackingIds = sKnownTrackingIds.split(K_PRMT_TREE_CACHE_LIST_SEP); for (var i = 0; i < aTrackingIds.length; i++) { var sTrackingId = aTrackingIds[i]; // build key for prompt names var sCacheKeyPromptNames = K_PRMT_TREE_CACHE_NAMES + sTrackingId; var sSavedPromptNames = window.sessionStorage.getItem(sCacheKeyPromptNames); var aPromptNames = sSavedPromptNames.split(K_PRMT_TREE_CACHE_LIST_SEP); for (var j = 0; j < aPromptNames.length; j++) { var sPromptName = aPromptNames[j]; // delete the display value var sPromptDisplayKey = K_PRMT_TREE_CACHE_VALUES + sTrackingId + sPromptName; window.sessionStorage.removeItem(sPromptDisplayKey); } // delete the prompt names window.sessionStorage.removeItem(sCacheKeyPromptNames); // delete the DateTime prompt names sCacheKeyPromptNames = K_PRMT_TREE_CACHE_SELECTDATETIME + sTrackingId; window.sessionStorage.removeItem(sCacheKeyPromptNames); } // delete the tracking ids window.sessionStorage.removeItem(K_PRMT_TREE_CACHE_TRACKING); } catch(e) { } } }; cognos.Prompt.Control.prototype.getCachedDateTimePromptNames = function(sTracking) { var sCacheKey = K_PRMT_TREE_CACHE_SELECTDATETIME + sTracking; var promptNames = window.sessionStorage.getItem(sCacheKey); return promptNames; }; cognos.Prompt.Control.prototype.getCachedPromptNames = function(sTracking) { var sCacheKey = K_PRMT_TREE_CACHE_NAMES + sTracking; var promptNames = window.sessionStorage.getItem(sCacheKey); return promptNames; }; cognos.Prompt.Control.prototype.getCachedDisplayValues = function (sTracking, sPrmtName) { var sCacheKey = K_PRMT_TREE_CACHE_VALUES + sTracking + sPrmtName; var sPromptValues = window.sessionStorage.getItem(sCacheKey); return sPromptValues; }; cognos.Prompt.Control.prototype.generateUniqueDateTimeKey = function(sTracking) { return K_PRMT_TREE_CACHE_SELECTDATETIME + sTracking; }; cognos.Prompt.Control.prototype.generateUniqueValueKey = function(sTracking) { return K_PRMT_TREE_CACHE_VALUES + sTracking + this.getName(); }; cognos.Prompt.Control.prototype.generateUniquePromptKey = function(sTracking) { return K_PRMT_TREE_CACHE_NAMES + sTracking; }; /** Sets a property for one control. Each control will defined what property they are 'listening' to. For examaple: This is to be able to set 'caseInsensitive' option for a Search control. Supported properties: [defined by the type of controls] @param {String} sName Property name. @param {object} oValue Can be a string, number, boolean, object. @return {void} @example */ cognos.Prompt.Control.prototype.setProperty = function(sName, oValue) {}; /** Overrides CSS style for a control. The control will decide which part of it is updated based on the style passed in. For example: You can't specify the width of the text box a date control here, setting the width will resize the whole calendar. Supported styles: background(-*), border(-*), color, display, font(-*), height (absolute sizes), overflow, text-decoration, text-transform, visibility, width (absolute sizes). @param {String} sStyle CSS string. @return {void} @example */ cognos.Prompt.Control.prototype.setStyle = function(sStyle) {}; /** The following function is included for the Cognos Mobile case, where the MooTools Javascript framework has also defined a function $( id ), which has a document context that is not able to find the element in the DOM. Mobile will be upgrading MooTools in their next release, and their $( id ) method is aliased in later version when a $ function already exists. So once the upgrade is done, this code will be able to be removed. @private @param id - identifier for the element being requested @return the element requested, or null */ cognos.Prompt.Control.prototype.$ = function(id) { var v_el = $( id ); if(!v_el){ v_el = document.getElementById(id); } return v_el; }; var C_PromptControl = cognos.Prompt.Control; // Keep old reference for backward compatibility with custom scripts.