123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| BI and PM: prmt
- *| (C) Copyright IBM Corp. 2002, 2018
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- function C_Choices( v_oPrompt )
- {
- this.m_oPrompt = v_oPrompt;
- this.m_selList = null;
- this.m_tpl_optionHTML = ['<option value="','','" display="','','" pvxml="','','" pvJSON="','','" style="white-space:pre"','','>','','</option>'];
- };
- /**
- See {@link cognos.Prompt.Control.addValues} for more info.
- @param {cognos.Value[]}
- @return {void}
- */
- C_Choices.prototype.addValues = function( aValues )
- {
- for (var v_idx = 0; v_idx < aValues.length; v_idx++)
- {
- this.F_AddPV( aValues[v_idx] );
- }
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.checkData = function()
- {
- this.f_updateWidth();
- var v_ef = this.m_oErrorFeedback;
- if ( v_ef )
- {
- var v_sClass = ( this.m_sErrorFeedbackClass ? this.m_sErrorFeedbackClass : "clsFeedbackWidgetParseError" );
- if ( this.m_oPrompt.isRequired() && this.F_IsEmpty() )
- {
- PRMTUtils.f_addClass( v_ef, v_sClass );
- PRMTUtils.f_showARIAFail(this.m_selList, this.f_getId(), this.m_oPrompt.m_sSkin, PMT_UIM_MISSING_VALUE, K_PRMT_ALERT_CHOICES_SUFFIX);
- }
- else
- {
- PRMTUtils.f_removeClass( v_ef, v_sClass );
- PRMTUtils.f_showARIAPass(this.m_selList, this.f_getId(), K_PRMT_ALERT_CHOICES_SUFFIX);
- }
- }
- this.m_oPrompt.checkData();
- };
- /**
- @private
- @return {boolean}
- */
- C_Choices.prototype.checkInsertRemove = function()
- {
- this.f_updateButton( this.m_btnRemove, this.f_hasSelection() );
- var v_oP = this.m_oPrompt;
- this.f_updateButton( this.m_btnInsert, v_oP.hasValue() );
- return this.f_getValid();
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_updateButton = function(v_btn, v_bState)
- {
- if ( v_btn )
- {
- var v_oImgEl = (v_btn.firstChild && v_btn.firstChild.tagName == "IMG"? v_btn.firstChild : v_btn.childNodes[1]);
- var v_bInsertType = (v_btn.id.indexOf("INSERT")!= -1? true:false);
- var v_dir = this.m_dir;
- if ( v_bState && !this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
- {
- v_btn.disabled = false;
- v_oImgEl.className = ( (v_bInsertType && v_dir== "ltr") || (!v_bInsertType && v_dir== "rtl") ? "clsInsertImg" : "clsRemoveImg" );
- }
- else
- {
- v_btn.className = "clsInsertRemoveButton";
- v_btn.disabled = true;
- if (v_oImgEl) {
- v_oImgEl.className = ( (v_bInsertType && v_dir== "ltr") || (!v_bInsertType && v_dir== "rtl") ? "clsInsertImgDisabled" : "clsRemoveImgDisabled" );
- }
- }
- }
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_updateWidth = function()
- {
- var v_selList = this.m_selList;
- if ( v_selList && !this["@listWidth"] )
- {
- v_selList.style.overflow = "auto";
- v_selList.style.width = "auto";
- if ( v_selList.offsetWidth < 200 )
- {
- v_selList.style.width = "200px";
- }
- if (window.ie)
- {
- if (v_selList.parentNode && v_selList.parentNode.style)
- {
- // 560392: make sure the table's width follows the select's width
- v_selList.parentNode.style.width = "200px";
- v_selList.parentNode.style.width = "auto";
- }
- else {
- // 585565
- return;
- }
- }
- if (v_selList.offsetWidth < 200)
- {
- setTimeout( this.f_updateWidth.bind( this ), 100 );
- }
- }
- };
- /**
- @private
- @return {boolean}
- */
- C_Choices.prototype.F_IsEmpty = function()
- {
- if ( this.m_selList && this.m_selList.options && this.m_selList.options.length > 0 )
- {
- return false;
- }
- return true;
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_Draw = function( v_el )
- {
- this.f_drawInsertRemoveButtons( v_el );
- this.f_drawList( $CE( "td", {"vAlign":"top"}, v_el ) );
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_getId = function( v_sPrefix )
- {
- return ( this.m_oPrompt.f_getId( v_sPrefix ) );
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_DrawCompleted = function()
- {
- var v_btnInsert = $( this.f_getId(K_PRMT_sLIST_BUTTON_INSERT_PREFIX) );
- if ( v_btnInsert )
- {
- v_btnInsert.m_oEH = this;
- PRMTUtils.f_addEvent( v_btnInsert, "click", this.F_Insert.bind(this) );
- this.m_btnInsert = v_btnInsert;
- }
- var v_btnRemove = $( this.f_getId(K_PRMT_sLIST_BUTTON_REMOVE_PREFIX) );
- if ( v_btnRemove )
- {
- v_btnRemove.m_oEH = this;
- PRMTUtils.f_addEvent( v_btnRemove, "click", this.F_Remove.bind(this) );
- this.m_btnRemove = v_btnRemove;
- }
- var v_selList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
- if ( v_selList )
- {
- v_selList.m_oPrompt = this.m_oPrompt;
- PRMTUtils.f_addEvent( v_selList, "change", this.checkData.bind(this) );
- this.m_selList = v_selList;
- }
- // dblclick
- var v_resultList = $( this.f_getId(K_PRMT_sSV_PREFIX) );
- if ( v_resultList )
- {
- PRMTUtils.f_addEvent( v_resultList, "dblclick", this.F_Insert.bind(this) );
- }
- var v_choicesList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
- if ( v_choicesList )
- {
- PRMTUtils.f_addEvent( v_choicesList, "dblclick", this.F_Remove.bind(this) );
- }
- var v_link = $( this.f_getId(K_PRMT_sLIST_LINK_SELECT_PREFIX) );
- if ( v_link )
- {
- v_link.m_oEH = this;
- PRMTUtils.f_addEvent( v_link, "click", this.F_SelectAll.bind(this) );
- }
- var v_link = $( this.f_getId(K_PRMT_sLIST_LINK_DESELECT_PREFIX) );
- if ( v_link )
- {
- v_link.m_oEH = this;
- PRMTUtils.f_addEvent( v_link, "click", this.F_DeselectAll.bind(this) );
- }
- this.m_oErrorFeedback = $( this.f_getId( K_PRMT_sLIST_FEEDBACK_PREFIX ) );
- this.checkData();
- if (typeof SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS != K_PRMT_sUNDEFINED && SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS)
- {
- this.f_CSW_init();
- }
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_drawInsertRemoveButtons = function( v_el )
- {
- var v_iTopPadding = ( this.m_oPrompt["@showCondition"] ? 42 : 16 );
- var v_td0 = $CE( "td", {"vAlign": "top", "class": "clsButtonLeftRightPadding", "style":"padding-top:" + v_iTopPadding + "px"}, v_el );
- var v_sCustomDir = cssParser( this.m_oPrompt["@style"], "direction", true );
- this.m_dir = ( ( v_sCustomDir == "rtl" || PRMT_BidiUtils.lookupDirection($( this.m_oPrompt.f_getId(this.m_oPrompt.m_sDivPrefix) )) == "rtl") ? "rtl" : "ltr");
- var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":2, "cellSpacing":0, "class":"clsInsertRemoveTable", "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_td0 );
- var v_tbd = $CE( "tbody", {}, v_tbl );
- var v_tr = $CE( "tr", {}, v_tbd );
- var v_td = $CE( "td", {"width": "100%"}, v_tr );
- this.f_drawInsertButton( v_td );
- v_tr = $CE( "tr", {}, v_tbd );
- v_td = $CE( "td", {"width": "100%"}, v_tr );
- this.f_drawRemoveButton( v_td );
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_drawInsertButton = function( v_el )
- {
- var v_btn = $CE( "button", {
- "id": this.f_getId(K_PRMT_sLIST_BUTTON_INSERT_PREFIX),
- "type": "button",
- "title": PMT_UIM_INSERTTIP,
- "class": "clsInsertRemoveButton"
- }, v_el );
- var v_span = $CE( "span", {}, v_btn);
- v_span.f_appendText( this.m_oPrompt[K_PRMT_LABEL_INSERT] );
- var v_sImgClass = ( this.m_dir == "ltr" ? "clsInsertImg" : "clsRemoveImg" );
- if ( this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
- {
- v_btn.f_setProperty( "disabled", "disabled" );
- v_sImgClass = ( this.m_dir == "ltr" ? "clsInsertImgDisabled" : "clsRemoveImgDisabled" );
- }
-
- var v_img = $CE( "img", {
- "src": this.m_oPrompt.m_sSkin + "/prompting/images/blank.gif",
- "alt": PMT_UIM_INSERTTIP,
- "class": v_sImgClass,
- "border": 0,
- "height": 16,
- "width": 16,
- "align": "top"
- }, v_btn);
- v_btn.f_setProperty( "onMouseOver", "this.className = 'clsInsertRemoveButtonOver';" );
- v_btn.f_setProperty( "onMouseOut", "this.className = 'clsInsertRemoveButton';" );
- return v_btn;
- };
- C_Choices.prototype.f_drawRemoveButton = function( v_el )
- {
- var v_btn = $CE( "button", {
- "id": this.f_getId(K_PRMT_sLIST_BUTTON_REMOVE_PREFIX),
- "type": "button",
- "title": PMT_UIM_REMOVETIP,
- "class": "clsInsertRemoveButton"
- }, v_el );
- var v_sImgClass = ( this.m_dir == "ltr" ? "clsRemoveImg" : "clsInsertImg" );
- if ( this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
- {
- v_btn.f_setProperty( "disabled", "disabled" );
- v_sImgClass = ( this.m_dir == "ltr" ? "clsRemoveImgDisabled" : "clsInsertImgDisabled" );
- }
- var v_img = $CE( "img", {
- "src": this.m_oPrompt.m_sSkin + "/prompting/images/blank.gif", //"/prompting/images/remove.gif",
- "alt": PMT_UIM_REMOVETIP,
- "class": v_sImgClass,
- "border": 0,
- "height": 16,
- "width": 16,
- "align": "top"
- }, v_btn);
- var v_span = $CE( "span", {}, v_btn);
- v_span.f_appendText( this.m_oPrompt[K_PRMT_LABEL_REMOVE] );
- v_btn.f_setProperty( "onMouseOver", "this.className = 'clsInsertRemoveButtonOver';" );
- v_btn.f_setProperty( "onMouseOut", "this.className = 'clsInsertRemoveButton';" );
- return v_btn;
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_drawList = function( v_el )
- {
- // Caption
- var v_tdCaption = $CE( "div", {"class": "clsControlLabel pc"}, v_el );
- if ( this.m_oPrompt.isRequired() && !this.m_oPrompt["@hideAdornments"] )
- {
- $CE( "img", {"src": this.m_oPrompt.m_sSkin + "/prompting/images/icon_required.gif", "class": "clsErrorRequired", "align":"top", "height":10, "width":10, "border":0, "alt":""}, v_tdCaption );
- }
- var v_selectId = this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX);
- if ( this.m_oPrompt["@showCondition"] )
- {
- v_tdCaption.f_setProperty("style", "padding:0px 0px 5px 0px;");
- var v_captionLabel = $CE( "label", { "for": v_selectId }, v_tdCaption );
- v_captionLabel.f_appendText( PMT_UIM_CONDITION );
- v_captionLabel.f_appendChild( "<br/>" );
- var v_select = $CE( "select", { "id": this.f_getId("oExcludeSelectedValues") }, v_tdCaption );
- var v_opt = $CE( "option", { "value": "false" }, v_select );
- v_opt.f_appendText( PMT_UIM_SHOWONLY );
- v_opt = $CE( "option", { "value": "true" }, v_select );
- v_opt.f_appendText( PMT_UIM_DONOTSHOW );
- }
- else
- {
- var v_captionLabel = $CE( "label", { "for": v_selectId }, v_tdCaption );
- v_captionLabel.f_appendText( this.m_oPrompt[K_PRMT_LABEL_CHOICES] );
- }
- // Select box to show selected values
- 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_trSelect = $CE( "tr", {}, v_tbd );
- var v_tdSelect = $CE( "td", {"vAlign":"top"}, v_trSelect );
- var v_select = $CE( "select", {
- "id": v_selectId,
- "size": ( this["@listSize"] ? this["@listSize"] : 7),
- "multiple": "multiple",
- "class": "clsListControl pv",
- "role": "listbox",
- "aria-multiselectable": "true"
- }, v_tdSelect );
- if ( this.m_oPrompt.isRequired() )
- {
- v_select.f_setProperty("aria-required","true");
- }
- // Combine @style && @listStyle, @listStyle is used by the Search control.
- var v_sListStyle = cssParser( this.m_oPrompt["@style"], 'color,font,text' );
- if ( this["@listStyle"] )
- {
- v_sListStyle = ( v_sListStyle ? v_sListStyle : K_PRMT_sEMPTY ) + this["@listStyle"];
- }
- if ( this["@listWidth"] )
- {
- v_sListStyle = ( v_sListStyle ? v_sListStyle + ";" : K_PRMT_sEMPTY ) + "width:" + this["@listWidth"];
- }
- if ( v_sListStyle )
- {
- v_sListStyle = cssParser( v_sListStyle, 'background,color,font,text,height,width' );
- v_select.f_setProperty( "style", v_sListStyle );
- }
- // Feedback for non-valid lists
- var v_trFB = $CE( "tr", {}, v_tbd );
- var v_tdFB = $CE( "td", {}, v_trFB );
- var v_divFB = $CE( "div", {
- "id": this.f_getId( K_PRMT_sLIST_FEEDBACK_PREFIX ),
- "class": "clsFeedbackWidget",
- "style": "min-width:200px; width:100%;"
- }, v_tdFB );
- var v_imgFB = $CE( "img", {
- "class": "clsFeedbackSpacer",
- "src": this.m_oPrompt.m_sSkin + "/prompting/images/spacer.gif",
- "alt": K_PRMT_sEMPTY,
- "width": "100%",
- "height": 3
- }, v_divFB);
- // Links to select/deselect all
- var v_trLinks = $CE( "tr", {}, v_tbd );
- var v_sCustomDir = cssParser( this.m_oPrompt["@style"], "direction", true );
- var v_FinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection($( this.m_oPrompt.f_getId(this.m_oPrompt.m_sDivPrefix) )));
- var v_sAlignStyle = ( ( v_FinalDir == "rtl" ) ? "left" : "right");
- var v_tdLinks = $CE( "td", {"align": v_sAlignStyle}, v_trLinks );
- // draw selectAll and deselectAll button-links
- if ( this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
- {
- v_select.f_setProperty( "disabled", "disabled" );
- var v_spanProps = {
- "class": "clsLink",
- "style": "text-decoration:underline;color: #CCCCCC"
- };
- var v_span = $CE( "span", v_spanProps, v_tdLinks );
- v_span.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL]);
- v_tdLinks.f_appendText( K_PRMT_sSP );
- v_span = $CE( "span", v_spanProps, v_tdLinks );
- v_span.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL]);
- }
- else
- {
- var v_a1 = $CE("a", {
- "id": (v_sAlignStyle == "right") ? this.f_getId(K_PRMT_sLIST_LINK_SELECT_PREFIX) : this.f_getId(K_PRMT_sLIST_LINK_DESELECT_PREFIX),
- "href": "javascript:;",
- "onclick": "document.location.hash='';",
- "class": "clsLink pl"
- }, v_tdLinks );
- v_a1.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL] );
- v_tdLinks.f_appendText( K_PRMT_sSP );
- var v_a2 = $CE( "a", {
- "id": (v_sAlignStyle == "right") ? this.f_getId(K_PRMT_sLIST_LINK_DESELECT_PREFIX) : this.f_getId(K_PRMT_sLIST_LINK_SELECT_PREFIX),
- "href": "javascript:;",
- "onclick": "document.location.hash='';",
- "class": "clsLink pl"
- }, v_tdLinks );
- v_a2.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL]);
- }
- };
- /**
- * formate unformated dates provided to use from report server
- **/
- C_Choices.prototype.formatDefaultDateChoice = function(dateChoice, calType) {
- var dateArray = dateChoice.replace("T","-").split("-");
- if (dateArray.length >= 3){
- var tmpDate = new Date(dateArray[0],dateArray[1] - 1,dateArray[2]);
- return getFormatDate(tmpDate,calType);
- }
- return null;
- };
- /**
- update display type attributes for items that report server does not gives us one
- **/
- C_Choices.prototype.f_fixDisplayValues = function(item, iType){
- if (item && item[K_PRMT_sUSE] && !item[K_PRMT_sDISPLAY]) {
- item[K_PRMT_sATTR_DISPLAY_VALUE] = this.formatDefaultDateChoice(item[K_PRMT_sATTR_USE_VALUE], iType);
- item[K_PRMT_sDISPLAY] = this.formatDefaultDateChoice(item[K_PRMT_sUSE], iType);
- }
- };
- /**
- * Set selection
- */
-
- C_Choices.prototype.f_setSelectChoices = function(v_oSelChoices)
- {
- if ( v_oSelChoices && this.m_selList )
- {
- var uniqueSet = {};
- // build the HTML string for the new options, preallocate the array
- var v_newOptions = new Array(v_oSelChoices.length);
- var v_len = v_oSelChoices.length;
- var v_item = null;
- var v_sUse = null;
- for ( var i = 0; i < v_len; i++ ){
- v_item = v_oSelChoices[ i ];
- v_item = cognos.Value.getValue(v_item);
- //have to manually parse this as the value returned by report server is inexcplicably unformated
- if (this.m_oPrompt.n == "selectDate"){
- if (v_item.f_isRange()){
- this.f_fixDisplayValues(v_item.start, this.m_oPrompt.m_oFrom.m_oControl.m_iType);
- this.f_fixDisplayValues(v_item.end, this.m_oPrompt.m_oFrom.m_oControl.m_iType);
- } else {
- this.f_fixDisplayValues(v_item, this.m_oPrompt.m_oControl.m_iType);
- }
- }
- // Skip duplicated
- v_sUse = this.f_getUseValueRO(v_item);
-
- if (!uniqueSet[v_sUse]) {
- v_newOptions[i] = this.f_generateOptionHTMLFromValue( v_item );
- uniqueSet[v_sUse] = 1;
- }
- }
- var v_sNewOpString = v_newOptions.join('');
- if (window.ie) {
- var sOuter = this.m_selList.outerHTML;
- var sNew = sOuter.replace(/<\/select\s*>\s*$/i, K_PRMT_sEMPTY) + v_sNewOpString + '<' + '/' + 'SELECT>';
- this.m_selList.outerHTML = sNew;
- // reset the object attributes and events
- this.m_selList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
- this.m_selList.m_oPrompt = this.m_oPrompt;
- PRMTUtils.f_addEvent( this.m_selList, "change", this.checkData.bind(this) );
- } else {
- this.m_selList.innerHTML += v_sNewOpString;
- }
- }
- this.checkData();
- };
- /*
- * Read Only get Use value
- */
- C_Choices.prototype.f_getUseValueRO = function(v_Value) {
- var v_sUseMember = v_Value['use'];
- var v_sUse = v_Value.f_getUse();
- if (v_Value['use'] != v_sUseMember) {
- if (typeof v_sUseMember == K_PRMT_sUNDEFINED) {
- delete v_Value['use'];
- } else {
- v_Value['use'] = v_sUseMember;
- }
- }
- return v_sUse;
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_DeselectAll = function()
- {
- if ( this.m_selList )
- {
- this.m_selList.selectedIndex = -1;
- for (var i = 0; i < this.m_selList.options.length; i++)
- {
- this.m_selList.options[i].selected = false;
- }
- //In IE10, the selected items still appear selected until the list box gets focus
- this.m_selList.focus();
- this.m_selList.blur();
- }
- this.checkInsertRemove();
- };
- /**
- @desc Build the string for one SELECT option for the given parameter
- @private
- @return {String} Object that hold the option data
- */
- C_Choices.prototype.f_generateOptionHTML = function( v_oPV )
- {
- v_oPV = cognos.Value.getValue(v_oPV);
- return this.f_generateOptionHTMLFromValue(v_oPV);
- };
- /**
- @desc Build the string for one SELECT option for the given parameter
- from already pre-processed value
- @private
- @return {String} Object that hold the option data
- */
- C_Choices.prototype.f_generateOptionHTMLFromValue = function( v_oPV )
- {
- var v_sJSON = cognos.Value.toJSON( v_oPV );
- var v_sUse = v_oPV.f_getUse();
- if ( G_IsBidiEnabled && this.m_oPrompt["@contentTextDirection"] )
- {
- v_oPV.contentTextDir = this.m_oPrompt["@contentTextDirection"];
- }
- var v_sDisplay = sHtmlEncode(v_oPV.f_getDisplay());
- var v_sXML = cognos.Value.toXML( v_oPV );
- /*
- Building an HTML option from the array template, which has the following structure. The variables follow the notation: v_VarName
- <option value=" (0)
- v_sUse (1)
- "display=" (2)
- v_sDisplay (3)
- " pvxml=" (4)
- v_sSafeXML (5)
- " pvJSON=" (6)
- v_sJSON (7)
- " style="white-space:pre" (8)
- [selected] (9)
- > (10)
- v_sDisplay (11)
- </option> (12)
- */
- this.m_tpl_optionHTML[1] = v_sUse;
- this.m_tpl_optionHTML[3] = v_sDisplay;
- this.m_tpl_optionHTML[5] = v_sXML.f_xmlSafe();
- this.m_tpl_optionHTML[7] = v_sJSON.replace(K_PRMT_reQU, K_PRMT_sQU_encoded);
- this.m_tpl_optionHTML[9] = v_oPV["@selected"]? ' selected' : '';
- this.m_tpl_optionHTML[11] = ( G_IsBidiEnabled && this.m_oPrompt["@contentTextDirection"] ? PRMT_BidiUtils.enforceBidiDirection(v_sDisplay, this.m_oPrompt["@contentTextDirection"]) : v_sDisplay);
- result = this.m_tpl_optionHTML.join('');
- return result;
- };
- /**
- Returns the parameter values selected in this control.
- @private
- @return {ParmValueItem[]} Array of parameter values (ParmValueItem and derived classes).
- */
- C_Choices.prototype.getParameterValues = function()
- {
- var v_aPV = [];
- var v_opt = null;
- var v_selList = this.m_selList;
- if ( v_selList.options && v_selList.options.length > 0 )
- {
- for ( var v_iIdx = 0; v_iIdx < v_selList.options.length; v_iIdx++ )
- {
- v_opt = v_selList.options[v_iIdx];
- var v_sJSON = v_opt.getAttribute("pvJSON");
- if ( v_sJSON ) {
- var v_oVal = cognos.Value.getValue( eval("v=" + v_sJSON) );
- v_aPV.push( v_oVal );
- }
- }
- };
- return v_aPV;
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_getPV = function()
- {
- var v_selList = this.m_selList;
- var v_aPV = [];
- var v_opt = null;
- var v_sXML = K_PRMT_sEMPTY;
- var v_sUse = K_PRMT_sEMPTY;
- var v_sDisplay = K_PRMT_sEMPTY;
- if ( v_selList && v_selList.options && v_selList.options.length > 0 )
- {
- for ( var v_iIdx = 0; v_iIdx < v_selList.options.length; v_iIdx++ )
- {
- v_opt = v_selList.options[v_iIdx];
- v_aPV.push( v_opt.getAttribute("pvXML") );
- }
- };
- return v_aPV;
- };
- //get the validity without checking the data first
- C_Choices.prototype.f_getValid = function()
- {
- return (!this.m_oPrompt.isRequired() || (this.m_selList && this.m_selList.options && this.m_selList.options.length > 0) );
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.f_hasSelection = function()
- {
- return ( this.m_selList && this.m_selList.selectedIndex >= 0 );
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_Contains = function( v_oPV )
- {
- if ( this.m_selList && this.m_selList.options && this.m_selList.options.length )
- {
- var v_sXML = cognos.Value.toXML( v_oPV );
- for ( var i = 0; i < this.m_selList.options.length; i++ )
- {
- if ( this.m_selList.options[i].getAttribute("pvXML") == v_sXML )
- {
- return true;
- }
- }
- }
- return false;
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_AddPV = function( v_oPV )
- {
- // Don't add it if it's already there
- if ( this.F_Contains( v_oPV ) )
- {
- return;
- }
- v_oPV = cognos.Value.getValue(v_oPV);
- var v_sJSON = cognos.Value.toJSON( v_oPV );
- var v_sUse = v_oPV.f_getUse();
- var v_sDisplay = v_oPV.f_getDisplay();
- var v_sXML = cognos.Value.toXML( v_oPV );
- var v_opt = PRMTUtils.f_createElement( "option", {"value": v_sUse, "display": v_sDisplay, "pvXML": v_sXML, "pvJSON": v_sJSON, "style": "white-space:pre"}, this.m_selList );
- if ( v_oPV["@selected"] )
- {
- v_opt["selected"] = "selected";
- }
- v_opt["pv"] = v_oPV;
- PRMTUtils.f_addText( v_opt, v_sDisplay );
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_Insert = function()
- {
- if ( this.m_oPrompt )
- {
- var v_oPV = this.m_oPrompt.f_getPV();
- if ( this.m_selList && v_oPV )
- {
- if ( !v_oPV.length ) { v_oPV = [ v_oPV] ; } // cast into an array
- // build the HTML string for the new options, preallocate the array
- var v_newOptions = new Array(v_oPV.length);
- for ( var v_idx = 0; v_idx < v_oPV.length; v_idx++ )
- {
- // Skip duplicated
- if (! this.F_Contains( v_oPV[ v_idx ] ) )
- {
- v_newOptions[v_idx] = this.f_generateOptionHTML( v_oPV[ v_idx ] );
- }
- }
- var v_sNewOpString = v_newOptions.join('');
- if (window.ie)
- {
- var sOuter = this.m_selList.outerHTML;
- var sNew = sOuter.replace(/<\/select\s*>\s*$/i, K_PRMT_sEMPTY) + v_sNewOpString + '<' + '/' + 'SELECT>';
- this.m_selList.outerHTML = sNew;
- // reset the object attributes and events
- this.m_selList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
- this.m_selList.m_oPrompt = this.m_oPrompt;
- PRMTUtils.f_addEvent( this.m_selList, "change", this.checkData.bind(this) );
- }
- else
- {
- this.m_selList.innerHTML += v_sNewOpString;
- }
- }
- if ( this.m_oPrompt && typeof this.m_oPrompt.f_clear == K_PRMT_sFUNCTION )
- {
- this.m_oPrompt.f_clear();
- }
- }
- this.checkData();
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_Remove = function()
- {
- if ( this.m_selList )
- {
- for (var i = this.m_selList.options.length-1; i >= 0; i--)
- {
- if ( this.m_selList.options[i].selected )
- {
- PRMTUtils.f_removeElement( this.m_selList.options[i] );
- }
- }
- }
- this.checkData();
- };
- /**
- @private
- @return {void}
- */
- C_Choices.prototype.F_SelectAll = function()
- {
- if ( this.m_selList )
- {
- for (var i = 0; i < this.m_selList.options.length; i++)
- {
- this.m_selList.options[i].selected = true;
- }
- }
- this.checkInsertRemove();
- };
- /*
- @private
- @desc Sets the JavaScript references used by custom scripts based on generated code from Blaring and before.
- (Custom Scripts Workaround)
- */
- C_Choices.prototype.f_CSW_init = function()
- {
- var v_sPrefix = null;
- var v_oPrompt = this.m_oPrompt;
- if (v_oPrompt)
- {
- switch( v_oPrompt.n )
- {
- case "selectInterval": v_sPrefix = "multipleIntervalPicker"; break;
- case "textBox": v_sPrefix = "multipleText"; break;
- case "selectDate": v_sPrefix = "multipleDatePicker"; break;
- case "selectDateTime": v_sPrefix = "multipleDateTimePicker"; break;
- case "selectTime": v_sPrefix = "multipleTimePicker"; break;
- }
- if ( v_sPrefix )
- {
- this.f_CSW_createJSObject( v_sPrefix );
- }
- }
- };
- /**
- @private
- @return {object} The newly associated object, incidently 'this'.
- @desc Adds a javascript reference using 'prefix' and this control's name.
- (Custom Scripts Workaround)
- */
- C_Choices.prototype.f_CSW_createJSObject = function( v_sPrefix )
- {
- var v_oPrompt = this.m_oPrompt;
- if ( v_oPrompt && v_oPrompt["@name"] )
- {
- var v_sName = v_sPrefix + v_oPrompt["@name"];
- if ( !window[v_sName] )
- {
- window[v_sName] = this;
- }
- return (window[v_sName]);
- }
- return null;
- };
- /**
- 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 <ul>
- <li>Text box prompt (single): <tt>[ {use: "Smith", display: "Smith"} ]</tt></li>
- <li>Select prompt (multiple): <tt>[ {use: "CAN", display: "Canada"}, {use: "JPN", display: "Japan"} ]</tt></li>
- <li>Tree prompt (multiple): <tt>[ {use: "[Americas].[Canada]", display: "Canada"}, {use: "[Asia].[Japan]", display: "Japan"} ]</tt></li>
- </ul>
- */
- C_Choices.prototype.getValues = function()
- {
- var v_aValues = [];
- var v_sJSON = null;
- var v_selList = this.m_selList;
- if ( v_selList != null && v_selList.options && v_selList.options.length > 0 )
- {
- for ( var v_iIdx = 0; v_iIdx < v_selList.options.length; v_iIdx++ )
- {
- v_sJSON = v_selList.options[v_iIdx].getAttribute("pvJSON");
- if ( v_sJSON ) {
- v_aValues.push( eval("v=" + v_sJSON) );
- }
- }
- };
- return v_aValues;
- };
|