module Yesod.TableView.NumEntriesForm
( runNumEntriesForm )
where
import Control.Arrow
import Control.Monad
import Data.String
import Text.Cassius
import Text.Hamlet
import Yesod
numEntriesForm :: String -> [Int] -> FormletField sub s Int
numEntriesForm prompt options mdata =
let numbers = map (id &&& show) options
in selectField numbers (fromString prompt) mdata
runNumEntriesForm :: Bool -> String -> [Int] -> Int -> (Int -> Route s) ->
GHandler sub s (GWidget sub s ())
runNumEntriesForm styled prompt options limit thisRoute = do
let formField = numEntriesForm prompt options (Just limit)
(res, form) <- runFormDivs (thisRoute limit) "Ok" formField
case res of
FormSuccess newLimit ->
redirect RedirectTemporary (thisRoute newLimit)
_ -> return $ do
when styled $ addCassius $(cassiusFile
"templates/form-numentries.cassius")
addWidget $(hamletFile "templates/form-numentries.hamlet")