From 14718c3c189418b0751e0f976ac621cf9421a2c9 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 19 Dec 2016 00:40:21 +0100 Subject: [PATCH] more licence stuff --- Handler/Upload.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Handler/Upload.hs b/Handler/Upload.hs index 834afea..20680a2 100755 --- a/Handler/Upload.hs +++ b/Handler/Upload.hs @@ -214,7 +214,13 @@ dUploadForm userId albumId = FileBulk <*> aopt textareaField (bfs ("Description" :: T.Text)) Nothing <*> areq tagField (bfs ("Enter tags" :: T.Text)) Nothing <*> pure albumId + <*> areq (selectField licences) (bfs ("Licence" :: T.Text)) (defLicence) <* bootstrapSubmit ("Upload" :: BootstrapSubmit T.Text) + where + licenses = optionsPairs $ I.map (\a -> (T.pack (show (toEnum a :: Licence)), a)) [-2..6] + defLicence = do + user <- runDB $ selectJust userId + return $ Just $ userDefaultLicence user data FileBulk = FileBulk @@ -242,7 +248,7 @@ getUploadR = do setMessage "Please create an album first" redirect NewAlbumR else do - (uploadWidget, enctype) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ bulkUploadForm userId user + (uploadWidget, enctype) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ bulkUploadForm userId defaultLayout $ do setTitle "Eidolon :: Upload Medium" $(widgetFile "bulkUpload") @@ -251,7 +257,7 @@ getUploadR = do redirect LoginR bulkUploadForm :: UserId -> User -> AForm Handler FileBulk -bulkUploadForm userId user = (\a b c d e f g -> FileBulk b c d e f g a) +bulkUploadForm userId = (\a b c d e f g h -> FileBulk b c d e f g a h) <$> areq (selectField albums) (bfs ("Album" :: T.Text)) Nothing <*> areq textField (bfs ("Title" :: T.Text)) Nothing <*> areq multiFileField "Select file(s)" Nothing @@ -259,7 +265,7 @@ bulkUploadForm userId user = (\a b c d e f g -> FileBulk b c d e f g a) <*> pure userId <*> aopt textareaField (bfs ("Description" :: T.Text)) Nothing <*> areq tagField (bfs ("Enter tags" :: T.Text)) Nothing - <*> areq (selectField licences) (bfs ("Licences" :: T.Text)) (Just $ userDefaultLicence user) + <*> areq (selectField licences) (bfs ("Licence" :: T.Text)) (defLicence) <* bootstrapSubmit ("Upload" :: BootstrapSubmit T.Text) where albums = do @@ -272,6 +278,9 @@ bulkUploadForm userId user = (\a b c d e f g -> FileBulk b c d e f g a) ) allEnts optionsPairs $ I.map (\alb -> (albumTitle $ entityVal alb, entityKey alb)) entities licenses = optionsPairs $ I.map (\a -> (T.pack (show (toEnum a :: Licence)), a)) [-2..6] + defLicence = do + user <- runDB $ selectJust userId + return $ Just $ userDefaultLicence user postUploadR :: Handler Html postUploadR = do @@ -279,8 +288,7 @@ postUploadR = do case msu of Just tempUserId -> do let userId = getUserIdFromText tempUserId - user <- runDB $ getJust userId - ((result, _), _) <- runFormPost $ renderBootstrap3 BootstrapBasicForm $ bulkUploadForm userId user + ((result, _), _) <- runFormPost $ renderBootstrap3 BootstrapBasicForm $ bulkUploadForm userId case result of FormSuccess temp -> do let fils = fileBulkFiles temp