Search in sources :

Example 66 with SingleSelection

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

the class UsrPropCfgTableController method buildPropertyHandlerTable.

/**
 * builds the userPropertyHandler-Table
 */
private void buildPropertyHandlerTable() {
    List<UserPropertyHandler> myHandlerList = usrPropCfgMng.getUserPropertiesConfigObject().getPropertyHandlers();
    // first search for all group-values in the propertyHandlers
    List<String> allGroupValues = new ArrayList<>();
    for (UserPropertyHandler handler : myHandlerList) {
        String group = handler.getGroup();
        if (!allGroupValues.contains(group))
            allGroupValues.add(group);
    }
    // take the defaults
    for (int k = 0; k < GROUP_KEYS.length; k++) {
        String group = GROUP_KEYS[k];
        if (!allGroupValues.contains(group))
            allGroupValues.add(group);
    }
    final String[] selectableGroups = allGroupValues.toArray(new String[0]);
    // the table-rows
    String handlerName;
    SingleSelection groupDropdown;
    FormToggle fi;
    FormLink translateLink;
    FormLink handlerLink;
    String translatedName;
    for (UserPropertyHandler handler : myHandlerList) {
        handlerName = handler.getName();
        // the group field
        groupDropdown = uifactory.addDropdownSingleselect(FT_NAME_PREFIX_GRPN + handlerName, propTableFlc, selectableGroups, selectableGroups, null);
        if (Arrays.asList(selectableGroups).contains(handler.getGroup())) {
            groupDropdown.select(handler.getGroup(), true);
        } else {
            logWarn("could not set group-select to " + handler.getGroup() + " (" + handler.getName() + ")", null);
        }
        groupDropdown.setUserObject(handler);
        groupDropdown.showLabel(false);
        groupDropdown.addActionListener(FormEvent.ONCHANGE);
        // the "active"-toggle button
        fi = uifactory.addToggleButton(FT_NAME_PREFIX_TGL + handlerName, "&nbsp;", propTableFlc, null, null);
        if (usrPropCfgMng.getUserPropertiesConfigObject().isActiveHandler(handler))
            fi.toggleOn();
        else
            fi.toggleOff();
        if (!UsrPropCfgManager.canBeDeactivated(handler))
            fi.setEnabled(false);
        fi.setUserObject(handler);
        rowToggleButtonsMap.put(handlerName, fi);
        // the "translate" link
        if (isPropertyHandlerTranslated(handler)) {
            translateLink = uifactory.addFormLink(FT_NAME_PREFIX_TRANSL + handlerName, "upc.edittranslate", "label", propTableFlc, Link.LINK);
        } else {
            translateLink = uifactory.addFormLink(FT_NAME_PREFIX_TRANSL + handlerName, "upc.translate", "label", propTableFlc, Link.LINK);
            translateLink.setCustomEnabledLinkCSS("o_ochre");
        }
        translateLink.setUserObject(handler);
        // the "handler-config" link
        if (handlerConfigCtrlFactory.hasConfig(handler)) {
            handlerLink = uifactory.addFormLink(FT_NAME_PREFIX_HDNL + handlerName, "upc.hndlconfig", "label", propTableFlc, Link.LINK);
            handlerLink.setUserObject(handler);
        }
        // put the translation (in the current language) for the property
        translatedName = I18nManager.getInstance().getLocalizedString(UserPropertyHandler.class.getPackage().getName(), handler.i18nFormElementLabelKey(), null, getLocale(), true, true);
        uifactory.addStaticTextElement(FT_NAME_PREFIX_TRANSNAME + handlerName, (translatedName == null ? "-" : translatedName), propTableFlc);
    }
    propTableFlc.contextPut("rows", myHandlerList);
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) FormToggle(org.olat.core.gui.components.form.flexible.elements.FormToggle) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 67 with SingleSelection

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

the class GenericSelectionPropertyHandler method isValid.

@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
    if (formItem.isMandatory()) {
        if (isMultiselect) {
            MultipleSelectionElement msel = (MultipleSelectionElement) formItem;
            msel.setErrorKey("form.legende.mandatory", null);
            return msel.isAtLeastSelected(1);
        } else {
            SingleSelection ssel = (SingleSelection) formItem;
            if (ssel.getSelectedKey().equals(NO_SEL_KEY)) {
                ssel.setErrorKey("form.legende.mandatory", null);
                return false;
            }
        }
    }
    return true;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection)

Example 68 with SingleSelection

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

the class GenericSelectionPropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale,
 *      org.olat.core.id.User, java.lang.String, boolean,
 *      org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    FormItem newItem = null;
    if (isMultiselect) {
        MultipleSelectionElement mse = FormUIFactory.getInstance().addCheckboxesHorizontal(getName(), i18nFormElementLabelKey(), formItemContainer, selectionKeys, getTranslatedValues(selectionKeys, locale));
        for (String sKey : getSelectedKeys(user)) {
            mse.select(sKey, true);
        }
        newItem = mse;
    } else {
        String[] allKeys = new String[selectionKeys.length + 1];
        System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
        allKeys[0] = NO_SEL_KEY;
        SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, getTranslatedValues(allKeys, locale), null);
        // make pre-selection of the formItem
        String internalValue = getInternalValue(user);
        if (isValidValue(user, internalValue, null, null) && internalValue != null)
            sse.select(internalValue, true);
        newItem = sse;
    }
    // enable/disable according to settings
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        newItem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        newItem.setMandatory(true);
    }
    return newItem;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserManager(org.olat.user.UserManager)

Example 69 with SingleSelection

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

the class YearPropertyHandler method addFormItem.

@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    /* let's load the years */
    loadSelectionKeysFromConfig();
    // add the no-selection entry to the dropdown
    String[] allKeys = new String[selectionKeys.length + 1];
    System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
    allKeys[0] = NO_SEL_KEY;
    SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, allKeys, null);
    String internalValue = getInternalValue(user);
    if (isValidValue(user, internalValue, null, null) && internalValue != null)
        sse.select(internalValue, true);
    // enable/disable according to settings
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        sse.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        sse.setMandatory(true);
    }
    return sse;
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) UserManager(org.olat.user.UserManager)

Example 70 with SingleSelection

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

the class CountryCodePropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale,
 *      org.olat.core.id.User, java.lang.String, boolean,
 *      org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    String[] allKeys = new String[countryKeys.length + 1];
    System.arraycopy(countryKeys, 0, allKeys, 1, countryKeys.length);
    allKeys[0] = NO_SEL_KEY;
    SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, getTranslatedValues(allKeys, locale), null);
    // make pre-selection of the formItem
    String internalValue = getInternalValue(user);
    if (internalValue == null || internalValue.isEmpty() || NO_SEL_KEY.equals(internalValue)) {
        sse.select(NO_SEL_KEY, true);
    } else if (isValidValue(user, internalValue, null, null) && internalValue != null) {
        sse.select("country.code." + internalValue, true);
    }
    // enable/disable according to settings
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        sse.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        sse.setMandatory(true);
    }
    return sse;
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) UserManager(org.olat.user.UserManager)

Aggregations

SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)88 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)34 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)26 FormItem (org.olat.core.gui.components.form.flexible.FormItem)18 ArrayList (java.util.ArrayList)14 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)12 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)10 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)8 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)8 File (java.io.File)6 Map (java.util.Map)6 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 SliderWrapper (org.olat.modules.forms.ui.model.SliderWrapper)6 UserManager (org.olat.user.UserManager)6 HashMap (java.util.HashMap)4 List (java.util.List)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4