From cc968c213aadd39305372cbe0da055dca3acfef4 Mon Sep 17 00:00:00 2001
From: srosse <stephane.rosse@frentix.com>
Date: Mon, 25 Mar 2019 08:56:55 +0100
Subject: [PATCH] OO-3993: allow to cancel a lecture without reason if not
 available

---
 .../CancelRollCallConfirmationController.java   | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/olat/modules/lecture/ui/CancelRollCallConfirmationController.java b/src/main/java/org/olat/modules/lecture/ui/CancelRollCallConfirmationController.java
index e03b26ecb54..fe90df50db1 100644
--- a/src/main/java/org/olat/modules/lecture/ui/CancelRollCallConfirmationController.java
+++ b/src/main/java/org/olat/modules/lecture/ui/CancelRollCallConfirmationController.java
@@ -99,7 +99,12 @@ public class CancelRollCallConfirmationController extends FormBasicController {
 			}
 		}
 		if(!found) {
-			effectiveEndReasonEl.select(reasonKeyList.get(0), true);
+			if(reasonKeyList.isEmpty()) {
+				effectiveEndReasonEl.setEnabled(false);
+				effectiveEndReasonEl.setVisible(false);
+			} else {
+				effectiveEndReasonEl.select(reasonKeyList.get(0), true);
+			}
 		}
 
 		
@@ -120,7 +125,7 @@ public class CancelRollCallConfirmationController extends FormBasicController {
 		boolean allOk = true;
 		
 		effectiveEndReasonEl.clearError();
-		if(!effectiveEndReasonEl.isOneSelected()) {
+		if(effectiveEndReasonEl.isEnabled() && !effectiveEndReasonEl.isOneSelected()) {
 			effectiveEndReasonEl.setErrorKey("error.reason.mandatory", null);
 			allOk &= false;
 		}
@@ -131,9 +136,11 @@ public class CancelRollCallConfirmationController extends FormBasicController {
 	@Override
 	protected void formOK(UserRequest ureq) {
 		String before = lectureService.toAuditXml(lectureBlock);
-		Long reasonKey = new Long(effectiveEndReasonEl.getSelectedKey());
-		Reason selectedReason = lectureService.getReason(reasonKey);
-		lectureBlock.setReasonEffectiveEnd(selectedReason);
+		if(effectiveEndReasonEl.isEnabled()) {
+			Long reasonKey = Long.valueOf(effectiveEndReasonEl.getSelectedKey());
+			Reason selectedReason = lectureService.getReason(reasonKey);
+			lectureBlock.setReasonEffectiveEnd(selectedReason);
+		}
 		lectureBlock = lectureService.cancel(lectureBlock);
 		String after = lectureService.toAuditXml(lectureBlock);
 		lectureService.auditLog(LectureBlockAuditLog.Action.cancelLectureBlock, before, after, null, lectureBlock, null, lectureBlock.getEntry(), null, getIdentity());
-- 
GitLab