Cleanup buttonForm & remove duplicate identifyForm calls

This commit is contained in:
Gregor Kleen 2019-03-28 12:06:50 +01:00
parent 4dbeff18c0
commit 68a0f7c566
4 changed files with 17 additions and 20 deletions

View File

@ -216,7 +216,7 @@ postAdminUserR uuid = do
let heading = let heading =
[whamlet|_{MsgAccessRightsFor} ^{nameWidget userDisplayName userSurname}|] [whamlet|_{MsgAccessRightsFor} ^{nameWidget userDisplayName userSurname}|]
-- Delete Button needed in data-delete -- Delete Button needed in data-delete
(btnWgt, btnEnctype) <- generateFormPost (buttonForm :: Form ButtonDelete) (btnWgt, btnEnctype) <- generateFormPost (identifyForm FIDUserDelete $ buttonForm :: Form ButtonDelete)
let btnForm = wrapForm btnWgt def let btnForm = wrapForm btnWgt def
{ formAction = Just $ SomeRoute $ AdminUserDeleteR uuid { formAction = Just $ SomeRoute $ AdminUserDeleteR uuid
, formEncoding = btnEnctype , formEncoding = btnEnctype
@ -231,7 +231,7 @@ postAdminUserR uuid = do
postAdminUserDeleteR :: CryptoUUIDUser -> Handler Html postAdminUserDeleteR :: CryptoUUIDUser -> Handler Html
postAdminUserDeleteR uuid = do postAdminUserDeleteR uuid = do
uid <- decrypt uuid uid <- decrypt uuid
((btnResult,_), _) <- runFormPost (buttonForm :: Form ButtonDelete) ((btnResult,_), _) <- runFormPost (identifyForm FIDUserDelete $ buttonForm :: Form ButtonDelete)
case btnResult of case btnResult of
(FormSuccess BtnDelete) -> do (FormSuccess BtnDelete) -> do
User{..} <- runDB $ get404 uid User{..} <- runDB $ get404 uid

View File

@ -138,20 +138,6 @@ linkButton lbl cls url = do
|] |]
-- buttonForm :: (Button UniWorX a, Finite a) => Markup -> MForm (HandlerT UniWorX IO) (FormResult a, Widget)
buttonForm :: (Button UniWorX a, Finite a) => Form a
buttonForm = identifyForm FIDbuttonForm buttonFormAux -- TODO: distinguish diffent buttons despite @disambiguateButtons@
where
buttonFormAux csrf = do
(res, ($ []) -> fViews) <- aFormToForm . disambiguateButtons $ combinedButtonFieldF ""
return (res, [whamlet|
$newline never
#{csrf}
$forall bView <- fViews
^{fvInput bView}
|])
------------ ------------
-- Fields -- -- Fields --
------------ ------------

View File

@ -179,8 +179,8 @@ data FormIdentifier
| FIDCourseRegister | FIDCourseRegister
| FIDuserRights | FIDuserRights
| FIDcUserNote | FIDcUserNote
| FIDbuttonForm
| FIDAdminDemo | FIDAdminDemo
| FIDUserDelete
deriving (Eq, Ord, Read, Show) deriving (Eq, Ord, Read, Show)
instance PathPiece FormIdentifier where instance PathPiece FormIdentifier where
@ -347,6 +347,17 @@ submitButtonView = do
fieldView bField btnId "" mempty (Right BtnSubmit) False fieldView bField btnId "" mempty (Right BtnSubmit) False
buttonForm :: (Button site a, Finite a) => Html -> MForm (HandlerT site IO) (FormResult a, WidgetT site IO ())
buttonForm csrf = do
(res, ($ []) -> fViews) <- aFormToForm . disambiguateButtons $ combinedButtonFieldF ""
return (res, [whamlet|
$newline never
#{csrf}
$forall bView <- fViews
^{fvInput bView}
|])
------------------- -------------------
-- Custom Fields -- -- Custom Fields --
------------------- -------------------

View File

@ -535,10 +535,10 @@ section {
margin-top: 20px; margin-top: 20px;
padding-top: 20px; padding-top: 20px;
} }
}
section:last-of-type { &:last-of-type {
border-bottom: none; border-bottom: none;
}
} }
.pseudonym { .pseudonym {