{-# LANGUAGE OverloadedStrings #-} module View.Scaffold where import Servant.Links import qualified Text.Blaze.Html5 as H import qualified Text.Blaze.Html5.Attributes as HA import qualified Data.Text as T import Data.String (fromString) import Data.Text.I18n import Data.Maybe (fromJust, isJust) import Control.Monad (when) -- internal imports import Types.Page import API import Util scaffold :: L10n -> Locale -> Maybe T.Text -> Page H.Html T.Text -> H.Html -> H.Html scaffold l10n locale mcookie page content = template page $ do H.header $ H.nav $ H.ul $ do H.li $ H.a H.! HA.href ("/" <> fromString (show $ linkURI userSelectLink)) $ H.toHtml $ translate "Home" maybe (return ()) (\uid -> H.li $ H.a H.! HA.href ("/" <> (fromString $ show $ linkURI $ userOverviewLink (read uid) Nothing)) $ H.toHtml $ translate "User Page" ) (getLogin mcookie) H.hr when (isJust message) (H.div H.! HA.id "message" H.! HA.class_ "message" $ H.toHtml (fromJust message) ) H.div H.! HA.id "main" H.! HA.role "main" $ content H.hr H.footer $ H.form $ do H.button H.! HA.formmethod "get" H.! HA.formaction ("/" <> (fromString $ show $ linkURI productGetPriceListLink)) $ H.toHtml $ translate "Price List" maybe (return ()) (\_ -> H.button H.! HA.formmethod "get" H.! HA.formaction ("/" <> (fromString $ show $ linkURI $ productGetRefillLink)) $ H.toHtml $ translate "Refill stock" ) (getLogin mcookie) where message = lookup "message" =<< fmap parseCookieText mcookie translate = localize l10n locale . gettext getLogin = snd . parseTokenAndUser