^{kWidget}
^{tWidget}
|]
((kindRes, typeRes), typedKindWidget) <- typedKindField kt ((referenceKind <$> proto), t)
let referenceRes = do
referenceKind <- kindRes
t <- typeRes
return $ Reference{ referenceNormKind = normalizeKind referenceKind, .. } `WithType` t
return . (referenceRes, ) $
[whamlet|
$newline never
#{identView}
^{typedKindWidget}
|]
referenceListing :: ReferenceState -> Widget
referenceListing ReferenceState{ refFormState = formState, ..} = $(widgetFile "referenceListing")
typedKindField :: (Widget -> Widget -> Widget) -- ^ `\kindWidget typeWidget -> _`
-> (Maybe Text, Maybe Text) -- ^ `(kindProto, typeProto)`
-> MForm Handler ((FormResult Text, FormResult Text), Widget) -- ^ `((kindRes, typeRes), typedKindWidget)`
typedKindField collate (kindProto, typeProto) = do
tOptionId <- newIdent
let
tAttrs = [ ("list", tOptionId)
, ("autocomplete", "off")
]
kOptionId <- newIdent
let
kAttrs = [ ("list", kOptionId)
, ("autocomplete", "off")
]
(kindRes, kindView) <- mreq textField ("" { fsAttrs = kAttrs }) kindProto
(typeRes, typeView) <- mreq textField ("" { fsAttrs = tAttrs }) typeProto
kOptions <- lift kinds
(Set.fromList . map (kindType . entityVal) -> tOptions) <- lift . runDB $ selectList [] []
return . ((kindRes, typeRes), ) $ do
toWidget $
[julius|
$(function () {
$("##{rawJS $ fvId kindView}").change(function () {
$.ajax({
url: '@{TypeR}',
type: 'GET',
contentType: 'application/json',
data: {
kind: $(this).val()
},
success: function (answer) {
$("##{rawJS $ fvId typeView}").val(answer);
typeChanged = false;
}
});
}) ;
});
|]
toWidget $
[cassius|
##{fvId kindView}
width: 12em
##{fvId typeView}
width: 8em
|]
let
kindWidget =
[whamlet|
$newline never
^{fvInput kindView}