propagated avatars. works.

This commit is contained in:
nek0 2015-04-16 02:51:08 +02:00
parent edc307a01f
commit fc83ae87df
8 changed files with 26 additions and 9 deletions

View file

@ -2,6 +2,7 @@ module Handler.Home where
import Import import Import
import qualified Text.Read as R import qualified Text.Read as R
import Data.Maybe
-- This is a handler function for the GET request method on the HomeR -- This is a handler function for the GET request method on the HomeR
-- resource pattern. All of your resource patterns are defined in -- resource pattern. All of your resource patterns are defined in

View file

@ -41,7 +41,7 @@ newUserForm secs = renderDivs $ User
data UserConf = UserConf data UserConf = UserConf
{ userConfEmail :: Maybe Text { userConfEmail :: Maybe Text
, userConfNotify :: Bool , userConfAvatar :: Maybe AvatarId
} }
getModifyUserR :: UserId -> Handler Html getModifyUserR :: UserId -> Handler Html
@ -63,11 +63,12 @@ postModifyUserR uId = do
Just user -> do Just user -> do
((res, _), _) <- runFormPost $ modifyUserForm user ((res, _), _) <- runFormPost $ modifyUserForm user
case res of case res of
FormSuccess email -> do FormSuccess uc -> do
runDB $ update uId runDB $ update uId
[ UserEmail =. email [ UserEmail =. userConfEmail uc
, UserAvatar =. userConfAvatar uc
] ]
liftIO $ notify user email liftIO $ notify user (userConfEmail uc)
setMessageI MsgUserEdited setMessageI MsgUserEdited
redirect $ SelectR uId redirect $ SelectR uId
_ -> do _ -> do
@ -77,9 +78,14 @@ postModifyUserR uId = do
setMessageI MsgUserUnknown setMessageI MsgUserUnknown
redirect $ HomeR redirect $ HomeR
modifyUserForm :: User -> Form (Maybe Text) modifyUserForm :: User -> Form UserConf
modifyUserForm user = renderDivs $ modifyUserForm user = renderDivs $ UserConf
aopt emailField (fieldSettingsLabel MsgEmailNotify) (Just $ userEmail user) <$> aopt emailField (fieldSettingsLabel MsgEmailNotify) (Just $ userEmail user)
<*> aopt (selectField avatars) (fieldSettingsLabel MsgSelectAvatar) (Just $ userAvatar user)
where
avatars = do
ents <- runDB $ selectList [] [Asc AvatarIdent]
optionsPairs $ map (\ent -> ((avatarIdent $ entityVal ent), entityKey ent)) ents
notify :: User -> Maybe Text -> IO () notify :: User -> Maybe Text -> IO ()
notify user email notify user email

View file

@ -72,8 +72,8 @@ newArticleForm = renderDivs $ Beverage
<*> areq currencyField (fieldSettingsLabel MsgPrice) (Just 100) <*> areq currencyField (fieldSettingsLabel MsgPrice) (Just 100)
<*> areq amountField (fieldSettingsLabel MsgAmount) (Just 0) <*> areq amountField (fieldSettingsLabel MsgAmount) (Just 0)
<*> areq amountField (fieldSettingsLabel MsgAmountWarning) (Just 0) <*> areq amountField (fieldSettingsLabel MsgAmountWarning) (Just 0)
<*> aopt (selectField albums) (fieldSettingsLabel MsgSelectAvatar) Nothing <*> aopt (selectField avatars) (fieldSettingsLabel MsgSelectAvatar) Nothing
where where
albums = do avatars = do
ents <- runDB $ selectList [] [Asc AvatarIdent] ents <- runDB $ selectList [] [Asc AvatarIdent]
optionsPairs $ map (\ent -> ((avatarIdent $ entityVal ent), entityKey ent)) ents optionsPairs $ map (\ent -> ((avatarIdent $ entityVal ent), entityKey ent)) ents

View file

@ -4,6 +4,7 @@ import Import
import Handler.Common import Handler.Common
import qualified Text.Read as R import qualified Text.Read as R
import qualified Data.Text as T import qualified Data.Text as T
import Data.Maybe
getSelectR :: UserId -> Handler Html getSelectR :: UserId -> Handler Html
getSelectR uId = do getSelectR uId = do

View file

@ -35,12 +35,15 @@ article#func.article {
position: relative; position: relative;
top: -7.75em; top: -7.75em;
text-align: left; text-align: left;
z-index: 0;
} }
.article a p { .article a p {
position: relative;
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
line-height: normal; line-height: normal;
z-index: 1;
} }
img.flag { img.flag {

View file

@ -15,6 +15,8 @@ $forall (Entity uId user) <- users
<article .article> <article .article>
<a href=@{SelectR uId}> <a href=@{SelectR uId}>
<p>#{userIdent user} <p>#{userIdent user}
$if userAvatar user /= Nothing
<img src=@{GetAvatarR $ fromJust $ userAvatar user}>
<article .article #func> <article .article #func>
<a href=@{ReactivateR}> <a href=@{ReactivateR}>

View file

@ -22,3 +22,5 @@ $forall (Entity bId bev) <- beverages
<a href=@{BuyR uId bId}> <a href=@{BuyR uId bId}>
<p> <p>
#{beverageIdent bev} #{beverageIdent bev}
$if beverageAvatar bev /= Nothing
<img src=@{GetAvatarR $ fromJust $ beverageAvatar bev}>

View file

@ -7,3 +7,5 @@ $forall (Entity bId bev) <- beverages
<a href=@{BuyCashR bId}> <a href=@{BuyCashR bId}>
<p> <p>
#{beverageIdent bev} #{beverageIdent bev}
$if beverageAvatar bev /= Nothing
<img src=@{GetAvatarR $ fromJust $ beverageAvatar bev}>