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

OO-3096: field reason mandatory for roll call (if any)

parent 35f254dc
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package org.olat.modules.lecture.ui; package org.olat.modules.lecture.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
...@@ -77,6 +78,7 @@ public class CancelRollCallConfirmationController extends FormBasicController { ...@@ -77,6 +78,7 @@ public class CancelRollCallConfirmationController extends FormBasicController {
List<String> reasonValueList = new ArrayList<>(); List<String> reasonValueList = new ArrayList<>();
List<Reason> allReasons = lectureService.getAllReasons(); List<Reason> allReasons = lectureService.getAllReasons();
Collections.sort(allReasons, new ReasonComparator());
for(Reason reason:allReasons) { for(Reason reason:allReasons) {
reasonKeyList.add(reason.getKey().toString()); reasonKeyList.add(reason.getKey().toString());
reasonValueList.add(reason.getTitle()); reasonValueList.add(reason.getTitle());
......
...@@ -50,6 +50,8 @@ import org.olat.modules.lecture.Reason; ...@@ -50,6 +50,8 @@ import org.olat.modules.lecture.Reason;
import org.olat.modules.lecture.RollCallSecurityCallback; import org.olat.modules.lecture.RollCallSecurityCallback;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import edu.emory.mathcs.backport.java.util.Collections;
/** /**
* *
* Initial date: 12 juin 2017<br> * Initial date: 12 juin 2017<br>
...@@ -138,33 +140,35 @@ public class CloseRollCallConfirmationController extends FormBasicController { ...@@ -138,33 +140,35 @@ public class CloseRollCallConfirmationController extends FormBasicController {
} }
effectiveEndMinuteEl.setValue(minuteStr); effectiveEndMinuteEl.setValue(minuteStr);
List<String> reasonKeyList = new ArrayList<>();
List<String> reasonValueList = new ArrayList<>();
reasonKeyList.add("-");
reasonValueList.add("-");
List<Reason> allReasons = lectureService.getAllReasons(); List<Reason> allReasons = lectureService.getAllReasons();
for(Reason reason:allReasons) { if(allReasons.size() > 0) {
reasonKeyList.add(reason.getKey().toString()); if(allReasons.size() > 2) {
reasonValueList.add(reason.getTitle()); Collections.sort(allReasons, new ReasonComparator());
} }
effectiveEndReasonEl = uifactory.addDropdownSingleselect("effective.reason", "lecture.block.effective.reason", formLayout,
reasonKeyList.toArray(new String[reasonKeyList.size()]), reasonValueList.toArray(new String[reasonValueList.size()]), null); int numOfReasons = allReasons.size();
effectiveEndReasonEl.setEnabled(secCallback.canEdit()); List<String> reasonKeys = new ArrayList<String>(numOfReasons + 1);
boolean found = false; List<String> reasonValues = new ArrayList<String>(numOfReasons + 1);
if(lectureBlock.getReasonEffectiveEnd() != null) { reasonKeys.add("-");
String selectedReasonKey = lectureBlock.getReasonEffectiveEnd().getKey().toString(); reasonValues.add("");
for(String reasonKey:reasonKeyList) { for(int i=numOfReasons; i-->0; ) {
if(reasonKey.equals(selectedReasonKey)) { Reason reason = allReasons.get(i);
effectiveEndReasonEl.select(reasonKey, true); reasonKeys.add(reason.getKey().toString());
found = true; reasonValues.add(reason.getTitle());
break; }
effectiveEndReasonEl = uifactory.addDropdownSingleselect("effective.reason", "lecture.block.effective.reason", formLayout,
reasonKeys.toArray(new String[reasonKeys.size()]), reasonValues.toArray(new String[reasonValues.size()]), null);
effectiveEndReasonEl.setEnabled(secCallback.canEdit());
if(lectureBlock.getReasonEffectiveEnd() != null) {
String selectedReasonKey = lectureBlock.getReasonEffectiveEnd().getKey().toString();
for(String reasonKey:reasonKeys) {
if(reasonKey.equals(selectedReasonKey)) {
effectiveEndReasonEl.select(reasonKey, true);
break;
}
} }
} }
} }
if(!found) {
effectiveEndReasonEl.select(reasonKeyList.get(0), true);
}
String blockComment = lectureBlock.getComment(); String blockComment = lectureBlock.getComment();
blockCommentEl = uifactory.addTextAreaElement("lecture.block.comment", 4, 72, blockComment, formLayout); blockCommentEl = uifactory.addTextAreaElement("lecture.block.comment", 4, 72, blockComment, formLayout);
...@@ -210,27 +214,24 @@ public class CloseRollCallConfirmationController extends FormBasicController { ...@@ -210,27 +214,24 @@ public class CloseRollCallConfirmationController extends FormBasicController {
boolean allOk = true; boolean allOk = true;
effectiveEndHourEl.clearError(); effectiveEndHourEl.clearError();
effectiveEndReasonEl.clearError();
//need to be the first validation //need to be the first validation
if(StringHelper.containsNonWhitespace(effectiveEndHourEl.getValue()) if(StringHelper.containsNonWhitespace(effectiveEndHourEl.getValue())
|| StringHelper.containsNonWhitespace(effectiveEndMinuteEl.getValue())) { || StringHelper.containsNonWhitespace(effectiveEndMinuteEl.getValue())) {
allOk &= validateInt(effectiveEndHourEl, 24); allOk &= validateInt(effectiveEndHourEl, 24);
allOk &= validateInt(effectiveEndMinuteEl, 60); allOk &= validateInt(effectiveEndMinuteEl, 60);
if(!effectiveEndReasonEl.isOneSelected()) {
effectiveEndReasonEl.setErrorKey("error.reason.mandatory", null);
allOk &= false;
} else if(effectiveEndReasonEl.isSelected(0)) {
if(getEffectiveEndDate() != null && this.differentEffectiveEndDate()) {
effectiveEndReasonEl.setErrorKey("error.reason.mandatory", null);
allOk &= false;
}
}
} else { } else {
effectiveEndHourEl.setErrorKey("form.legende.mandatory", null); effectiveEndHourEl.setErrorKey("form.legende.mandatory", null);
allOk &= false; allOk &= false;
} }
if(effectiveEndReasonEl != null) {
effectiveEndReasonEl.clearError();
if(!effectiveEndReasonEl.isOneSelected() || effectiveEndReasonEl.isSelected(0)) {
effectiveEndReasonEl.setErrorKey("error.reason.mandatory", null);
allOk &= false;
}
}
if(effectiveLecturesEl != null) { if(effectiveLecturesEl != null) {
effectiveLecturesEl.clearError(); effectiveLecturesEl.clearError();
if(!effectiveLecturesEl.isOneSelected()) { if(!effectiveLecturesEl.isOneSelected()) {
...@@ -242,14 +243,6 @@ public class CloseRollCallConfirmationController extends FormBasicController { ...@@ -242,14 +243,6 @@ public class CloseRollCallConfirmationController extends FormBasicController {
return allOk & super.validateFormLogic(ureq); return allOk & super.validateFormLogic(ureq);
} }
private boolean differentEffectiveEndDate() {
Date endDate = lectureBlock.getEndDate();
if(endDate == null) return true;
Date effectiveEndDate = getEffectiveEndDate();
long diff = endDate.getTime() - effectiveEndDate.getTime();
return Math.abs(diff) > 60000l;//bigger than a minute
}
private boolean validateInt(TextElement element, int max) { private boolean validateInt(TextElement element, int max) {
boolean allOk = true; boolean allOk = true;
...@@ -320,7 +313,7 @@ public class CloseRollCallConfirmationController extends FormBasicController { ...@@ -320,7 +313,7 @@ public class CloseRollCallConfirmationController extends FormBasicController {
lectureBlock.setReasonEffectiveEnd(null); lectureBlock.setReasonEffectiveEnd(null);
} else { } else {
lectureBlock.setEffectiveEndDate(effectiveEndDate); lectureBlock.setEffectiveEndDate(effectiveEndDate);
if("-".equals(effectiveEndReasonEl.getSelectedKey())) { if(effectiveEndReasonEl == null || "-".equals(effectiveEndReasonEl.getSelectedKey())) {
lectureBlock.setReasonEffectiveEnd(null); lectureBlock.setReasonEffectiveEnd(null);
} else { } else {
Long reasonKey = new Long(effectiveEndReasonEl.getSelectedKey()); Long reasonKey = new Long(effectiveEndReasonEl.getSelectedKey());
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.lecture.ui;
import java.util.Comparator;
import java.util.Date;
import org.olat.modules.lecture.Reason;
/**
*
* Initial date: 26 oct. 2017<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class ReasonComparator implements Comparator<Reason> {
@Override
public int compare(Reason r1, Reason r2) {
if(r1 == null && r2 == null) return 0;
if(r1 == null) return -1;
if(r2 == null) return 1;
Date c1 = r1.getCreationDate();
Date c2 = r2.getCreationDate();
return c2.compareTo(c1);
}
}
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