Search in sources :

Example 1 with EmailProperty

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

the class MemberSearchForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer leftContainer = FormLayoutContainer.createDefaultFormLayout("left_1", getTranslator());
    leftContainer.setRootForm(mainForm);
    formLayout.add(leftContainer);
    // user property
    login = uifactory.addTextElement("login", "search.login", 128, "", leftContainer);
    login.setDisplaySize(28);
    userPropertyHandlers = userManager.getUserPropertyHandlersFor(getClass().getCanonicalName(), false);
    propFormItems = new HashMap<String, FormItem>();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, getClass().getCanonicalName(), false, leftContainer);
        fi.setTranslator(this.getTranslator());
        // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
        if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
            TextElement textElement = (TextElement) fi;
            textElement.setItemValidatorProvider(null);
        }
        if (fi instanceof TextElement) {
            ((TextElement) fi).setDisplaySize(28);
        }
        propFormItems.put(userPropertyHandler.getName(), fi);
    }
    // others
    FormLayoutContainer rightContainer = FormLayoutContainer.createDefaultFormLayout("right_1", getTranslator());
    rightContainer.setRootForm(mainForm);
    formLayout.add(rightContainer);
    // roles
    String[] roleValues = new String[roleKeys.length];
    for (int i = roleKeys.length; i-- > 0; ) {
        roleValues[i] = translate("search." + roleKeys[i]);
    }
    rolesEl = uifactory.addCheckboxesHorizontal("roles", "search.roles", rightContainer, roleKeys, roleValues);
    for (String roleKey : roleKeys) {
        rolesEl.select(roleKey, true);
    }
    String[] openValues = new String[originKeys.length];
    for (int i = originKeys.length; i-- > 0; ) {
        openValues[i] = translate("search." + originKeys[i]);
    }
    originEl = uifactory.addRadiosHorizontal("openBg", "search.origin", rightContainer, originKeys, openValues);
    originEl.select("all", true);
    FormLayoutContainer buttonLayout = FormLayoutContainer.createDefaultFormLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    searchButton = uifactory.addFormLink("search", buttonLayout, Link.BUTTON);
    searchButton.setCustomEnabledLinkCSS("btn btn-primary");
}
Also used : EmailProperty(org.olat.user.propertyhandlers.EmailProperty) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 2 with EmailProperty

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

the class LecturesSearchFormController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    login = uifactory.addTextElement("login", "search.form.login", 128, "", formLayout);
    login.setVisible(adminProps);
    userPropertyHandlers = userManager.getUserPropertyHandlersFor(PROPS_IDENTIFIER, adminProps);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, PROPS_IDENTIFIER, false, formLayout);
            fi.setMandatory(false);
            // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
            if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
                TextElement textElement = (TextElement) fi;
                textElement.setItemValidatorProvider(null);
            }
            propFormItems.put(userPropertyHandler.getName(), fi);
        }
    }
    bulkEl = uifactory.addTextAreaElement("bulk", 4, 72, "", formLayout);
    bulkEl.setHelpText(translate("bulk.hint"));
    bulkEl.setExampleKey("bulk.example", null);
    List<RepositoryEntryLifecycle> cycles = lifecycleDao.loadPublicLifecycle();
    String[] dateKeys;
    String[] dateValues;
    if (cycles.isEmpty()) {
        dateKeys = new String[] { "none", "private" };
        dateValues = new String[] { translate("dates.none"), translate("dates.private") };
    } else {
        dateKeys = new String[] { "none", "private", "public" };
        dateValues = new String[] { translate("dates.none"), translate("dates.private"), translate("dates.public") };
    }
    dateTypesEl = uifactory.addRadiosVertical("dates", formLayout, dateKeys, dateValues);
    dateTypesEl.select(dateKeys[0], true);
    dateTypesEl.addActionListener(FormEvent.ONCHANGE);
    List<RepositoryEntryLifecycle> filteredCycles = new ArrayList<>();
    for (RepositoryEntryLifecycle cycle : cycles) {
        if (cycle.getValidTo() == null) {
            filteredCycles.add(cycle);
        }
    }
    String[] publicKeys = new String[filteredCycles.size()];
    String[] publicValues = new String[filteredCycles.size()];
    int count = 0;
    for (RepositoryEntryLifecycle cycle : filteredCycles) {
        publicKeys[count] = cycle.getKey().toString();
        StringBuilder sb = new StringBuilder(32);
        boolean labelAvailable = StringHelper.containsNonWhitespace(cycle.getLabel());
        if (labelAvailable) {
            sb.append(cycle.getLabel());
        }
        if (StringHelper.containsNonWhitespace(cycle.getSoftKey())) {
            if (labelAvailable)
                sb.append(" - ");
            sb.append(cycle.getSoftKey());
        }
        publicValues[count++] = sb.toString();
    }
    publicDatesEl = uifactory.addDropdownSingleselect("public.dates", formLayout, publicKeys, publicValues, null);
    String privateDatePage = velocity_root + "/cycle_dates.html";
    privateDatesCont = FormLayoutContainer.createCustomFormLayout("private.date", getTranslator(), privateDatePage);
    privateDatesCont.setRootForm(mainForm);
    privateDatesCont.setLabel("private.dates", null);
    formLayout.add("private.date", privateDatesCont);
    startDateEl = uifactory.addDateChooser("date.start", "date.start", null, privateDatesCont);
    startDateEl.setElementCssClass("o_sel_repo_lifecycle_validfrom");
    endDateEl = uifactory.addDateChooser("date.end", "date.end", null, privateDatesCont);
    endDateEl.setElementCssClass("o_sel_repo_lifecycle_validto");
    FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonCont);
    uifactory.addFormSubmitButton("search", buttonCont);
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 3 with EmailProperty

