Search in sources :

Example 76 with FormItem

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

the class RegistrationForm2 method getLastName.

protected String getLastName() {
    FormItem fi = propFormItems.get("lastName");
    TextElement fn = (TextElement) fi;
    return fn.getValue().trim();
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem)

Example 77 with FormItem

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

the class RegistrationForm2 method initForm.

/**
 * Initialize the form
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("title.register");
    // first the configured user properties
    UserManager um = UserManager.getInstance();
    userPropertyHandlers = um.getUserPropertyHandlersFor(USERPROPERTIES_FORM_IDENTIFIER, false);
    Translator tr = Util.createPackageTranslator(UserPropertyHandler.class, getLocale(), getTranslator());
    // Add all available user fields to this form
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
        fi.setTranslator(tr);
        propFormItems.put(userPropertyHandler.getName(), fi);
    }
    uifactory.addSpacerElement("lang", formLayout, true);
    // second the user language
    Map<String, String> languages = i18nManager.getEnabledLanguagesTranslated();
    lang = uifactory.addDropdownSingleselect("user.language", formLayout, StringHelper.getMapKeysAsStringArray(languages), StringHelper.getMapValuesAsStringArray(languages), null);
    lang.select(languageKey, true);
    uifactory.addSpacerElement("loginstuff", formLayout, true);
    if (usernameReadonly) {
        usernameStatic = uifactory.addStaticTextElement("username", "user.login", proposedUsername, formLayout);
    } else {
        username = uifactory.addTextElement("username", "user.login", 128, "", formLayout);
        username.setMandatory(true);
    }
    if (proposedUsername != null) {
        setLogin(proposedUsername);
    }
    if (userInUse) {
        setLoginErrorKey("form.check6");
    }
    newpass1 = uifactory.addPasswordElement("newpass1", "form.password.new1", 128, "", formLayout);
    newpass1.setMandatory(true);
    newpass1.setAutocomplete("new-password");
    newpass2 = uifactory.addPasswordElement("newpass2", "form.password.new2", 128, "", formLayout);
    newpass2.setMandatory(true);
    newpass2.setAutocomplete("new-password");
    // Button layout
    buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("submit.speichernUndweiter", buttonLayout);
}
Also used : Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 78 with FormItem

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

the class I18nConfigSubNewLangController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // New language elements:
    // A title, displayed in fieldset
    setFormTitle("configuration.management.create.title");
    String[] args = new String[] { "<a href='http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt' target='_blank'><i class='o_icon o_icon_link_extern'> </i> ISO639</a>", "<a href='http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html' target='_blank'><i class='o_icon o_icon_link_extern'> </i> ISO3166</a>" };
    setFormDescription("configuration.management.create.description", args);
    // 
    // a) the language code
    newLanguage = uifactory.addTextElement("configuration.management.create.language", "configuration.management.create.language", 2, "", formLayout);
    newLanguage.setExampleKey("configuration.management.create.language.example", null);
    newLanguage.setMandatory(true);
    newLanguage.setRegexMatchCheck("[a-z]{2}", "configuration.management.create.language.error");
    newLanguage.setDisplaySize(2);
    newLanguage.addActionListener(FormEvent.ONCHANGE);
    // b) the country code
    newCountry = uifactory.addTextElement("configuration.management.create.country", "configuration.management.create.country", 2, "", formLayout);
    newCountry.setExampleKey("configuration.management.create.country.example", null);
    newCountry.setRegexMatchCheck("[A-Z]{0,2}", "configuration.management.create.country.error");
    newCountry.addActionListener(FormEvent.ONCHANGE);
    newCountry.setDisplaySize(2);
    // c) the variant, only available when country code is filled out
    newVariant = uifactory.addTextElement("configuration.management.create.variant", "configuration.management.create.variant", 50, "", formLayout);
    newVariant.setExampleKey("configuration.management.create.variant.example", null);
    newVariant.setRegexMatchCheck("[A-Za-z0-9_]*", "configuration.management.create.variant.error");
    newVariant.setDisplaySize(10);
    // Rule1: hide variant when country is empty
    Set<FormItem> hideItems = new HashSet<FormItem>();
    RulesFactory.createHideRule(newCountry, "", hideItems, formLayout);
    hideItems.add(newVariant);
    // Rule 2: show variant when country is not empty
    FormItemDependencyRule showRule = new FormItemDependencyRuleImpl(newCountry, ".{2}", hideItems, FormItemDependencyRuleImpl.MAKE_VISIBLE) {

        @Override
        protected boolean doesTrigger() {
            TextElement te = (TextElement) this.triggerElement;
            String val = te.getValue();
            // 
            if (val == null && triggerVal == null) {
                // triggerVal and val are NULL -> true
                return true;
            } else if (val != null) {
                // val can be compared
                String stringTriggerValString = (String) triggerVal;
                boolean matches = val.matches(stringTriggerValString);
                return matches;
            } else {
                // triggerVal is null but val is not null -> false
                return false;
            }
        }
    };
    formLayout.addDependencyRule(showRule);
    // 
    // Language name and translator data
    newTranslatedInEnglish = uifactory.addTextElement("configuration.management.create.inEnglish", "configuration.management.create.inEnglish", 255, "", formLayout);
    newTranslatedInEnglish.setExampleKey("configuration.management.create.inEnglish.example", null);
    newTranslatedInEnglish.setMandatory(true);
    newTranslatedInEnglish.setNotEmptyCheck("configuration.management.create.inEnglish.error");
    newTranslatedInLanguage = uifactory.addTextElement("configuration.management.create.inYourLanguage", "configuration.management.create.inYourLanguage", 255, "", formLayout);
    newTranslatedInLanguage.setExampleKey("configuration.management.create.inYourLanguage.example", null);
    newTranslator = uifactory.addTextElement("configuration.management.create.translator", "configuration.management.create.translator", 255, "", formLayout);
    newTranslator.setExampleKey("configuration.management.create.translator.example", null);
    // Add warn message
    String warnPage = Util.getPackageVelocityRoot(this.getClass()) + "/i18nConfigurationNewWarnMessage.html";
    FormLayoutContainer logoutWarnMessage = FormLayoutContainer.createCustomFormLayout("logoutWarnMessage", getTranslator(), warnPage);
    formLayout.add(logoutWarnMessage);
    // Add cancel and submit in button group layout
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    cancelButton = uifactory.addFormLink("cancel", buttonGroupLayout, Link.BUTTON);
    uifactory.addFormSubmitButton("configuration.management.create", buttonGroupLayout);
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule) FormItemDependencyRuleImpl(org.olat.core.gui.components.form.flexible.impl.rules.FormItemDependencyRuleImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HashSet(java.util.HashSet)

Example 79 with FormItem

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

the class AttributeEasyRowAdderController method addRowAt.

/**
 * Internal method to add a new row at the given position
 *
 * @param i
 */
private void addRowAt(final int rowPos) {
    // 1) Make room for the new row if the row is inserted between existing
    // rows. Increment the row id in the user object of the form elements and
    // move them in the form element arrays
    final Map<String, FormItem> formComponents = flc.getFormComponents();
    for (int move = rowPos + 1; move <= columnAttribute.size(); move++) {
        FormItem oldPos = formComponents.get(columnAttribute.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnOperator.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnValueText.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnValueSelection.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnAddRow.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnRemoveRow.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
    }
    // 2) create the new row
    // get gui translated shib attributes - fallback is to use the key also as value
    final String[] guiTranslatedAttKeys = new String[attrKeys.length];
    for (int j = 0; j < attrKeys.length; j++) {
        final String key = attrKeys[j];
        // OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
        // of Translator because that's the only one not
        String translated = getTranslator().translate(key, null, Level.OFF);
        if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
            final Translator translator = UserManager.getInstance().getPropertyHandlerTranslator(getTranslator());
            final String prefix = "form.name.";
            // OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
            // of Translator because that's the only one not
            translated = translator.translate(prefix + key, null, Level.OFF);
            if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
                // could not translate this key, use key for non-translated values
                guiTranslatedAttKeys[j] = key;
            } else {
                guiTranslatedAttKeys[j] = translated;
            }
        } else {
            guiTranslatedAttKeys[j] = translated;
        }
    }
    // sort after the values
    ArrayHelper.sort(attrKeys, guiTranslatedAttKeys, false, true, true);
    // use this sorted keys-values
    final SingleSelection attribute = uifactory.addDropdownSingleselect(PRE_ATTRIBUTE + rowCreationCounter, null, flc, attrKeys, guiTranslatedAttKeys, null);
    attribute.setUserObject(Integer.valueOf(rowPos));
    attribute.addActionListener(FormEvent.ONCHANGE);
    columnAttribute.add(rowPos, attribute.getName());
    // 2b) Operator selector
    final String[] values = OperatorManager.getRegisteredAndAlreadyTranslatedOperatorLabels(getLocale(), operatorKeys);
    final FormItem operator = uifactory.addDropdownSingleselect(PRE_OPERATOR + rowCreationCounter, null, flc, operatorKeys, values, null);
    operator.setUserObject(Integer.valueOf(rowPos));
    columnOperator.add(rowPos, operator.getName());
    // 2c) Attribute value - can be either a text input field or a selection
    // drop down box - create both and hide the selection box
    // 
    final TextElement valuetxt = uifactory.addTextElement(PRE_VALUE_TEXT + rowCreationCounter, null, -1, null, flc);
    valuetxt.setDisplaySize(25);
    valuetxt.setNotEmptyCheck("form.easy.error.attribute");
    valuetxt.setUserObject(Integer.valueOf(rowPos));
    columnValueText.add(rowPos, valuetxt.getName());
    // now the selection box
    final FormItem iselect = uifactory.addDropdownSingleselect(PRE_VALUE_SELECTION + rowCreationCounter, null, flc, new String[0], new String[0], null);
    iselect.setUserObject(Integer.valueOf(rowPos));
    iselect.setVisible(false);
    columnValueSelection.add(rowPos, iselect.getName());
    // 3) Init values for this row, assume selection of attribute at position 0
    if (ArrayUtils.contains(attrKeys, preselectedAttribute)) {
        attribute.select(preselectedAttribute, true);
        updateValueElementForAttribute(attribute.getKey(ArrayUtils.indexOf(attrKeys, preselectedAttribute)), rowPos, preselectedAttributeValue);
    } else {
        updateValueElementForAttribute(attribute.getKey(0), rowPos, null);
    }
    // 4) Add the 'add' and 'remove' buttons
    final FormLinkImpl addL = new FormLinkImpl("add_" + rowCreationCounter, "add." + rowPos, "+", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    addL.setUserObject(Integer.valueOf(rowPos));
    flc.add(addL);
    columnAddRow.add(rowPos, addL.getName());
    // 
    final FormLinkImpl removeL = new FormLinkImpl("remove_" + rowCreationCounter, "remove." + rowPos, "-", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    removeL.setUserObject(Integer.valueOf(rowPos));
    flc.add(removeL);
    columnRemoveRow.add(rowPos, removeL.getName());
    // new row created, increment counter for unique form element id's
    rowCreationCounter++;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) AttributeTranslator(org.olat.shibboleth.util.AttributeTranslator) Translator(org.olat.core.gui.translator.Translator) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)

Example 80 with FormItem

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

the class ConditionConfigEasyController method addRules.

/**
 * you may find here now the complexest rule set ever use in OLAT<br>
 * This form has a 5 switches<br>
 * <ul>
 * <li>[] 1 Learners only</li>
 * <li>[] 2 Date dependent</li>
 * <li>[] 3 Group dependent</li>
 * <li>[] 4 Assess dependent</li>
 * <li>[] 5 Apply rules also to coaches</li>
 * </ul>
 * enable [1] this greys out all others<br>
 * if one of [2] [3] or [4] is selected -> [5] becomes selectable<br>
 * selecting [2] [3] or [4] opens their respective subconfiguration<br>
 * "[2] date dependent" shows an end and startdate where at least one must be
 * selected and the start date must be before the enddate.<br>
 * "[3] group dependent" shows a group or area input field. which takes group
 * or area names comma separated. the form evaluates if the areas or groups
 * exists, and if not, a quick fix is provided to create the missing groups/areas.
 * furthermore there is a "choose" button to choose groups/areas. This choose
 * button is named "create" if there are no groups or areas to choose from. If
 * create is clicked a create group/area workflow is started directly. If some
 * comma separated values are in the input field, it allows to create them at
 * once. At least an area or groupname must be specified, and all the specified
 * names must exist.<br>
 * "[4] assessment " allows to choose a node and to define a cut value or if
 * it should be checked for passed.<br>
 * To accomplish all the hiding, disabling, enabling, resetting to initial values
 * the following rules are added. this may look confusing, and it is confusing.
 * It took quite some days and testing until to get it right.
 * @param formLayout
 */
private void addRules(FormItemContainer formLayout) {
    // disable date choosers if date switch is set to no
    // enable it otherwise.
    final Set<FormItem> dependenciesDateSwitch = new HashSet<FormItem>();
    dependenciesDateSwitch.add(toDate);
    dependenciesDateSwitch.add(fromDate);
    dependenciesDateSwitch.add(dateSubContainer);
    final Set<FormItem> dependenciesAttributeSwitch = new HashSet<FormItem>();
    // only add when initialized. is null when shibboleth module is not enabled
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        dependenciesAttributeSwitch.add(attributeBconnector);
    }
    // show elements dependent on other values set.
    FormItemDependencyRule hideClearDateSwitchDeps = RulesFactory.createCustomRule(dateSwitch, null, dependenciesDateSwitch, formLayout);
    hideClearDateSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            toDate.setDate(null);
            toDate.setVisible(false);
            fromDate.setDate(null);
            fromDate.setVisible(false);
            toDate.clearError();
            fromDate.clearError();
            dateSwitch.clearError();
            dateSubContainer.setVisible(false);
            fromDate.setFocus(false);
            /*
				 * special rules for apply rules for coach and for assessment dependent
				 */
            // assessment switch only enabled if nodes to be selected
            boolean coachExclIsOn = coachExclusive.getSelectedKeys().size() == 1;
            assessmentSwitch.setEnabled(!coachExclIsOn && (nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    RulesFactory.createShowRule(dateSwitch, "ison", dependenciesDateSwitch, formLayout);
    FormItemDependencyRule toggleApplyRule = RulesFactory.createCustomRule(dateSwitch, "ison", dependenciesDateSwitch, formLayout);
    toggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            fromDate.setFocus(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        FormItemDependencyRule hideClearAttibuteSwitchDeps = RulesFactory.createCustomRule(attributeSwitch, null, dependenciesAttributeSwitch, formLayout);
        hideClearAttibuteSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

            public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
                attributeSwitch.clearError();
                attributeBconnector.select(BCON_VAL_AND, true);
                attributeBconnector.setVisible(false);
                if (attribteRowAdderSubform != null) {
                    attribteRowAdderSubform.cleanUp();
                }
                showOrHideApplyRulesForCoach();
            }
        });
        RulesFactory.createShowRule(attributeSwitch, "ison", dependenciesAttributeSwitch, formLayout);
        FormItemDependencyRule attributeSwitchtoggleApplyRule = RulesFactory.createCustomRule(attributeSwitch, "ison", dependenciesAttributeSwitch, formLayout);
        attributeSwitchtoggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

            public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
                attributeBconnector.setVisible(true);
                if (attribteRowAdderSubform != null) {
                    attribteRowAdderSubform.init();
                }
                showOrHideApplyRulesForCoach();
            }
        });
    }
    // 
    // enable textfields and subworkflow-start-links if groups is yes
    // disable it otherwise
    final Set<FormItem> dependenciesGroupSwitch = new HashSet<FormItem>();
    dependenciesGroupSwitch.add(groupSubContainer);
    FormItemDependencyRule hideClearGroupSwitchDeps = RulesFactory.createCustomRule(groupSwitch, null, dependenciesGroupSwitch, formLayout);
    hideClearGroupSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            easyAreaList.clearError();
            easyGroupList.clearError();
            groupSwitch.clearError();
            groupSubContainer.setVisible(false);
            if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
                attributeSwitch.clearError();
            }
            easyGroupList.setFocus(false);
            // assessment switch only enabled if nodes to be selected
            boolean coachExclIsOn = coachExclusive.getSelectedKeys().size() == 1;
            assessmentSwitch.setEnabled(!coachExclIsOn && (nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    RulesFactory.createShowRule(groupSwitch, "ison", dependenciesGroupSwitch, formLayout);
    toggleApplyRule = RulesFactory.createCustomRule(groupSwitch, "ison", dependenciesGroupSwitch, formLayout);
    toggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            easyGroupList.setFocus(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    // 
    // dependencies of assessment switch
    final Set<FormItem> assessDeps = new HashSet<FormItem>();
    assessDeps.add(assessmentTypeSwitch);
    assessDeps.add(nodePassed);
    assessDeps.add(cutValue);
    assessDeps.add(assessSubContainer);
    // show elements dependent on other values set.
    FormItemDependencyRule showAssessmentSwitchDeps = RulesFactory.createCustomRule(assessmentSwitch, "ison", assessDeps, formLayout);
    showAssessmentSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            boolean cutValueVisibility = assessmentTypeSwitch.getSelectedKey().equals(NODEPASSED_VAL_SCORE);
            assessSubContainer.setVisible(true);
            assessmentTypeSwitch.setVisible(true);
            nodePassed.setVisible(true);
            cutValue.setVisible(cutValueVisibility);
            assessmentSwitch.clearError();
            cutValue.clearError();
            nodePassed.clearError();
            showOrHideApplyRulesForCoach();
        }
    });
    // hide elements and reset values.
    FormItemDependencyRule hideResetAssessmentSwitchDeps = RulesFactory.createCustomRule(assessmentSwitch, null, assessDeps, formLayout);
    hideResetAssessmentSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            assessSubContainer.setVisible(false);
            assessmentTypeSwitch.select(NODEPASSED_VAL_PASSED, true);
            assessmentTypeSwitch.setVisible(false);
            nodePassed.select(NO_NODE_SELECTED_IDENTIFYER, true);
            nodePassed.setVisible(false);
            cutValue.setIntValue(0);
            cutValue.setVisible(false);
            showOrHideApplyRulesForCoach();
        }
    });
    final Set<FormItem> assessTypeDeps = new HashSet<FormItem>();
    assessTypeDeps.add(cutValue);
    RulesFactory.createHideRule(assessmentTypeSwitch, NODEPASSED_VAL_PASSED, assessTypeDeps, assessSubContainer);
    RulesFactory.createShowRule(assessmentTypeSwitch, NODEPASSED_VAL_SCORE, assessTypeDeps, assessSubContainer);
    // 
    // 
    final Set<FormItem> dependenciesCoachExclusiveReadonly = new HashSet<FormItem>();
    dependenciesCoachExclusiveReadonly.addAll(dependenciesDateSwitch);
    dependenciesCoachExclusiveReadonly.addAll(dependenciesGroupSwitch);
    dependenciesCoachExclusiveReadonly.addAll(assessDeps);
    dependenciesCoachExclusiveReadonly.addAll(dependenciesAttributeSwitch);
    // coach exclusive switch rules
    // -> custom rule implementation because it is not a simple hide / show rule
    // while disabling reset the elements
    FormItemDependencyRule disableAndResetOthers = RulesFactory.createCustomRule(coachExclusive, "ison", dependenciesCoachExclusiveReadonly, formLayout);
    disableAndResetOthers.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            // disable and remove checkbox selection
            // uncheck and disable checkboxes
            dateSwitch.select("ison", false);
            groupSwitch.select("ison", false);
            assessmentSwitch.select("ison", false);
            dateSwitch.setEnabled(false);
            toDate.setDate(null);
            fromDate.setDate(null);
            groupSwitch.setEnabled(false);
            easyAreaList.setValue("");
            easyAreaList.setUserObject(new ArrayList<Long>());
            easyGroupList.setValue("");
            easyGroupList.setUserObject(new ArrayList<Long>());
            assessmentSwitch.setEnabled(false);
            assessmentMode.select("ison", false);
            assessmentMode.setEnabled(false);
            // disable the shibboleth attributes switch and reset the row subform
            if (attributeSwitch != null) {
                attributeSwitch.select("ison", false);
                attributeSwitch.setEnabled(false);
                attribteRowAdderSubform.cleanUp();
                attributeSwitch.clearError();
            }
            showOrHideApplyRulesForCoach();
            // hide (e.g. remove) general erros
            dateSwitch.clearError();
            groupSwitch.clearError();
            assessmentSwitch.clearError();
            // all dependent elements become invisible
            for (Iterator<FormItem> iter = dependenciesCoachExclusiveReadonly.iterator(); iter.hasNext(); ) {
                FormItem element = iter.next();
                element.setVisible(false);
            }
        }
    });
    // two rules to bring them back visible and also checkable
    // dependencies of assessment switch
    final Set<FormItem> switchesOnly = new HashSet<FormItem>();
    switchesOnly.add(dateSwitch);
    switchesOnly.add(groupSwitch);
    switchesOnly.add(assessmentSwitch);
    switchesOnly.add(applyRulesForCoach);
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        switchesOnly.add(attributeSwitch);
    }
    FormItemDependencyRule enableOthers = RulesFactory.createCustomRule(coachExclusive, null, switchesOnly, formLayout);
    enableOthers.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        private boolean firedDuringInit = true;

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            dateSwitch.setEnabled(true);
            groupSwitch.setEnabled(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            assessmentMode.setEnabled(true);
            // default is a checked disabled apply rules for coach
            if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
                attributeSwitch.setEnabled(true);
            }
            if (!firedDuringInit) {
                showOrHideApplyRulesForCoach();
            }
            firedDuringInit = false;
        }
    });
    // 
    // dependencies of assessment mode
    final Set<FormItem> assessModeDeps = new HashSet<FormItem>();
    // show elements dependent on other values set.
    FormItemDependencyRule showAssessmentModeDeps = RulesFactory.createCustomRule(assessmentMode, "ison", assessModeDeps, formLayout);
    showAssessmentModeDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            showOrHideApplyRulesForCoach();
        }
    });
    // hide elements and reset values.
    FormItemDependencyRule hideResetAssessmentModeDeps = RulesFactory.createCustomRule(assessmentMode, null, assessModeDeps, formLayout);
    hideResetAssessmentModeDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            showOrHideApplyRulesForCoach();
        }
    });
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule) DependencyRuleApplayable(org.olat.core.gui.components.form.flexible.DependencyRuleApplayable) HashSet(java.util.HashSet)

Aggregations

FormItem (org.olat.core.gui.components.form.flexible.FormItem)142 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)62 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)34 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)30 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)22 Identity (org.olat.core.id.Identity)20 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)16 User (org.olat.core.id.User)16 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)14 UserManager (org.olat.user.UserManager)12 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)12 HashSet (java.util.HashSet)10 Translator (org.olat.core.gui.translator.Translator)10 File (java.io.File)8 Map (java.util.Map)8 Component (org.olat.core.gui.components.Component)8 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)8 Date (java.util.Date)6 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)6