Search in sources :

Example 16 with Reason

use of org.olat.modules.lecture.Reason in project OpenOLAT by OpenOLAT.

the class CloseRollCallConfirmationController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_lecture_confirm_close_form");
    if (lectureModule.isStatusPartiallyDoneEnabled()) {
        int plannedLectures = lectureBlock.getPlannedLecturesNumber();
        String[] effectiveKeys = new String[plannedLectures];
        for (int i = plannedLectures; i-- > 0; ) {
            effectiveKeys[i] = Integer.toString(i + 1);
        }
        effectiveLecturesEl = uifactory.addDropdownSingleselect("effective.lectures", formLayout, effectiveKeys, effectiveKeys, null);
        int selectedEffectiveLectures = lectureBlock.getPlannedLecturesNumber();
        if (lectureBlock.getEffectiveLecturesNumber() > 0) {
            selectedEffectiveLectures = lectureBlock.getEffectiveLecturesNumber();
        }
        String selectedKey = Integer.toString(selectedEffectiveLectures);
        for (String effectiveKey : effectiveKeys) {
            if (effectiveKey.equals(selectedKey)) {
                effectiveLecturesEl.select(effectiveKey, true);
                break;
            }
        }
    }
    String datePage = velocity_root + "/date_end.html";
    FormLayoutContainer dateCont = FormLayoutContainer.createCustomFormLayout("start_end", getTranslator(), datePage);
    dateCont.setLabel("lecture.block.effective.end", null);
    formLayout.add(dateCont);
    effectiveEndHourEl = uifactory.addTextElement("lecture.end.hour", null, 2, "", dateCont);
    effectiveEndHourEl.setDomReplacementWrapperRequired(false);
    effectiveEndHourEl.setDisplaySize(2);
    effectiveEndHourEl.setEnabled(secCallback.canEdit());
    effectiveEndMinuteEl = uifactory.addTextElement("lecture.end.minute", null, 2, "", dateCont);
    effectiveEndMinuteEl.setDomReplacementWrapperRequired(false);
    effectiveEndMinuteEl.setDisplaySize(2);
    effectiveEndMinuteEl.setEnabled(secCallback.canEdit());
    Calendar cal = Calendar.getInstance();
    if (lectureBlock.getEffectiveEndDate() != null) {
        cal.setTime(lectureBlock.getEffectiveEndDate());
    } else if (lectureBlock.getEndDate() != null) {
        cal.setTime(lectureBlock.getEndDate());
    }
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    effectiveEndHourEl.setValue(Integer.toString(hour));
    String minuteStr = Integer.toString(minute);
    if (minuteStr.length() == 1) {
        minuteStr = "0" + minuteStr;
    }
    effectiveEndMinuteEl.setValue(minuteStr);
    List<Reason> allReasons = lectureService.getAllReasons();
    if (allReasons.size() > 0) {
        if (allReasons.size() > 2) {
            Collections.sort(allReasons, new ReasonComparator());
        }
        int numOfReasons = allReasons.size();
        List<String> reasonKeys = new ArrayList<String>(numOfReasons + 1);
        List<String> reasonValues = new ArrayList<String>(numOfReasons + 1);
        reasonKeys.add("-");
        reasonValues.add("");
        for (int i = numOfReasons; i-- > 0; ) {
            Reason reason = allReasons.get(i);
            reasonKeys.add(reason.getKey().toString());
            reasonValues.add(reason.getTitle());
        }
        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;
                }
            }
        }
    }
    String blockComment = lectureBlock.getComment();
    blockCommentEl = uifactory.addTextAreaElement("lecture.block.comment", 4, 72, blockComment, formLayout);
    blockCommentEl.setEnabled(secCallback.canEdit());
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsCont.setRootForm(mainForm);
    formLayout.add(buttonsCont);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
    quickSaveButton = uifactory.addFormLink("save.temporary", buttonsCont, Link.BUTTON);
    uifactory.addFormSubmitButton("close.lecture.blocks", buttonsCont);
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Reason(org.olat.modules.lecture.Reason)

Example 17 with Reason

use of org.olat.modules.lecture.Reason in project OpenOLAT by OpenOLAT.

the class CloseRollCallConfirmationController method commitLectureBlocks.

