/*
*+------------------------------------------------------------------------+
*| 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.
*|
*+------------------------------------------------------------------------+
*/
/*
CSelectValueInputList.js
This script is used to provide interactivity for the SelectValue check box
and radio button prompt components.
*/
//Constructor to create a checkboxlist component
// oForm: the name of the form checkbox 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
// iItemCount: the total number of items in the input list
// iSelectedCount: the number of selected items in the input 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
// bAutoSubmit:
// sType:
// sName:
// sParameterName: the name of the prompt parameter
//
// Global variables
var goSelectValueResizeHeightList = {};
var goSelectValueResizeHeightTimer = null;
function CSelectValueInputList(sFormName, sFormElements, oSubmit, oImgTest, bRequired, sSubmitType, oErrorFeedback, iItemCount, iSelectedCount, bDisabled, sAutoSubmitType, sRef, bAutoSubmit, sType, sName, sParameterName, sCVId)
{
this.setCVId(sCVId);
this.m_sRef = sRef;
this.m_sParameterName = sParameterName;
this.m_sFormName = sFormName;
this.m_sFormElements = sFormElements;
this.m_oSubmit = oSubmit;
this.m_sName = sName;
this.m_oSelectElt = document.getElementById("selectList" + sRef);
this.m_bRequired = bRequired;
this.m_bAutoSubmit = bAutoSubmit;
this.m_sType = sType;
this.m_bValid = false;
this.m_sSubmitType = sSubmitType;
this.m_iItemCount = iItemCount;
this.m_iSelectedCount = iSelectedCount;
if (bDisabled)
{
this.m_bDisabled = true;
}
else
{
this.m_bDisabled = false;
}
this.m_sAutoSubmitType = (sAutoSubmitType == K_ACTION_REPROMPT ? K_ACTION_REPROMPT : K_ACTION_PROMPT);
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.listHTML = new StringArray();
this.checkData();
}
CSelectValueInputList.prototype = new CPromptControl();
//add an item to the list without any checking by the control
//this method provides an efficient way to add items, but
//the update() method should be called to clean up the control
//when finished adding
function CSelectValueInputList_addNoUpdate(sText, sValue, bSelected, sParentDetail)
{
var sStyle = K_PRMT_sEMPTY;
if (this.m_oSelectElt != null)
{
if (window.ie) {
sStyle = this.m_oSelectElt.style.cssText;
}
else {
sStyle = this.m_oSelectElt.getAttribute("style");
}
// Array of Style Attributes To Remove
var aSatr = [
"display", "visibility", "zIndex", "position", "clip", "float",
"top", "bottom", "left", "right", "height", "width",
"(margin|padding)(-left)*(-right)*(-top)*(-bottom)*",
"border(-left|-right|-top|-bottom)*(-style|-width|-color|-spacing|-collapse)*",
"(pos|pixel)(Top)*(Bottom)*(Left)*(Right)*(Height)*(Width)*"
];
for (var i = 0; i < aSatr.length; ++i)
{
var re = new RegExp("(^|;)+\\s*" + aSatr[i] + "\\s*:[^;]*", K_PRMT_sGI);
sStyle = sStyle.replace(re, K_PRMT_sEMPTY);
}
// remove starting semi-colons
sStyle = sStyle.replace(/^\s*(;\s*)+/gi, K_PRMT_sEMPTY);
}
sText = sDecodeU003( sText );
if (this.m_sSubmitType == K_PRMT_sXML) {
this.listHTML.append("");
}
this.listHTML.append('
');
sValue = sDecodeU003( sValue );
this.listHTML.append("" );
if (typeof sParentDetail == K_PRMT_sSTRING) {
this.listHTML.append(" ");
var reOne = new RegExp( "\\^1", K_PRMT_sG);
this.listHTML.append(PMT_UIM_PARENTDETAILS.replace(reOne,sParentDetail));
this.listHTML.append("");
}
this.listHTML.append("
");
this.m_iItemCount++;
}
function CSelectValueInputList_update()
{
this.m_oSelectElt.innerHTML = this.listHTML.toString();
this.m_oForm = eval("document.forms['" + this.m_sFormName + "'].elements['" + this.m_sFormElements + "'];");
var bottomRowTR = document.getElementById("selectListBottomRow" + this.m_sRef);
if (bottomRowTR != null)
{
if (this.m_iItemCount == 1)
{
bottomRowTR.style.display = "none";
}
else
{
bottomRowTR.removeAttribute("style");
}
}
var selectListDIV = document.getElementById("selectList" + this.m_sRef);
if (selectListDIV != null)
{
if (this.m_iItemCount == 1)
{
selectListDIV.className = K_PRMT_sEMPTY;
}
else
{
selectListDIV.className = selectListDIV.getAttribute("oldclass");
}
}
this.checkData();
CPromptControl_updateSelectWidth( document.getElementById("selectList" + this.m_sRef) );
CSelectValueInputList_updateHeight( document.getElementById("selectList" + this.m_sRef) );
}
function CSelectValueInputList_updateHeight( oSelect )
{
if ( typeof goSelectValueResizeHeightList == K_PRMT_sUNDEFINED )
{
goSelectValueResizeHeightList = {};
}
if ( oSelect && !oSelect.id && oSelect.name)
{
oSelect.id = oSelect.name;
}
if ( oSelect && !goSelectValueResizeHeightList[ oSelect.id ] )
{
oSelect.m_sOriginalHeight = oSelect.style.height;
goSelectValueResizeHeightList[ oSelect.id ] = oSelect;
}
if (document.readyState == "complete")
{
for (var sId in goSelectValueResizeHeightList)
{
var oTemp = goSelectValueResizeHeightList[ sId ];
if ( oTemp && typeof oTemp.style && !CSelectValueInputList_hasExplicitHeight( oTemp ) )
{
// Setting the height to "auto" will resize the box
oTemp.style.height = "auto";
if (oTemp.offsetHeight > 165)
{
oTemp.style.height = "165px";
}
}
}
}
else if ( document.readyState )
{
// IE is still loading the page.
if ( goSelectValueResizeHeightTimer )
{
clearTimeout( goSelectValueResizeHeightTimer );
}
goSelectValueResizeHeightTimer = setTimeout(CSelectValueInputList_updateHeight, 100);
}
else
{
// Firefox, Mozilla
if ( !CSelectValueInputList_hasExplicitHeight( oSelect ) )
{
oSelect.style.height = "auto";
oSelect.style.maxHeight = "165px";
}
}
}
function CSelectValueInputList_hasExplicitHeight( oHTMLElement )
{
var sHeight = null;
if (oHTMLElement)
{
sHeight = oHTMLElement.m_sOriginalHeight;
if ( typeof sHeight == K_PRMT_sUNDEFINED )
{
sHeight = oHTMLElement.style.height;
}
}
// Only update if the height was previously set and it's not 'auto'
return ( sHeight && sHeight.match(/\d/g) );
}
//select all check box items
function CSelectValueInputList_selectAll()
{
if (this.m_bDisabled != true)
{
if (typeof this.m_oForm != K_PRMT_sUNDEFINED)
{
var i=0;
for (i=0; i < this.m_oForm.length; i++)
{
this.m_oForm[i].checked = true;
}
this.m_iSelectedCount = this.m_iItemCount;
this.checkData();
}
}
}
//remove selection from all check box items
function CSelectValueInputList_deSelectAll()
{
if (this.m_bDisabled != true)
{
if (typeof this.m_oForm != K_PRMT_sUNDEFINED)
{
var i=0;
for (i=0; i < this.m_oForm.length; i++)
{
this.m_oForm[i].checked = false;
}
this.m_iSelectedCount = 0;
this.checkData();
}
}
}
//render the validated state
function CSelectValueInputList_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 CSelectValueInputList_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);
}
function CSelectValueInputList_updateSelected(bSelected)
{
if (bSelected == true)
{
this.m_iSelectedCount += 1;
if (this.m_iSelectedCount > this.m_iItemCount) {
this.m_iSelectedCount = this.m_iItemCount;
}
}
else
{
this.m_iSelectedCount -= 1;
if (this.m_iSelectedCount < 0) {
this.m_iSelectedCount = 0;
}
}
}
//validate the input into the control
function CSelectValueInputList_checkData()
{
//check to see if any of the items are selected
if (this.m_bRequired && this.m_iSelectedCount === 0)
{
this.m_bValid = false;
this.checkFail();
return false;
}
else
{
this.m_bValid = true;
this.checkPass();
return true;
}
}
function CSelectValueInputList_preProcess()
{
if (this.m_sSubmitType == K_PRMT_sXML)
{
var sURLValues = K_PRMT_sEMPTY;
if (this.m_oForm)
{
var sTextElement = K_PRMT_sEMPTY;
var oTextElement = null;
var sTextValue = K_PRMT_sEMPTY;
if (this.m_oForm.length > 0)
{
for(var i = 0; i < this.m_oForm.length; i ++)
{
if (this.m_oForm[i].checked)
{
sTextElement = "document." + this.m_oForm[i].form.name + K_PRMT_sDOT + this.m_oForm[i].name + "Text" + i;
oTextElement = eval(sTextElement);
if (oTextElement != null)
{
sTextValue = oTextElement.value;
sURLValues += '';
}
if (this.m_sType == "radio")
{
this.m_oSubmit.value = K_PRMT_sEMPTY;
break;
}
}
}
}
else if (this.m_oForm.checked)
{
sTextElement = "document." + this.m_oForm.form.name + K_PRMT_sDOT + this.m_oForm.name + "Text0";
oTextElement = eval(sTextElement);
sTextValue = oTextElement.value;
sURLValues += '';
}
}
addSelectChoices(this.m_oSubmit, sURLValues);
}
}
//update the control, then submit the page
//submit the page
function CSelectValueInputList_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);
}
}
}
// Show/Hide parent details
// Set CSS class clsParentDetail's display attribute to 'inline' or 'none'
function CSelectValueInputList_showParentDetails(bShow)
{
var cssClass = null;
var c = "clsParentDetail";
for (var i = 0; i < document.styleSheets.length; i++)
{
var ss = document.styleSheets[i];
var aCSSRules = (ss.cssRules ? ss.cssRules : ss.rules);
for (var j = 0; j < aCSSRules.length; j++)
{
var cr = aCSSRules[j];
var reClass = new RegExp('\\b' + c + '\\b', K_PRMT_sG);
if (cr.selectorText && cr.selectorText.match(reClass)) {
cssClass = cr;
}
}
}
if (cssClass != null) {
cssClass.style['display'] = (bShow ? 'inline' : 'none');
}
var link = document.getElementById('showParentLink' + this.m_sRef);
if (link)
{
link.href = "javascript:" + this.m_sName + ".showParentDetails(" + (bShow ? "false" : "true") + ")";
var textNode = link;
while(textNode.firstChild != null) {
textNode = textNode.firstChild;
}
textNode.nodeValue = (bShow ? PMT_UIM_HIDEPARENTDETAILS : PMT_UIM_SHOWPARENTDETAILS);
}
CPromptControl_updateSelectWidth( document.getElementById("selectList" + this.m_sRef) );
}
//Prototypes to assign methods to new instances of the object
CSelectValueInputList.prototype.addNoUpdate = CSelectValueInputList_addNoUpdate;
CSelectValueInputList.prototype.update = CSelectValueInputList_update;
CSelectValueInputList.prototype.selectAll = CSelectValueInputList_selectAll;
CSelectValueInputList.prototype.deSelectAll = CSelectValueInputList_deSelectAll;
CSelectValueInputList.prototype.preProcess = CSelectValueInputList_preProcess;
CSelectValueInputList.prototype.checkData = CSelectValueInputList_checkData;
CSelectValueInputList.prototype.checkPass = CSelectValueInputList_checkPass;
CSelectValueInputList.prototype.checkFail = CSelectValueInputList_checkFail;
CSelectValueInputList.prototype.updateSelected = CSelectValueInputList_updateSelected;
CSelectValueInputList.prototype.autoSubmit = CSelectValueInputList_autoSubmit;
CSelectValueInputList.prototype.showParentDetails = CSelectValueInputList_showParentDetails;