Search in sources :

Example 41 with FormItem

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

the class RegistrationForm2 method getFirstName.

protected String getFirstName() {
    FormItem fi = propFormItems.get("firstName");
    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 42 with FormItem

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

the class ProfileFormController method formOK.

@Override
protected void formOK(final UserRequest ureq) {
    User user = identityToModify.getUser();
    // update each user field
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem formItem = formItems.get(userPropertyHandler.getName());
        if (formItem.isEnabled()) {
            userPropertyHandler.updateUserFromFormItem(user, formItem);
        }
    }
    if (portraitDeleted) {
        File img = dps.getLargestPortrait(identityToModify.getName());
        if (img != null) {
            dps.deletePortrait(identityToModify);
            notifyPortraitChanged();
        }
    }
    File uploadedImage = portraitUpload.getUploadFile();
    String uploadedFilename = portraitUpload.getUploadFileName();
    if (uploadedImage != null) {
        dps.setPortrait(uploadedImage, uploadedFilename, identityToModify.getName());
        notifyPortraitChanged();
    }
    if (logoDeleted) {
        File img = dps.getLargestLogo(identityToModify.getName());
        if (img != null) {
            dps.deleteLogo(identityToModify);
            notifyPortraitChanged();
        }
    }
    if (logoUpload != null) {
        File uploadedLogo = logoUpload.getUploadFile();
        String uploadedLogoname = logoUpload.getUploadFileName();
        if (uploadedLogo != null) {
            dps.setLogo(uploadedLogo, uploadedLogoname, identityToModify.getName());
            notifyPortraitChanged();
        }
    }
    // Store the "about me" text.
    HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
    conf.setTextAboutMe(textAboutMe.getValue());
    hpcm.saveConfigTo(identityToModify.getName(), conf);
    // fire the appropriate event
    fireEvent(ureq, Event.DONE_EVENT);
    // update the user profile data
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey()), new SyncerExecutor() {

        @Override
        public void execute() {
            UserManager um = UserManager.getInstance();
            identityToModify = (Identity) DBFactory.getInstance().loadObject(identityToModify);
            currentEmail = identityToModify.getUser().getProperty("email", null);
            identityToModify = updateIdentityFromFormData(identityToModify);
            changedEmail = identityToModify.getUser().getProperty("email", null);
            emailChanged = false;
            if ((currentEmail == null && StringHelper.containsNonWhitespace(changedEmail)) || (currentEmail != null && !currentEmail.equals(changedEmail))) {
                if (isAllowedToChangeEmailWithoutVerification(ureq) || !StringHelper.containsNonWhitespace(changedEmail)) {
                    String key = identityToModify.getUser().getProperty("emchangeKey", null);
                    TemporaryKey tempKey = rm.loadTemporaryKeyByRegistrationKey(key);
                    if (tempKey != null) {
                        rm.deleteTemporaryKey(tempKey);
                    }
                    securityManager.deleteInvalidAuthenticationsByEmail(currentEmail);
                } else {
                    emailChanged = true;
                    // change email address to old address until it is verified
                    identityToModify.getUser().setProperty("email", currentEmail);
                }
            }
            if (!um.updateUserFromIdentity(identityToModify)) {
                getWindowControl().setInfo(translate("profile.unsuccessful"));
                // reload user data from db
                identityToModify = BaseSecurityManager.getInstance().loadIdentityByKey(identityToModify.getKey());
            }
            OLATResourceable modRes = OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new MultiUserEvent("changed"), modRes);
            if (!emailChanged) {
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        }
    });
    if (emailChanged) {
        removeAsListenerAndDispose(dialogCtr);
        String dialogText = "";
        if (identityToModify.equals(ureq.getIdentity())) {
            dialogText = translate("email.change.dialog.text");
        } else {
            dialogText = translate("email.change.dialog.text.usermanager");
        }
        dialogCtr = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), translate("email.change.dialog.title"), dialogText);
        listenTo(dialogCtr);
        dialogCtr.activate();
    }
}
Also used : User(org.olat.core.id.User) OLATResourceable(org.olat.core.id.OLATResourceable) FormItem(org.olat.core.gui.components.form.flexible.FormItem) TemporaryKey(org.olat.registration.TemporaryKey) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Identity(org.olat.core.id.Identity) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 43 with FormItem

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

