Search in sources :

Example 21 with TextElement

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

the class GenericSelectionPropertyHandlerController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // save the data to config
    boolean m = modeRadio.isSelected(1);
    handler.setMultiSelect(m);
    List<String> selectionKeys = new ArrayList<String>();
    for (int i = 0; i < optionFieldNames.size(); i++) {
        TextElement te = (TextElement) hcFlc.getFormComponent(OPTFIELD_PREFIX + optionFieldNames.get(i));
        String textValue = te.getValue();
        if (StringHelper.containsNonWhitespace(textValue))
            selectionKeys.add(textValue);
    }
    String[] selectionKeysArray = new String[selectionKeys.size()];
    handler.setSelectionKeys(selectionKeys.toArray(selectionKeysArray));
    handler.saveConfig();
    // remove i18nKeys that are no longer used (prevent orphans)
    if (singleKeyTrsCtrl == null) {
        singleKeyTrsCtrl = new SingleKeyTranslatorController(ureq, getWindowControl(), "", GenericSelectionPropertyHandler.class);
    }
    for (String key : i18nKeysToDelete) {
        singleKeyTrsCtrl.deleteI18nKey(key);
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleKeyTranslatorController(org.olat.core.util.i18n.ui.SingleKeyTranslatorController) ArrayList(java.util.ArrayList)

Example 22 with TextElement

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

the class ICQPropertyHandler 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(ICQ_NAME_MAX_LENGTH);
    if (!UserManager.getInstance().isUserViewReadOnly(usageIdentifyer, this) || isAdministrativeUser) {
        textElement.setExampleKey("form.example.icqname", null);
    }
    return textElement;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 23 with TextElement

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

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

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

the class UserNameReadOnlyPropertyHandler method addFormItem.

@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    TextElement tElem = null;
    tElem = FormUIFactory.getInstance().addTextElement(getName(), i18nFormElementLabelKey(), 127, getInternalValue(user), formItemContainer);
    tElem.setLabel(i18nFormElementLabelKey(), null);
    // always read-only
    tElem.setEnabled(false);
    return tElem;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 25 with TextElement

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

the class AttributeEasyRowAdderController method hasError.

/**
 * Checks if this form produces an error
 *
 * @return true: has an error; false: is valid
 */
public boolean hasError() {
    for (final Iterator<String> iterator = columnValueText.iterator(); iterator.hasNext(); ) {
        final String name = iterator.next();
        final TextElement tei = (TextElement) flc.getFormComponent(name);
        if (tei.isVisible() && tei.getValue().trim().length() == 0) {
            return true;
        }
    }
    return false;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

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