moved tagField to Helpers

This commit is contained in:
nek0 2014-08-30 20:23:57 +02:00
parent 9d33fea611
commit 2f1ecdb318
2 changed files with 13 additions and 11 deletions

View file

@ -168,14 +168,3 @@ dUploadForm userId albumId = renderDivs $ TempMedium
<*> areq textareaField "Description" Nothing
<*> areq tagField "Enter tags" Nothing
<*> pure albumId
tagField :: Field Handler [Text]
tagField = Field
{ fieldParse = \rawVals _ -> do
case rawVals of
[x] -> return $ Right $ Just $ splitOn " " x
_ -> return $ Left $ error "unexpected tag list"
, fieldView = \idAttr nameAttr _ eResult isReq ->
[whamlet|<input id=#{idAttr} type="text" name=#{nameAttr}>|]
, fieldEnctype = UrlEncoded
}

View file

@ -7,6 +7,7 @@ module Helper
, toHex
, makeRandomToken
, generateSalt
, tagField
)
where
@ -25,6 +26,7 @@ import System.FilePath
import System.Random
import Yesod.Persist.Core
import Yesod.Core.Types
import Yesod
import Numeric (readHex, showHex)
getUserIdFromText :: T.Text -> UserId
@ -69,3 +71,14 @@ makeRandomToken = (T.pack . take 16 . randoms) `fmap` newStdGen
generateSalt :: IO B.ByteString
generateSalt = (B.pack . take 8 . randoms) <$> getStdGen
-- tagField :: Field Handler [T.Text]
tagField = Field
{ fieldParse = \rawVals _ -> do
case rawVals of
[x] -> return $ Right $ Just $ T.splitOn " " x
_ -> return $ Left $ error "unexpected tag list"
, fieldView = \idAttr nameAttr _ eResult isReq ->
[whamlet|<input id=#{idAttr} type="text" name=#{nameAttr}>|]
, fieldEnctype = UrlEncoded
}