chore: disable accept button for failing results
This commit is contained in:
parent
02589e4d00
commit
f9b545952d
@ -26,6 +26,7 @@ makeLenses_ ''ExamAutoOccurrenceCalculateForm
|
||||
data ExamAutoOccurrenceAcceptForm = ExamAutoOccurrenceAcceptForm
|
||||
{ eaofMapping :: ExamOccurrenceMapping ExamOccurrenceId
|
||||
, eaofAssignment :: Map UserId (Maybe ExamOccurrenceId)
|
||||
, eaofSuccess :: Bool
|
||||
} deriving (Eq, Ord, Read, Show, Generic, Typeable)
|
||||
|
||||
deriveJSON defaultOptions
|
||||
@ -153,7 +154,9 @@ examAutoOccurrenceIgnoreRoomsForm occId calculateRes protoForm html = do
|
||||
examAutoOccurrenceAcceptForm :: Maybe ExamAutoOccurrenceAcceptForm -> Form ExamAutoOccurrenceAcceptForm
|
||||
examAutoOccurrenceAcceptForm confirmData = identifyForm FIDExamAutoOccurrenceConfirm $ \html -> do
|
||||
(confirmDataRes, confirmDataView) <- mreq secretJsonField "" confirmData
|
||||
(acceptRes, acceptView) <- buttonForm' [BtnExamAutoOccurrenceAccept] mempty
|
||||
let fs :: FieldSettings UniWorX
|
||||
fs = (if maybe False eaofSuccess confirmData then id else set _fsAttrs [("disabled", "")]) ""
|
||||
(acceptRes, acceptView) <- buttonForm'' [BtnExamAutoOccurrenceAccept] fs mempty
|
||||
return (acceptRes *> confirmDataRes, toWidget html <> fvWidget confirmDataView <> acceptView)
|
||||
|
||||
|
||||
@ -199,7 +202,7 @@ postEAutoOccurrenceR tid ssh csh examn = do
|
||||
|
||||
calcResult <- formResultMaybe calculateRes' $ \ExamAutoOccurrenceCalculateForm{..} -> do
|
||||
let autoOccurrenceResult = examAutoOccurrence eId examOccurrenceRule eaofConfig occurrences' participants'
|
||||
(eaofMapping, eaofAssignment) <- case autoOccurrenceResult of
|
||||
(eaofMapping, eaofAssignment, eaofSuccess) <- case autoOccurrenceResult of
|
||||
(Left e) -> do
|
||||
addMessageI Error e
|
||||
pure ( ExamOccurrenceMapping {
|
||||
@ -207,8 +210,9 @@ postEAutoOccurrenceR tid ssh csh examn = do
|
||||
examOccurrenceMappingMapping = Map.empty
|
||||
}
|
||||
, Map.map (view _2) participants'
|
||||
, False
|
||||
)
|
||||
(Right r) -> pure r
|
||||
(Right res) -> pure $ uncurry (,,True) res
|
||||
return $ Just ExamAutoOccurrenceAcceptForm{..}
|
||||
|
||||
((confirmRes, confirmView), confirmEncoding) <- runFormPost $ examAutoOccurrenceAcceptForm calcResult
|
||||
|
||||
@ -415,8 +415,12 @@ buttonForm = buttonForm' universeF
|
||||
|
||||
-- | like `buttonForm`, but for a given list of buttons, i.e. a subset or for buttons outside the Finite typeclass
|
||||
buttonForm' :: (MonadHandler m, Button (HandlerSite m) a) => [a] -> Html -> MForm m (FormResult a, WidgetT (HandlerSite m) IO ())
|
||||
buttonForm' btns csrf = do
|
||||
(res, ($ []) -> fViews) <- aFormToForm . disambiguateButtons $ combinedButtonField btns ""
|
||||
buttonForm' btns = buttonForm'' btns ""
|
||||
|
||||
-- | like `buttonForm'`, but for a given list of FieldSettings
|
||||
buttonForm'' :: (MonadHandler m, Button (HandlerSite m) a) => [a] -> FieldSettings (HandlerSite m) -> Html -> MForm m (FormResult a, WidgetT (HandlerSite m) IO ())
|
||||
buttonForm'' btns settings csrf = do
|
||||
(res, ($ []) -> fViews) <- aFormToForm . disambiguateButtons $ combinedButtonField btns settings
|
||||
return (res, [whamlet|
|
||||
$newline never
|
||||
#{csrf}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user