use of org.olat.user.propertyhandlers.EmailProperty in project openolat by klemens.

the class UserSearchFlexiController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        // insert a autocompleter search
        Roles roles = ureq.getUserSession().getRoles();
        boolean autoCompleteAllowed = securityModule.isUserAllowedAutoComplete(roles);
        boolean ajax = Windows.getWindows(ureq).getWindowManager().isAjaxEnabled();
        if (ajax && autoCompleteAllowed) {
            // auto complete
            String velocityAutoCRoot = Util.getPackageVelocityRoot(FlexiAutoCompleterController.class);
            String autoCPage = velocityAutoCRoot + "/autocomplete.html";
            autoCompleterContainer = FormLayoutContainer.createCustomFormLayout("autocompletionsearch", getTranslator(), autoCPage);
            autoCompleterContainer.setRootForm(mainForm);
            layoutCont.add(autoCompleterContainer);
            layoutCont.add("autocompletionsearch", autoCompleterContainer);
            setupAutoCompleter(ureq, autoCompleterContainer, null, isAdministrativeUser, 60, 3, null);
        }
        // user search form
        backLink = uifactory.addFormLink("btn.back", formLayout);
        backLink.setIconLeftCSS("o_icon o_icon_back");
        searchFormContainer = FormLayoutContainer.createDefaultFormLayout("usersearchPanel", getTranslator());
        searchFormContainer.setRootForm(mainForm);
        searchFormContainer.setElementCssClass("o_sel_usersearch_searchform");
        searchFormContainer.setFormTitle(translate("header.normal"));
        layoutCont.add(searchFormContainer);
        layoutCont.add("usersearchPanel", searchFormContainer);
        loginEl = uifactory.addTextElement("login", "search.form.login", 128, "", searchFormContainer);
        loginEl.setVisible(isAdministrativeUser);
        propFormItems = new HashMap<>();
        for (UserPropertyHandler userPropertyHandler : userSearchFormPropertyHandlers) {
            if (userPropertyHandler == null)
                continue;
            FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, UserSearchForm.class.getCanonicalName(), false, searchFormContainer);
            // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
            if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
                TextElement textElement = (TextElement) fi;
                textElement.setItemValidatorProvider(null);
            }
            propFormItems.put(userPropertyHandler.getName(), fi);
        }
        FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
        buttonGroupLayout.setRootForm(mainForm);
        searchFormContainer.add(buttonGroupLayout);
        // Don't use submit button, form should not be marked as dirty since this is
        // not a configuration form but only a search form (OLAT-5626)
        searchButton = uifactory.addFormLink("submit.search", buttonGroupLayout, Link.BUTTON);
        layoutCont.contextPut("noList", "false");
        layoutCont.contextPut("showButton", "false");
        // add the table
        FlexiTableColumnModel tableColumnModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
        int colPos = 0;
        if (isAdministrativeUser) {
            tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.user.login", colPos++, true, "login"));
        }
        List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
        List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<>();
        // followed by the users fields
        for (int i = 0; i < userPropertyHandlers.size(); i++) {
            UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
            boolean visible = UserManager.getInstance().isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
            if (visible) {
                resultingPropertyHandlers.add(userPropertyHandler);
                tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++, true, userPropertyHandler.getName()));
            }
        }
        tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("select", translate("select"), "select"));
        Translator myTrans = userManager.getPropertyHandlerTranslator(getTranslator());
        userTableModel = new UserSearchFlexiTableModel(Collections.<Identity>emptyList(), resultingPropertyHandlers, isAdministrativeUser, getLocale(), tableColumnModel);
        tableEl = uifactory.addTableElement(getWindowControl(), "users", userTableModel, 250, false, myTrans, formLayout);
        tableEl.setCustomizeColumns(false);
        tableEl.setMultiSelect(true);
        tableEl.setSelectAllEnable(true);
        layoutCont.put("userTable", tableEl.getComponent());
    }
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Roles(org.olat.core.id.Roles) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) Translator(org.olat.core.gui.translator.Translator) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)