the class ProfileFormController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    formContext.put("username", identityToModify.getName());
    User user = identityToModify.getUser();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem formItem = formItems.get(userPropertyHandler.getName());
        if (formItem.isEnabled()) {
            formItem.clearError();
            allOk &= userPropertyHandler.isValid(user, formItem, formContext);
        }
    }
    try {
        String aboutMe = textAboutMe.getValue();
        if (aboutMe.length() > 10000) {
            textAboutMe.setErrorKey("input.toolong", new String[] { "10000" });
            allOk = false;
        } else {
            textAboutMe.clearError();
        }
    } catch (Exception e) {
        textAboutMe.setErrorKey("input.toolong", new String[] { "10000" });
        allOk = false;
    }
    return allOk & super.validateFormLogic(ureq);
}
Also used : User(org.olat.core.id.User) FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 44 with FormItem

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

the class DateDisplayPropertyHandler method addFormItem.

@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    Date date = getDateValue(user);
    String dateString = StringHelper.formatLocaleDate(date.getTime(), locale);
    FormItem item = FormUIFactory.getInstance().addStaticTextElement(getName(), i18nFormElementLabelKey(), dateString, formItemContainer);
    return item;
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) Date(java.util.Date)

Example 45 with FormItem

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

the class UsrPropContextEditController method formInnerEvent.

@Override
@SuppressWarnings("unused")
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source instanceof FormToggle) {
        int activeCount = 0;
        FormToggle sourceToggle = (FormToggle) source;
        UserPropertyHandler handler = (UserPropertyHandler) sourceToggle.getUserObject();
        if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_MAND)) {
            context.setAsMandatoryUserProperty(handler, sourceToggle.isOn());
        } else if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_ADMN)) {
            context.setAsAdminstrativeUserOnly(handler, sourceToggle.isOn());
        } else if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_USR)) {
            context.setAsUserViewReadOnly(handler, sourceToggle.isOn());
        } else if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_INCL)) {
            if (sourceToggle.isOn()) {
                // activate the toggles on this row
                List<FormItem> rowFormItems = rowToggleButtonsMap.get(handler.getName());
                for (FormItem item : rowFormItems) {
                    item.setEnabled(true);
                    item.setVisible(true);
                }
                context.addPropertyHandler(handler);
                includedPropertiesCount++;
            } else {
                // this is removing property from context
                // deactivate the toggles on this row
                List<FormItem> rowFormItems = rowToggleButtonsMap.get(handler.getName());
                for (FormItem item : rowFormItems) {
                    item.setEnabled(false);
                    item.setVisible(false);
                }
                context.removePropertyHandler(handler);
                includedPropertiesCount--;
                if (!UsrPropCfgManager.canBeOptionalInContext(handler, contextName)) {
                    showInfo("upc.deact_infotext");
                }
            }
        }
        // something was toggled, save changes!
        usrPropCfgMng.saveUserPropertiesConfig();
        contTableFlc.contextPut("activePropCount", includedPropertiesCount);
    } else if (source instanceof FormLink) {
        // a link, (up/down)
        UserPropertyHandler handler = (UserPropertyHandler) source.getUserObject();
        if (source.getName().startsWith(FT_NAME_PREFIX_MUP)) {
            context.moveHandlerUp(handler);
            usrPropCfgMng.saveUserPropertiesConfig();
            buildPropertyHandlerListFromContext();
        } else if (source.getName().startsWith(FT_NAME_PREFIX_MDN)) {
            context.moveHandlerDown(handler);
            usrPropCfgMng.saveUserPropertiesConfig();
            buildPropertyHandlerListFromContext();
        }
    }
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormToggle(org.olat.core.gui.components.form.flexible.elements.FormToggle) ArrayList(java.util.ArrayList) List(java.util.List) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

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