123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| BI and PM: prmt
- *| (C) Copyright IBM Corp. 2002, 2011
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- /*
- CMultipleDatePicker.js
- This script is used to provide interactivity for the
- multiple selectDate prompt component. This component is
- a combination of the date picker and a list box.
- */
- //Constructor to create a checkboxlist component
- // oPicker: the date picker control
- // oLstChoices: the name of the select form control
- // oSubmit: the form control to submit selections to the server
- // bRequired: is this a required field true/false
- // sSubmitType: submit this as a standard form, or as XML
- // oErrorFeedback: object used to provide validation feedback
- // oSizer: image object used to control the minimum size of the list
- // oInsertButton: the insert button
- // oRemoveButton: the remove button
- function CMultipleDatePicker(oPicker, oLstChoices, oSubmit, bRequired, sSubmitType, oErrorFeedback, oSizer, oInsertButton, oRemoveButton, sCVId)
- {
- this.setCVId(sCVId);
- this.m_oPicker = oPicker;
- this.m_oLstChoices = oLstChoices;
- this.m_oSubmit = oSubmit;
- this.m_bRequired = bRequired;
- this.m_bValid = false;
- this.m_sSubmitType = sSubmitType;
- this.m_oErrorFeedback = oErrorFeedback;
- if (oInsertButton)
- {
- this.m_oInsertButton = oInsertButton;
- }
- if (oRemoveButton)
- {
- this.m_oRemoveButton = oRemoveButton;
- }
- this.checkData();
- //resize the list if necessary
- if(oSizer)
- {
- this.m_oSizer = oSizer;
- this.resizeList();
- }
- //check the states of the insert and remove buttons
- this.checkInsertRemove();
- }
- CMultipleDatePicker.prototype = new CPromptControl();
- //select all items
- function CMultipleDatePicker_selectAll()
- {
- for (var i = 0; i < this.m_oLstChoices.options.length; i++)
- {
- this.m_oLstChoices.options[i].selected = true;
- }
- //check the states of the insert and remove buttons
- this.checkInsertRemove();
- }
- //remove selection from all items
- function CMultipleDatePicker_deSelectAll()
- {
- for (var i = 0; i < this.m_oLstChoices.options.length; i++)
- {
- this.m_oLstChoices.options[i].selected = false;
- }
- //check the states of the insert and remove buttons
- this.checkInsertRemove();
- }
- //insert values from the picker control
- function CMultipleDatePicker_insert()
- {
- var dInsertDate = this.m_oPicker.m_dDate;
- if (dInsertDate)
- {
- var sDisplayValue = this.m_oPicker.sGetFormatValue();
- var sUseValue = this.m_oPicker.sGetValue();
- if ((sDisplayValue) && (sUseValue))
- {
- this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sUseValue, false, false);
- }
- }
- this.checkData();
- this.resizeList();
- this.resizeList();
- //check the states of the insert and remove buttons
- this.checkInsertRemove();
- }
- //remove selections from the list of choices
- function CMultipleDatePicker_remove()
- {
- this.removeSelectedChoices();
- //check the states of the insert and remove buttons
- this.checkInsertRemove();
- }
- //perform any special processing for the server.
- //this function will wrap all list items in XML.
- //This is required for cases where the unselected items need
- //to be submitted too.
- function CMultipleDatePicker_preProcess()
- {
- var i = 0;
- if (this.m_sSubmitType == K_PRMT_sXML)
- {
- var sURLValues = K_PRMT_sEMPTY;
- if (this.m_oLstChoices.options.length > 0)
- {
- for(i = 0; i < this.m_oLstChoices.options.length; i ++)
- {
- sURLValues += '<selectOption';
- sURLValues += ' displayValue="' + sXmlEncode(this.m_oLstChoices.options[i].text) +'"';
- sURLValues += ' useValue="' + sXmlEncode(this.m_oLstChoices.options[i].value) + '"';
- if (this.m_oLstChoices.options[i].selected == true)
- {
- sURLValues += ' selected="true" />';
- }
- else
- {
- sURLValues += ' selected="false" />';
- }
- }
- }
- addSelectChoices(this.m_oSubmit, sURLValues);
- }
- else
- {
- //select all the choices so they can be submitted with the form
- for(i = 0; i < this.m_oLstChoices.options.length; i ++)
- {
- this.m_oLstChoices.options[i].selected = true;
- }
- }
- }
- //return true unless this is a required prompt
- //and there are no values
- function CMultipleDatePicker_checkData()
- {
- if ((this.m_bRequired == true) && (this.m_oLstChoices.options.length === 0))
- {
- this.m_bValid = false;
- this.checkFail();
- return false;
- }
- else
- {
- this.m_bValid = true;
- this.checkPass();
- return true;
- }
- }
- //make sure that choices are always visible and set a minimum size
- //resize the list to fit the data if required
- //if there are no items, prevent the list from
- //shrinking too small
- //allow the list to expand to fit the biggest item
- function CMultipleDatePicker_resizeList()
- {
- if (this.m_oSizer)
- {
- this.m_oLstChoices.style.width='auto';
- if (this.m_oSizer.width < 200)
- {
- this.m_oLstChoices.style.width='200px';
- }
- }
- }
- //enable and disable the insert and remove buttons
- //based on what the user has selected
- function CMultipleDatePicker_checkInsertRemove()
- {
- if (this.m_oInsertButton)
- {
- if ((this.m_oPicker.getValid() == true) && (this.m_oPicker.hasValue()))
- {
- this.m_oInsertButton.disabled = false;
- }
- else
- {
- this.m_oInsertButton.disabled = true;
- this.m_oInsertButton.className = "clsInsertRemoveButton";
- }
- }
- if (this.m_oRemoveButton)
- {
- if (this.m_oLstChoices.selectedIndex == -1)
- {
- this.m_oRemoveButton.disabled = true;
- this.m_oRemoveButton.className = "clsInsertRemoveButton";
- }
- else
- {
- this.m_oRemoveButton.disabled = false;
- }
- }
- }
- //add a value to the list via javascript
- function CMultipleDatePicker_add(sDisplayValue, sInsertText)
- {
- this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, false, false);
- this.checkData();
- this.resizeList();
- this.resizeList();
- //check the states of the insert and remove buttons
- this.checkInsertRemove();
- }
- //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 CMultipleDatePicker_addNoUpdate(sDisplayValue, sInsertText, sel)
- {
- sDisplayValue = sDecodeU003( sDisplayValue );
- sInsertText = sDecodeU003( sInsertText );
- if (sel == true) {
- this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, true, true);
- }
- else {
- this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, false, false);
- }
- }
- //clean up the control
- function CMultipleDatePicker_update()
- {
- this.checkData();
- this.resizeList();
- this.resizeList();
- //check the states of the insert and remove buttons
- this.checkInsertRemove();
- }
- //Prototypes to assign methods to new instances of the object
- CMultipleDatePicker.prototype.selectAll = CMultipleDatePicker_selectAll;
- CMultipleDatePicker.prototype.deSelectAll = CMultipleDatePicker_deSelectAll;
- CMultipleDatePicker.prototype.insert = CMultipleDatePicker_insert;
- CMultipleDatePicker.prototype.remove = CMultipleDatePicker_remove;
- CMultipleDatePicker.prototype.preProcess = CMultipleDatePicker_preProcess;
- CMultipleDatePicker.prototype.checkData = CMultipleDatePicker_checkData;
- CMultipleDatePicker.prototype.resizeList = CMultipleDatePicker_resizeList;
- CMultipleDatePicker.prototype.checkInsertRemove = CMultipleDatePicker_checkInsertRemove;
- CMultipleDatePicker.prototype.add = CMultipleDatePicker_add;
- CMultipleDatePicker.prototype.addNoUpdate = CMultipleDatePicker_addNoUpdate;
- CMultipleDatePicker.prototype.update = CMultipleDatePicker_update;
|