/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| BI and PM: prmt
*| (C) Copyright IBM Corp. 2002, 2016
*|
*| US Government Users Restricted Rights - Use, duplication or
*| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*|
*+------------------------------------------------------------------------+
*/
/*
CSelectValueSelectList.js
This script is used to provide interactivity for the SelectValue single and
multiple select prompt components.
*/
//Constructor to create a checkboxlist component
// oForm: the name of the form list box control
// oSubmit: the form control to submit selections to the server
// oImgTest: the image object used for validation handling
// bRequired: a flag to determine whether input is required
// sSubmitType: 'default' will submit as a standard form
// 'XML' will convert the submission to XML and submit
// oErrorFeedback: object used to provide validation feedback
// oSizer: image object used to control the minimum size of the list
// bDisabled: the control has been disabled [true|false]
// sAutoSubmitType: specify whether the autosubmit should stay on the same page (reprompt)
// or move to the next prompt page (prompt)
// ['prompt'|'reprompt']
// sRef: the name of the javascript variable for this object
// sParameterName: the name of the prompt parameter
//
function CSelectValueSelectList(oForm, oSubmit, oImgTest, bRequired, sSubmitType, oErrorFeedback, oSizer, bDisabled, sAutoSubmitType, sRef, sParameterName, sCVId)
{
this.setCVId(sCVId);
this.m_oForm = oForm;
this.m_oSubmit = oSubmit;
this.m_bRequired = bRequired;
this.m_bValid = false;
this.m_sSubmitType = sSubmitType;
this.m_sRef = sRef;
this.m_sParameterName = sParameterName;
this.m_oSelectElt = document.getElementById("selectList" + sRef);
this.m_sAutoSubmitType = (sAutoSubmitType == K_ACTION_REPROMPT ? K_ACTION_REPROMPT : K_ACTION_PROMPT);
//this variable is used to trap auto-submit
//behavior in drop down lists
this.m_bAutoSubmitTrigger = false;
if (bDisabled)
{
this.m_bDisabled = true;
}
else
{
this.m_bDisabled = false;
}
this.m_oErrorFeedback = oErrorFeedback;
//skin folder
this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
//images for handling errors
this.m_oImgCheck = oImgTest;
if (this.m_oImgCheck != null)
{
this.m_oImgErrorFalse= new Image();
this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
this.m_oImgErrorTrue = new Image();
this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif";
}
this.checkData(oForm);
//check to see if the user has hardcoded the size
if (oForm.style && oForm.style.width != K_PRMT_sEMPTY)
{
oSizer = null;
}
this.oOptionsHTML = new StringArray();
}
CSelectValueSelectList.prototype = new CPromptControl();
function CSelectValueSelectList_addNoUpdate(sDisplayValue, sInsertText, sel)
{
var sDisplay = sDecodeU003( sDisplayValue );
var sUse = sDecodeU003( sInsertText );
var bSelected = (sel == true);
if (window.ie)
{
this.oOptionsHTML.append('');
}
else
{
var o = new Option(sDisplay, sUse, bSelected, bSelected);
o.style.whiteSpace = "pre";
this.m_oSelectElt.options[this.m_oSelectElt.options.length] = o;
}
}
function CSelectValueSelectList_update()
{
if (window.ie)
{
var sId = this.m_oSelectElt.id;
var bReplaceFormControl = ( this.m_oForm == this.m_oSelectElt );
var sOuter = this.m_oSelectElt.outerHTML;
this.m_oSelectElt.outerHTML = sOuter.replace(/<\/select.*/i, K_PRMT_sEMPTY) + this.oOptionsHTML.toString() + '<' + '/' + 'SELECT>';
// need to refresh references to objects after using outerHTML.
this.m_oSelectElt = document.getElementById(sId);
if (bReplaceFormControl) {
this.m_oForm = this.m_oSelectElt;
}
this.oOptionsHTML.reset();
}
this.checkData();
CPromptControl_updateSelectWidth( document.getElementById("selectList" + this.m_sRef) );
}
//select all check box items
function CSelectValueSelectList_selectAll()
{
if (this.m_bDisabled != true)
{
var i=0;
for (i=0; i < this.m_oForm.options.length; i++)
{
this.m_oForm.options[i].selected = true;
}
this.checkData();
}
}
//remove selection from all check box items
function CSelectValueSelectList_deSelectAll()
{
if (this.m_bDisabled != true)
{
var i=0;
for (i=0; i < this.m_oForm.options.length; i++)
{
this.m_oForm.options[i].selected = false;
}
this.checkData();
}
}
//render the validated state
function CSelectValueSelectList_checkPass()
{
if ((this.m_oImgCheck != null) && (this.m_oImgCheck.src != this.m_oImgErrorFalse.src))
{
this.m_oImgCheck.src = this.m_oImgErrorFalse.src;
}
if (this.m_oErrorFeedback)
{
this.m_oErrorFeedback.className ="clsFeedbackWidget";
}
this.notify(gPASS, this);
}
//render the validation error state
function CSelectValueSelectList_checkFail()
{
if (this.m_oImgCheck != null)
{
this.m_oImgCheck.src = this.m_oImgErrorTrue.src + '?' + Math.random();
}
if (this.m_oErrorFeedback)
{
this.m_oErrorFeedback.className ="clsFeedbackWidgetParseErrorArrowLeft";
}
this.notify(gFAIL, this);
}
//validate the input into the control
function CSelectValueSelectList_checkData()
{
//check to see if any of the items are selected
var bCheckSelect = false;
var i=0;
for (i=0; i < this.m_oForm.options.length; i++)
{
if ((this.m_oForm.options[i].selected == true) && (this.m_oForm.options[i].value != K_PRMT_sEMPTY))
{
bCheckSelect = true;
}
}
if ((this.m_bRequired == true) && (bCheckSelect == false))
{
this.m_bValid = false;
this.checkFail();
return false;
}
else
{
this.m_bValid = true;
this.checkPass();
return true;
}
}
function CSelectValueSelectList_preProcess()
{
if (this.m_sSubmitType == K_PRMT_sXML)
{
var sURLValues = "";
if (this.m_oForm.options.length > 0)
{
for(var i = 0; i < this.m_oForm.options.length; i ++)
{
if ((this.m_oForm.options[i].selected == true) && (this.m_oForm.options[i].value!=K_PRMT_sEMPTY))
{
var sDisplayValue = this.m_oForm.options[i].displayValue;
if ( !sDisplayValue )
{
sDisplayValue = this.m_oForm.options[i].text;
}
sURLValues += '';
}
}
}
else
{
sURLValues = "";
}
addSelectChoices(this.m_oSubmit, sURLValues);
}
}
//update the control, then submit the page
//submit the page
function CSelectValueSelectList_autoSubmit()
{
this.checkData();
if (!this.m_bRequired || this.m_bValid)
{
var oCV = this.getCV();
if (oCV && typeof oCV.submitPromptValues == K_PRMT_sFUNCTION && typeof ViewerDispatcherEntry == K_PRMT_sFUNCTION){
var oReq = new ViewerDispatcherEntry(oCV);
oReq.addFormField("ui.action", K_ACTION_FORWARD);
oReq.addFormField("_autosubmitParameter", this.m_sParameterName);
oReq.addFormField("_promptControl", this.m_sAutoSubmitType);
oCV.submitPromptValues(oReq);
}
else
{
SetPromptMethod(K_ACTION_FORWARD);
if (document.forms[0]._autosubmitParameter) {
document.forms[0]._autosubmitParameter.value = this.m_sParameterName;
}
SetPromptControl(this.m_sAutoSubmitType);
}
}
}
//return a valid value from the selected index
//use only with the single select version of the control
function CSelectValueSelectList_sGetValue()
{
this.checkData();
if ((this.m_bValid == true) && (this.m_oForm.options.length > 0) && (this.m_oForm.options.selectedIndex != -1))
{
return this.m_oForm.options[this.m_oForm.options.selectedIndex].value;
}
return false;
}
//return a valid value from the selected index
//use only with the single select version of the control
function CSelectValueSelectList_sGetFormatValue()
{
this.checkData();
if ((this.m_bValid == true) && (this.m_oForm.options.length > 0) && (this.m_oForm.options.selectedIndex != -1))
{
return this.m_oForm.options[this.m_oForm.options.selectedIndex].text;
}
return false;
}
function CSelectValueSelectList_hasValue()
{
if (this.m_oForm.value == K_PRMT_sEMPTY)
{
return false;
}
return true;
}
//used to set the list to a particular use value if it exists
//in the list.
function CSelectValueSelectList_selectByUseValue(sUseValue)
{
for (var j=0; j < this.m_oForm.options.length; j++)
{
if (this.m_oForm.options[j].value == sUseValue)
{
this.m_oForm.options[j].selected = true;
this.checkData(this.m_oForm);
return;
}
}
}
//Prototypes to assign methods to new instances of the object
CSelectValueSelectList.prototype.addNoUpdate = CSelectValueSelectList_addNoUpdate;
CSelectValueSelectList.prototype.update = CSelectValueSelectList_update;
CSelectValueSelectList.prototype.selectAll = CSelectValueSelectList_selectAll;
CSelectValueSelectList.prototype.deSelectAll = CSelectValueSelectList_deSelectAll;
CSelectValueSelectList.prototype.preProcess = CSelectValueSelectList_preProcess;
CSelectValueSelectList.prototype.checkData = CSelectValueSelectList_checkData;
CSelectValueSelectList.prototype.checkPass = CSelectValueSelectList_checkPass;
CSelectValueSelectList.prototype.checkFail = CSelectValueSelectList_checkFail;
CSelectValueSelectList.prototype.autoSubmit = CSelectValueSelectList_autoSubmit;
CSelectValueSelectList.prototype.sGetValue = CSelectValueSelectList_sGetValue;
CSelectValueSelectList.prototype.sGetFormatValue = CSelectValueSelectList_sGetFormatValue;
CSelectValueSelectList.prototype.hasValue = CSelectValueSelectList_hasValue;
CSelectValueSelectList.prototype.selectByUseValue = CSelectValueSelectList_selectByUseValue;