Search in sources :

Example 41 with TextElement

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

the class XingPropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#addFormItem(java.util.Locale,
 *      org.olat.core.id.User, java.lang.String, boolean,
 *      org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    TextElement textElement = (TextElement) super.addFormItem(locale, user, usageIdentifyer, isAdministrativeUser, formItemContainer);
    textElement.setMaxLength(XING_NAME_MAX_LENGTH);
    if (!UserManager.getInstance().isUserViewReadOnly(usageIdentifyer, this) || isAdministrativeUser) {
        textElement.setExampleKey("form.example.xingname", null);
    }
    return textElement;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 42 with TextElement

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

the class MSNPropertyHandler method isValid.

/**
 * @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem, java.util.Map)
 */
@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
    boolean result;
    TextElement textElement = (TextElement) formItem;
    if (StringHelper.containsNonWhitespace(textElement.getValue())) {
        // Use an HttpClient to fetch a profile information page from MSN.
        CloseableHttpClient httpClient = HttpClientFactory.getHttpClientInstance(false);
        try {
            URIBuilder uriBuilder = new URIBuilder(MSN_NAME_VALIDATION_URL);
            uriBuilder.addParameter(MSN_NAME_URL_PARAMETER, textElement.getValue());
            HttpGet httpMethod = new HttpGet(uriBuilder.build());
            // Get the user profile page
            HttpResponse response = httpClient.execute(httpMethod);
            int httpStatusCode = response.getStatusLine().getStatusCode();
            // Looking at the HTTP status code tells us whether a user with the given MSN name exists.
            if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
                // If the user exists, we get a 301...
                result = true;
            } else if (httpStatusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
                // ...and if the user doesn't exist, MSN sends a 500.
                textElement.setErrorKey("form.name.msn.error", null);
                result = false;
            } else {
                // For HTTP status codes other than 301 and 500 we will assume that the given MSN name is valid, but inform the user about this.
                textElement.setExampleKey("form.example.msnname.notvalidated", null);
                log.warn("MSN name validation: Expected HTTP status 301 or 500, but got " + httpStatusCode);
                result = true;
            }
        } catch (Exception e) {
            // In case of any exception, assume that the given MSN name is valid (The opposite would block easily upon network problems), and inform the user about this.
            textElement.setExampleKey("form.example.msnname.notvalidated", null);
            log.warn("MSN name validation: Exception: " + e.getMessage());
            result = true;
        } finally {
            IOUtils.closeQuietly(httpClient);
        }
    } else {
        result = true;
    }
    return result;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 43 with TextElement

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

the class EPShareListController method secureListBox.

/**
 * loops over all EPSharePolicyWrappers and updates the datamodel according to the
 * current form-values
 */
protected void secureListBox() {
    if (isLogDebugEnabled())
        logDebug(" 'securing' ListBox -->  updating policyWrappers with field values...", null);
    for (EPSharePolicyWrapper policyWrapper : policyWrappers) {
        if (policyWrapper.getUserListBox() != null) {
            List<Identity> identities = policyWrapper.getIdentities();
            policyWrapper.setIdentities(identities);
        }
        if (policyWrapper.getGroups() != null) {
            List<BusinessGroup> selectedGroups = policyWrapper.getGroups();
            policyWrapper.setGroups(selectedGroups);
        }
        TextElement firstNameEl = policyWrapper.getFirstNameEl();
        if (firstNameEl != null) {
            policyWrapper.getInvitation().setFirstName(firstNameEl.getValue());
        }
        TextElement lastNameEl = policyWrapper.getLastNameEl();
        if (lastNameEl != null) {
            policyWrapper.getInvitation().setLastName(lastNameEl.getValue());
        }
        TextElement mailEl = policyWrapper.getMailEl();
        if (mailEl != null) {
            policyWrapper.getInvitation().setMail(mailEl.getValue());
        }
        if (policyWrapper.getFromChooser() != null) {
            policyWrapper.setFrom(policyWrapper.getFromChooser().getDate());
        }
        if (policyWrapper.getToChooser() != null) {
            policyWrapper.setTo(policyWrapper.getToChooser().getDate());
        }
    }
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity)

Example 44 with TextElement

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

the class EPShareListController method createContainerForInvitation.

private void createContainerForInvitation(Invitation invitation, EPSharePolicyWrapper policyWrapper, String cmpName, FormLayoutContainer container) {
    FormLayoutContainer invitationContainer = FormLayoutContainer.createDefaultFormLayout("map.share.with." + cmpName, getTranslator());
    invitationContainer.contextPut("wrapper", policyWrapper);
    invitationContainer.setRootForm(mainForm);
    container.add("map.share.with." + cmpName, invitationContainer);
    TextElement firstNameEl = uifactory.addTextElement("map.share.with.firstName." + cmpName, "map.share.with.firstName", 64, invitation.getFirstName(), invitationContainer);
    firstNameEl.setMandatory(true);
    firstNameEl.setNotEmptyCheck("map.share.empty.warn");
    TextElement lastNameEl = uifactory.addTextElement("map.share.with.lastName." + cmpName, "map.share.with.lastName", 64, invitation.getLastName(), invitationContainer);
    lastNameEl.setMandatory(true);
    lastNameEl.setNotEmptyCheck("map.share.empty.warn");
    TextElement mailEl = uifactory.addTextElement("map.share.with.mail." + cmpName, "map.share.with.mail", 128, invitation.getMail(), invitationContainer);
    mailEl.setMandatory(true);
    mailEl.setNotEmptyCheck("map.share.empty.warn");
    if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
        SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
        List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(invitation.getMail()));
        if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
            mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { invitation.getMail() });
        }
    }
    policyWrapper.setFirstNameEl(firstNameEl);
    policyWrapper.setLastNameEl(lastNameEl);
    policyWrapper.setMailEl(mailEl);
    String link = getInvitationLink(invitation, map);
    StaticTextElement linkEl = uifactory.addStaticTextElement("map.share.with.link." + cmpName, link, invitationContainer);
    linkEl.setLabel("map.share.with.link", null);
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity)

Example 45 with TextElement

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

the class ShibbolethRegistrationUserPropertiesFrom method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // Add all available user fields to this form
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
            propFormItems.put(userPropertyHandler.getName(), fi);
            if (fi instanceof TextElement) {
                String value = shibbolethAttributes.getValueForUserPropertyName(userPropertyHandler.getName());
                if (StringHelper.containsNonWhitespace(value)) {
                    TextElement formElement = (TextElement) fi;
                    formElement.setValue(value);
                    formElement.setEnabled(false);
                }
            }
        }
    }
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("save", buttonLayout);
}
Also used : 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)

Aggregations

TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)146 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)40 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)36 FormItem (org.olat.core.gui.components.form.flexible.FormItem)34 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)30 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)26 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)24 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)18 ArrayList (java.util.ArrayList)16 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)16 Identity (org.olat.core.id.Identity)12 HashMap (java.util.HashMap)8 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)8 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)8 Date (java.util.Date)6 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)6 StaticTextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.StaticTextElementImpl)6 TextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.TextElementImpl)6 RichTextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl)6 File (java.io.File)4