// File: datefield.html
//
// Date/Time webscript can be called by other webscripts. It will insert the Date/Time popups or label
// in the HTML page.
//
// Parameters:
//
// fieldName The signature of the fieldname.
//
// now The initial Date/Time it will display.
//
// showTime Show the Time field or show the Date field only.
//
// modifyable If true, it shows the selectable popups. Otherwise it displays
// a HTML label in proper Date/Time format.
//
// tzOffset The Time Zone Offset this widget will use. In most cases, it should be
// defaulted to .fTZOffset.
//
// callBackName A JavaScript function to call when the popup value got changed.
//
// showMinute Show the Minute field if the showTime is true.
//
//
// Methods
// `fieldname`_getDate( form ): Returns the current javascript date for the datepicker. Typical usage to do
date checking between multiple date fields in JS
//
;;webscript DateField( String fieldname, Dynamic now, Boolean showTime, Boolean modifyable, Dynamic tzOffset = .fTZOffset,
String callbackName = Undefined, Boolean showMinute = FALSE )
//This comment is needed for web forms data binding to realize that a date picker begin
`%LStr.Format( "", fieldname )`
;Boolean noApplet = FALSE
;if ( IsFeature( this, "fPrgCtx" ) )
;noApplet = $Webll.WebUtils.NoJavaInHTML( .fPrgCtx )
;else
;//Used when first setting up CS and the Admin user might not have been able to adjust their personal
settings.
;noApplet = TRUE
;end
;if ( modifyable )
;Boolean is12HourFmt
;Boolean separateCentury
;Date nowWithTZOffset
;Date serverNow
;Integer century
;Integer d
;Integer decade
;Integer minute
;Integer origMinute
;Integer outBoundCentury1
;Integer outBoundCentury2
;Integer outBoundYear1
;Integer outBoundYear2
;Integer day
;Integer daysInMonth
;Integer hour
;Integer i
;Integer j
;Integer month
;Integer origHour
;Integer year
;List months
;List t
;String fmt
;String value
;String editValueDateString
;String nowJSString
;Integer year1
;Integer year2
;Integer century1
;Integer century2
;Dynamic twoDigit
;List prm
;List timeprm
;String jQueryOscriptFmt
;String img = .Img()
;Object sysPref = $Kernel.SystemPreferences
;Boolean wantYearRange = sysPref.GetPrefBoolean( "dateformats", "WantYearRange", FALSE )
;Integer decade1 = 0
;Integer decade2 = 99
;List fmts = { "MDY", "DMY", "YMD", "YDM", "MYD", "DYM" }
;List threeSeparators = { "", "", "" }
;Boolean euro = FALSE
;Boolean isDef = ( Type( now ) == DateType )
;String oscriptFmt = sysPref.GetPrefLocale( "ShortDateFormat", "%m/%d/%Y" )
;if( wantYearRange || noApplet )
;year1 = Str.StringToValue( sysPref.GetPref( "dateformats", "InputDateMinYear", Str.String(
Date.Year( Date.Now() ) - 15 ) ) )
;year2 = Str.StringToValue( sysPref.GetPref( "dateformats", "InputDateMaxYear",Str.String(
Date.Year( Date.Now() ) + 15 ) ) )
;else
;year1 = 0
;year2 = 9999
;end
;if( noApplet )
;prm = Str.StringToValue( sysPref.GetPrefLocale( "InputDateSeqFormat", "{ 1, 1, 2, 1, '/', '/' }"
) )
;else
;prm = Str.StringToValue( sysPref.GetPrefLocale( "ShortDateSeqFormat", "{ 1, 1, 2, 1, '/', '/' }"
) )
;end
;timeprm = Str.StringToValue( sysPref.GetPrefLocale( "InputDateSeqFormat", "{ 1, 1, 2, 1, '/', '/' }" ) )
;century1 = year1 / 100
;century2 = year2 / 100
;fmt = fmts[ prm[ 1 ] ]
;if ( fmt in { 'DMY', 'YDM', 'DYM' } )
;euro = TRUE
;end
;is12HourFmt = ( timeprm[ 4 ] == 1 )
;separateCentury = ( prm[ 3 ] == 1 )
//
// Spec says all times are based off database time
//
;if ( IsFeature( this, "fPrgCtx" ) )
// Use Database time
;serverNow = CAPI.Now( this.fPrgCtx.fDbConnect.fConnection )
;else
// Use CS time
;serverNow = Date.Now()
;end
//
// Take timezone difference into consideration
//
;if ( IsUndefined( tzOffset ) || !showTime )
;t = Date.DateToList( ( isDef ? now : serverNow ) )
;nowWithTZOffset = ( isDef ? now : serverNow )
;else
;t = Date.DateToList( ( isDef ? now : serverNow ) - tzOffset )
;nowWithTZOffset = ( ( isDef ? now : serverNow ) - tzOffset )
;end
;value = ( isDef ? Str.ValueToString( nowWithTZOffset ) : Str.String( now ) )
;hour = origHour = t[ 4 ]
;minute = origMinute = t[ 5 ]
;if ( noApplet )
;//get months format
;if ( Str.StringToValue( sysPref.GetPrefLocale( "NoMonthFormat", "FALSE" ) ) )
;months = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }
;else
;months = { [WebDsp_HTMLLabel.January], [WebDsp_HTMLLabel.February],
[WebDsp_HTMLLabel.March], [WebDsp_HTMLLabel.April], [WebDsp_HTMLLabel.May], [WebDsp_HTMLLabel.June],
[WebDsp_HTMLLabel.July], [WebDsp_HTMLLabel.August], [WebDsp_HTMLLabel.September], [WebDsp_HTMLLabel.October],
[WebDsp_HTMLLabel.November], [WebDsp_HTMLLabel.December] }
;end
;//get separators
;if ( Str.StringToValue( sysPref.GetPrefLocale( "ThreeSeparators", "FALSE" ) ) ) && \
; ( IsDefined( prm[ 5 ] ) ) && \
; ( IsDefined( prm[ 6 ] ) ) && \
; ( IsDefined( prm[ 7 ] ) )
;threeSeparators = { prm[ 5 ], prm[ 6 ], prm[ 7 ] }
;end
;year = t[ 1 ]
;month = t[ 2 ]
;day = t[ 3 ]
;century = year / 100
;decade = year % 100
;if .MSIEclient( "3.0" ) || euro
;daysInMonth = 31
;elseif Date.ListToDate( { year, month, 31, 0, 0, 0 } )
;daysInMonth = 31
;elseif Date.ListToDate( { year, month, 30, 0, 0, 0 } )
;daysInMonth = 30
;elseif Date.ListToDate( { year, month, 29, 0, 0, 0 } )
;daysInMonth = 29
;else
;daysInMonth = 28
;end
;if( !isDef )
;daysInMonth = 31
;year = -1
;month = -1
;day = -1
;hour = -1
;minute = -1
;century = -1
;decade = -1
;else
;if( separateCentury )
;if( century < century1 )
;outBoundCentury1 = century
;elseif( century > century2 )
;outBoundCentury2 = century
;end
;else
;if( year < year1 )
;outBoundYear1 = year
;elseif( year > year2 )
;outBoundYear2 = year
;end
;end
;end
;for j = 1 to 3
;switch fmt[ j ]
;case "M"
;end
;case "D"
;end
;case "Y"
;if( !separateCentury )
;else
;end
;end
;end
;end
;else
;jQueryOscriptFmt = oscriptFmt
;//Convert the OScript date format into a format that jQuery understands
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%a", "D" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%b", "M" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%d", "dd" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%j", "oo" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%m", "mm" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%y", "y" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%A", "DD" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%B", "MM" )
;jQueryOscriptFmt = Str.ReplaceAll( jQueryOscriptFmt, "%Y", "yy" )
;end
;if ( showTime )
;if( showMinute )
// Date and time seperator
`[WebDsp_HTMLLabel.DateTimeSeperator]`
;else
;end
// Hour
;if ( showMinute )
// Hour and minute seperator
`[WebDsp_HTMLLabel.HourMinuteSeperator]`
// Minute
// AM or PM
;if ( is12HourFmt )
;end
;else
;end
// Second
;else
;end
;if ( !noApplet )
;end
;else
`.FmtDate( now, showTime )`
;end
//This comment is needed for web forms data binding to realize that a date picker ends
`%LStr.Format( "", fieldname )`
;;end