Search in sources :

Example 36 with FormItem

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

the class CourseLayoutGeneratorController method prepareStyleEditor.

private void prepareStyleEditor(Map<String, Map<String, Object>> customConfig) {
    // keep config order
    guiWrapper = new LinkedHashMap<String, Map<String, FormItem>>();
    List<AbstractLayoutElement> allElements = customCMgr.getAllAvailableElements();
    List<AbstractLayoutAttribute> allAttribs = customCMgr.getAllAvailableAttributes();
    styleFlc.contextPut("allAttribs", allAttribs);
    // needed reference to get listener back.
    styleFlc.setUserObject(this);
    for (AbstractLayoutElement abstractLayoutElement : allElements) {
        String elementType = abstractLayoutElement.getLayoutElementTypeName();
        Map<String, Object> elConf = customConfig.get(elementType);
        AbstractLayoutElement concreteElmt = abstractLayoutElement.createInstance(elConf);
        HashMap<String, FormItem> elAttribGui = new HashMap<String, FormItem>();
        List<AbstractLayoutAttribute> attributes = concreteElmt.getAvailableAttributes();
        for (AbstractLayoutAttribute attrib : attributes) {
            String compName = elementType + ELEMENT_ATTRIBUTE_DELIM + attrib.getLayoutAttributeTypeName();
            FormItem fi = attrib.getFormItem(compName, styleFlc);
            fi.addActionListener(FormEvent.ONCHANGE);
            elAttribGui.put(attrib.getLayoutAttributeTypeName(), fi);
        }
        guiWrapper.put(elementType, elAttribGui);
    }
    styleFlc.contextPut("guiWrapper", guiWrapper);
}
Also used : AbstractLayoutElement(org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) AbstractLayoutAttribute(org.olat.course.config.ui.courselayout.attribs.AbstractLayoutAttribute) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 37 with FormItem

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

the class MetadataBulkChangeController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (checkboxSwitch.contains(source)) {
        MultipleSelectionElement checkbox = (MultipleSelectionElement) source;
        FormItem item = (FormItem) checkbox.getUserObject();
        item.setVisible(checkbox.isAtLeastSelected(1));
        checkboxContainer.get(checkbox).setDirty(true);
    } else if (licenseEl == source) {
        updateLicenseVisibility();
        licenseWrapperCont.setDirty(true);
    } else {
        super.formInnerEvent(ureq, source, event);
    }
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem)

Example 38 with FormItem

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

the class RegistrationController method createNewUserAfterRegistration.

/**
 * OO-92
 * this will finally create the user, set all it's userproperties
 *
 * @return User the newly created, persisted User Object
 */
private Identity createNewUserAfterRegistration() {
    // create user with mandatory fields from registration-form
    UserManager um = UserManager.getInstance();
    User volatileUser = um.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
    // set user configured language
    Preferences preferences = volatileUser.getPreferences();
    preferences.setLanguage(registrationForm.getLangKey());
    volatileUser.setPreferences(preferences);
    // create an identity with the given username / pwd and the user object
    String login = registrationForm.getLogin();
    String pwd = registrationForm.getPassword();
    Identity persistedIdentity = registrationManager.createNewUserAndIdentityFromTemporaryKey(login, pwd, volatileUser, tempKey);
    if (persistedIdentity == null) {
        showError("user.notregistered");
        return null;
    } else {
        // update other user properties from form
        List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
        User persistedUser = persistedIdentity.getUser();
        // add eventually static value
        UserPropertiesConfig userPropertiesConfig = CoreSpringFactory.getImpl(UserPropertiesConfig.class);
        if (registrationModule.isStaticPropertyMappingEnabled()) {
            String propertyName = registrationModule.getStaticPropertyMappingName();
            String propertyValue = registrationModule.getStaticPropertyMappingValue();
            if (StringHelper.containsNonWhitespace(propertyName) && StringHelper.containsNonWhitespace(propertyValue) && userPropertiesConfig.getPropertyHandler(propertyName) != null) {
                try {
                    persistedUser.setProperty(propertyName, propertyValue);
                } catch (Exception e) {
                    logError("Cannot set the static property value", e);
                }
            }
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            FormItem fi = registrationForm.getPropFormItem(userPropertyHandler.getName());
            userPropertyHandler.updateUserFromFormItem(persistedUser, fi);
        }
        // persist changes in db
        um.updateUserFromIdentity(persistedIdentity);
        // send notification mail to sys admin
        String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail();
        if (notiEmail != null) {
            registrationManager.sendNewUserNotificationMessage(notiEmail, persistedIdentity);
        }
        // tell system that this user did accept the disclaimer
        registrationManager.setHasConfirmedDislaimer(persistedIdentity);
        return persistedIdentity;
    }
}
Also used : User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Preferences(org.olat.core.id.Preferences) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig)

Example 39 with FormItem

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

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 40 with FormItem

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

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)

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