123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230 |
- /*
- *+------------------------------------------------------------------------+
- *| 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.
- *|
- *+------------------------------------------------------------------------+
- */
- /*
- CIntervalPickerIE5.js
- This script is used to provide interactivity for the selectTime prompt control
- */
- //Constructor to create a selectTime component
- // oSubmit: the field used to submit values to the server
- // oForm: the field used to store processed user input
- // oDays: hours form control
- // oHours: hours form control
- // oMinutes: minutes form control
- // oSeconds: seconds form control, null if not shown
- // oMilliseconds: milliseconds form control, null if not shown
- // oImgTest: error feedback image object
- // sRef: the name of this object
- // sDefaultValue: the initial value for the control
- // bRequired: boolean, specify if user input is required
- // sSubmitType: 'default' will submit as a standard form
- // 'XML' will convert the submission to XML and submit
- // bShowSeconds: true/false, determine whether to show seconds edit box
- // bShowMilliseconds: true/false, determine whether to show Milliseconds edit box
- // bAllowNegative: true/false, some intervals cannot be negative
- function CIntervalPicker(oSubmit, oForm, oDays, oHours, oMinutes, oSeconds, oMilliseconds, oImgTest, sRef, sDefaultValue, bRequired, sSubmitType, bShowSeconds, bShowMilliseconds, bAllowNegative, sCVId)
- {
- this.setCVId(sCVId);
- //get references to form controls
- this.m_oSubmit = oSubmit;
- this.m_oForm = oForm;
- this.m_oDays = oDays;
- this.m_oHours = oHours;
- this.m_oMinutes = oMinutes;
- this.m_bShowSeconds = bShowSeconds;
- this.m_bShowMilliseconds = bShowMilliseconds;
- //handle negative values
- this.m_bNegative = false;
- //create regular expressions for parsing with current locale
- initIntervalRegularExpressions();
- //bShowSeconds
- if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
- {
- this.m_oSeconds = oSeconds;
- }
- else
- {
- this.m_oSeconds = null;
- }
- //bShowMilliseconds
- if (this.m_bShowMilliseconds == true)
- {
- this.m_oMilliseconds = oMilliseconds;
- }
- else
- {
- this.m_oMilliseconds = null;
- }
- //specify whether the user must enter a date or not
- this.m_bRequired = bRequired;
- this.m_bDisabled = false;
- //indicate whether the control has valid data
- this.m_bValid = false;
- //submit as XML or as a standard html form
- this.m_sSubmitType = sSubmitType;
- //can the user type a negative interval?
- this.m_bAllowNegative = bAllowNegative ? bAllowNegative : false;
- //define default interval
- var sDefaultTime = sDefaultValue ? sDefaultValue : K_PRMT_sEMPTY;
- //check to see if this is an XML schema duration data type
- if (sDefaultTime.indexOf ('P') != -1)
- {
- this.parseXSDIntervalValue(sDefaultTime);
- }
- //check to see if this is a UDA format interval
- else
- {
- //search for a negative value
- var z = sDefaultTime.search(rMinusSign);
- if (z == -1)
- {
- this.m_bNegative = false;
- }
- else
- {
- this.m_bNegative = true;
- //strip of the minus sign
- sDefaultTime = sDefaultTime.replace(rMinusSign, K_PRMT_sEMPTY);
- }
- var arDefaultTime = sDefaultTime.split(/[:.\s]/g);
- //do we have a valid date?
- switch (arDefaultTime.length)
- {
- case 5:
- //set default
- this.m_iDays = arDefaultTime[0];
- this.m_iHours = arDefaultTime[1];
- this.m_iMinutes = arDefaultTime[2];
- this.m_iSeconds = arDefaultTime[3];
- this.m_iMilliseconds = arDefaultTime[4];
- break;
- default:
- //no valid default set
- if (this.m_bRequired == true)
- {
- this.m_iDays = 0;
- this.m_iHours = 0;
- this.m_iMinutes = 0;
- this.m_iSeconds = 0;
- this.m_iMilliseconds = 0;
- }
- else
- {
- this.m_iDays = null;
- this.m_iHours = null;
- this.m_iMinutes = null;
- this.m_iSeconds = null;
- this.m_iMilliseconds = null;
- }
- }
- }
- //skin folder
- this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
- //images for handling errors
- this.m_oImgCheckDate = oImgTest;
- if (this.m_oImgCheckDate != 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";
- }
- //create a pointer to this function
- this.m_sRef = sRef;
- this.draw();
- this.updateFormField();
- this.checkInterval();
- }
- CIntervalPicker.prototype = new CPromptControl();
- function CIntervalPicker_draw()
- {
- var sDayVal = (this.m_iDays != null) ? this.m_iDays : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
- if (this.m_bNegative == true)
- {
- this.m_oDays.value = "-" + sDayVal;
- }
- else
- {
- this.m_oDays.value = sDayVal;
- }
- this.m_oHours.value = (this.m_iHours != null) ? this.m_iHours : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
- this.m_oMinutes.value = (this.m_iMinutes != null) ? this.m_iMinutes : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
- if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
- {
- this.m_oSeconds.value = (this.m_iSeconds != null) ? this.m_iSeconds : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
- }
- if (this.m_bShowMilliseconds == true)
- {
- this.m_oMilliseconds.value = (this.m_iMilliseconds != null) ? this.m_iMilliseconds : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
- }
- }
- function CIntervalPicker_updateFormField()
- {
- //return a valid interval data type
- //DDD HH:MT:SS.PPP, e.g. 2 10:20:30.888
- //hours
- var iDaysPart = 0;
- var iHoursPart = 0;
- var iMinutesPart = 0;
- var sDays = K_PRMT_sEMPTY;
- var sHours = K_PRMT_sEMPTY;
- var sMinutes = K_PRMT_sEMPTY;
- var sSeconds = K_PRMT_sEMPTY;
- var sMilliseconds = K_PRMT_sEMPTY;
- var sNegative = K_PRMT_sEMPTY;
- if (this.m_bNegative == true)
- {
- sNegative = '-';
- }
- if (this.m_iSeconds != null)
- {
- if (parseInt(this.m_iSeconds,10) >= 60)
- {
- iMinutesPart = 1;
- //Note the UI prevents this value from being > 2 characters
- sSeconds = (parseInt(this.m_iSeconds,10) - 60).toString();
- }
- else {
- sSeconds = this.m_iSeconds.toString();
- }
- if (sSeconds.length == 1)
- {
- sSeconds = '0' + sSeconds;
- }
- }
- if (this.m_iMinutes != null)
- {
- if (parseInt(this.m_iMinutes,10) >= 60)
- {
- iHoursPart = 1;
- //Note the UI prevents this value from being > 2 characters
- sMinutes = (parseInt(this.m_iMinutes,10) + iMinutesPart) - 60;
- }
- else {
- sMinutes = this.m_iMinutes.toString();
- }
- if (sMinutes.length == 1)
- {
- sMinutes = '0' + sMinutes;
- }
- }
- if (this.m_iHours > 24)
- {
- iDaysPart = (parseInt(this.m_iHours,10) + iHoursPart) / 24;
- iDaysPart = parseInt(iDaysPart, 10);
- iHoursPart += parseInt(this.m_iHours,10) % 24;
- if (this.m_iDays != null) {
- sDays = (parseInt(this.m_iDays,10) + iDaysPart).toString();
- }
- else {
- sDays = iDaysPart.toString();
- }
- sHours = iHoursPart.toString();
- }
- else
- {
- if (this.m_iDays != null)
- {
- sDays = this.m_iDays.toString();
- }
- else
- {
- sDays = '00';
- }
- if (this.m_iHours != null)
- {
- sHours = (parseInt(this.m_iHours,10) + iHoursPart).toString();
- }
- else if (iHoursPart > 0)
- {
- sHours = iHoursPart.toString();
- }
- else
- {
- sHours = '00';
- }
- }
- //days
- if (sDays.length == 2)
- {
- sDays = '0' + sDays;
- }
- else if (sDays.length == 1)
- {
- sDays = '00' + sDays;
- }
- //hours
- if (sHours.length == 1)
- {
- sHours = '0' + sHours;
- }
- //minutes
- if (iMinutesPart > 0)
- {
- sMinutes = iMinutesPart.toString();
- if (sMinutes.length == 1) {
- sMinutes = '0' + sMinutes;
- }
- }
- else if (sMinutes == K_PRMT_sEMPTY)
- {
- sMinutes = '00';
- }
- //seconds
- if (sSeconds == K_PRMT_sEMPTY)
- {
- sSeconds = '00';
- }
- //milliseconds
- if (this.m_iMilliseconds != null)
- {
- sMilliseconds = this.m_iMilliseconds.toString();
- if (sMilliseconds.length == 2)
- {
- sMilliseconds = '0' + sMilliseconds;
- }
- else if (sMilliseconds.length == 1)
- {
- sMilliseconds = '00' + sMilliseconds;
- }
- }
- else
- {
- sMilliseconds = '000';
- }
- this.m_oForm.value = sNegative + sDays + K_PRMT_sSP +sHours + K_PRMT_sCOLON + sMinutes + K_PRMT_sCOLON + sSeconds + K_PRMT_sDOT + sMilliseconds;
- }
- //catch the backspace key
- //some browsers (IE5.5 don't capture this event)
- function CIntervalPicker_keyPress(sKeyCode,sObj)
- {
- if (sKeyCode=='8')
- {
- switch (sObj)
- {
- case 'checkDay':
- this.checkDay();
- break;
- case 'checkHour':
- this.checkHour();
- break;
- case 'checkMinute':
- this.checkMinute();
- break;
- case 'checkSecond':
- this.checkSecond();
- break;
- case 'checkMillisecond':
- this.checkMillisecond();
- break;
- default:
- this.checkInterval();
- }
- }
- return true;
- }
- //check for a valid interval
- function CIntervalPicker_checkInterval()
- {
- var bCheckFlag = false;
- var bCheckNegative = false;
- if (this.m_bRequired == true)
- {
- var bIntervalExists = true;
- if ((this.m_bShowMilliseconds == true) && (this.m_oMilliseconds.value == K_PRMT_sEMPTY))
- {
- bIntervalExists = false;
- }
- if ((bIntervalExists == true) && ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true)) && (this.m_oSeconds.value == K_PRMT_sEMPTY))
- {
- bIntervalExists = false;
- }
- if (bIntervalExists == true)
- {
- if ((this.m_oDays.value == K_PRMT_sEMPTY) || (this.m_oHours.value == K_PRMT_sEMPTY) || (this.m_oMinutes.value == K_PRMT_sEMPTY))
- {
- bIntervalExists = false;
- }
- }
- //if no values have been entered and this is a required prompt
- //then return an error
- if (bIntervalExists == false)
- {
- //show error animation
- this.checkIntervalFail();
- return;
- }
- }
- //are any of the controls negative
- //check days, hours and minutes
- if (this.bIsNegative(this.m_oDays.value)|| this.bIsNegative(this.m_oHours.value) || this.bIsNegative(this.m_oMinutes.value))
- {
- bCheckNegative = true;
- }
- //check seconds if seconds and milliseconds are enabled
- if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
- {
- if (this.bIsNegative(this.m_oSeconds.value) == true)
- {
- bCheckNegative = true;
- }
- }
- //check milliseconds if milliseconds are enabled
- if (this.m_bShowMilliseconds == true)
- {
- if (this.bIsNegative(this.m_oMilliseconds.value) == true)
- {
- bCheckNegative = true;
- }
- }
- //check days, hours and minutes to see if they are correct
- if (this.bcheckNumber(this.m_oDays.value) && this.bcheckNumber(this.m_oHours.value) && this.bcheckNumber(this.m_oMinutes.value))
- {
- bCheckFlag = true;
- }
- //check seconds if seconds and milliseconds are enabled
- if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
- {
- if (this.bcheckNumber(this.m_oSeconds.value) != true)
- {
- bCheckFlag = false;
- }
- }
- //check milliseconds if milliseconds are enabled
- if (this.m_bShowMilliseconds == true)
- {
- if (this.bcheckNumber(this.m_oMilliseconds.value) != true)
- {
- bCheckFlag = false;
- }
- }
- //handle negative values
- if (bCheckNegative == true)
- {
- this.m_bNegative = true;
- if (this.m_bAllowNegative==false)
- {
- bCheckFlag = false;
- }
- }
- else
- {
- this.m_bNegative = false;
- }
- //determine pass/fail
- if (bCheckFlag == true)
- {
- this.updateFormField();
- this.checkIntervalPass();
- this.m_bValid = true;
- }
- else
- {
- //show error animation
- this.checkIntervalFail();
- this.m_bValid = false;
- }
- }
- //render control in validated state
- function CIntervalPicker_checkIntervalPass()
- {
- if ((this.m_oImgCheckDate != null) && (this.m_oImgCheckDate.src != this.m_oImgErrorFalse.src))
- {
- this.m_oImgCheckDate.src = this.m_oImgErrorFalse.src;
- }
- this.m_bValid = true;
- this.notify(gPASS, this);
- }
- //render control in error state
- function CIntervalPicker_checkIntervalFail()
- {
- if (this.m_oImgCheckDate != null)
- {
- this.m_oImgCheckDate.src = this.m_oImgErrorTrue.src + '?' + Math.random();
- }
- this.m_bValid = false;
- this.notify(gFAIL, this);
- }
- function CIntervalPicker_checkDay()
- {
- if (this.m_oDays.value != K_PRMT_sEMPTY)
- {
- var sDays = this.m_oDays.value;
- //check for a negative interval
- if (this.bcheckNumber(sDays) == true)
- {
- //update the variable
- sDays = this.sStripNegative(sDays);
- this.m_iDays = (sDays != K_PRMT_sEMPTY) ? sDays : null;
- this.m_oDays.className = "clsIntervalWidget";
- }
- else
- {
- //show error state
- this.m_iDays = null;
- this.m_oDays.className = "clsIntervalWidgetParseError";
- }
- }
- else
- {
- //no value, reset the variable
- this.m_iDays = null;
- if (this.m_bRequired == true)
- {
- this.m_oDays.className = "clsIntervalWidgetParseError";
- }
- else
- {
- this.m_oDays.className = "clsIntervalWidget";
- }
- }
- //update the form control
- this.checkInterval();
- }
- function CIntervalPicker_checkHour()
- {
- if (this.m_oHours.value != K_PRMT_sEMPTY)
- {
- var sHours = this.m_oHours.value;
- if (this.bcheckNumber(sHours) == true)
- {
- //update the variable
- sHours = this.sStripNegative(sHours);
- this.m_iHours = (sHours != K_PRMT_sEMPTY) ? sHours : null;
- this.m_oHours.className = "clsIntervalWidget";
- }
- else
- {
- this.m_iHours = null;
- //show error state
- this.m_oHours.className = "clsIntervalWidgetParseError";
- }
- }
- else
- {
- //no value, reset the variable
- this.m_iHours = null;
- if (this.m_bRequired == true)
- {
- this.m_oHours.className = "clsIntervalWidgetParseError";
- }
- else
- {
- this.m_oHours.className = "clsIntervalWidget";
- }
- }
- //update the form control
- this.checkInterval();
- }
- function CIntervalPicker_checkMinute()
- {
- if (this.m_oMinutes.value != K_PRMT_sEMPTY)
- {
- var sMinutes = this.m_oMinutes.value;
- if (this.bcheckNumber(this.m_oMinutes.value) == true)
- {
- //update the variable
- sMinutes = this.sStripNegative(sMinutes);
- this.m_iMinutes = (sMinutes != K_PRMT_sEMPTY) ? sMinutes : null;
- this.m_oMinutes.className = "clsIntervalWidget";
- }
- else
- {
- this.m_iMinutes = null;
- //show error state
- this.m_oMinutes.className = "clsIntervalWidgetParseError";
- }
- }
- else
- {
- //no value, reset the variable
- this.m_iMinutes = null;
- if (this.m_bRequired == true)
- {
- this.m_oMinutes.className = "clsIntervalWidgetParseError";
- }
- else
- {
- this.m_oMinutes.className = "clsIntervalWidget";
- }
- }
- //update the form control
- this.checkInterval();
- }
- function CIntervalPicker_checkSecond()
- {
- if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
- {
- if (this.m_oSeconds.value != K_PRMT_sEMPTY)
- {
- var sSeconds = this.m_oSeconds.value;
- if (this.bcheckNumber(sSeconds) == true)
- {
- //update the variable
- sSeconds = this.sStripNegative(sSeconds);
- this.m_iSeconds = (sSeconds != K_PRMT_sEMPTY) ? sSeconds : null;
- this.m_oSeconds.className = "clsIntervalWidget";
- }
- else
- {
- this.m_iSeconds = null;
- //show error state
- this.m_oSeconds.className = "clsIntervalWidgetParseError";
- }
- }
- else
- {
- //no value, reset the variable
- this.m_iSeconds = null;
- if (this.m_bRequired == true)
- {
- this.m_oSeconds.className = "clsIntervalWidgetParseError";
- }
- else
- {
- this.m_oSeconds.className = "clsIntervalWidget";
- }
- }
- //update the form control
- this.checkInterval();
- }
- }
- function CIntervalPicker_checkMillisecond()
- {
- if (this.m_bShowMilliseconds == true)
- {
- if (this.m_oMilliseconds.value != K_PRMT_sEMPTY)
- {
- var sMilliseconds = this.m_oMilliseconds.value;
- if (this.bcheckNumber(sMilliseconds) == true)
- {
- //update the variable
- sMilliseconds = this.sStripNegative(sMilliseconds);
- this.m_iMilliseconds = (sMilliseconds != K_PRMT_sEMPTY) ? sMilliseconds : null;
- this.m_oMilliseconds.className = "clsIntervalWidget";
- }
- else
- {
- this.m_iMilliseconds = null;
- //show error state
- this.m_oMilliseconds.className = "clsIntervalWidgetParseError";
- }
- }
- else
- {
- //no value, reset the variable
- this.m_iMilliseconds = null;
- if (this.m_bRequired == true)
- {
- this.m_oMilliseconds.className = "clsIntervalWidgetParseError";
- }
- else
- {
- this.m_oMilliseconds.className = "clsIntervalWidget";
- }
- }
- //update the form control
- this.checkInterval();
- }
- }
- //set an interval in which the control will check for changed/valid data
- function CIntervalPicker_startCheckDataInterval(field, interval)
- {
- var functionString = this.m_sRef + ".checkValueChange('" + field + "')";
- if (field == "day")
- {
- this.m_sDaysCurrentValue = this.m_oDays.value;
- this.m_intervalIdDays = setInterval(functionString, interval);
- }
- else if (field == "hour")
- {
- this.m_sHoursCurrentValue = this.m_oHours.value;
- this.m_intervalIdHours = setInterval(functionString, interval);
- }
- else if (field == "minute")
- {
- this.m_sMinutesCurrentValue = this.m_oMinutes.value;
- this.m_intervalIdMinutes = setInterval(functionString, interval);
- }
- else if (field == "second" && this.m_oSeconds != null)
- {
- this.m_sSecondsCurrentValue = this.m_oSeconds.value;
- this.m_intervalIdSeconds = setInterval(functionString, interval);
- }
- else if (field == "millisecond" && this.m_oMilliseconds != null)
- {
- this.m_sMillisecondsCurrentValue = this.m_oMilliseconds.value;
- this.m_intervalIdMilliseconds = setInterval(functionString, interval);
- }
- }
- //stop the control from checking for changed/valid data
- function CIntervalPicker_endCheckDataInterval(intervalId)
- {
- if (typeof intervalId != K_PRMT_sUNDEFINED && intervalId !== K_PRMT_sEMPTY)
- {
- clearInterval(intervalId);
- }
- }
- //check if value has changed
- function CIntervalPicker_checkValueChange(field)
- {
- if (field == "day" && typeof this.m_sDaysCurrentValue != K_PRMT_sUNDEFINED)
- {
- if (this.m_oDays.value != this.m_sDaysCurrentValue)
- {
- this.endCheckDataInterval(this.m_intervalIdDays);
- this.checkDay();
- }
- }
- else if (field == "hour" && typeof this.m_sHoursCurrentValue != K_PRMT_sUNDEFINED)
- {
- if (this.m_oHours.value != this.m_sHoursCurrentValue)
- {
- this.endCheckDataInterval(this.m_intervalIdHours);
- this.checkHour();
- }
- }
- else if (field == "minute" && typeof this.m_sMinutesCurrentValue != K_PRMT_sUNDEFINED)
- {
- if (this.m_oMinutes.value != this.m_sMinutesCurrentValue)
- {
- this.endCheckDataInterval(this.m_intervalIdMinutes);
- this.checkMinute();
- }
- }
- else if (field == "second" && this.m_oSeconds != null && typeof this.m_sSecondsCurrentValue != K_PRMT_sUNDEFINED)
- {
- if (this.m_oSeconds.value != this.m_sSecondsCurrentValue)
- {
- this.endCheckDataInterval(this.m_intervalIdSeconds);
- this.checkSecond();
- }
- }
- else if (field == "millisecond" && this.m_oMilliseconds != null && typeof this.m_sMillisecondsCurrentValue != K_PRMT_sUNDEFINED)
- {
- if (this.m_oMilliseconds.value != this.m_sMillisecondsCurrentValue)
- {
- this.endCheckDataInterval(this.m_intervalIdMilliseconds);
- this.checkMillisecond();
- }
- }
- }
- //test to see if the value is an integer
- function CIntervalPicker_bcheckNumber(sTestString)
- {
- //strip out the negative sign if it exists
- sTestString = sTestString.replace('-', K_PRMT_sEMPTY);
- //check for non-numeric characters
- var z = sTestString.search(/[^0-9]/);
- if (z == -1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //return the time in SQL format
- function CIntervalPicker_sGetInterval()
- {
- this.updateFormField();
- var sValue = K_PRMT_sEMPTY;
- sValue = this.m_oForm.value;
- return sValue;
- }
- //return the time in SQL format
- function CIntervalPicker_sGetFormatInterval()
- {
- var sValue = K_PRMT_sEMPTY;
- if (this.m_bNegative == true)
- {
- sValue += g_minusSign;
- }
- var sDays = "0";
- if (this.m_iDays != null)
- {
- sDays = this.m_iDays.toString();
- }
- var sHours = "0";
- if (this.m_iHours != null)
- {
- sHours = this.m_iHours.toString();
- }
- var sMinutes = "00";
- if (this.m_iMinutes != null)
- {
- sMinutes = this.m_iMinutes.toString();
- if (sMinutes.length == 1)
- {
- sMinutes = '0' + sMinutes;
- }
- }
- sValue += sDays + K_PRMT_sSP + sHours + K_PRMT_sCOLON + sMinutes;
- if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
- {
- var sSeconds = '00';
- if (this.m_iSeconds != null)
- {
- sSeconds = this.m_iSeconds.toString();
- if (sSeconds.length == 1)
- {
- sSeconds = '0' + sSeconds;
- }
- }
- sValue += K_PRMT_sCOLON + sSeconds;
- }
- if (this.m_bShowMilliseconds == true)
- {
- var sMilliseconds = '000';
- if (this.m_iMilliseconds != null)
- {
- sMilliseconds = this.m_iMilliseconds.toString();
- if (sMilliseconds.length == 2)
- {
- sMilliseconds = '0' + sMilliseconds;
- }
- else if (sMilliseconds.length == 1)
- {
- sMilliseconds = '00' + sMilliseconds;
- }
- }
- sValue += K_PRMT_sDOT + sMilliseconds;
- }
- return sValue;
- }
- //validate the input into the control
- function CIntervalPicker_checkData()
- {
- this.checkInterval();
- if ((this.m_bRequired == true) && (this.m_oForm.value==K_PRMT_sEMPTY))
- {
- this.m_bValid = false;
- this.checkIntervalFail();
- return false;
- }
- else
- {
- this.m_bValid = true;
- this.checkIntervalPass();
- return true;
- }
- }
- //perform any special processing for the server.
- function CIntervalPicker_preProcess()
- {
- if (this.m_sSubmitType == K_PRMT_sXML)
- {
- var sURLValues = K_PRMT_sEMPTY;
- if (this.hasValue() == true)
- {
- if ((this.m_oForm.value != K_PRMT_sEMPTY) && (this.m_bDisabled!=true))
- {
- sURLValues += '<selectOption';
- sURLValues += ' displayValue="' + this.sGetFormatInterval() +'"';
- sURLValues += ' useValue="' + this.sGetXSDValue() +'"';
- sURLValues += ' selected="true" />';
- }
- }
- addSelectChoices(this.m_oSubmit, sURLValues);
- }
- else
- {
- if (this.m_bDisabled != true)
- {
- this.m_oSubmit.value = this.sGetInterval();
- }
- else
- {
- //this control is disabled
- this.m_oSubmit.value = K_PRMT_sEMPTY;
- }
- }
- }
- //return interval data type
- function CIntervalPicker_sGetValue()
- {
- if (this.m_sSubmitType == K_PRMT_sXML)
- {
- return this.sGetXSDValue();
- }
- else
- {
- return this.sGetInterval();
- }
- }
- //return locale formatted value
- function CIntervalPicker_sGetFormatValue()
- {
- return this.sGetFormatInterval();
- }
- //return XML schema formatted value
- //The value space of duration is a six-dimensional space where the coordinates designate the
- //Gregorian year, month, day, hour, minute, and second components
- //PnYnMnDTnHnMnS
- //If the number of years, months, days, hours, minutes, or seconds in any expression equals zero,
- //the number and its corresponding designator may be omitted.
- //However, at least one number and its designator must be present.
- //The seconds part ·may· have a decimal fraction.
- //The designator 'T' shall be absent if all of the time items are absent.
- //The designator 'P' must always be present.
- //An optional preceding minus sign ('-') is allowed, to indicate a negative duration.
- //If the sign is omitted a positive duration is indicated.
- function CIntervalPicker_sGetXSDValue()
- {
- var sPeriod = K_PRMT_sEMPTY;
- //determine the number Days
- if (this.m_iDays != null)
- {
- sPeriod += this.sStripNegative(this.m_iDays.toString()) + "D";
- }
- //add the time designator
- if ((this.m_iHours != null) || (this.m_iMinutes != null) || (this.m_iSeconds != null) || (this.m_iMilliseconds != null))
- {
- sPeriod += "T";
- if (this.m_iHours != null)
- {
- sPeriod += this.sStripNegative(this.m_iHours.toString()) + "H";
- }
- if (this.m_iMinutes != null)
- {
- sPeriod += this.sStripNegative(this.m_iMinutes.toString()) + "M";
- }
- if (this.m_iSeconds != null)
- {
- sPeriod += this.sStripNegative(this.m_iSeconds.toString());
- }
- if (this.m_iMilliseconds != null)
- {
- sPeriod += K_PRMT_sDOT + this.sStripNegative(this.m_iMilliseconds.toString()) + "S";
- }
- }
- //has the user specified an interval?
- if (sPeriod != K_PRMT_sEMPTY)
- {
- sPeriod = "P" + sPeriod;
- //if the interval is negative, prepend with the minus sign
- if (this.m_bNegative == true)
- {
- sPeriod = g_minusSign + sPeriod;
- }
- }
- return sPeriod;
- }
- function CIntervalPicker_parseXSDIntervalValue(s)
- {
- var parseString = s;
- var iYearVal = 0;
- var iMonthVal = 0;
- var iDayVal = 0;
- var iDays = 0;
- var iHourVal = 0;
- var iMinuteVal = 0;
- var iSecondVal = 0;
- var iMillisecondVal = 0;
- //is the negative symbol there?
- //search for a negative value
- var z = parseString.search(rMinusSign);
- if (z == -1)
- {
- this.m_bNegative = false;
- }
- else
- {
- this.m_bNegative = true;
- //strip of the minus sign
- parseString = parseString.replace(rMinusSign, K_PRMT_sEMPTY);
- }
- //is the prefix P there?
- var iPeriodSymbolPosition = parseString.indexOf('P');
- if (iPeriodSymbolPosition != -1)
- {
- //remove the P and a minus if necessary
- parseString = parseString.substring(iPeriodSymbolPosition + 1);
- var iTimeSymbolPosition = parseString.indexOf('T');
- //split into date and time portions
- var parseArray = parseString.split ('T');
- if (((parseArray.length > 0) && (iTimeSymbolPosition > 0)) || (iTimeSymbolPosition == -1))
- {
- //Deal with date
- //nYnMnD
- //convert years to days
- var iYearPos = parseArray[0].indexOf('Y');
- if (iYearPos != -1)
- {
- iYearVal = parseInt(parseArray[0].substring(currentPos, iYearPos),10);
- parseArray[0] = parseArray[0].substring(iYearPos+1);
- }
- //convert months to days
- var iMonthPos = parseArray[0].indexOf('M');
- if (iMonthPos != -1)
- {
- iMonthVal = parseInt(parseArray[0].substring(0, iMonthPos),10);
- parseArray[0] = parseArray[0].substring(iMonthPos+1);
- }
- //add days
- var iDayPos = parseArray[0].indexOf('D');
- if (iDayPos != -1)
- {
- iDayVal = parseInt(parseArray[0].substring(0, iDayPos),10);
- }
- //ToDo: get the correct conversion
- iDays = (iYearVal * 365) + (iMonthVal * 30) + iDayVal;
- }
- else
- {
- //set date to zero
- iDays = 0;
- }
- //Deal with time
- if ((parseArray.length == 2) || (iTimeSymbolPosition != -1))
- {
- var iArrayObj = parseArray.length - 1;
- //TnHnMnS
- //get hours
- //convert years to days
- var iHourPos = parseArray[iArrayObj].indexOf('H');
- if (iHourPos != -1)
- {
- iHourVal = parseInt(parseArray[iArrayObj].substring(0, iHourPos),10);
- parseArray[iArrayObj] = parseArray[iArrayObj].substring(iHourPos + 1);
- }
- //get minutes
- var iMinutePos = parseArray[iArrayObj].indexOf('M');
- if (iMinutePos != -1)
- {
- iMinuteVal = parseInt(parseArray[iArrayObj].substring(0, iMinutePos),10);
- parseArray[iArrayObj] = parseArray[iArrayObj].substring(iMinutePos +1);
- }
- //get seconds
- //get Milliseconds
- var iSecondPos = parseArray[iArrayObj].indexOf('S');
- if (iSecondPos != -1)
- {
- //split on . to separate seconds and milliseconds
- var decimalPosition = parseArray[iArrayObj].indexOf(K_PRMT_sDOT);
- var secondArray = parseArray[iArrayObj].substring(0, iSecondPos).split(K_PRMT_sDOT);
- if ((secondArray.length == 2) || (decimalPosition == -1))
- {
- iSecondVal = parseInt(secondArray[0],10);
- }
- if ((secondArray.length == 2) || (decimalPosition != -1))
- {
- iMillisecondVal = parseInt(secondArray[secondArray.length - 1],10);
- }
- }
- }
- //create the interval
- this.m_iDays = iDays;
- this.m_iHours = iHourVal;
- this.m_iMinutes = iMinuteVal;
- this.m_iSeconds = iSecondVal;
- this.m_iMilliseconds = iMillisecondVal;
- }
- }
- function CIntervalPicker_iConvertMonthToDays()
- {
- //not entirely accurate, but without the month and year
- //it's impossible to tell
- return 30;
- }
- function CIntervalPicker_hasValue()
- {
- if ((this.m_iDays != null) || (this.m_iHours != null) ||
- (this.m_iMinutes != null) || (this.m_iSeconds != null) ||
- (this.m_iMilliseconds != null))
- {
- return true;
- }
- return false;
- }
- //test to see if a string contains a negative
- function CIntervalPicker_bIsNegative(s)
- {
- if (s == null)
- {
- return false;
- }
- //search for a negative value
- var z = s.toString().search(rMinusSign);
- if (z == -1)
- {
- return false;
- }
- return true;
- }
- //return a string with the minus sign removed
- function CIntervalPicker_sStripNegative(s)
- {
- if (s != null)
- {
- return s.toString().replace(rMinusSign, K_PRMT_sEMPTY);
- }
- return K_PRMT_sEMPTY;
- }
- //user has left a field in the interval control
- function CIntervalPicker_lostFocus()
- {
- }
- //Prototypes to assign methods to new instances of the object
- CIntervalPicker.prototype.draw = CIntervalPicker_draw;
- CIntervalPicker.prototype.updateFormField = CIntervalPicker_updateFormField;
- CIntervalPicker.prototype.keyPress = CIntervalPicker_keyPress;
- CIntervalPicker.prototype.checkInterval = CIntervalPicker_checkInterval;
- CIntervalPicker.prototype.checkDay = CIntervalPicker_checkDay;
- CIntervalPicker.prototype.checkHour = CIntervalPicker_checkHour;
- CIntervalPicker.prototype.checkMinute = CIntervalPicker_checkMinute;
- CIntervalPicker.prototype.checkSecond = CIntervalPicker_checkSecond;
- CIntervalPicker.prototype.checkMillisecond = CIntervalPicker_checkMillisecond;
- CIntervalPicker.prototype.bcheckNumber = CIntervalPicker_bcheckNumber;
- CIntervalPicker.prototype.checkIntervalPass = CIntervalPicker_checkIntervalPass;
- CIntervalPicker.prototype.checkIntervalFail = CIntervalPicker_checkIntervalFail;
- CIntervalPicker.prototype.sGetInterval = CIntervalPicker_sGetInterval;
- CIntervalPicker.prototype.sGetFormatInterval = CIntervalPicker_sGetFormatInterval;
- CIntervalPicker.prototype.checkData= CIntervalPicker_checkData;
- CIntervalPicker.prototype.preProcess = CIntervalPicker_preProcess;
- CIntervalPicker.prototype.sGetFormatValue = CIntervalPicker_sGetFormatValue;
- CIntervalPicker.prototype.sGetValue = CIntervalPicker_sGetValue;
- CIntervalPicker.prototype.sGetXSDValue = CIntervalPicker_sGetXSDValue;
- CIntervalPicker.prototype.parseXSDIntervalValue = CIntervalPicker_parseXSDIntervalValue;
- CIntervalPicker.prototype.iConvertMonthToDays = CIntervalPicker_iConvertMonthToDays;
- CIntervalPicker.prototype.hasValue = CIntervalPicker_hasValue;
- CIntervalPicker.prototype.bIsNegative = CIntervalPicker_bIsNegative;
- CIntervalPicker.prototype.sStripNegative = CIntervalPicker_sStripNegative;
- CIntervalPicker.prototype.lostFocus = CIntervalPicker_lostFocus;
- CIntervalPicker.prototype.startCheckDataInterval = CIntervalPicker_startCheckDataInterval;
- CIntervalPicker.prototype.endCheckDataInterval = CIntervalPicker_endCheckDataInterval;
- CIntervalPicker.prototype.checkValueChange = CIntervalPicker_checkValueChange;
- //create regular expressions for parsing with current locale
- function initIntervalRegularExpressions()
- {
- rMinusSign = new RegExp(sEscapeRegularExpression(g_minusSign), K_PRMT_sG);
- }
- var g_minusSign = "-";
- var rMinusSign = new RegExp(g_minusSign, K_PRMT_sG);
|