{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} module Handler.Utils.Form where import Import import qualified Data.Char as Char import Handler.Utils.DateTime import Data.String (IsString(..)) import qualified Data.Foldable as Foldable -- import Yesod.Core import qualified Data.Text as T -- import Yesod.Form.Types import Yesod.Form.Functions (parseHelper) import Yesod.Form.Bootstrap3 ---------------------------- -- Buttons (new version ) -- ---------------------------- data ButtonCssClass = Default | Primary | Success | Info | Warning | Danger | Link deriving (Enum, Eq, Ord, Bounded, Read, Show) bcc2txt :: ButtonCssClass -> Text bcc2txt bcc = T.pack $ "btn-" ++ (Char.toLower <$> show bcc) class (Enum a, Bounded a, Ord a, PathPiece a) => Button a where label :: a -> Widget label = toWidget . toPathPiece cssClass :: a -> ButtonCssClass cssClass _ = Default buttonField :: Button a => a -> Field Handler a buttonField btn = Field {fieldParse, fieldView, fieldEnctype} where fieldEnctype = UrlEncoded fieldView fid name attrs _val _ = [whamlet|