-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.ur
205 lines (183 loc) · 9.68 KB
/
widget.ur
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
con t (value :: Type) (state :: Type) (config :: Type) =
{ Configure : transaction config,
Create : config -> transaction state,
Initialize : config -> value -> transaction state,
Reset : state -> transaction unit,
AsWidget : state -> option id -> xbody,
Value : state -> signal value,
AsValue : value -> xbody }
con t' (value :: Type, state :: Type, config :: Type) = t value state config
fun configure [value] [state] [config] (t : t value state config) = t.Configure
fun create [value] [state] [config] (t : t value state config) = t.Create
fun initialize [value] [state] [config] (t : t value state config) = t.Initialize
fun reset [value] [state] [config] (t : t value state config) = t.Reset
fun asWidget [value] [state] [config] (t : t value state config) = t.AsWidget
fun value [value] [state] [config] (t : t value state config) = t.Value
fun asValue [value] [state] [config] (t : t value state config) = t.AsValue
fun make [value] [state] [config] r = r
val textbox = { Configure = return (),
Create = fn () => source "",
Initialize = fn () => source,
Reset = fn s => set s "",
AsWidget = fn s ido =>
case ido of
None => <xml><ctextbox class={Bootstrap3.form_control} source={s}/></xml>
| Some id => <xml><ctextbox class={Bootstrap3.form_control} source={s} id={id}/></xml>,
Value = signal,
AsValue = txt }
val opt_textbox = { Configure = return (),
Create = fn () => source "",
Initialize = fn () o => source (Option.get "" o),
Reset = fn s => set s "",
AsWidget = fn s ido =>
case ido of
None => <xml><ctextbox class={Bootstrap3.form_control} source={s}/></xml>
| Some id => <xml><ctextbox class={Bootstrap3.form_control} source={s} id={id}/></xml>,
Value = fn s =>
v <- signal s;
return (case v of
"" => None
| _ => Some v),
AsValue = fn o => case o of
None => <xml></xml>
| Some s => txt s }
val checkbox = { Configure = return (),
Create = fn () => source False,
Initialize = fn () => source,
Reset = fn s => set s False,
AsWidget = fn s ido =>
case ido of
None => <xml><ccheckbox class={Bootstrap3.form_control} source={s}/></xml>
| Some id => <xml><ccheckbox class={Bootstrap3.form_control} source={s} id={id}/></xml>,
Value = signal,
AsValue = txt }
val intbox = { Configure = return (),
Create = fn () => source "",
Initialize = fn () n => source (show n),
Reset = fn s => set s "",
AsWidget = fn s ido =>
case ido of
None => <xml><ctextbox class={Bootstrap3.form_control} source={s}/></xml>
| Some id => <xml><ctextbox class={Bootstrap3.form_control} source={s} id={id}/></xml>,
Value = fn s => v <- signal s; return (Option.get 0 (read v)),
AsValue = txt }
val timebox = { Configure = return (),
Create = fn () => source "",
Initialize = fn () n => source (show n),
Reset = fn s => set s "",
AsWidget = fn s ido =>
case ido of
None => <xml><ctextbox class={Bootstrap3.form_control} source={s}/></xml>
| Some id => <xml><ctextbox class={Bootstrap3.form_control} source={s} id={id}/></xml>,
Value = fn s => v <- signal s; return (Option.get minTime (read v)),
AsValue = fn t => if t = minTime then <xml><b>INVALID</b></xml> else txt t }
val urlbox = { Configure = return (),
Create = fn () => source "",
Initialize = fn () => source,
Reset = fn s => set s "",
AsWidget = fn s ido =>
case ido of
None => <xml><ctextbox class={Bootstrap3.form_control} source={s}/></xml>
| Some id => <xml><ctextbox class={Bootstrap3.form_control} source={s} id={id}/></xml>,
Value = signal,
AsValue = fn s =>
case checkUrl s of
None => <xml><b>[BLOCKED URL]</b></xml>
| Some url => <xml><a href={url}><tt>{[url]}</tt></a></xml> }
val undoEtc = Ckeditor.Bar {Nam = Some "Undo, etc.",
Buttons = Ckeditor.Cut
:: Ckeditor.Copy
:: Ckeditor.Paste
:: Ckeditor.PasteText
:: Ckeditor.PasteFromWord
:: Ckeditor.Undo
:: Ckeditor.Redo
:: []}
val find = Ckeditor.Bar {Nam = Some "Find",
Buttons = Ckeditor.Find
:: Ckeditor.Replace
:: Ckeditor.SelectAll
:: []}
val basic = Ckeditor.Bar {Nam = Some "Basic Formatting",
Buttons = Ckeditor.Bold
:: Ckeditor.Italic
:: Ckeditor.Underline
:: Ckeditor.RemoveFormat
:: []}
val links = Ckeditor.Bar {Nam = Some "Links",
Buttons = Ckeditor.Link
:: Ckeditor.Unlink
:: []}
fun ed s = Ckeditor.editor {Width = Ckeditor.DefaultSize,
Height = Ckeditor.DefaultSize,
ToolbarSet = Ckeditor.Custom (undoEtc :: find :: basic :: links :: []),
InitialText = s}
fun html s =
case Html.format (Html.b, Html.i, Html.a, Html.strong, Html.em, Html.p) s of
Html.Failure msg => <xml><b>HTML error: {[msg]}</b></xml>
| Html.Success xm => xm
val htmlbox = { Configure = return (),
Create = fn () => ed "",
Initialize = fn () => ed,
Reset = fn me => Ckeditor.setContent me "",
AsWidget = fn me _ => Ckeditor.show me,
Value = Ckeditor.content,
AsValue = html }
type foreignbox (a :: Type) =
{ Choices : list a,
Source : source string }
type foreignbox_config (a :: Type) = list a
fun foreignbox [a ::: Type] [f ::: Name] (_ : show a) (_ : read a) (q : sql_query [] [] [] [f = a]) =
{ Configure = List.mapQuery q (fn r => r.f),
Create = fn ls =>
s <- source "";
return {Choices = ls, Source = s},
Initialize = fn ls v =>
s <- source (show v);
return {Choices = ls, Source = s},
Reset = fn me => set me.Source "",
AsWidget = fn me id =>
let
val inner = <xml>
<coption></coption>
{List.mapX (fn v => <xml><coption>{[v]}</coption></xml>) me.Choices}
</xml>
in
case id of
None => <xml><cselect class={Bootstrap3.form_control} source={me.Source}>{inner}</cselect></xml>
| Some id => <xml><cselect class={Bootstrap3.form_control} id={id} source={me.Source}>{inner}</cselect></xml>
end,
Value = fn me =>
v <- signal me.Source;
return (case v of
"" => None
| _ => read v),
AsValue = txt }
con foreignbox_default = foreignbox
con foreignbox_default_config = foreignbox_config
fun foreignbox_default [a ::: Type] [f ::: Name] (_ : show a) (_ : read a) (q : sql_query [] [] [] [f = a]) (default : a) =
{ Configure = List.mapQuery q (fn r => r.f),
Create = fn ls =>
s <- source "";
return {Choices = ls, Source = s},
Initialize = fn ls v =>
s <- source (show v);
return {Choices = ls, Source = s},
Reset = fn me => set me.Source "",
AsWidget = fn me id =>
let
val inner = <xml>
<coption></coption>
{List.mapX (fn v => <xml><coption>{[v]}</coption></xml>) me.Choices}
</xml>
in
case id of
None => <xml><cselect class={Bootstrap3.form_control} source={me.Source}>{inner}</cselect></xml>
| Some id => <xml><cselect class={Bootstrap3.form_control} id={id} source={me.Source}>{inner}</cselect></xml>
end,
Value = fn me =>
v <- signal me.Source;
return (case v of
"" => default
| _ => Option.get default (read v)),
AsValue = txt }