Search in sources :

Example 11 with FormItemDependencyRule

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

the class RulesFactory method createResetRule.

/**
 * creates a reset rule
 *
 * @param triggerElement
 * @param triggerValue
 * @param targets
 * @param formLayout
 * @return
 */
public static FormItemDependencyRule createResetRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets, FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.RESET);
    formLayout.addDependencyRule(fidr);
    return fidr;
}
Also used : FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule)

Example 12 with FormItemDependencyRule

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

the class RulesFactory method createWritableRule.

/**
 * @param triggerElement
 * @param triggerValue
 * @param targets
 * @return
 */
public static FormItemDependencyRule createWritableRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets, FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.MAKE_WRITABLE);
    formLayout.addDependencyRule(fidr);
    return fidr;
}
Also used : FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule)

Example 13 with FormItemDependencyRule

use of org.olat.core.gui.components.form.flexible.FormItemDependencyRule 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 14 with FormItemDependencyRule

use of org.olat.core.gui.components.form.flexible.FormItemDependencyRule 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)

Example 15 with FormItemDependencyRule

use of org.olat.core.gui.components.form.flexible.FormItemDependencyRule in project openolat by klemens.

the class RulesFactory method createResetRule.

/**
 * creates a reset rule
 *
 * @param triggerElement
 * @param triggerValue
 * @param targets
 * @param formLayout
 * @return
 */
public static FormItemDependencyRule createResetRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets, FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.RESET);
    formLayout.addDependencyRule(fidr);
    return fidr;
}
Also used : FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule)

Aggregations

FormItemDependencyRule (org.olat.core.gui.components.form.flexible.FormItemDependencyRule)18 HashSet (java.util.HashSet)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 DependencyRuleApplayable (org.olat.core.gui.components.form.flexible.DependencyRuleApplayable)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 FormItemDependencyRuleImpl (org.olat.core.gui.components.form.flexible.impl.rules.FormItemDependencyRuleImpl)2