Commit 47ea739e authored by Bas Lijnse's avatar Bas Lijnse

Fixed the checkbox combinators

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/branches/fancyTasks@354 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent e5aad21b
......@@ -184,7 +184,6 @@ where
simpleButton :: !String !String !(a -> a) !*HSt -> (Form (a -> a),!*HSt)
simpleButton id label fun hst
// = FuncBut (Init, nFormId (id +++ label) (LButton defpixel label,fun)) hst
= FuncBut (Init, nFormId id (HtmlButton label False,fun)) hst
counterForm :: !(InIDataId a) !*HSt -> (Form a,!*HSt) | +, -, one, iData a
......@@ -316,9 +315,10 @@ ListFuncBut :: !(InIDataId [(HtmlButton, a -> a)]) !*HSt -> (Form (a -> a),!*HSt
ListFuncBut (init,formid) hSt
= layoutIndexForm (\f1 f2 -> [DivTag [] (f1 ++ f2)]) FuncButNr id (o) 0 (init,formid) hSt
ListFuncCheckBox :: !(InIDataId [(HtmlCheckbox, Bool [Bool] a -> a)]) !*HSt -> (Form (a -> a,[Bool]),!*HSt)
ListFuncCheckBox (init,formid) hst
# (check,hst) = ListFuncCheckBox` formid.ival hst
# (check,hst) = ListFuncCheckBox` formid.ival 0 hst
# (f,bools) = check.Form.value
= ({ changed = False
, value = (f bools,bools)
......@@ -326,35 +326,35 @@ ListFuncCheckBox (init,formid) hst
, inputs = check.inputs
},hst)
where
ListFuncCheckBox` :: ![(HtmlCheckbox, Bool [Bool] a -> a)] !*HSt -> (Form ([Bool] a -> a,[Bool]),!*HSt)
ListFuncCheckBox` [] hst
= ({ changed = False
, value = (const2,[])
, form = []
, inputs = []
},hst)
ListFuncCheckBox` [x:xs] hst
# (rowfun,hst) = ListFuncCheckBox` xs hst
# (fun ,hst) = FuncCheckBox formid x hst
# (rowfunv,boolsv) = rowfun.Form.value
# (funv,nboolv) = fun.Form.value
= ({ changed = rowfun.changed || fun.changed
, value = (funcomp funv rowfunv,[nboolv:boolsv])
, form = fun.form ++ rowfun.form
, inputs = fun.inputs ++ rowfun.inputs
},hst)
ListFuncCheckBox` :: ![(HtmlCheckbox, Bool [Bool] a -> a)] !Int !*HSt -> (Form ([Bool] a -> a,[Bool]),!*HSt)
ListFuncCheckBox` [] i hst
= ({ changed = False
, value = (const2,[])
, form = []
, inputs = []
},hst)
ListFuncCheckBox` [x:xs] i hst
# (xform ,hst) = FuncCheckBox (init, formid) x i hst
# (xsform ,hst) = ListFuncCheckBox` xs (inc i) hst
# (xfun,xbool) = xform.Form.value
# (xsfun,xsbools) = xsform.Form.value
= ({ changed = xform.changed || xsform.changed
, value = (funcomp xfun xsfun, [xbool:xsbools])
, form = xform.Form.form ++ xsform.Form.form
, inputs = xform.inputs ++ xsform.inputs
},hst)
where
funcomp f g = \bools a = f bools (g bools a)
FuncCheckBox formid (checkbox,cbf) hst
= mkViewForm (init, nformid) bimap hst
funcomp f g = \bools a -> g bools (f bools a)
FuncCheckBox (init, formid) (checkbox, cbf) i hst
= mkViewForm (init, nformid) bimap hst
where
bimap = { toForm = \init _ v -> toViewId init checkbox v
, updForm = \b v -> v
, fromForm = \b (HtmlCheckbox label val) -> if b.isChanged (cbf val,val) (const2,val)
, resetForm = Nothing
}
nformid = {formid & ival = (const2,False)} <@ formid.id
nformid = subFormId formid ("cb" +++ toString i) (const2,False)
FuncMenu :: !(InIDataId (Int,[(String, a -> a)])) !*HSt -> (Form (a -> a,Int),!*HSt)
......
......@@ -90,4 +90,4 @@ toHtmlForm :: !(*HSt -> *(Form a,*HSt)) -> [HtmlTag] // toHtmlForm di
mkInput :: !(InIDataId d) String String !*HSt -> ([HtmlTag],[InputId],*HSt)
mkButton :: !(InIDataId d) String String !*HSt -> ([HtmlTag],[InputId],*HSt)
mkSelect :: !(InIDataId d) String String [(String,String)] !*HSt -> ([HtmlTag],[InputId],*HSt)
mkCheckBox :: !(InIDataId d) String Bool !*HSt -> ([HtmlTag],[InputId],*HSt)
\ No newline at end of file
mkCheckBox :: !(InIDataId d) String [HtmlTag] Bool !*HSt -> ([HtmlTag],[InputId],*HSt)
\ No newline at end of file
......@@ -137,7 +137,7 @@ gForm{|Real|} (init,formid) hst
},hst)
gForm{|Bool|} (init,formid) hst
# (html,inputs,hst) = mkCheckBox (init,formid) "Bool" formid.ival hst
# (html,inputs,hst) = mkCheckBox (init,formid) "Bool" [] formid.ival hst
= ({ changed = False
, value = formid.ival
, form = html
......@@ -282,7 +282,7 @@ where
gForm{|Maybe|} gHa (init,formid) hst
= case formid.ival of
Just a
# (html,inputs,hst) = mkCheckBox (init,formid) "Maybe" True hst
# (html,inputs,hst) = mkCheckBox (init,formid) "Maybe" [] True hst
# (na,hst) = gHa (init,reuseFormId formid a) hst
= ( { changed = na.changed
, value = Just na.Form.value
......@@ -296,7 +296,7 @@ gForm{|Maybe|} gHa (init,formid) hst
, inputs = inputs ++ na.inputs
},hst)
Nothing
# (html,inputs,hst) = mkCheckBox (init,formid) "Maybe" False hst
# (html,inputs,hst) = mkCheckBox (init,formid) "Maybe" [] False hst
= ( { changed = False
, value = Nothing
, form = html
......@@ -469,14 +469,15 @@ mkSelect (init, formid=:{mode}) type val options hst =:{cntr,prefix}
, [{formid = formid.id, inputid = cntr, type = type, updateon = (if (mode == Edit) OnChange OnSubmit)}]
, setHStCntr (cntr + 1) hst)
mkCheckBox :: !(InIDataId d) String Bool !*HSt -> ([HtmlTag],[InputId],*HSt)
mkCheckBox (init, formid=:{mode}) type val hst =:{cntr,prefix}
# inputid = (prefix +++ formid.id +++ "-" +++ toString cntr)
= ( [InputTag [ NameAttr inputid
mkCheckBox :: !(InIDataId d) String [HtmlTag] Bool !*HSt -> ([HtmlTag],[InputId],*HSt)
mkCheckBox (init, formid=:{mode}) type label val hst =:{cntr,prefix}
# inputname = formid.id +++ "-" +++ toString cntr
# inputid = prefix +++ inputname
= ( [InputTag [ NameAttr inputname
, IdAttr inputid
, TypeAttr "checkbox"
: (if (mode == Display) [DisabledAttr] []) ++ (if val [CheckedAttr] [])
]]
]: if (isEmpty label) [] [LabelTag [ForAttr inputid] label] ]
, [{formid = formid.id, inputid = cntr, type = type, updateon = (if (mode == Edit) OnChange OnSubmit)}]
, setHStCntr (cntr + 1) hst)
......
......@@ -80,17 +80,12 @@ where
(HtmlButton l t) = formid.ival
gForm{|HtmlCheckbox|} (init,formid =: {mode}) hst =:{cntr,prefix}
# inputid = prefix +++ formid.id +++ "-" +++ toString cntr
# (html, inputs, hst) = mkCheckBox (init,formid) "HtmlCheckbox" l t hst
= ({ changed = False
, value = formid.ival
, form = [InputTag [ TypeAttr "checkbox"
, NameAttr inputid
, IdAttr inputid
: if t [CheckedAttr] []
]]
++ if (isEmpty l) [] [LabelTag [ForAttr inputid] l]
, inputs = [{formid = formid.id, inputid = cntr, type = "HtmlCheckBox", updateon = if (mode == Edit ) OnChange OnSubmit}]
},setHStCntr (cntr + 1) hst)
, form = html
, inputs = inputs
},hst)
where
(HtmlCheckbox l t) = formid.ival
......
......@@ -138,29 +138,29 @@ where
selectTask_cbox :: ![(!Bool,!ChoiceUpdate,![HtmlTag])] ![LabeledTask a] -> Task [Int]
selectTask_cbox htmlcodes taskOptions = Task (selectTask_cbox` taskOptions)
where
selectTask_cbox` [] tst = ([],{tst& activated = True})
selectTask_cbox` [] tst = ([],{tst& activated = True})
selectTask_cbox` taskOptions tst=:{tasknr,html,options,userId} // choose one subtask out of the list
# seltaskId = iTaskId userId tasknr ("MtpChSel" <+++ length taskOptions)
# donetaskId = iTaskId userId tasknr "MtpChSt"
# (cboxes,tst) = liftHst (ListFuncCheckBox (Init,cFormId options seltaskId initCheckboxes)) tst
# (fun,nblist) = cboxes.Form.value
# nsettings = fun nblist
# (cboxes,tst) = liftHst (ListFuncCheckBox (Set ,cFormId options seltaskId (setCheckboxes nsettings))) tst
# (done,tst) = liftHst (mkStoreForm (Init,storageFormId options donetaskId False) id) tst
# (_,tst=:{html=ahtml,activated = adone})
= appTaskTSt (editTaskLabel "" "OK" Void) {tst & activated = True, html = BT [] [], tasknr = [-1:tasknr]}
| not adone
# optionsform = cboxes.form <=|> [DivTag [] ([showLabel label] <||> htmlcode) \\ (_,_,htmlcode) <- htmlcodes & (label,_) <- taskOptions]
= ([],{tst & html = html +|+ BT optionsform cboxes.inputs +|+ ahtml})
# (_,tst) = liftHst (mkStoreForm (Init,storageFormId options donetaskId False) (\_ -> True)) tst
= ([i \\ True <- snd cboxes.Form.value & i <- [0..]],{tst & tasknr = tasknr, html = html, options = options, userId =userId, activated = True}) // choose one subtask out of the list
# seltaskId = iTaskId userId tasknr ("MtpChSel" <+++ length taskOptions)
# donetaskId = iTaskId userId tasknr "MtpChSt"
# (cboxes,tst) = liftHst (ListFuncCheckBox (Init,cFormId options seltaskId initCheckboxes)) tst
# (fun,nblist) = cboxes.Form.value
# nsettings = fun nblist
# (cboxes,tst) = liftHst (ListFuncCheckBox (Set ,cFormId options seltaskId (setCheckboxes nsettings))) tst
# (done,tst) = liftHst (mkStoreForm (Init,storageFormId options donetaskId False) id) tst
# (_,tst=:{html=ahtml,activated = adone})
= appTaskTSt (editTaskLabel "" "OK" Void) {tst & activated = True, html = BT [] [], tasknr = [-1:tasknr]}
| not adone
= ([],{tst & html = html +|+ BT cboxes.form cboxes.inputs +|+ ahtml})
| otherwise
# (_,tst) = liftHst (mkStoreForm (Init,storageFormId options donetaskId False) (\_ -> True)) tst
= ([i \\ True <- snd cboxes.Form.value & i <- [0..]],{tst & tasknr = tasknr, html = html, options = options, userId =userId, activated = True})
initCheckboxes =
[(HtmlCheckbox [Text label] set, \b bs _ -> setfun b bs) \\ (set,setfun,_) <- htmlcodes & (label,_) <- taskOptions & i <- [0..]]
[(HtmlCheckbox [Text label : htmlcode] set, \b bs _ -> setfun b bs) \\ (set,setfun,htmlcode) <- htmlcodes & (label,_) <- taskOptions ]
setCheckboxes boollist =
[(HtmlCheckbox [Text label] set, \b bs _ -> setfun b bs) \\ (_,setfun,_) <- htmlcodes & (label,_) <- taskOptions
[(HtmlCheckbox [Text label: htmlcode] set, \b bs _ -> setfun b bs) \\ (_,setfun, htmlcode) <- htmlcodes & (label,_) <- taskOptions
& i <- [0..] & set <- boollist]
// ******************************************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment