^{fvInput dayView}
|]
inventoryListing :: InventoryState -> Widget
inventoryListing InventoryState{ invFormState = formState, ..} = $(widgetFile "inventoryListing")
referenceForm :: Maybe Reference -- ^ Update existing item or insert new?
-> Html -> MForm Handler (FormResult (WithType Reference), Widget)
referenceForm proto identView = do
t <- lift . runDB $ maybe (return Nothing) (fmap (Just . kindType) . getType) proto
let kt kWidget tWidget =
[whamlet|
^{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 <- ("options" <>) . tshow . hashUnique <$> liftIO newUnique
let
tAttrs = [ ("list", tOptionId)
, ("autocomplete", "off")
]
kOptionId <- ("options" <>) . tshow . hashUnique <$> liftIO newUnique
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;
}
});
}) ;
});
|]
let
kindWidget =
[whamlet|
$newline never
^{fvInput kindView}