-- genericCreateOf

-- Provides a read-only view on a type
genericReadViewOf :: Data d => d -> Template -> Fields -> ServerPart Response
genericReadViewOf value template exclude =
    let
        ValueInfo name fields values = extractInfo value
        toDiv k v = 
            if k `elem` exclude then
                no
            else
                do H.div ! A.class_ "row" $ do
                    H.div ! A.class_ "label" $ H.toHtml $ formatTitle k
                    H.div ! A.class_ "value" $ H.toHtml v
    in
        ok $ template $ do
            H.h2 $ H.toHtml name
            zipWithM_ toDiv fields values

-- Provides Edit functionality
-- TODO: more detailed generation for different types
-- TODO: add the concept of an id field
-- TODO: figure out how to cast things
genericReadViewOf :: Data d => d -> Template -> Fields -> ServerPart Response
genericReadViewOf value template exclude =
    let
        ValueInfo name fields values = extractInfo value
        toDiv k v = 
            if k `elem` exclude then
                no
            else
                do H.div ! A.class_ "row" $ do
                    H.div ! A.class_ "label" $ H.toHtml $ formatTitle k
                    H.div ! A.class_ "value" $ H.toHtml v
    in
        ok $ template $ do
            H.h2 $ H.toHtml name
            zipWithM_ toDiv fields values

-- Provides Edit functionality
-- TODO: more detailed generation for different types
-- TODO: add the concept of an id field
-- TODO: figure out how to cast things
genericReadViewOf value template exclude =
    let
        ValueInfo name fields values = extractInfo value
        toDiv k v = 
            if k `elem` exclude then
                no
            else
                do H.div ! A.class_ "row" $ do
                    H.div ! A.class_ "label" $ H.toHtml $ formatTitle k
                    H.div ! A.class_ "value" $ H.toHtml v
    in
        ok $ template $ do
            H.h2 $ H.toHtml name
            zipWithM_ toDiv fields values

-- Provides Edit functionality
-- TODO: more detailed generation for different types
-- TODO: add the concept of an id field
-- TODO: figure out how to cast things