Search in sources :

Example 91 with MultipleSelectionElement

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

the class GroupsAndRightsController method fillCheckbox.

private void fillCheckbox(BGRightsRow groupRights, List<String> permissions) {
    List<BGRight> selections = new ArrayList<>();
    for (String permission : CourseRights.getAvailableRights()) {
        BGRight permissionEl = new BGRight(permission);
        boolean selected = permissions == null ? false : permissions.contains(permission);
        MultipleSelectionElement selection = createSelection(selected);
        permissionEl.setSelection(selection);
        selection.setUserObject(permissionEl);
        selections.add(permissionEl);
    }
    groupRights.setRightsEl(selections);
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) ArrayList(java.util.ArrayList) BGRight(org.olat.course.groupsandrights.BGRightsRow.BGRight)

Example 92 with MultipleSelectionElement

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

the class GroupsAndRightsController method createSelection.

private MultipleSelectionElement createSelection(boolean selected) {
    String name = "cb_" + (++counter);
    MultipleSelectionElement selection = uifactory.addCheckboxesHorizontal(name, null, flc, keys, values);
    selection.setEnabled(!readOnly);
    flc.add(name, selection);
    if (selected) {
        selection.select(keys[0], true);
    }
    return selection;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)

Example 93 with MultipleSelectionElement

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

the class CheckListAssessmentController method doDisableEditingMode.

private void doDisableEditingMode() {
    table.setEditMode(false);
    List<CheckListAssessmentRow> rows = model.getBackedUpRows();
    for (CheckListAssessmentRow row : rows) {
        MultipleSelectionElement[] checkedEls = row.getCheckedEl();
        if (checkedEls != null) {
            for (MultipleSelectionElement checkEl : checkedEls) {
                flc.remove(checkEl);
            }
        }
        row.setCheckedEl(null);
    }
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)

Example 94 with MultipleSelectionElement

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

the class CheckListAssessmentController method doSave.

private void doSave() {
    int numOfCheckbox = checkboxList.getNumOfCheckbox();
    // save all rows
    List<CheckListAssessmentRow> rows = model.getBackedUpRows();
    List<AssessmentBatch> batchElements = new ArrayList<>(rows.size());
    Set<Long> assessedIdentityToUpdate = new HashSet<>();
    for (CheckListAssessmentRow row : rows) {
        Boolean[] checked = row.getChecked();
        Boolean[] editedChecked = new Boolean[numOfCheckbox];
        MultipleSelectionElement[] checkedEls = row.getCheckedEl();
        if (checkedEls != null) {
            for (int i = 0; i < numOfCheckbox; i++) {
                MultipleSelectionElement checkEl = checkedEls[i];
                boolean editedValue = checkEl.isAtLeastSelected(1);
                editedChecked[i] = new Boolean(editedValue);
                boolean currentValue;
                if (checked != null && checked.length > 0 && i < checked.length && checked[i] != null) {
                    currentValue = checked[i].booleanValue();
                } else {
                    currentValue = false;
                }
                if (editedValue != currentValue) {
                    Checkbox checkbox = checkboxList.getList().get(i);
                    String checkboxId = checkbox.getCheckboxId();
                    Float score = editedValue ? checkbox.getPoints() : new Float(0f);
                    batchElements.add(new AssessmentBatch(row.getIdentityKey(), checkboxId, score, editedValue));
                    assessedIdentityToUpdate.add(row.getIdentityKey());
                }
                flc.remove(checkEl);
            }
        }
        row.setCheckedEl(null);
        row.setChecked(editedChecked);
    }
    doDisableEditingMode();
    checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
    if (assessedIdentityToUpdate.size() > 0) {
        DBFactory.getInstance().commit();
        ICourse course = CourseFactory.loadCourse(courseOres);
        List<Identity> assessedIdentities = securityManager.loadIdentityByKeys(assessedIdentityToUpdate);
        for (Identity assessedIdentity : assessedIdentities) {
            UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
        }
    }
    reloadTable();
}
Also used : UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 95 with MultipleSelectionElement

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

