Skip to content
Snippets Groups Projects
Commit b01b1d89 authored by srosse's avatar srosse
Browse files

OO-936: better validation of the point fields

parent 9bf9d5e3
No related branches found
No related tags found
No related merge requests found
...@@ -163,7 +163,9 @@ public class AssessmentForm extends FormBasicController { ...@@ -163,7 +163,9 @@ public class AssessmentForm extends FormBasicController {
@Override @Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if(saveAndCloseLink == source) { if(saveAndCloseLink == source) {
fireEvent(ureq, Event.DONE_EVENT); if(validateFormLogic(ureq)) {
fireEvent(ureq, Event.DONE_EVENT);
}
} }
super.formInnerEvent(ureq, source, event); super.formInnerEvent(ureq, source, event);
} }
...@@ -182,7 +184,7 @@ public class AssessmentForm extends FormBasicController { ...@@ -182,7 +184,7 @@ public class AssessmentForm extends FormBasicController {
} }
@Override @Override
protected boolean validateFormLogic (UserRequest ureq) { protected boolean validateFormLogic(UserRequest ureq) {
if (hasScore) { if (hasScore) {
try { try {
if(parseFloat(score) == null) { if(parseFloat(score) == null) {
......
...@@ -167,7 +167,11 @@ public class AssessedIdentityCheckListController extends FormBasicController { ...@@ -167,7 +167,11 @@ public class AssessedIdentityCheckListController extends FormBasicController {
pointEl.setExampleKey("checklist.point.example", new String[]{ "0", maxValue}); pointEl.setExampleKey("checklist.point.example", new String[]{ "0", maxValue});
} }
// hide when not yet checked // hide when not yet checked
pointEl.setVisible(check.getChecked()); if(check != null) {
pointEl.setVisible(check.getChecked());
} else {
pointEl.setVisible(false);
}
} }
CheckboxWrapper wrapper = new CheckboxWrapper(checkbox, check, boxEl, pointEl); CheckboxWrapper wrapper = new CheckboxWrapper(checkbox, check, boxEl, pointEl);
...@@ -197,13 +201,45 @@ public class AssessedIdentityCheckListController extends FormBasicController { ...@@ -197,13 +201,45 @@ public class AssessedIdentityCheckListController extends FormBasicController {
CheckboxWrapper wrapper = (CheckboxWrapper)boxEl.getUserObject(); CheckboxWrapper wrapper = (CheckboxWrapper)boxEl.getUserObject();
doUpdateCheck(wrapper, boxEl.isAtLeastSelected(1)); doUpdateCheck(wrapper, boxEl.isAtLeastSelected(1));
} else if(saveAndCloseLink == source) { } else if(saveAndCloseLink == source) {
doSave(); if(validateFormLogic(ureq)) {
fireEvent(ureq, Event.DONE_EVENT); doSave();
fireEvent(ureq, Event.DONE_EVENT);
}
} }
super.formInnerEvent(ureq, source, event); super.formInnerEvent(ureq, source, event);
} }
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean allOk = true;
for(CheckboxWrapper wrapper:wrappers) {
TextElement pointEl = wrapper.getPointEl();
if(pointEl != null) {
pointEl.clearError();
String val = pointEl.getValue();
if(StringHelper.containsNonWhitespace(val)) {
try {
Float max = wrapper.getCheckbox().getPoints();
float maxScore = max == null ? 0f : max.floatValue();
float score = Float.parseFloat(val);
if(score < 0f || score > maxScore) {
pointEl.setErrorKey("form.error.scoreOutOfRange", null);
allOk &= false;
}
} catch (NumberFormatException e) {
pointEl.setErrorKey("form.error.wrongFloat", null);
allOk &= false;
}
}
}
}
return allOk & super.validateFormLogic(ureq);
}
private void doSave() { private void doSave() {
List<AssessmentBatch> batchElements = new ArrayList<>(); List<AssessmentBatch> batchElements = new ArrayList<>();
for(CheckboxWrapper wrapper:wrappers) { for(CheckboxWrapper wrapper:wrappers) {
......
...@@ -104,6 +104,7 @@ public class CheckListAssessmentController extends FormBasicController implement ...@@ -104,6 +104,7 @@ public class CheckListAssessmentController extends FormBasicController implement
private static final String[] onKeys = new String[] { "on" }; private static final String[] onKeys = new String[] { "on" };
private static final String[] onValues = new String[] { "" }; private static final String[] onValues = new String[] { "" };
private final Float maxScore;
private final Date dueDate; private final Date dueDate;
private final boolean withScore; private final boolean withScore;
private final CheckboxList checkboxList; private final CheckboxList checkboxList;
...@@ -174,6 +175,8 @@ public class CheckListAssessmentController extends FormBasicController implement ...@@ -174,6 +175,8 @@ public class CheckListAssessmentController extends FormBasicController implement
Boolean hasScore = (Boolean)config.get(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD); Boolean hasScore = (Boolean)config.get(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD);
withScore = (hasScore == null || hasScore.booleanValue()); withScore = (hasScore == null || hasScore.booleanValue());
maxScore = (Float)config.get(MSCourseNode.CONFIG_KEY_SCORE_MAX);
initForm(ureq); initForm(ureq);
} }
...@@ -346,7 +349,6 @@ public class CheckListAssessmentController extends FormBasicController implement ...@@ -346,7 +349,6 @@ public class CheckListAssessmentController extends FormBasicController implement
} }
private List<CheckListAssessmentRow> getAssessmentDataViews(List<AssessmentData> datas, List<Checkbox> checkbox) { private List<CheckListAssessmentRow> getAssessmentDataViews(List<AssessmentData> datas, List<Checkbox> checkbox) {
List<CheckListAssessmentRow> dataViews = new ArrayList<>(); List<CheckListAssessmentRow> dataViews = new ArrayList<>();
int numOfcheckbox = checkbox.size(); int numOfcheckbox = checkbox.size();
...@@ -368,6 +370,8 @@ public class CheckListAssessmentController extends FormBasicController implement ...@@ -368,6 +370,8 @@ public class CheckListAssessmentController extends FormBasicController implement
if(check.getChecked() == null) continue; if(check.getChecked() == null) continue;
check.getCheckbox();
Integer index = indexed.get(check.getCheckbox().getCheckboxId()); Integer index = indexed.get(check.getCheckbox().getCheckboxId());
if(index != null) { if(index != null) {
int i = index.intValue(); int i = index.intValue();
...@@ -377,6 +381,10 @@ public class CheckListAssessmentController extends FormBasicController implement ...@@ -377,6 +381,10 @@ public class CheckListAssessmentController extends FormBasicController implement
} }
} }
} }
if(maxScore != null && maxScore.floatValue() > 0f && totalPoints > maxScore.floatValue()) {
totalPoints = maxScore.floatValue();
}
CheckListAssessmentRow row = new CheckListAssessmentRow(data.getIdentity(), checkBool, scores, totalPoints, userPropertyHandlers, getLocale()); CheckListAssessmentRow row = new CheckListAssessmentRow(data.getIdentity(), checkBool, scores, totalPoints, userPropertyHandlers, getLocale());
dataViews.add(row); dataViews.add(row);
} }
......
...@@ -127,6 +127,7 @@ pdf.export.checked=Erledigte Checkboxen als PDF ...@@ -127,6 +127,7 @@ pdf.export.checked=Erledigte Checkboxen als PDF
award.point.on=Punkte vergeben bei Auswahl award.point.on=Punkte vergeben bei Auswahl
description=Beschreibung description=Beschreibung
participants=Mitglieder participants=Mitglieder
form.error.scoreOutOfRange=$org.olat.course.assessment\:form.error.scoreOutOfRange
file=Datei file=Datei
select.checkbox=Auswahl Checkbox select.checkbox=Auswahl Checkbox
signature=Unterschrift signature=Unterschrift
......
...@@ -80,6 +80,7 @@ help.hover.config=Help regarding configuration ...@@ -80,6 +80,7 @@ help.hover.config=Help regarding configuration
help.hover.coach.assessment=Help regarding assessment and management of checklists help.hover.coach.assessment=Help regarding assessment and management of checklists
help.hover.assessment.checkbox=help regarding assessment per box help.hover.assessment.checkbox=help regarding assessment per box
info.title=$org.olat.course.nodes.ms\:info.title info.title=$org.olat.course.nodes.ms\:info.title
form.error.scoreOutOfRange=$org.olat.course.assessment\:form.error.scoreOutOfRange
label=Label label=Label
label.controlled=Verified label.controlled=Verified
label.done=Done label.done=Done
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment