Search in sources :

Example 21 with FormItem

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

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

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

the class ProfileFormController method updateFromFormData.

/**
 * Stores the data from the form into a) the user's home page configuration
 * and b) the user's properties.
 *
 * @param config The user's home page configuration (i.e. flags for publicly
 *          visible fields).
 * @param identity The user's identity
 */
public void updateFromFormData() {
    User user = identityToModify.getUser();
    // For each user property...
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        // ...get the value from the form field and store it into the user
        // property...
        FormItem formItem = formItems.get(userPropertyHandler.getName());
        if (formItem.isEnabled()) {
            userPropertyHandler.updateUserFromFormItem(user, formItem);
        }
    }
    // Store the "about me" text.
    HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
    conf.setTextAboutMe(textAboutMe.getValue());
    hpcm.saveConfigTo(identityToModify.getName(), conf);
}
Also used : User(org.olat.core.id.User) FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 23 with FormItem

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

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

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

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

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

the class AttributeEasyRowAdderController method event.

@Override
protected void event(final UserRequest ureq, final Controller source, final Event event) {
    if (event instanceof FormEvent) {
        final FormEvent fe = (FormEvent) event;
        final FormItem sourceItem = fe.getFormItemSource();
        final String compName = sourceItem.getName();
        if (columnAddRow.contains(compName)) {
            // add link clicked
            final int clickPos = ((Integer) sourceItem.getUserObject()).intValue();
            addRowAt(clickPos + 1);
        } else if (columnRemoveRow.contains(compName)) {
            // remove link clicked
            final int clickPos = ((Integer) sourceItem.getUserObject()).intValue();
            removeRowAt(clickPos);
        }
    }
}
Also used : FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) 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