/*
*+------------------------------------------------------------------------+
*| 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 = [''];
};
/**
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( "
" );
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
(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