private void commitLectureBlocks() {
    lectureBlock.setComment(blockCommentEl.getValue());
    int effectiveLectures = lectureBlock.getPlannedLecturesNumber();
    if (effectiveLecturesEl != null) {
        try {
            String selectedKey = effectiveLecturesEl.getSelectedKey();
            effectiveLectures = Integer.parseInt(selectedKey);
        } catch (Exception ex) {
            logError("", ex);
        }
    }
    lectureBlock.setEffectiveLecturesNumber(effectiveLectures);
    Date effectiveEndDate = getEffectiveEndDate();
    if (effectiveEndDate == null) {
        lectureBlock.setReasonEffectiveEnd(null);
    } else {
        lectureBlock.setEffectiveEndDate(effectiveEndDate);
        if (effectiveEndReasonEl == null || "-".equals(effectiveEndReasonEl.getSelectedKey())) {
            lectureBlock.setReasonEffectiveEnd(null);
        } else {
            Long reasonKey = new Long(effectiveEndReasonEl.getSelectedKey());
            Reason selectedReason = lectureService.getReason(reasonKey);
            lectureBlock.setReasonEffectiveEnd(selectedReason);
        }
    }
}
Also used : Date(java.util.Date) Reason(org.olat.modules.lecture.Reason)

Example 18 with Reason

use of org.olat.modules.lecture.Reason in project OpenOLAT by OpenOLAT.

the class CancelRollCallConfirmationController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    List<String> reasonKeyList = new ArrayList<>();
    List<String> reasonValueList = new ArrayList<>();
    List<Reason> allReasons = lectureService.getAllReasons();
    Collections.sort(allReasons, new ReasonComparator());
    for (Reason reason : allReasons) {
        reasonKeyList.add(reason.getKey().toString());
        reasonValueList.add(reason.getTitle());
    }
    effectiveEndReasonEl = uifactory.addDropdownSingleselect("effective.reason", "lecture.block.effective.reason", formLayout, reasonKeyList.toArray(new String[reasonKeyList.size()]), reasonValueList.toArray(new String[reasonValueList.size()]), null);
    effectiveEndReasonEl.setEnabled(secCallback.canEdit());
    boolean found = false;
    if (lectureBlock.getReasonEffectiveEnd() != null) {
        String selectedReasonKey = lectureBlock.getReasonEffectiveEnd().getKey().toString();
        for (String reasonKey : reasonKeyList) {
            if (reasonKey.equals(selectedReasonKey)) {
                effectiveEndReasonEl.select(reasonKey, true);
                found = true;
                break;
            }
        }
    }
    if (!found) {
        effectiveEndReasonEl.select(reasonKeyList.get(0), true);
    }
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsCont.setRootForm(mainForm);
    formLayout.add(buttonsCont);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
    uifactory.addFormSubmitButton("cancel.lecture.blocks", buttonsCont);
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Reason(org.olat.modules.lecture.Reason)

Example 19 with Reason

use of org.olat.modules.lecture.Reason in project OpenOLAT by OpenOLAT.

the class CancelRollCallConfirmationController method formOK.

@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);
    lectureBlock = lectureService.cancel(lectureBlock);
    String after = lectureService.toAuditXml(lectureBlock);
    lectureService.auditLog(LectureBlockAuditLog.Action.cancelLectureBlock, before, after, null, lectureBlock, null, lectureBlock.getEntry(), null, getIdentity());
    fireEvent(ureq, Event.DONE_EVENT);
    ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LECTURE_BLOCK_ROLL_CALL_CANCELLED, getClass(), CoreLoggingResourceable.wrap(lectureBlock, OlatResourceableType.lectureBlock, lectureBlock.getTitle()));
}
Also used : Reason(org.olat.modules.lecture.Reason)

Example 20 with Reason

use of org.olat.modules.lecture.Reason in project OpenOLAT by OpenOLAT.

the class ReasonAdminController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (addReasonButton == source) {
        doAddReason(ureq);
    } else if (tableEl == source) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            String cmd = se.getCommand();
            ReasonRow row = dataModel.getObject(se.getIndex());
            if ("edit".equals(cmd)) {
                doEditReason(ureq, row.getReason());
            }
        }
    } else if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        String cmd = link.getCmd();
        if (cmd != null && cmd.startsWith("tools-")) {
            Reason row = (Reason) link.getUserObject();
            doOpenTools(ureq, row, link);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Reason(org.olat.modules.lecture.Reason)

Aggregations

Reason (org.olat.modules.lecture.Reason)28 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)6 Date (java.util.Date)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 LectureBlock (org.olat.modules.lecture.LectureBlock)4 Calendar (java.util.Calendar)2 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)2 Identity (org.olat.core.id.Identity)2 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)2 LectureBlockWithTeachers (org.olat.modules.lecture.model.LectureBlockWithTeachers)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2