123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- /*
- *+------------------------------------------------------------------------+
- *| 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.
- *|
- *+------------------------------------------------------------------------+
- */
- /*
- CDateTime.js
- This script provides interactivity for the dateTime prompt control.
- The dateTime control is a combination of a date control and a time control
- */
- // Constructor to create a new DateTime prompt
- // oDate: the Date control hidden form field
- // oDateControl: the Date control javascript object
- // oTime: the time control hidden form field
- // oTimeControl: the Time control javascript object
- // oImgTest: the image object used for validation handling
- // oSubmit: the form control to send the value to the server
- // oForm: the hidden dateTime form control to satisfy the prompt
- // 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
- // sDefaultValue: a default value to initialize the controls
- // 'yyyy-mm-dd hh:mm:ss.ddd'(SQL) or 'yyyy-mm-ddThh:mm:ss.ddd' (XSD)
- // bXSDformat: [true]|[false] specify whether date times should be returned
- // in XSD format (true, default) or SQL format (false)
- function CDateTime(oDateControl, oTimeControl, oSubmit, oForm, bRequired, sSubmitType, sDefaultValue, bXSDformat, sCVId)
- {
- this.setCVId(sCVId);
- this.m_oDateControl = oDateControl;
- this.m_oTimeControl = oTimeControl;
- this.m_oForm = oForm;
- this.m_oSubmit = oSubmit;
- this.m_bRequired = bRequired;
- this.m_bDisabled = false;
- //set the date and time controls to required
- //so that they report errors properly
- if (this.m_bRequired === true)
- {
- this.m_oDateControl.m_bRequired = true;
- this.m_oTimeControl.m_bRequired = true;
- }
- var sDate = K_PRMT_sEMPTY;
- var sTime = K_PRMT_sEMPTY;
- if (sDefaultValue)
- {
- //split the string into a date and time
- var rSplit = /[T\s]/;
- var arDefaultValue = sDefaultValue.split(rSplit);
- if (arDefaultValue.length > 2)
- {
- sDate = K_PRMT_sEMPTY;
- var lastIndex = arDefaultValue.length - 1;
- sTime = arDefaultValue[lastIndex]; // the last value is going to be the time
- // all other parts of the array will become the date
- for (var i = 0; i < lastIndex; i++)
- {
- sDate += arDefaultValue[i];
- // add the space that has been removed earlier but don't add it to the end of the
- // string
- if (i < lastIndex - 1)
- {
- sDate += K_PRMT_sSP;
- }
- }
- this.m_oDateControl.setValue(sDate);
- this.m_oTimeControl.setValue(sTime);
- }
- else if (arDefaultValue.length == 2)
- {
- sDate = arDefaultValue[0];
- this.m_oDateControl.setValue(sDate);
- sTime = arDefaultValue[1];
- this.m_oTimeControl.setValue(sTime);
- }
- else if (arDefaultValue.length == 1)
- {
- sDate = arDefaultValue[0];
- this.m_oDateControl.setValue(sDate);
- }
- }
- if (bXSDformat === false)
- {
- this.m_bXSDformat = false;
- }
- else
- {
- this.m_bXSDformat = true;
- }
- this.m_bValid = false;
- this.m_sSubmitType = sSubmitType;
- //check the default value to see if it is valid
- this.checkData();
- }
- CDateTime.prototype = new CPromptControl();
- function CDateTime_updateFormValue()
- {
- this.m_oDateControl.m_bRequired = true;
- this.m_oTimeControl.m_bRequired = true;
- }
- //this function prepares the date for the server
- function CDateTime_preProcess()
- {
- var sURLValues = K_PRMT_sEMPTY;
- if (this.m_sSubmitType == K_PRMT_sXML)
- {
- if (this.m_bDisabled !== true)
- {
- sURLValues += '<selectOption';
- sURLValues += ' displayValue="' + this.sGetFormatValue() +'"';
- sURLValues += ' useValue="' + this.sGetXSDValue() +'"';
- sURLValues += ' selected="true" />';
- }
- addSelectChoices(this.m_oSubmit, sURLValues);
- }
- else
- {
- sURLValues = this.sGetSQLDateTime();
- this.m_oSubmit.value = sURLValues;
- }
- }
- //validate the input into the control
- function CDateTime_checkData()
- {
- if (this.m_bRequired === true)
- {
- if ((this.m_oDateControl.isValid() === true) && (this.m_oTimeControl.isValid() === true))
- {
- this.m_bValid = true;
- this.checkPass();
- return true;
- }
- else if (this.m_oDateControl.isValid() === false)
- {
- this.m_bValid = false;
- this.m_oDateControl.checkFail();
- return false;
- }
- else if (this.m_oTimeControl.isValid() === false)
- {
- this.m_bValid = false;
- this.m_oTimeControl.checkFail();
- return false;
- }
- else
- {
- this.m_bValid = false;
- return false;
- }
- }
- else
- {
- this.m_bValid = true;
- this.checkPass();
- return true;
- }
- }
- //get the validity without checking the data first
- function CDateTime_getValid()
- {
- if ((this.m_oDateControl.getValid() === true) && (this.m_oTimeControl.getValid() === true))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- // return the date time in SQL specified form
- function CDateTime_sGetSQLDateTime()
- {
- var dateVal = this.m_oDateControl.sGetValue();
- var timeVal = this.m_oTimeControl.sGetSQLTime();
- if ((dateVal === false) || (timeVal === false))
- {
- this.m_oForm.value = K_PRMT_sEMPTY;
- return false;
- }
- else
- {
- this.m_oForm.value = dateVal + K_PRMT_sSP + timeVal;
- return this.m_oForm.value;
- }
- }
- // return the date time in XSD specified form
- function CDateTime_sGetXSDValue()
- {
- var dateVal = this.m_oDateControl.sGetValue();
- var timeVal = this.m_oTimeControl.sGetSQLTime();
- if ((dateVal === false) || (timeVal === false))
- {
- return false;
- }
- else
- {
- var sXSDvalue = this.m_oDateControl.sGetValue() + "T" + this.m_oTimeControl.sGetSQLTime();
- return sXSDvalue;
- }
- }
- // Return date time as displayed
- function CDateTime_sGetFormatDateTime()
- {
- var iType = this.m_oDateControl.m_iType;
- var sInputOrder = this.m_oDateControl.m_sInputOrder;
- var dInsertDate = this.m_oDateControl.m_dDate;
- var sDisplayDateValue = getFormatDate (dInsertDate, iType, sInputOrder);
- var sDisplayTimeValue =this.m_oTimeControl.sGetFormatTime();
- var sDisplayDateTimeValue = sDisplayDateValue + K_PRMT_sSP + sDisplayTimeValue;
- return sDisplayDateTimeValue;
- }
- function CDateTime_enable()
- {
- if (this.m_bRequired === true)
- {
- this.m_oDateControl.m_bRequired = true;
- this.m_oTimeControl.m_bRequired = true;
- }
- this.m_oDateControl.enable();
- this.m_oTimeControl.enable();
- this.m_bDisabled = false;
- }
- function CDateTime_disable()
- {
- if (this.m_bRequired === true)
- {
- this.m_oDateControl.m_bRequired = false;
- this.m_oTimeControl.m_bRequired = false;
- }
- this.m_oDateControl.disable();
- this.m_oTimeControl.disable();
- this.m_bDisabled = true;
- }
- // return the date time in XSD specified form
- function CDateTime_sGetValue()
- {
- this.checkData();
- if ((this.m_bValid === true) && ((this.m_oDateControl.hasValue() === true) && (this.m_oTimeControl.hasValue() === true)))
- {
- if (this.m_bXSDformat === false)
- {
- return this.sGetSQLDateTime();
- }
- else
- {
- return this.sGetXSDValue();
- }
- }
- else
- {
- return false;
- }
- }
- // Return date time as displayed
- function CDateTime_sGetFormatValue()
- {
- this.checkData();
- if ((this.m_bValid === true) && ((this.m_oDateControl.hasValue() === true) && (this.m_oTimeControl.hasValue() === true)))
- {
- return this.sGetFormatDateTime();
- }
- else
- {
- return false;
- }
- }
- function CDateTime_hasValue()
- {
- if ((this.m_oDateControl.hasValue()) && (this.m_oTimeControl.hasValue()))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- function CDateTime_toggleDisable(bState)
- {
- if (this.isRequired() === false)
- {
- if (bState === false)
- {
- this.disable();
- }
- else
- {
- this.enable();
- }
- }
- this.checkData();
- }
- //Prototypes to assign methods to new instances of the object
- CDateTime.prototype.preProcess = CDateTime_preProcess;
- CDateTime.prototype.sGetSQLDateTime = CDateTime_sGetSQLDateTime;
- CDateTime.prototype.sGetFormatDateTime = CDateTime_sGetFormatDateTime;
- CDateTime.prototype.checkData = CDateTime_checkData;
- CDateTime.prototype.enable = CDateTime_enable;
- CDateTime.prototype.disable = CDateTime_disable;
- CDateTime.prototype.toggleDisable = CDateTime_toggleDisable;
- CDateTime.prototype.sGetValue = CDateTime_sGetValue;
- CDateTime.prototype.sGetFormatValue = CDateTime_sGetFormatValue;
- CDateTime.prototype.sGetXSDValue = CDateTime_sGetXSDValue;
- CDateTime.prototype.getValid = CDateTime_getValid;
- CDateTime.prototype.hasValue = CDateTime_hasValue;
|