-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimezone-override-templates.app
96 lines (87 loc) · 2.94 KB
/
timezone-override-templates.app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module elib/elib-timezones/timezone-override-templates
section overridden templates
override template dateoutputgeneric( d: ref Date, defaultformat: String ){
var dateformat := defaultformat
var timezone : TimeZone
init{
if(d != null){
timezone := getViewTimeZone(d.getEntity());
//@TODO add support for ref arg in function, to avoid repeating this in both output and input
var attr := attribute( "format" );
if( attr != null
&& attr != ""
){
dateformat := attr;
}
else{
if( d.getReflectionProperty() != null ){
var formatanno := d.getReflectionProperty().getFormatAnnotation();
if( formatanno != null ){
dateformat := formatanno;
}
}
}
}
}
if(d != null){ output( d.toLocalTime(timezone).format( dateformat ) ) output(timezone) }
}
override template datepickerinput( d: ref Date, internalJavaDateFormat : String, visibleJavaDateFormat: String, tname: String, options: String ){
var s: String
var defaultFlatPickrFormat := convertJavaDateFormatToFlatPickr( internalJavaDateFormat )
var req := getRequestParameter( tname )
var flatPickrAltDateFormat := convertJavaDateFormatToFlatPickr( visibleJavaDateFormat )
var onOpen := "onOpen: function(dateObj, dateStr, instance){ if(dateStr == ''){ instance.jumpToDate( new Date() ); } }"
var timezone : TimeZone
var extraOptions := options
init{
if( d == null ){
s := "";
timezone := getViewTimeZone(null);
}
else{
timezone := getViewTimeZone(d.getEntity());
s := d.toLocalTime(timezone).format( internalJavaDateFormat );
}
if(req != null){
s := req;
}
//static option is needed when using bootstrap modals
if( attribute("static") != "" ){
extraOptions := "static: " + attribute("static") + ", " + extraOptions;
}
}
datepickerIncludes
<input
if( getPage().inLabelContext() ){
id = getPage().getLabelString()
}
class = "flatpickr"
name = tname
type = "text"
value = s
inputDate attributes
all attributes
title = timezone.getDisplayName()
/>
output(timezone)
<script>
$("input:not(.flatpickr-input)[name=~tname]").flatpickr({~onOpen, allowInput: true, dateformat: '~defaultFlatPickrFormat', altFormat: '~flatPickrAltDateFormat' , altInput: true, time_24hr: true, ~extraOptions});
</script>
databind{
if( req != null ){
if( req == "" ){
d := null;
}
else{
var newdate := req.parseDateTime( internalJavaDateFormat );
if( newdate != null ){
newdate := newdate.toServerTime(timezone);
//first compare dates on Unix epoch time before changing d. Prevents triggering a change when timezone information is different or added, while timestamp is the same
if( d == null || d.getTime() != newdate.getTime()){
d := newdate;
}
}
}
}
}
}