medium settings can now be changed
This commit is contained in:
parent
2f1ecdb318
commit
8a15b7d71d
6 changed files with 92 additions and 0 deletions
|
@ -37,6 +37,7 @@ import Handler.NewAlbum
|
|||
import Handler.Album
|
||||
import Handler.Medium
|
||||
import Handler.AlbumSettings
|
||||
import Handler.MediumSettings
|
||||
|
||||
-- This line actually creates our YesodDispatch instance. It is the second half
|
||||
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
||||
|
|
77
Handler/MediumSettings.hs
Normal file
77
Handler/MediumSettings.hs
Normal file
|
@ -0,0 +1,77 @@
|
|||
module Handler.MediumSettings where
|
||||
|
||||
import Import
|
||||
|
||||
getMediumSettingsR :: MediumId -> Handler Html
|
||||
getMediumSettingsR mediumId = do
|
||||
tempMedium <- runDB $ get mediumId
|
||||
case tempMedium of
|
||||
Just medium -> do
|
||||
ownerId <- return $ mediumOwner medium
|
||||
owner <- runDB $ getJust ownerId
|
||||
msu <- lookupSession "userId"
|
||||
case msu of
|
||||
Just tempUserId -> do
|
||||
userId <- return $ getUserIdFromText tempUserId
|
||||
presence <- return (userId == ownerId)
|
||||
case presence of
|
||||
True -> do
|
||||
(mediumSettingsWidget, enctype) <- generateFormPost $ mediumSettingsForm medium
|
||||
defaultLayout $ do
|
||||
$(widgetFile "mediumSettings")
|
||||
False -> do
|
||||
setMessage "You must own this medium to change its settings"
|
||||
redirect $ MediumR mediumId
|
||||
Nothing -> do
|
||||
setMessage "You must be logged in to change settings"
|
||||
redirect $ LoginR
|
||||
Nothing -> do
|
||||
setMessage "This medium does not exist"
|
||||
redirect $ HomeR
|
||||
|
||||
postMediumSettingsR :: MediumId -> Handler Html
|
||||
postMediumSettingsR mediumId = do
|
||||
tempMedium <- runDB $ get mediumId
|
||||
case tempMedium of
|
||||
Just medium -> do
|
||||
ownerId <- return $ mediumOwner medium
|
||||
owner <- runDB $ getJust ownerId
|
||||
msu <- lookupSession "userId"
|
||||
case msu of
|
||||
Just tempUserId -> do
|
||||
userId <- return $ getUserIdFromText tempUserId
|
||||
presence <- return (userId == ownerId)
|
||||
case presence of
|
||||
True -> do
|
||||
((result, mediumSettingsWidget), enctype) <- runFormPost $ mediumSettingsForm medium
|
||||
case result of
|
||||
FormSuccess temp -> do
|
||||
mId <- runDB $ update mediumId
|
||||
[ MediumTitle =. mediumTitle temp
|
||||
, MediumDescription =. mediumDescription temp
|
||||
, MediumTags =. mediumTags temp
|
||||
]
|
||||
setMessage "Medium settings changed succesfully"
|
||||
redirect $ MediumR mediumId
|
||||
_ -> do
|
||||
setMessage "There was an error changing the settings"
|
||||
redirect $ MediumSettingsR mediumId
|
||||
False -> do
|
||||
setMessage "You must own this medium to change its settings"
|
||||
redirect $ MediumR mediumId
|
||||
Nothing -> do
|
||||
setMessage "You must be logged in to change settings"
|
||||
redirect $ LoginR
|
||||
Nothing -> do
|
||||
setMessage "This medium does not exist"
|
||||
redirect $ HomeR
|
||||
|
||||
mediumSettingsForm :: Medium -> Form Medium
|
||||
mediumSettingsForm medium = renderDivs $ Medium
|
||||
<$> areq textField "Title" (Just $ mediumTitle medium)
|
||||
<*> pure (mediumPath medium)
|
||||
<*> pure (mediumTime medium)
|
||||
<*> pure (mediumOwner medium)
|
||||
<*> areq textareaField "Description" (Just $ mediumDescription medium)
|
||||
<*> areq tagField "tags" (Just $ mediumTags medium)
|
||||
<*> pure (mediumAlbum medium)
|
|
@ -17,3 +17,4 @@
|
|||
/album/#AlbumId/upload DirectUploadR GET POST
|
||||
/album/#AlbumId/settings AlbumSettingsR GET POST
|
||||
/album/#AlbumId/delete AlbumDeleteR GET POST
|
||||
/medium/#MediumId/settings MediumSettingsR GET POST
|
||||
|
|
|
@ -30,6 +30,7 @@ library
|
|||
Handler.Album
|
||||
Handler.Medium
|
||||
Handler.AlbumSettings
|
||||
Handler.MediumSettings
|
||||
|
||||
if flag(dev) || flag(library-only)
|
||||
cpp-options: -DDEVELOPMENT
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
by <a href=@{UserR ownerName}>#{ownerName}</a>
|
||||
|
||||
|
||||
|
||||
<div class="image">
|
||||
<img src=#{mediumPath medium}>
|
||||
|
||||
|
@ -11,3 +12,6 @@ by <a href=@{UserR ownerName}>#{ownerName}</a>
|
|||
Uploaded on: #{formatTime defaultTimeLocale "%A %F %H:%M" (mediumTime medium)}<br>
|
||||
Description:<br>
|
||||
#{mediumDescription medium}
|
||||
<br>
|
||||
$if presence == True
|
||||
<a href=@{MediumSettingsR mediumId}>Change medium settings
|
||||
|
|
8
templates/mediumSettings.hamlet
Normal file
8
templates/mediumSettings.hamlet
Normal file
|
@ -0,0 +1,8 @@
|
|||
$newline always
|
||||
<h3>Medium settings
|
||||
|
||||
<form method="post" enctype=#{enctype}>
|
||||
^{mediumSettingsWidget}
|
||||
<div>
|
||||
<input type=submit value="Change settings">
|
||||
|
Loading…
Reference in a new issue