123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- /*
- *+------------------------------------------------------------------------+
- *| 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("<input type='hidden' name='" + this.m_sFormElements + "Text" + this.m_iItemCount + "' value=\"" + sQuotEncode( sText ) + "\"/>");
- }
- this.listHTML.append('<div class="clsCheckBox"'+ (sStyle!=K_PRMT_sEMPTY? ' style="'+sStyle+'"' : K_PRMT_sEMPTY) +'><nobr>');
- sValue = sDecodeU003( sValue );
- this.listHTML.append("<label><input name='" + this.m_sFormElements + "' type='" + this.m_sType + "' value=\"" + sQuotEncode( sValue ) + "\" align='middle' style='vertical-align:middle' ");
- this.listHTML.append("onClick='" + this.m_sName + ".updateSelected(this.checked);" + this.m_sName + ".checkData();");
- if (this.m_bAutoSubmit) {
- this.listHTML.append(this.m_sName + ".autoSubmit();");
- }
- this.listHTML.append("' ");
- if (this.m_bDisabled) {
- this.listHTML.append("disabled='disabled' ");
- }
- if (bSelected)
- {
- this.listHTML.append("checked='checked'");
- this.m_iSelectedCount++;
- }
- this.listHTML.append(">");
- this.listHTML.append( sQuotEncode( sHtmlEncode(sText) ).replace(/\s/g, " ") + "</input></label>" );
- if (typeof sParentDetail == K_PRMT_sSTRING) {
- this.listHTML.append("<span class='clsParentDetail'> ");
- var reOne = new RegExp( "\\^1", K_PRMT_sG);
- this.listHTML.append(PMT_UIM_PARENTDETAILS.replace(reOne,sParentDetail));
- this.listHTML.append("</span>");
- }
- this.listHTML.append("</nobr></div>");
- 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 += '<selectOption';
- sURLValues += ' displayValue="' + sXmlEncode(sTextValue) +'"';
- sURLValues += ' useValue="' + sXmlEncode(this.m_oForm[i].value) + '"';
- sURLValues += ' selected="true" />';
- }
- 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 += '<selectOption';
- sURLValues += ' displayValue="' + sXmlEncode(sTextValue) +'"';
- sURLValues += ' useValue="' + sXmlEncode(this.m_oForm.value) + '"';
- sURLValues += ' selected="true" />';
- }
- }
- 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;
|