From 4109db6f815fbb49c861177b3caecb98c2a963d8 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Sat, 19 Jun 2021 09:56:33 +0200 Subject: [PATCH] fix(exams): fixhance exam authship form section --- src/Handler/Exam/Form.hs | 43 +++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/Handler/Exam/Form.hs b/src/Handler/Exam/Form.hs index 7ea49ca6c..25cf5740d 100644 --- a/src/Handler/Exam/Form.hs +++ b/src/Handler/Exam/Form.hs @@ -148,29 +148,26 @@ examForm (Entity _ Course{..}) template csrf = hoist liftHandler $ do <* aformSection MsgExamFormParts <*> examPartsForm (efExamParts <$> template) -- TODO: refactor messages to be used across scopes, then define this form section separately (to be used for exams and sheets) - <* aformSection MsgExamAuthorshipStatementSection - <*> optionalActionA - ( areq htmlField - ( if schoolSheetExamAuthorshipStatementAllowOther - then fslI MsgExamAuthorshipStatementContent - else fslI MsgExamAuthorshipStatementContent - & addAttr "disabled" "disabled" - & setTooltip MsgExamAuthorshipStatementAllowOtherFalseTip - ) - ( (bool Nothing (join $ efAuthorshipStatement <$> template) schoolSheetExamAuthorshipStatementAllowOther) -- TODO: allow reverting from template to school definition (e.g. show school definition somewhere else, implement some kind of reset button, at least explain workaround (create new exam -> copy from there)...) - <|> (authorshipStatementDefinitionContent . entityVal <$> mSchoolAuthorshipStatement) - ) - ) - ( case schoolSheetExamAuthorshipStatementMode of - SchoolAuthorshipStatementModeNone -> fslI MsgExamAuthorshipStatementRequired & addAttr "disabled" "disabled" & setTooltip MsgExamAuthorshipStatementRequiredDisabledOffTip - SchoolAuthorshipStatementModeOptional -> fslI MsgExamAuthorshipStatementRequired & setTooltip MsgExamAuthorshipStatementRequiredTip - SchoolAuthorshipStatementModeRequired -> fslI MsgExamAuthorshipStatementRequired & addAttr "disabled" "disabled" & setTooltip MsgExamAuthorshipStatementRequiredDisabledOnTip - ) - ( case schoolSheetExamAuthorshipStatementMode of - SchoolAuthorshipStatementModeNone -> Just False - SchoolAuthorshipStatementModeOptional -> (is _Just . efAuthorshipStatement <$> template) <|> (pure $ is _Just schoolSheetExamAuthorshipStatementDefinition) - SchoolAuthorshipStatementModeRequired -> Just True -- FIXME: checkbox is unticked after form submit with school defaults (e.g. required, school definition given and unchanged) - ) + <*> let + reqContentField :: (FieldSettings UniWorX -> FieldSettings UniWorX) -> AForm Handler StoredMarkup + reqContentField ttip = areq htmlField + (fslI MsgExamAuthorshipStatementContent & ttip) + ( join $ (efAuthorshipStatement <$> template) + <|> (pure . authorshipStatementDefinitionContent . entityVal <$> mSchoolAuthorshipStatement) + ) + forcedContentField = aforced htmlField + (fslI MsgExamAuthorshipStatementContent & setTooltip MsgExamAuthorshipStatementAllowOtherFalseTip) + (maybe mempty (authorshipStatementDefinitionContent . entityVal) mSchoolAuthorshipStatement) + contentField ttipReq = bool forcedContentField (reqContentField ttipReq) schoolSheetExamAuthorshipStatementAllowOther + in case schoolSheetExamAuthorshipStatementMode of + SchoolAuthorshipStatementModeNone -> pure Nothing + SchoolAuthorshipStatementModeOptional -> aformSection MsgExamAuthorshipStatementSection + *> optionalActionA + (contentField id) + (fslI MsgExamAuthorshipStatementRequired & setTooltip MsgExamAuthorshipStatementRequiredTip) + ((is _Just . efAuthorshipStatement <$> template) <|> (pure $ is _Just schoolSheetExamAuthorshipStatementDefinition)) + SchoolAuthorshipStatementModeRequired -> aformSection MsgExamAuthorshipStatementSection + *> (fmap Just $ contentField (setTooltip MsgExamAuthorshipStatementRequiredDisabledOnTip)) officeSchoolsForm :: Maybe (Set SchoolId) -> AForm Handler (Set SchoolId) officeSchoolsForm mPrev = wFormToAForm $ do