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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
|
{-# OPTIONS_FRONTEND -Wno-incomplete-patterns #-}
module HTML.WUI
(
Rendering,WuiSpec,
withRendering,withError,withCondition,adaptWSpec,transformWSpec,
wHidden,wConstant,wInt,
wString,wStringSize,wRequiredString,wRequiredStringSize,wTextArea,
wPassword, wPasswordSize,
wSelect,wSelectInt,wSelectBool,wRadioSelect,wRadioBool,wCheckBool,
wMultiCheckSelect,
wPair,wTriple,w4Tuple,w5Tuple,w6Tuple,w7Tuple,w8Tuple,
w9Tuple,w10Tuple,w11Tuple,w12Tuple,w13Tuple,w14Tuple,
wCons2,wCons3,wCons4,wCons5,wCons6,wCons7,wCons8,
wCons9,wCons10,wCons11,wCons12,wCons13,wCons14,
wJoinTuple,wMaybe,wCheckMaybe,wRadioMaybe,
wList,wListWithHeadings,wHList,wMatrix,wEither,
WTree(..),wTree,
WuiHandler,wuiHandler2button,
renderTuple,renderTaggedTuple,renderList,
WuiStore, WuiSessionStore, setWuiStore, wui2FormDef,
ParWuiSessionStore, setParWuiStore, pwui2FormDef,
wuiSimpleRenderer
)
where
import Data.Char ( isDigit, isSpace )
import Data.List ( elemIndex )
import Data.Function.Inversion ( invf1 )
import HTML.Base
import HTML.Session
infixl 0 `withRendering`
infixl 0 `withError`
infixl 0 `withCondition`
data WuiState =
Ref HtmlRef
| Hidden String
| CompNode [WuiState]
| AltNode (Int,WuiState)
cgiRef2state :: HtmlRef -> WuiState
cgiRef2state cr = Ref cr
state2cgiRef :: WuiState -> HtmlRef
state2cgiRef (Ref cr) = cr
value2state :: Show a => a -> WuiState
value2state v = Hidden (show v)
state2value :: Read a => WuiState -> a
state2value (Hidden s) = read s
states2state :: [WuiState] -> WuiState
states2state sts = CompNode sts
state2states :: WuiState -> [WuiState]
state2states (CompNode sts) = sts
altstate2state :: (Int,WuiState) -> WuiState
altstate2state alt = AltNode alt
state2altstate :: WuiState -> (Int,WuiState)
state2altstate (AltNode alt) = alt
type Rendering = [HtmlExp] -> HtmlExp
type WuiParams a = (Rendering, String, a -> Bool)
renderOf :: WuiParams a -> Rendering
renderOf (render,_,_) = render
errorOf :: WuiParams a -> String
errorOf (_,err,_) = err
conditionOf :: WuiParams a -> (a -> Bool)
conditionOf (_,_,c) = c
type HtmlState = (HtmlExp,WuiState)
data WuiHandler = WHandler HtmlHandler
wuiHandler2button :: String -> WuiHandler -> HtmlExp
wuiHandler2button title (WHandler handler) = button title handler
data WuiSpec a =
WuiSpec (WuiParams a)
(WuiParams a -> Bool -> a -> HtmlState)
(WuiParams a -> a -> Bool)
(HtmlEnv -> WuiState -> a)
withRendering :: WuiSpec a -> Rendering -> WuiSpec a
withRendering (WuiSpec (_,errmsg,legal) showhtml correct readvalue) render =
WuiSpec (render,errmsg,legal) showhtml correct readvalue
withError :: WuiSpec a -> String -> WuiSpec a
withError (WuiSpec (render,_,legal) showhtml correct readvalue) errmsg =
WuiSpec (render,errmsg,legal) showhtml correct readvalue
withCondition :: WuiSpec a -> (a -> Bool) -> WuiSpec a
withCondition (WuiSpec (render,errmsg,_) showhtml correct readvalue) legal =
(WuiSpec (render,errmsg,legal) showhtml correct readvalue)
transformWSpec :: (a->b,b->a) -> WuiSpec a -> WuiSpec b
transformWSpec (a2b,b2a) (WuiSpec wparamsa showhtmla correcta readvaluea) =
WuiSpec (transParam b2a wparamsa)
(\wparamsb nchk b -> showhtmla (transParam a2b wparamsb) nchk (b2a b))
(\wparamsb b -> correcta wparamsa (b2a b) && conditionOf wparamsb b)
(\env wst -> a2b (readvaluea env wst))
where
transParam :: (b->a) -> WuiParams a -> WuiParams b
transParam toa (render,errmsg,legal) = (render,errmsg,legal . toa)
adaptWSpec :: (Data a, Data b) => (a -> b) -> WuiSpec a -> WuiSpec b
adaptWSpec a2b = transformWSpec (a2b, invf1 a2b)
wHidden :: (Read a, Show a) => WuiSpec a
wHidden =
WuiSpec (head, "?", const True)
(\_ _ v -> (hempty, value2state v))
(\_ _ -> True)
(\_ wst -> (state2value wst))
wConstant :: (Read a, Show a) => (a -> HtmlExp) -> WuiSpec a
wConstant showhtml =
WuiSpec (head, "?", const True)
(\wparams _ v -> ((renderOf wparams) [showhtml v], value2state v))
(\_ _ -> True)
(\_ wst -> state2value wst)
wInt :: WuiSpec Int
wInt =
WuiSpec (head,"Illegal integer:",const True)
(checkLegalInput intWidget)
(\wparams -> conditionOf wparams)
(\env wst ->
let input = env (state2cgiRef wst)
in maybe 0 id (readMaybeInt (stripSpaces input)))
where
intWidget render i = let ref free in
(render [textField ref (show i) `addAttr` ("size","6")], cgiRef2state ref)
stripSpaces :: String -> String
stripSpaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace
readMaybeInt :: String -> Maybe Int
readMaybeInt "" = Nothing
readMaybeInt (v:s) | v=='-' = maybe Nothing (\i->Just (-i)) (acc 0 s)
| isDigit v = acc 0 (v:s)
| otherwise = Nothing
where
acc n "" = Just n
acc n (c:cs) | isDigit c = acc (10*n + ord c - ord '0') cs
| otherwise = Nothing
checkLegalInput :: (Rendering -> a -> HtmlState) -> WuiParams a -> Bool -> a
-> HtmlState
checkLegalInput value2widget (render,errmsg,legal) nocheck value =
if nocheck || legal value
then value2widget render value
else value2widget (renderError render errmsg) value
filterStringInput :: String -> String
filterStringInput = removeCRs
removeCRs :: String -> String
removeCRs [] = []
removeCRs [c] = [c]
removeCRs (c1:c2:cs) =
if c1=='\r' && c2=='\n' then '\n' : removeCRs cs
else c1 : removeCRs (c2:cs)
wString :: WuiSpec String
wString = wStringAttrs []
wStringSize :: Int -> WuiSpec String
wStringSize size = wStringAttrs [("size",show size)]
wStringAttrs :: [(String,String)] -> WuiSpec String
wStringAttrs attrs =
WuiSpec (head, "?", const True)
(checkLegalInput stringWidget)
(\wparams -> conditionOf wparams)
(\env s -> filterStringInput (env (state2cgiRef s)))
where
stringWidget render v = let ref free in
(render [foldr (flip addAttr) (textField ref v) attrs], cgiRef2state ref)
wRequiredString :: WuiSpec String
wRequiredString =
wString `withError` "Missing input:"
`withCondition` (not . null)
wRequiredStringSize :: Int -> WuiSpec String
wRequiredStringSize size =
wStringSize size `withError` "Missing input:"
`withCondition` (not . null)
wTextArea :: (Int,Int) -> WuiSpec String
wTextArea dims =
WuiSpec (head, "?", const True)
(checkLegalInput textareaWidget)
(\wparams -> conditionOf wparams)
(\env s -> filterStringInput (env (state2cgiRef s)))
where
textareaWidget render v = let ref free in
(render [textArea ref dims v], cgiRef2state ref)
wPassword :: WuiSpec String
wPassword = wPasswordAttrs []
wPasswordSize :: Int -> WuiSpec String
wPasswordSize size = wPasswordAttrs [("size",show size)]
wPasswordAttrs :: [(String,String)] -> WuiSpec String
wPasswordAttrs attrs =
WuiSpec (head, "Missing input:", (not . null))
(checkLegalInput passwordWidget)
(\wparams -> conditionOf wparams)
(\env s -> env (state2cgiRef s))
where
passwordWidget render _ = let ref free in
(render [foldr (flip addAttr) (password ref) attrs], cgiRef2state ref)
wSelect :: Eq a => (a -> String) -> [a] -> WuiSpec a
wSelect showelem selset =
WuiSpec (head, "?", const True)
(checkLegalInput selWidget)
(\wparams -> conditionOf wparams)
(\env s -> selset !! read (env (state2cgiRef s)))
where
selWidget render v =
let ref free
idx = elemIndex v selset
namevalues = zip (map showelem selset) (map show [0..])
in (render [maybe (selection ref namevalues)
(\i -> selectionInitial ref namevalues i)
idx],
cgiRef2state ref)
wSelectInt :: [Int] -> WuiSpec Int
wSelectInt = wSelect show
wSelectBool :: String -> String -> WuiSpec Bool
wSelectBool true false = wSelect (\b -> if b then true else false) [True,False]
wCheckBool :: [HtmlExp] -> WuiSpec Bool
wCheckBool hexps =
WuiSpec (head, "?", const True)
(checkLegalInput checkWidget)
(\wparams -> conditionOf wparams)
(\env wst -> env (state2cgiRef wst)=="True")
where
checkWidget render v = let ref free in
(render [inline ((if v then checkedBox else checkBox) ref "True" : hexps)],
cgiRef2state ref)
wMultiCheckSelect :: Eq a => (a -> [HtmlExp]) -> [a] -> WuiSpec [a]
wMultiCheckSelect showelem selset =
WuiSpec (renderTuple, tupleError, const True)
(checkLegalInput checkWidget)
(\wparams -> conditionOf wparams)
(\env st ->
concatMap (\ (ref,s) -> if env ref=="True" then [s] else [])
(zip (map state2cgiRef (state2states st)) selset))
where
checkWidget render vs =
let refs = take (length selset) newVars
numsetitems = zip refs selset
showItem (ref,s) =
inline ((if s `elem` vs then checkedBox else checkBox)
ref "True" : showelem s)
in (render (map showItem numsetitems),
states2state (map cgiRef2state refs))
newVars :: Data a => [a]
newVars = unknown : newVars
wRadioSelect :: Eq a => (a->[HtmlExp]) -> [a] -> WuiSpec a
wRadioSelect showelem selset =
WuiSpec (renderTuple, tupleError, const True)
(checkLegalInput radioWidget)
(\wparams -> conditionOf wparams)
(\env s -> selset !! read (env (state2cgiRef s)))
where
radioWidget render v =
let ref free
idx = maybe 0 id (elemIndex v selset)
numhitems = zip [0..] (map showelem selset)
showItem (i,s) = table [[[(if i==idx then radioMain else radioOther)
ref (show i)],s]]
in (render (map showItem numhitems),
cgiRef2state ref)
wRadioBool :: [HtmlExp] -> [HtmlExp] -> WuiSpec Bool
wRadioBool truehexps falsehexps =
wRadioSelect (\b -> if b then truehexps else falsehexps) [True,False]
wPair :: (Data a, Data b) => WuiSpec a -> WuiSpec b -> WuiSpec (a,b)
wPair (WuiSpec wparamsa showa cora reada) (WuiSpec wparamsb showb corb readb) =
WuiSpec (renderTuple, tupleError, const True) showc corc readc
where
showc (render,errmsg,legal) nocheck (va,vb) =
let (hea,rta) = showa wparamsa nocheck va
(heb,rtb) = showb wparamsb nocheck vb
in ((if nocheck || legal (va,vb)
then render
else renderError render errmsg) [hea,heb], states2state [rta,rtb])
corc wparamsc (va,vb) = conditionOf wparamsc (va,vb) &&
cora wparamsa va && corb wparamsb vb
readc env s =
let [ra,rb] = state2states s
in (reada env ra, readb env rb)
wCons2 :: (Data a, Data b, Data c) =>
(a->b->c) -> WuiSpec a -> WuiSpec b -> WuiSpec c
wCons2 cons (WuiSpec wparamsa showa cora reada)
(WuiSpec wparamsb showb corb readb) =
WuiSpec (renderTuple, tupleError, const True) showc corc readc
where
showc (render,errmsg,legal) nocheck vc | cons va vb =:<= vc =
let (hea,rta) = showa wparamsa nocheck va
(heb,rtb) = showb wparamsb nocheck vb
in ((if nocheck || legal (cons va vb)
then render
else renderError render errmsg) [hea,heb], states2state [rta,rtb])
where va,vb free
corc wparamsc vc | cons va vb =:<= vc =
conditionOf wparamsc (cons va vb) &&
cora wparamsa va && corb wparamsb vb where va,vb free
readc env s =
let [ra,rb] = state2states s
in cons (reada env ra) (readb env rb)
wTriple :: (Data a, Data b, Data c) =>
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec (a,b,c)
wTriple (WuiSpec wparamsa showa cora reada)
(WuiSpec wparamsb showb corb readb)
(WuiSpec wparamsc showc corc readc) =
WuiSpec (renderTuple, tupleError, const True) showd cord readd
where
showd (render,errmsg,legal) nocheck (va,vb,vc) =
let (hea,rta) = showa wparamsa nocheck va
(heb,rtb) = showb wparamsb nocheck vb
(hec,rtc) = showc wparamsc nocheck vc
in ((if nocheck || legal (va,vb,vc)
then render
else renderError render errmsg) [hea,heb,hec],
states2state [rta,rtb,rtc])
cord wparamsd (va,vb,vc) = conditionOf wparamsd (va,vb,vc) &&
cora wparamsa va &&
corb wparamsb vb &&
corc wparamsc vc
readd env s =
let [ra,rb,rc] = state2states s
in (reada env ra, readb env rb, readc env rc)
wCons3 :: (Data a, Data b, Data c, Data d) => (a -> b -> c -> d)
-> WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d
wCons3 cons (WuiSpec wparamsa showa cora reada)
(WuiSpec wparamsb showb corb readb)
(WuiSpec wparamsc showc corc readc) =
WuiSpec (renderTuple, tupleError, const True) showd cord readd
where
showd (render,errmsg,legal) nocheck vd | cons va vb vc =:<= vd =
let (hea,rta) = showa wparamsa nocheck va
(heb,rtb) = showb wparamsb nocheck vb
(hec,rtc) = showc wparamsc nocheck vc
in ((if nocheck || legal (cons va vb vc)
then render
else renderError render errmsg) [hea,heb,hec],
states2state [rta,rtb,rtc])
where va,vb,vc free
cord wparamsd vd | cons va vb vc =:<= vd =
conditionOf wparamsd (cons va vb vc) &&
cora wparamsa va &&
corb wparamsb vb &&
corc wparamsc vc where va,vb,vc free
readd env s =
let [ra,rb,rc] = state2states s
in cons (reada env ra) (readb env rb) (readc env rc)
w4Tuple :: (Data a, Data b, Data c, Data d) => WuiSpec a -> WuiSpec b -> WuiSpec c
-> WuiSpec d -> WuiSpec (a,b,c,d)
w4Tuple wa wb wc wd =
transformWSpec (\ ((a,b),(c,d)) -> (a,b,c,d),
\ (a,b,c,d) -> ((a,b),(c,d)))
(wJoinTuple (wPair wa wb) (wPair wc wd))
wCons4 :: (Data a, Data b, Data c, Data d, Data e) => (a->b->c->d->e) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e
wCons4 cons wa wb wc wd =
adaptWSpec (\ ((a,b),(c,d)) -> cons a b c d)
(wJoinTuple (wPair wa wb) (wPair wc wd))
w5Tuple :: (Data a, Data b, Data c, Data d, Data e) => WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec (a,b,c,d,e)
w5Tuple wa wb wc wd we =
transformWSpec (\ ((a,b,c),(d,e)) -> (a,b,c,d,e),
\ (a,b,c,d,e) -> ((a,b,c),(d,e)))
(wJoinTuple (wTriple wa wb wc) (wPair wd we))
wCons5 :: (Data a, Data b, Data c, Data d, Data e, Data f) => (a->b->c->d->e->f) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f
wCons5 cons wa wb wc wd we =
adaptWSpec (\ ((a,b,c),(d,e)) -> cons a b c d e)
(wJoinTuple (wTriple wa wb wc) (wPair wd we))
w6Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f) => WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec (a,b,c,d,e,f)
w6Tuple wa wb wc wd we wf =
transformWSpec (\ ((a,b,c),(d,e,f)) -> (a,b,c,d,e,f),
\ (a,b,c,d,e,f) -> ((a,b,c),(d,e,f)))
(wJoinTuple (wTriple wa wb wc) (wTriple wd we wf))
wCons6 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g) =>
(a->b->c->d->e->f->g) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g
wCons6 cons wa wb wc wd we wf =
adaptWSpec (\ ((a,b,c),(d,e,f)) -> cons a b c d e f)
(wJoinTuple (wTriple wa wb wc) (wTriple wd we wf))
w7Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g) => WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec (a,b,c,d,e,f,g)
w7Tuple wa wb wc wd we wf wg =
transformWSpec (\ ((a,b,c,d),(e,f,g)) -> (a,b,c,d,e,f,g),
\ (a,b,c,d,e,f,g) -> ((a,b,c,d),(e,f,g)))
(wJoinTuple (w4Tuple wa wb wc wd) (wTriple we wf wg))
wCons7 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h) =>
(a->b->c->d->e->f->g->h) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h
wCons7 cons wa wb wc wd we wf wg =
adaptWSpec (\ ((a,b,c,d),(e,f,g)) -> cons a b c d e f g)
(wJoinTuple (w4Tuple wa wb wc wd) (wTriple we wf wg))
w8Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h) => WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec (a,b,c,d,e,f,g,h)
w8Tuple wa wb wc wd we wf wg wh =
transformWSpec (\ ((a,b,c,d),(e,f,g,h)) -> (a,b,c,d,e,f,g,h),
\ (a,b,c,d,e,f,g,h) -> ((a,b,c,d),(e,f,g,h)))
(wJoinTuple (w4Tuple wa wb wc wd) (w4Tuple we wf wg wh))
wCons8 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h, Data i) =>
(a->b->c->d->e->f->g->h->i) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i
wCons8 cons wa wb wc wd we wf wg wh =
adaptWSpec (\ ((a,b,c,d),(e,f,g,h)) -> cons a b c d e f g h)
(wJoinTuple (w4Tuple wa wb wc wd) (w4Tuple we wf wg wh))
w9Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h, Data i) => WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i ->
WuiSpec (a,b,c,d,e,f,g,h,i)
w9Tuple wa wb wc wd we wf wg wh wi =
transformWSpec (\ ((a,b,c,d,e),(f,g,h,i)) -> (a,b,c,d,e,f,g,h,i),
\ (a,b,c,d,e,f,g,h,i) -> ((a,b,c,d,e),(f,g,h,i)))
(wJoinTuple (w5Tuple wa wb wc wd we) (w4Tuple wf wg wh wi))
wCons9 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h, Data i, Data j) => (a->b->c->d->e->f->g->h->i->j) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j
wCons9 cons wa wb wc wd we wf wg wh wi =
adaptWSpec (\ ((a,b,c,d,e),(f,g,h,i)) -> cons a b c d e f g h i)
(wJoinTuple (w5Tuple wa wb wc wd we) (w4Tuple wf wg wh wi))
w10Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h, Data i, Data j) => WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec (a,b,c,d,e,f,g,h,i,j)
w10Tuple wa wb wc wd we wf wg wh wi wj =
transformWSpec (\ ((a,b,c,d,e),(f,g,h,i,j)) -> (a,b,c,d,e,f,g,h,i,j),
\ (a,b,c,d,e,f,g,h,i,j) -> ((a,b,c,d,e),(f,g,h,i,j)))
(wJoinTuple (w5Tuple wa wb wc wd we) (w5Tuple wf wg wh wi wj))
wCons10 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h, Data i, Data j, Data k) => (a->b->c->d->e->f->g->h->i->j->k) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k
wCons10 cons wa wb wc wd we wf wg wh wi wj =
adaptWSpec (\ ((a,b,c,d,e),(f,g,h,i,j)) -> cons a b c d e f g h i j)
(wJoinTuple (w5Tuple wa wb wc wd we) (w5Tuple wf wg wh wi wj))
w11Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h, Data i, Data j, Data k) => WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec (a,b,c,d,e,f,g,h,i,j,k)
w11Tuple wa wb wc wd we wf wg wh wi wj wk =
transformWSpec (\ ((a,b,c,d,e),(f,g,h,i,j,k)) -> (a,b,c,d,e,f,g,h,i,j,k),
\ (a,b,c,d,e,f,g,h,i,j,k) -> ((a,b,c,d,e),(f,g,h,i,j,k)))
(wJoinTuple (w5Tuple wa wb wc wd we) (w6Tuple wf wg wh wi wj wk))
wCons11 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h, Data i, Data j, Data k, Data l) =>
(a->b->c->d->e->f->g->h->i->j->k->l) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec l
wCons11 cons wa wb wc wd we wf wg wh wi wj wk =
adaptWSpec (\ ((a,b,c,d,e),(f,g,h,i,j,k)) -> cons a b c d e f g h i j k)
(wJoinTuple (w5Tuple wa wb wc wd we) (w6Tuple wf wg wh wi wj wk))
w12Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h,
Data i, Data j, Data k, Data l) =>
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec l -> WuiSpec (a,b,c,d,e,f,g,h,i,j,k,l)
w12Tuple wa wb wc wd we wf wg wh wi wj wk wl =
transformWSpec (\ ((a,b,c,d,e,f),(g,h,i,j,k,l)) -> (a,b,c,d,e,f,g,h,i,j,k,l),
\ (a,b,c,d,e,f,g,h,i,j,k,l) -> ((a,b,c,d,e,f),(g,h,i,j,k,l)))
(wJoinTuple (w6Tuple wa wb wc wd we wf) (w6Tuple wg wh wi wj wk wl))
wCons12 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h,
Data i, Data j, Data k, Data l, Data m) =>
(a->b->c->d->e->f->g->h->i->j->k->l->m) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec l -> WuiSpec m
wCons12 cons wa wb wc wd we wf wg wh wi wj wk wl =
adaptWSpec (\ ((a,b,c,d,e,f),(g,h,i,j,k,l)) -> cons a b c d e f g h i j k l)
(wJoinTuple (w6Tuple wa wb wc wd we wf) (w6Tuple wg wh wi wj wk wl))
w13Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h,
Data i, Data j, Data k, Data l, Data m) =>
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec l -> WuiSpec m ->
WuiSpec (a,b,c,d,e,f,g,h,i,j,k,l,m)
w13Tuple wa wb wc wd we wf wg wh wi wj wk wl wm =
transformWSpec
(\ ((a,b,c,d,e,f),(g,h,i,j,k,l,m)) -> (a,b,c,d,e,f,g,h,i,j,k,l,m),
\ (a,b,c,d,e,f,g,h,i,j,k,l,m) -> ((a,b,c,d,e,f),(g,h,i,j,k,l,m)))
(wJoinTuple (w6Tuple wa wb wc wd we wf) (w7Tuple wg wh wi wj wk wl wm))
wCons13 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h,
Data i, Data j, Data k, Data l, Data m, Data n) =>
(a->b->c->d->e->f->g->h->i->j->k->l->m->n) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec l -> WuiSpec m -> WuiSpec n
wCons13 cons wa wb wc wd we wf wg wh wi wj wk wl wm =
adaptWSpec
(\ ((a,b,c,d,e,f),(g,h,i,j,k,l,m)) -> cons a b c d e f g h i j k l m)
(wJoinTuple (w6Tuple wa wb wc wd we wf) (w7Tuple wg wh wi wj wk wl wm))
w14Tuple :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h,
Data i, Data j, Data k, Data l, Data m, Data n) =>
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec l -> WuiSpec m -> WuiSpec n ->
WuiSpec (a,b,c,d,e,f,g,h,i,j,k,l,m,n)
w14Tuple wa wb wc wd we wf wg wh wi wj wk wl wm wn =
transformWSpec
(\ ((a,b,c,d,e,f,g),(h,i,j,k,l,m,n)) -> (a,b,c,d,e,f,g,h,i,j,k,l,m,n),
\ (a,b,c,d,e,f,g,h,i,j,k,l,m,n) -> ((a,b,c,d,e,f,g),(h,i,j,k,l,m,n)))
(wJoinTuple (w7Tuple wa wb wc wd we wf wg) (w7Tuple wh wi wj wk wl wm wn))
wCons14 :: (Data a, Data b, Data c, Data d, Data e, Data f, Data g, Data h,
Data i, Data j, Data k, Data l, Data m, Data n, Data o) =>
(a->b->c->d->e->f->g->h->i->j->k->l->m->n->o) ->
WuiSpec a -> WuiSpec b -> WuiSpec c -> WuiSpec d -> WuiSpec e ->
WuiSpec f -> WuiSpec g -> WuiSpec h -> WuiSpec i -> WuiSpec j ->
WuiSpec k -> WuiSpec l -> WuiSpec m -> WuiSpec n -> WuiSpec o
wCons14 cons wa wb wc wd we wf wg wh wi wj wk wl wm wn =
adaptWSpec
(\ ((a,b,c,d,e,f,g),(h,i,j,k,l,m,n)) -> cons a b c d e f g h i j k l m n)
(wJoinTuple (w7Tuple wa wb wc wd we wf wg) (w7Tuple wh wi wj wk wl wm wn))
wJoinTuple :: (Data a, Data b) => WuiSpec a -> WuiSpec b -> WuiSpec (a,b)
wJoinTuple (WuiSpec wparamsa showa cora reada)
(WuiSpec wparamsb showb corb readb) =
WuiSpec (renderTuple, tupleError, const True) showc corc readc
where
render2joinrender render [h1,h2] =
let h1s = unRenderTuple h1
h2s = unRenderTuple h2
in render (h1s ++ h2s)
showc (render,errmsg,legal) nocheck (va,vb) =
let (hea,rta) = showa wparamsa nocheck va
(heb,rtb) = showb wparamsb nocheck vb
in ((if nocheck || legal (va,vb)
then render2joinrender render
else renderError (render2joinrender render) errmsg) [hea,heb],
states2state [rta,rtb])
corc wparamsc (va,vb) = conditionOf wparamsc (va,vb) &&
cora wparamsa va && corb wparamsb vb
readc env s =
let [ra,rb] = state2states s
in (reada env ra, readb env rb)
wList :: Eq a => WuiSpec a -> WuiSpec [a]
wList (WuiSpec wparamsa showa cora reada) =
WuiSpec (renderList, "Illegal list:", const True)
(\ (render,errmsg,legal) nocheck vas ->
listWidget
(if nocheck || legal vas
then render
else renderError render errmsg)
(unzip (map (showa wparamsa nocheck) vas)))
(\wparams vas -> conditionOf wparams vas &&
all (cora wparamsa) vas)
(\env wst -> map (reada env) (state2states wst))
where
listWidget render (hes,refs) = (render hes, states2state refs)
wListWithHeadings :: Eq a => [String] -> WuiSpec a -> WuiSpec [a]
wListWithHeadings headings wspec =
wList wspec `withRendering` renderHeadings
where
renderHeadings hs = addHeadings (renderList hs) (map (\s->[htxt s]) headings)
addHeadings :: HtmlExp -> [[HtmlExp]] -> HtmlExp
addHeadings htable headings = case htable of
HtmlStruct "table" attrs rows ->
HtmlStruct "table" attrs
(HtmlStruct "tr" [] (map (HtmlStruct "th" []) headings) : rows)
_ -> htable
wHList :: Eq a => WuiSpec a -> WuiSpec [a]
wHList wspec = wList wspec `withRendering` renderTuple
wMatrix :: Eq a => WuiSpec a -> WuiSpec [[a]]
wMatrix wspec = wList (wHList wspec)
wMaybe :: Eq a => WuiSpec Bool -> WuiSpec a -> a -> WuiSpec (Maybe a)
wMaybe (WuiSpec paramb showb _ readb) (WuiSpec parama showa cora reada) def =
WuiSpec
(renderTuple, tupleError, const True)
(\ (render,errmsg,legal) nocheck mbs ->
let (heb,rtb) = showb paramb nocheck (mbs/=Nothing)
(hea,rta) = showa parama nocheck (maybe def id mbs)
in ((if nocheck || legal mbs
then render
else renderError render errmsg) [heb,hea],
states2state [rtb,rta]))
(\wparams mbv -> conditionOf wparams mbv &&
maybe True (\v -> cora parama v) mbv)
(\env s ->
let [rb,ra] = state2states s
vb = readb env rb
va = reada env ra
in if vb then Just va else Nothing)
wCheckMaybe :: Eq a => WuiSpec a -> [HtmlExp] -> a -> WuiSpec (Maybe a)
wCheckMaybe wspec exps = wMaybe (wCheckBool exps) wspec
wRadioMaybe :: Eq a => WuiSpec a -> [HtmlExp] -> [HtmlExp] -> a
-> WuiSpec (Maybe a)
wRadioMaybe wspec hnothing hjust = wMaybe wBool wspec
where
wBool = wRadioSelect (\b->if b then hjust else hnothing) [False,True]
wEither :: (Eq a, Eq b) => WuiSpec a -> WuiSpec b -> WuiSpec (Either a b)
wEither (WuiSpec rendera showa cora reada) (WuiSpec renderb showb corb readb) =
WuiSpec (head, "?", const True) showEither corEither readEither
where
showEither (render,errmsg,legal) nocheck (Left va) =
let (hea,rta) = showa rendera nocheck va
in ((if nocheck || legal (Left va)
then render
else renderError render errmsg) [hea], altstate2state (1,rta))
showEither (render,errmsg,legal) nocheck (Right vb) =
let (heb,rtb) = showb renderb nocheck vb
in ((if nocheck || legal (Right vb)
then render
else renderError render errmsg) [heb], altstate2state (2,rtb))
corEither wparam vab = conditionOf wparam vab &&
either (cora rendera) (corb renderb) vab
readEither env s =
let (altindex,rab) = state2altstate s
in case altindex of
1 -> Left (reada env rab)
2 -> Right (readb env rab)
data WTree a = WLeaf a | WNode [WTree a]
deriving Eq
wTree :: Eq a => WuiSpec a -> WuiSpec (WTree a)
wTree (WuiSpec wparama showa cora reada) =
WuiSpec (renderList, "Illegal tree:", const True) showTree corTree readTree
where
showTree (render,errmsg,legal) nocheck (WLeaf va) =
let (hea,rta) = showa wparama nocheck va
in ((if nocheck || legal (WLeaf va)
then render
else renderError render errmsg) [hea],
altstate2state (1,rta))
showTree wparams@(render,errmsg,legal) nocheck (WNode ns) =
let (hes,sts) = unzip (map (showTree wparams nocheck) ns)
in ((if nocheck || legal (WNode ns)
then render
else renderError render errmsg) hes,
altstate2state (2,states2state sts))
corTree wparam (WLeaf va) = conditionOf wparam (WLeaf va) && cora wparama va
corTree wparam (WNode tvs) = conditionOf wparam (WNode tvs) &&
all (corTree wparam) tvs
readTree env wst =
let (altindex,rab) = state2altstate wst
in case altindex of
1 -> WLeaf (reada env rab)
2 -> WNode (map (readTree env) (state2states rab))
renderTuple :: Rendering
renderTuple hexps = table [map (\h->[h]) hexps]
unRenderTuple :: HtmlExp -> [HtmlExp]
unRenderTuple hexp =
if isTupleTable hexp
then getTupleTableElems hexp
else [hexp]
where
isTupleTable he = case he of
HtmlStruct "table" [] [HtmlStruct "tr" [] tds] -> all isSingleElem tds
_ -> False
isSingleElem he = case he of
HtmlStruct "td" _ [_] -> True
_ -> False
getTupleTableElems (HtmlStruct "table" [] [HtmlStruct "tr" [] tds]) =
map (\ (HtmlStruct "td" _ [e]) -> e) tds
tupleError :: String
tupleError = "Illegal combination:"
renderTaggedTuple :: [String] -> Rendering
renderTaggedTuple tags hexps =
table (map (\(t,h)->[[bold [htxt t]],[h]]) (zip tags hexps))
renderList :: Rendering
renderList hexps = mergeTableOfTable (table (map (\h->[[h]]) hexps))
`addAttr` ("border","1")
renderError :: Rendering -> String -> Rendering
renderError render errmsg hexps =
table [[[boldRedTxt errmsg]], [[render hexps]]]
`addAttr` ("bgcolor","#ffff00")
boldRedTxt :: String -> HtmlExp
boldRedTxt s = HtmlStruct "font" [("color","#ff0000")] [bold [htxt s]]
mergeTableOfTable :: HtmlExp -> HtmlExp
mergeTableOfTable (HtmlStruct "table" attrs rows) =
HtmlStruct "table" attrs
(if all isRowWithSingleTableData rows
then map mergeRowWithSingleTableData rows
else rows )
isRowWithSingleTableData :: HtmlExp -> Bool
isRowWithSingleTableData row = case row of
(HtmlStruct "tr" []
[HtmlStruct "td" []
[HtmlStruct "table" _ [HtmlStruct "tr" _ _]]]) -> True
_ -> False
mergeRowWithSingleTableData :: HtmlExp -> HtmlExp
mergeRowWithSingleTableData
(HtmlStruct "tr" [] [HtmlStruct "td" [] [HtmlStruct "table" _ [row]]]) = row
type WuiStore a = (Bool, Maybe a)
type WuiSessionStore a = SessionStore (WuiStore a)
type ParWuiSessionStore b a = SessionStore (b, WuiStore a)
setWuiStore :: (Read a, Show a) => WuiSessionStore a -> a -> IO ()
setWuiStore wuistore val = putSessionData wuistore (True, Just val)
getWuiStore :: (Read a, Show a) =>
WuiSessionStore a -> FormReader (WuiStore a)
getWuiStore wuistore = getSessionData wuistore (True, Nothing)
setParWuiStore :: (Read a, Show a, Read b, Show b) =>
ParWuiSessionStore b a -> b -> a -> IO ()
setParWuiStore wuistore par val =
putSessionData wuistore (par, (True, Just val))
getParWuiStore :: (Read a, Show a, Read b, Show b) =>
ParWuiSessionStore b a -> FormReader (b,WuiStore a)
getParWuiStore wuistore = getSessionData wuistore (failed, (True, Nothing))
wui2FormDef :: (Read a, Show a) =>
String
-> WuiSessionStore a
-> WuiSpec a
-> (a -> IO [BaseHtml])
-> (HtmlExp -> (HtmlEnv -> IO [BaseHtml]) -> [HtmlExp])
-> HtmlFormDef (WuiStore a)
wui2FormDef formqname wuistore wuispec storepage renderwui =
let wuiformdef = formDefWithID formqname (getWuiStore wuistore)
(formHtml wuiformdef)
in wuiformdef
where
formHtml iform sdata =
wui2HtmlExp wuistore wuispec storepage renderwui iform sdata
wui2HtmlExp :: (Read a, Show a) =>
WuiSessionStore a
-> WuiSpec a
-> (a -> IO [BaseHtml])
-> (HtmlExp -> (HtmlEnv -> IO [BaseHtml]) -> [HtmlExp])
-> HtmlFormDef (WuiStore a)
-> WuiStore a -> [HtmlExp]
wui2HtmlExp _ _ _ _ _ (_,Nothing) =
[h1 [htxt "Execution error!"],
htxt "Cookie not yet set, please run again or accept cookies!"]
wui2HtmlExp wuistore (WuiSpec wparams wshow wcor wread) storepage renderwui
wuiformdef (fstcall,Just val) =
let (hexp,wst) = wshow wparams fstcall val
in renderwui hexp (handler wst)
where
handler wst env = do
let newval = id $## wread env wst
if (wcor wparams) newval
then do putSessionData wuistore (True, Nothing)
storepage newval
else do putSessionData wuistore (False, Just newval)
return [formElem wuiformdef]
pwui2FormDef :: (Read a, Show a, Read b, Show b) =>
String
-> ParWuiSessionStore b a
-> (b -> WuiSpec a)
-> (b -> a -> IO [BaseHtml])
-> (b -> HtmlExp -> (HtmlEnv -> IO [BaseHtml]) -> [HtmlExp])
-> HtmlFormDef (b, WuiStore a)
pwui2FormDef formqname wuistore wuispec storepage renderwui =
let wuiformdef = formDefWithID formqname (getParWuiStore wuistore)
(formHtml wuiformdef)
in wuiformdef
where
formHtml iform sdata =
pwui2HtmlExp wuistore wuispec storepage renderwui iform sdata
pwui2HtmlExp :: (Read a, Show a, Read b, Show b) =>
ParWuiSessionStore b a
-> (b -> WuiSpec a)
-> (b -> a -> IO [BaseHtml])
-> (b -> HtmlExp -> (HtmlEnv -> IO [BaseHtml]) -> [HtmlExp])
-> HtmlFormDef (b,WuiStore a)
-> (b, WuiStore a) -> [HtmlExp]
pwui2HtmlExp _ _ _ _ _ (_,(_,Nothing)) =
[h1 [htxt "Execution error!"],
htxt "Cookie not yet set, please run again or accept cookies!"]
pwui2HtmlExp wuistore pwuispec storepage renderwui
wuiformdef (par, (fstcall,Just val)) =
let (WuiSpec wparams wshow wcor wread) = pwuispec par
(hexp,wst) = wshow wparams fstcall val
in renderwui par hexp (handler wparams wcor wread wst)
where
handler wparams wcor wread wst env = do
let newval = id $## wread env wst
if (wcor wparams) newval
then do putSessionData wuistore (par, (True, Nothing))
storepage par newval
else do putSessionData wuistore (par, (False, Just newval))
return [formElem wuiformdef]
wuiSimpleRenderer :: HtmlExp -> (HtmlEnv -> IO [BaseHtml]) -> [HtmlExp]
wuiSimpleRenderer inputhexp storehandler =
[inputhexp, breakline,
button "Submit" (\env -> storehandler env >>= return . page "Answer")]
|