Search in sources :

Example 6 with MultipleSelectionElement

use of org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement in project OpenOLAT by OpenOLAT.

the class CheckboxAssessmentController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (checkboxEl == source) {
        int nextCheckboxIndex = checkboxEl.getSelected();
        saveCurrentSelectCheckbox();
        Checkbox box = checkboxList.getList().get(nextCheckboxIndex);
        boolean hasPoints = box.getPoints() != null && box.getPoints().floatValue() > 0f;
        List<CheckboxAssessmentRow> rows = model.getObjects();
        for (CheckboxAssessmentRow row : rows) {
            Boolean[] checkedArr = row.getChecked();
            if (checkedArr[nextCheckboxIndex] != null && checkedArr[nextCheckboxIndex].booleanValue()) {
                row.getCheckedEl().select(onKeys[0], true);
            } else {
                row.getCheckedEl().select(onKeys[0], false);
            }
            Float[] scores = row.getScores();
            if (scores[nextCheckboxIndex] != null && scores[nextCheckboxIndex] != null) {
                row.getPointEl().setValue(AssessmentHelper.getRoundedScore(scores[nextCheckboxIndex]));
            } else {
                row.getPointEl().setValue("");
            }
            row.getPointEl().setVisible(hasPoints);
        }
        currentCheckboxIndex = nextCheckboxIndex;
    } else if (source instanceof MultipleSelectionElement) {
        MultipleSelectionElement checkEl = (MultipleSelectionElement) source;
        if (checkEl.getUserObject() instanceof CheckboxAssessmentRow) {
            CheckboxAssessmentRow row = (CheckboxAssessmentRow) checkEl.getUserObject();
            if (row.getPointEl().isVisible()) {
                boolean checked = checkEl.isAtLeastSelected(1);
                if (checked) {
                    int nextCheckboxIndex = checkboxEl.getSelected();
                    Checkbox box = checkboxList.getList().get(nextCheckboxIndex);
                    String pointVal = AssessmentHelper.getRoundedScore(box.getPoints());
                    row.getPointEl().setValue(pointVal);
                } else {
                    row.getPointEl().setValue("");
                }
            }
        }
    } else if (selectAllBoxButton == source) {
        doSelectAll();
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Checkbox(org.olat.course.nodes.cl.model.Checkbox)

Example 7 with MultipleSelectionElement

use of org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement in project OpenOLAT by OpenOLAT.

the class GroupAssessmentController method loadModel.

/**
 * @return True if all results are the same
 */
private ModelInfos loadModel() {
    // load participants, load datas
    ICourse course = CourseFactory.loadCourse(courseEntry);
    List<Identity> identities = businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());
    Map<Identity, AssessmentEntry> identityToEntryMap = new HashMap<>();
    List<AssessmentEntry> entries = course.getCourseEnvironment().getAssessmentManager().getAssessmentEntries(assessedGroup, gtaNode);
    for (AssessmentEntry entry : entries) {
        identityToEntryMap.put(entry.getIdentity(), entry);
    }
    int count = 0;
    boolean same = true;
    StringBuilder duplicateWarning = new StringBuilder();
    Float scoreRef = null;
    Boolean passedRef = null;
    String commentRef = null;
    Boolean userVisibleRef = null;
    List<AssessmentRow> rows = new ArrayList<>(identities.size());
    for (Identity identity : identities) {
        AssessmentEntry entry = identityToEntryMap.get(identity);
        ScoreEvaluation scoreEval = null;
        if (withScore || withPassed) {
            scoreEval = gtaNode.getUserScoreEvaluation(entry);
            if (scoreEval == null) {
                scoreEval = ScoreEvaluation.EMPTY_EVALUATION;
            }
        }
        String comment = null;
        if (withComment && entry != null) {
            comment = entry.getComment();
        }
        boolean duplicate = duplicateMemberKeys.contains(identity.getKey());
        if (duplicate) {
            if (duplicateWarning.length() > 0)
                duplicateWarning.append(", ");
            duplicateWarning.append(StringHelper.escapeHtml(userManager.getUserDisplayName(identity)));
        }
        AssessmentRow row = new AssessmentRow(identity, duplicate);
        rows.add(row);
        if (withScore) {
            Float score = scoreEval.getScore();
            String pointVal = AssessmentHelper.getRoundedScore(score);
            TextElement pointEl = uifactory.addTextElement("point" + count, null, 5, pointVal, flc);
            pointEl.setDisplaySize(5);
            row.setScoreEl(pointEl);
            if (count == 0) {
                scoreRef = score;
            } else if (!same(scoreRef, score)) {
                same = false;
            }
        }
        if (withPassed && cutValue == null) {
            Boolean passed = scoreEval.getPassed();
            MultipleSelectionElement passedEl = uifactory.addCheckboxesHorizontal("check" + count, null, flc, onKeys, onValues);
            if (passed != null && passed.booleanValue()) {
                passedEl.select(onKeys[0], passed.booleanValue());
            }
            row.setPassedEl(passedEl);
            if (count == 0) {
                passedRef = passed;
            } else if (!same(passedRef, passed)) {
                same = false;
            }
        }
        if (withComment) {
            FormLink commentLink = uifactory.addFormLink("comment-" + CodeHelper.getRAMUniqueID(), "comment", "comment", null, flc, Link.LINK);
            if (StringHelper.containsNonWhitespace(comment)) {
                commentLink.setIconLeftCSS("o_icon o_icon_comments");
            } else {
                commentLink.setIconLeftCSS("o_icon o_icon_comments_none");
            }
            commentLink.setUserObject(row);
            row.setComment(comment);
            row.setCommentEditLink(commentLink);
            if (count == 0) {
                commentRef = comment;
            } else if (!same(commentRef, comment)) {
                same = false;
            }
        }
        if (withScore || withPassed || withPassed) {
            Boolean userVisible = scoreEval.getUserVisible();
            if (userVisible == null) {
                userVisible = Boolean.TRUE;
            }
            if (count == 0) {
                userVisibleRef = userVisible;
            } else if (!same(userVisibleRef, userVisible)) {
                same = false;
            }
        }
        count++;
    }
    model.setObjects(rows);
    table.reset();
    return new ModelInfos(same, scoreRef, passedRef, commentRef, userVisibleRef, duplicateWarning.toString());
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Identity(org.olat.core.id.Identity)

Example 8 with MultipleSelectionElement

use of org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement in project OpenOLAT by OpenOLAT.

the class HotspotEditorController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (newCircleButton == source) {
        createHotspotChoice(Shape.CIRCLE, "60,60,25");
        updateHotspots(ureq);
    } else if (newRectButton == source) {
        createHotspotChoice(Shape.RECT, "50,50,100,100");
        updateHotspots(ureq);
    } else if (backgroundEl == source) {
        // upload in itemDirectory;
        if (FileElementEvent.DELETE.equals(event.getCommand())) {
            if (backgroundEl.getUploadFile() != null && backgroundEl.getUploadFile() != backgroundEl.getInitialFile()) {
                backgroundEl.reset();
                if (initialBackgroundImage != null) {
                    backgroundEl.setInitialFile(initialBackgroundImage);
                }
            } else if (initialBackgroundImage != null) {
                initialBackgroundImage = null;
                backgroundEl.setInitialFile(null);
            }
            flc.setDirty(true);
        } else if (backgroundEl.isUploadSuccess()) {
            List<ValidationStatus> status = new ArrayList<>();
            backgroundEl.validate(status);
            if (status.isEmpty()) {
                flc.setDirty(true);
                backgroundImage = backgroundEl.moveUploadFileTo(itemFile.getParentFile());
                Size size = imageService.getSize(new LocalFileImpl(backgroundImage), null);
                optimizeResizeEl(size, true);
            }
        }
        Size backgroundSize = updateBackground();
        updateHotspots(ureq);
        updateHotspotsPosition(backgroundSize);
    } else if (correctHotspotsEl == source) {
        MultipleSelectionElement correctEl = (MultipleSelectionElement) source;
        Collection<String> correctResponseIds = correctEl.getSelectedKeys();
        doCorrectAnswers(correctResponseIds);
        flc.setDirty(true);
    } else if (layoutEl == source) {
        updateLayoutCssClass();
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with MultipleSelectionElement

use of org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement in project OpenOLAT by OpenOLAT.

the class EditScoreCalculationEasyForm method initNodeSelectionElement.

/**
 * Initializes the node selection form elements first check if the form has a
 * selection on a node that has been deleted in since the last edition of this
 * form. if so, set remember this to later add a dummy placeholder for the
 * deleted node. We do not just ignore this since the form would look ok then
 * to the user, the generated rule visible in the expert mode however would
 * still be invalid. user must explicitly uncheck this deleted node reference.
 *
 * @param elemId name of the generated form element
 * @param scoreCalculator
 * @param selectedNodeList List of course nodes that are preselected
 * @param allNodesList List of all assessable course nodes
 * @return StaticMultipleSelectionElement The configured form element
 */
private MultipleSelectionElement initNodeSelectionElement(FormItemContainer formLayout, String elemId, ScoreCalculator scoreCalculator, List<String> selectedNodeList, List<CourseNode> allNodesList) {
    boolean addDeletedNodeIdent = false;
    if (scoreCalculator != null && selectedNodeList != null) {
        for (Iterator<String> iter = selectedNodeList.iterator(); iter.hasNext(); ) {
            String nodeIdent = iter.next();
            boolean found = false;
            for (Iterator<CourseNode> nodeIter = allNodesList.iterator(); nodeIter.hasNext(); ) {
                CourseNode node = nodeIter.next();
                if (node.getIdent().equals(nodeIdent)) {
                    found = true;
                }
            }
            if (!found)
                addDeletedNodeIdent = true;
        }
    }
    String[] nodeKeys = new String[allNodesList.size() + (addDeletedNodeIdent ? 1 : 0)];
    String[] nodeValues = new String[allNodesList.size() + (addDeletedNodeIdent ? 1 : 0)];
    for (int i = 0; i < allNodesList.size(); i++) {
        CourseNode courseNode = allNodesList.get(i);
        nodeKeys[i] = courseNode.getIdent();
        nodeValues[i] = courseNode.getShortName() + " (Id:" + courseNode.getIdent() + ")";
    }
    // add a deleted dummy node at last position
    if (addDeletedNodeIdent) {
        nodeKeys[allNodesList.size()] = DELETED_NODE_IDENTIFYER;
        nodeValues[allNodesList.size()] = translate("scform.deletedNode");
    }
    MultipleSelectionElement mse = uifactory.addCheckboxesVertical(elemId, formLayout, nodeKeys, nodeValues, 2);
    // preselect nodes from configuration
    if (scoreCalculator != null && selectedNodeList != null) {
        for (Iterator<String> iter = selectedNodeList.iterator(); iter.hasNext(); ) {
            String nodeIdent = iter.next();
            boolean found = false;
            for (Iterator<CourseNode> nodeIter = allNodesList.iterator(); nodeIter.hasNext(); ) {
                CourseNode node = nodeIter.next();
                if (node.getIdent().equals(nodeIdent)) {
                    found = true;
                }
            }
            if (found) {
                mse.select(nodeIdent, true);
            } else {
                mse.select(DELETED_NODE_IDENTIFYER, true);
            }
        }
    }
    return mse;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) CourseNode(org.olat.course.nodes.CourseNode)

Example 10 with MultipleSelectionElement

use of org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement in project OpenOLAT by OpenOLAT.

the class ProjectEventFormController method initForm.

/**
 * Initialize form.
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    int index = 1;
    for (Project.EventType eventType : Project.EventType.values()) {
        if (index++ > 1) {
            uifactory.addSpacerElement("event_spacer" + index, formLayout, false);
        }
        String[] keys = new String[] { "event.enabled", KEY_EVENT_TABLE_VIEW_ENABLED };
        String[] values = new String[] { translate(eventType.getI18nKey() + ".label"), translate(KEY_EVENT_TABLE_VIEW_ENABLED) };
        boolean isEventEnabled = config.isProjectEventEnabled(eventType);
        boolean isTableViewEnabled = config.isProjectEventTableViewEnabled(eventType);
        MultipleSelectionElement projectEventElement = uifactory.addCheckboxesVertical(eventType.toString(), null, formLayout, keys, values, 1);
        projectEventElement.select(keys[0], isEventEnabled);
        projectEventElement.setVisible(keys[1], isEventEnabled);
        projectEventElement.select(keys[1], isTableViewEnabled);
        projectEventElement.addActionListener(FormEvent.ONCLICK);
        projectEventElementList.put(eventType, projectEventElement);
    }
    uifactory.addFormSubmitButton("save", formLayout);
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)

Aggregations

MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)136 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)22 ArrayList (java.util.ArrayList)20 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)16 MultipleSelectionElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl)16 HashMap (java.util.HashMap)12 HashSet (java.util.HashSet)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)10 FormItem (org.olat.core.gui.components.form.flexible.FormItem)8 Identity (org.olat.core.id.Identity)8 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)8 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)6 ICourse (org.olat.course.ICourse)6 Checkbox (org.olat.course.nodes.cl.model.Checkbox)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)5 VFSItem (org.olat.core.util.vfs.VFSItem)5 Section (org.olat.modules.portfolio.Section)5 File (java.io.File)4 UserShortDescription (org.olat.admin.user.UserShortDescription)4