Search in sources :

Example 26 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class MembersOverviewIdentitiesController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_user_import_overview");
    if (notfounds != null && !notfounds.isEmpty()) {
        String page = velocity_root + "/warn_notfound.html";
        FormLayoutContainer warnLayout = FormLayoutContainer.createCustomFormLayout("warnNotFounds", getTranslator(), page);
        warnLayout.setRootForm(mainForm);
        formLayout.add(warnLayout);
        StringBuilder sb = new StringBuilder();
        for (String notfound : notfounds) {
            if (sb.length() > 0)
                sb.append(", ");
            sb.append(notfound);
        }
        String msg = translate("user.notfound", new String[] { sb.toString() });
        addToRunContext("notFounds", sb.toString());
        warnLayout.contextPut("notFounds", msg);
    }
    // add the table
    FlexiTableColumnModel tableColumnModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    int colIndex = 0;
    if (isAdministrativeUser) {
        tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.user.login", colIndex++));
    }
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_PROPS_ID, isAdministrativeUser);
    List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<UserPropertyHandler>();
    // followed by the users fields
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        boolean visible = UserManager.getInstance().isMandatoryUserProperty(USER_PROPS_ID, userPropertyHandler);
        if (visible) {
            resultingPropertyHandlers.add(userPropertyHandler);
            tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex++));
        }
    }
    Translator myTrans = userManager.getPropertyHandlerTranslator(getTranslator());
    MembersOverviewDataModel userTableModel = new MembersOverviewDataModel(oks, resultingPropertyHandlers, isAdministrativeUser, getLocale(), tableColumnModel);
    FlexiTableElement tableEl = uifactory.addTableElement(getWindowControl(), "users", userTableModel, myTrans, formLayout);
    tableEl.setCustomizeColumns(false);
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Translator(org.olat.core.gui.translator.Translator) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) FlexiTableElement(org.olat.core.gui.components.form.flexible.elements.FlexiTableElement)

Example 27 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

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 28 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler 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 29 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler 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 30 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler 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)

Aggregations

UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)319 Identity (org.olat.core.id.Identity)84 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)74 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)70 ArrayList (java.util.ArrayList)62 FormItem (org.olat.core.gui.components.form.flexible.FormItem)62 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)56 User (org.olat.core.id.User)52 HashMap (java.util.HashMap)40 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)36 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)34 Translator (org.olat.core.gui.translator.Translator)32 Date (java.util.Date)30 UserManager (org.olat.user.UserManager)28 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)24 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)24 File (java.io.File)22 BusinessGroup (org.olat.group.BusinessGroup)22 SortKey (org.olat.core.commons.persistence.SortKey)18 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)18