the class CheckboxAssessmentController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormDescription("assessment.checkbox.description");
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    if (isAdministrativeUser) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.username.i18nKey(), Cols.username.ordinal(), true, Cols.username.name()));
    }
    int i = 0;
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        int colIndex = CheckListAssessmentDataModel.USER_PROPS_OFFSET + i++;
        if (userPropertyHandler == null)
            continue;
        String propName = userPropertyHandler.getName();
        boolean visible = userManager.isMandatoryUserProperty(CheckListAssessmentController.USER_PROPS_ID, userPropertyHandler);
        if (visible) {
            FlexiColumnModel col;
            if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName)) {
                col = new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, userPropertyHandler.getName(), true, propName, new StaticFlexiCellRenderer(userPropertyHandler.getName(), new TextFlexiCellRenderer()));
            } else {
                col = new DefaultFlexiColumnModel(true, userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, true, propName);
            }
            columnsModel.addFlexiColumnModel(col);
        }
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.check.i18nKey(), Cols.check.ordinal(), true, Cols.check.name()));
    if (withScore) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.points.i18nKey(), Cols.points.ordinal(), true, Cols.points.name()));
    }
    int numOfCheckbox = checkboxList.getList().size();
    String[] keys = new String[numOfCheckbox];
    String[] values = new String[numOfCheckbox];
    List<Checkbox> checkbox = checkboxList.getList();
    for (int j = 0; j < numOfCheckbox; j++) {
        keys[j] = checkbox.get(j).getCheckboxId();
        values[j] = checkbox.get(j).getTitle();
    }
    FormLayoutContainer selectCont = FormLayoutContainer.createDefaultFormLayout("checkbox_sel_cont", getTranslator());
    formLayout.add(selectCont);
    checkboxEl = uifactory.addDropdownSingleselect("checkbox", "select.checkbox", selectCont, keys, values, null);
    checkboxEl.addActionListener(FormEvent.ONCHANGE);
    checkboxEl.select(keys[0], true);
    Checkbox box = checkboxList.getList().get(currentCheckboxIndex);
    boolean hasPoints = box.getPoints() != null && box.getPoints().floatValue() > 0f;
    boxRows = new ArrayList<CheckboxAssessmentRow>(initialRows.size());
    for (CheckListAssessmentRow initialRow : initialRows) {
        Boolean[] checked = new Boolean[numOfCheckbox];
        if (initialRow.getChecked() != null) {
            System.arraycopy(initialRow.getChecked(), 0, checked, 0, initialRow.getChecked().length);
        }
        Float[] scores = new Float[numOfCheckbox];
        if (initialRow.getScores() != null) {
            System.arraycopy(initialRow.getScores(), 0, scores, 0, initialRow.getScores().length);
        }
        CheckboxAssessmentRow row = new CheckboxAssessmentRow(initialRow, checked, scores);
        String name = "box_" + boxRows.size() + "_";
        String pointVal = "";
        if (scores != null && scores.length > currentCheckboxIndex && scores[currentCheckboxIndex] != null) {
            pointVal = AssessmentHelper.getRoundedScore(scores[currentCheckboxIndex]);
        }
        TextElement pointEl = uifactory.addTextElement(name + "point", null, 5, pointVal, formLayout);
        pointEl.setDisplaySize(5);
        MultipleSelectionElement checkEl = uifactory.addCheckboxesHorizontal(name + "check", null, formLayout, onKeys, onValues);
        checkEl.setDomReplacementWrapperRequired(false);
        checkEl.addActionListener(FormEvent.ONCHANGE);
        checkEl.setUserObject(row);
        if (checked != null && checked.length > currentCheckboxIndex && checked[currentCheckboxIndex] != null && checked[currentCheckboxIndex].booleanValue()) {
            checkEl.select(onKeys[0], true);
        }
        pointEl.setVisible(hasPoints);
        row.setCheckedEl(checkEl);
        row.setPointEl(pointEl);
        boxRows.add(row);
    }
    model = new CheckboxAssessmentDataModel(boxRows, columnsModel, getLocale());
    table = uifactory.addTableElement(getWindowControl(), "checkbox-list", model, getTranslator(), formLayout);
    table.setCustomizeColumns(true);
    table.setEditMode(true);
    table.setAndLoadPersistedPreferences(ureq, "checkbox-assessment");
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("save", buttonsCont);
    selectAllBoxButton = uifactory.addFormLink("selectall", buttonsCont, Link.BUTTON);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
Also used : DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Checkbox(org.olat.course.nodes.cl.model.Checkbox) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

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