/
calendar_controls.opa
215 lines (196 loc) · 6.62 KB
/
calendar_controls.opa
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @category COMPONENT
* @author Adam Koprowski, 2011
*/
import stdlib.widgets.core
import stdlib.widgets.button
import stdlib.widgets.datepicker
import stdlib.components.fragment
// ***************************************************************************************
/**
* {1 Types}
**/
// ***************************************************************************************
type CCalendarControls.config('event) =
{
generate : string, CCalendar.instance('event) -> xhtml
}
// ***************************************************************************************
/**
* {1 Implementation}
**/
// ***************************************************************************************
@client CCalendarControls = {{
@private generate_button(cal, style, cmd, id, content) =
onclick(_) = CCalendar.perform(cal, cmd)
WButton.html(style, id, [({click}, onclick)], content)
@private make_buttons_style(class) =
mk_button_stl(state) = WStyler.make_class([class, state])
{ WButton.bare_config with
common_style = mk_button_stl("common")
default_style = mk_button_stl("default")
over_style = mk_button_stl("over")
active_style = mk_button_stl("active")
disabled_style = mk_button_stl("disabled")
toggled_style = mk_button_stl("toggled")
}
@private register_date_range_view(cal) =
update_date(_state, {ViewChanged=~{first_weekday mode}}) =
{re_render=<>{CCalendar.date_range_string(first_weekday, mode)}</>}
(date_range_xhtml, date_range_fragment) = CFragment.create(void, <></>, update_date)
ViewChanged(vc) = CFragment.notify(date_range_fragment, {ViewChanged=vc})
do CCalendar.perform(cal, {UpdateCallbacks=(callbacks -> {callbacks with ~ViewChanged })})
date_range_xhtml
extensible_style_config =
{
generate(id, cal) =
date_range_xhtml = register_date_range_view(cal)
// buttons
button = generate_button(cal, make_buttons_style("ccalendar_ext_ctrl_btn"), _, _, _)
// left panel
today = button({GoToday}, "{id}_today", <>Today</>)
next = button({Next}, "{id}_next", <>»</>)
prev = button({Prev}, "{id}_prev", <>«</>)
do_goto(date) = CCalendar.perform(cal, {SetDate=date})
goto_ctrl = WDatepicker.edit_default(do_goto, "{id}_goto", Date.now())
goto = <span>{goto_ctrl}</>
|> style_stl(WStyler.make_class(["ccalendar_ext_ctrl_goto"]))
// right panel
// day_view = button({ChangeMode={day}}, "{id}_day", <>Day</>)
// week_view = button({ChangeMode={week}}, "{id}_week", <>Week</>)
two_weeks_view = button({ChangeMode={weeks=2}}, "{id}_two_weeks", <>2 Weeks</>)
month_view = button({ChangeMode={month}}, "{id}_month", <>Month</>)
// style
left_panel_style = css { float: left }
right_panel_style = css { float: right }
panel_style = css
{
border: 1px solid #99BBE8;
border-bottom: none;
height: 22px;
background: #D0DEF0
}
// html
<div id={id} style={panel_style}>
<span style={left_panel_style}>
{today}{prev}{next}{date_range_xhtml}{goto}
</>
<span style={right_panel_style}>
{two_weeks_view}{month_view}
</>
</>
}
google_style_config =
{
generate(id, cal) =
date_range_xhtml = register_date_range_view(cal)
// buttons
buttons_config = make_buttons_style("ccalendar_ext_ctrl_btn")
blue_button = generate_button(cal, buttons_config, _, _, _)
gray_button(op, id, label) =
WSimpleButton.html(id, (_ -> CCalendar.perform(cal, op)), label)
|> style_css(css { margin: 0px 5px })
// left panel
today = gray_button({GoToday}, "{id}_today", "Today")
next = blue_button({Next}, "{id}_next", <>»</>)
prev = blue_button({Prev}, "{id}_prev", <>«</>)
// right panel
// day_view = gray_button({ChangeMode={day}}, "{id}_day", "Day")
// week_view = gray_button({ChangeMode={week}}, "{id}_week", "Week")
two_weeks_view = gray_button({ChangeMode={weeks=2}}, "{id}_two_weeks", "2 Weeks")
month_view = gray_button({ChangeMode={month}}, "{id}_month", "Month")
do WButton.set_toggled(buttons_config, "{id}_month")
// styles
left_panel_style = css { float: left }
right_panel_style = css { float: right }
panel_style = css
{
height: 24px;
background: #BCF;
padding: 4px 10px 4px 5px;
overflow: hidden;
}
// xhtml
<div style={panel_style} id={id}>
<span style={left_panel_style}>
{today}{prev}{next}{date_range_xhtml}
</>
<span style={right_panel_style}>
{month_view}{two_weeks_view}
</>
</>
}
create( id : string
, config : CCalendarControls.config
, cal : CCalendar.instance
) : void =
do Dom.transform([#{id} <- config.generate(id, cal)])
void
}}
ccalendar_controls_css = css
td{}
.ccalendar_ext_ctrl_btn
{
display: inline-block;
cursor: pointer;
line-height: 12px;
heigth: 16px;
background: transparent;
padding: 2px 10px;
border: 1px solid transparent;
color: #555;
font: normal 11px arial,tahoma,verdana,helvetica;
}
.ccalendar_ext_ctrl_btn.over
{
background: #E0EEFF;
border: 1px solid #99BBE8;
}
.ccalendar_ext_ctrl_btn.active
{
background: #C0CEE0;
border: 1px solid #99BBE8;
}
.ccalendar_ext_ctrl_goto input
{
border: 1px solid #7EADD9;
padding: 3px 3px 0px;
width: 70px;
height: 16px;
margin: 0px;
margin-left: 5px;
font: normal 11px arial,tahoma,verdana,helvetica;
}
.ccalendar_google_ctrl_btn
{
display: inline-block;
color: #FFF;
background: #68E;
cursor: pointer;
width: 29px;
height: 17px;
line-height: 3px;
vertical-align: middle;
font: Arial, sans-serif;
border: 1px solid transparent;
padding: 0px 2px;
margin: 0px 3px;
border-radius: 2px;
}
.ccalendar_google_ctrl_btn.active
{
border: 1px solid #CFB17F;
}