123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- /*
- *+------------------------------------------------------------------------+
- *| 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('<option value="' + sQuotEncode( sUse ) + '"' +(bSelected ? ' selected="selected"' : K_PRMT_sEMPTY) + ' displayValue="' + sQuotEncode( sDisplay ) + '">' + sHtmlEncode(sDisplay).replace(/\s/g, ' ') + '</option>');
- }
- 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 += '<selectOption';
- sURLValues += ' displayValue="' + sXmlEncode(sDisplayValue) +'"';
- sURLValues += ' useValue="' + sXmlEncode(this.m_oForm.options[i].value) + '"';
- sURLValues += ' selected="true" />';
- }
- }
- }
- else
- {
- sURLValues = "<selectChoices></selectChoices>";
- }
- 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;
|