Example 4 with EmailProperty

use of org.olat.user.propertyhandlers.EmailProperty in project openolat by klemens.

the class UserSearchForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_user_search_form");
    login = uifactory.addTextElement("login", "search.form.login", 128, "", formLayout);
    login.setVisible(isAdminProps);
    login.setElementCssClass("o_sel_user_search_username");
    Translator tr = Util.createPackageTranslator(UserPropertyHandler.class, getLocale(), getTranslator());
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, getClass().getCanonicalName(), false, formLayout);
        fi.setTranslator(tr);
        // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
        if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
            TextElement textElement = (TextElement) fi;
            textElement.setItemValidatorProvider(null);
        }
        fi.setElementCssClass("o_sel_user_search_".concat(userPropertyHandler.getName().toLowerCase()));
        propFormItems.put(userPropertyHandler.getName(), fi);
    }
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    // Don't use submit button, form should not be marked as dirty since this is
    // not a configuration form but only a search form (OLAT-5626)
    searchButton = uifactory.addFormLink("submit.search", buttonGroupLayout, Link.BUTTON);
    searchButton.setElementCssClass("o_sel_user_search_button");
    if (cancelButton) {
        uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
    }
}
Also used : EmailProperty(org.olat.user.propertyhandlers.EmailProperty) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) Translator(org.olat.core.gui.translator.Translator) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 5 with EmailProperty

use of org.olat.user.propertyhandlers.EmailProperty in project openolat by klemens.

the class UsermanagerUserSearchForm method findIdentitiesFromSearchForm.

/**
 * @return List of identities that match the criterias from the search form
 */
private List<Identity> findIdentitiesFromSearchForm() {
    // get user attributes from form
    String login = searchform.getStringValue("login");
    // when searching for deleted users, add wildcard to match with backup prefix
    if (searchform.getStatus().equals(Identity.STATUS_DELETED)) {
        login = "*" + login;
    }
    Integer status = null;
    // get user fields from form
    // build user fields search map
    Map<String, String> userPropertiesSearch = new HashMap<String, String>();
    for (UserPropertyHandler userPropertyHandler : searchform.getPropertyHandlers()) {
        if (userPropertyHandler == null)
            continue;
        FormItem ui = searchform.getItem(userPropertyHandler.getName());
        String uiValue = userPropertyHandler.getStringValue(ui);
        if (userPropertyHandler.getName().startsWith("genericCheckboxProperty") && ui instanceof MultipleSelectionElement) {
            if (!"false".equals(uiValue)) {
                // ignore false for the search
                userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
            }
        } else if (StringHelper.containsNonWhitespace(uiValue)) {
            // when searching for deleted users, add wildcard to match with backup prefix
            if (userPropertyHandler instanceof EmailProperty && searchform.getStatus().equals(Identity.STATUS_DELETED)) {
                uiValue = "*" + uiValue;
            }
            userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
        }
    }
    if (userPropertiesSearch.isEmpty())
        userPropertiesSearch = null;
    // get group memberships from form
    List<SecurityGroup> groupsList = new ArrayList<SecurityGroup>();
    if (searchform.getRole("admin")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
        groupsList.add(group);
    }
    if (searchform.getRole("author")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
        groupsList.add(group);
    }
    if (searchform.getRole("groupmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
        groupsList.add(group);
    }
    if (searchform.getRole("usermanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
        groupsList.add(group);
    }
    if (searchform.getRole("oresmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
        groupsList.add(group);
    }
    if (searchform.getRole("poolmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_POOL_MANAGER);
        groupsList.add(group);
    }
    status = searchform.getStatus();
    SecurityGroup[] groups = groupsList.toArray(new SecurityGroup[groupsList.size()]);
    // no permissions in this form so far
    PermissionOnResourceable[] permissionOnResources = null;
    String[] authProviders = searchform.getAuthProviders();
    // get date constraints from form
    Date createdBefore = searchform.getBeforeDate();
    Date createdAfter = searchform.getAfterDate();
    Date userLoginBefore = searchform.getUserLoginBefore();
    Date userLoginAfter = searchform.getUserLoginAfter();
    // now perform power search
    List<Identity> myIdentities = securityManager.getIdentitiesByPowerSearch((login.equals("") ? null : login), userPropertiesSearch, true, groups, permissionOnResources, authProviders, createdAfter, createdBefore, userLoginAfter, userLoginBefore, status);
    return myIdentities;
}
Also used : HashMap(java.util.HashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable)

Aggregations

FormItem (org.olat.core.gui.components.form.flexible.FormItem)12 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)12 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)8 ArrayList (java.util.ArrayList)6 Translator (org.olat.core.gui.translator.Translator)4 Identity (org.olat.core.id.Identity)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 PermissionOnResourceable (org.olat.basesecurity.PermissionOnResourceable)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)2 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)2 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)2 Roles (org.olat.core.id.Roles)2 RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)2