diff options
author | Camil Staps | 2017-10-17 08:52:34 +0200 |
---|---|---|
committer | Camil Staps | 2017-10-17 08:52:34 +0200 |
commit | a47cf5e1bb0ecacda14dc09b33248680740c46b6 (patch) | |
tree | b5dc779aac6ff5f4afa59c446ed2f06648969710 /assignment-6/multiplechoice.icl | |
parent | Fix authentication (diff) |
Don't accept incorrect correct answer indices
Diffstat (limited to 'assignment-6/multiplechoice.icl')
-rw-r--r-- | assignment-6/multiplechoice.icl | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/assignment-6/multiplechoice.icl b/assignment-6/multiplechoice.icl index da6690d..b26d11c 100644 --- a/assignment-6/multiplechoice.icl +++ b/assignment-6/multiplechoice.icl @@ -73,11 +73,14 @@ where <<@ ApplyLayout (setUIAttributes (directionAttr Horizontal)) >>| teacherTask - cancelable :: (Task a) -> Task (Maybe a) | iTask a + cancelable :: (Task Question) -> Task (Maybe Question) cancelable t = t >>* - [ OnAction (Action "Cancel") $ always $ return Nothing - , OnAction (Action "Save") $ hasValue $ return o Just + [ OnAction (Action "Cancel") $ always $ return Nothing + , OnAction (Action "Save") $ ifValue isCorrect $ return o Just ] + where + isCorrect :: Question -> Bool + isCorrect q = q.Question.correct < length q.answers && q.Question.correct >= 0 append i = cancelable (enterInformation "New item" []) >>= ifJust (flip upd questions o insertAt i) edit (i,q) = cancelable (updateInformation "Edit item" [] q) >>= ifJust (flip upd questions o updateAt i) |