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 qualified Text.Read as R
import Data.Maybe
-- This is a handler function for the GET request method on the HomeR
-- resource pattern. All of your resource patterns are defined in

View File

@ -41,7 +41,7 @@ newUserForm secs = renderDivs $ User
data UserConf = UserConf
{ userConfEmail :: Maybe Text
, userConfNotify :: Bool
, userConfAvatar :: Maybe AvatarId
}
getModifyUserR :: UserId -> Handler Html
@ -63,11 +63,12 @@ postModifyUserR uId = do
Just user -> do
((res, _), _) <- runFormPost $ modifyUserForm user
case res of
FormSuccess email -> do
FormSuccess uc -> do
runDB $ update uId
[ UserEmail =. email
[ UserEmail =. userConfEmail uc
, UserAvatar =. userConfAvatar uc
]
liftIO $ notify user email
liftIO $ notify user (userConfEmail uc)
setMessageI MsgUserEdited
redirect $ SelectR uId
_ -> do
@ -77,9 +78,14 @@ postModifyUserR uId = do
setMessageI MsgUserUnknown
redirect $ HomeR
modifyUserForm :: User -> Form (Maybe Text)
modifyUserForm user = renderDivs $
aopt emailField (fieldSettingsLabel MsgEmailNotify) (Just $ userEmail user)
modifyUserForm :: User -> Form UserConf
modifyUserForm user = renderDivs $ UserConf
<$> 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 email

View File

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

View File

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

View File

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

View File

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

View File

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