Search in sources :

Example 1 with ItemValidatorProvider

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

the class LinksPortletEditController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    title = uifactory.addTextElement("link.title", "link.title", 200, portletLink.getTitle(), formLayout);
    title.setMandatory(true);
    title.setNotEmptyCheck("link.title.not.empty");
    desc = uifactory.addRichTextElementForStringDataMinimalistic("link.desc", "link.desc", portletLink.getDescription(), 5, -1, formLayout, getWindowControl());
    linkURL = uifactory.addTextElement("link.url", "link.url", 1024, portletLink.getUrl(), formLayout);
    linkURL.setMandatory(true);
    linkURL.setNotEmptyCheck("link.url.not.empty");
    linkURL.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, final ValidationError validationError, final Locale locale) {
            try {
                if (!value.contains("://")) {
                    value = "http://".concat(value);
                }
                new URL(value);
            } catch (final MalformedURLException e) {
                validationError.setErrorKey("link.url.not.empty");
                return false;
            }
            return true;
        }
    });
    openPopup = uifactory.addCheckboxesHorizontal("link.open.new.window", "link.open.new.window", formLayout, new String[] { TARGET_BLANK }, new String[] { "" });
    if (portletLink.getTarget().equals(TARGET_BLANK)) {
        openPopup.selectAll();
    }
    // language
    Map<String, String> locdescs = I18nManager.getInstance().getEnabledLanguagesTranslated();
    Set<String> lkeys = locdescs.keySet();
    String[] languageKeys = new String[lkeys.size() + 1];
    String[] languageValues = new String[lkeys.size() + 1];
    languageKeys[0] = "*";
    languageValues[0] = translate("link.lang.all");
    int p = 1;
    for (Iterator<String> iter = lkeys.iterator(); iter.hasNext(); ) {
        String key = iter.next();
        languageKeys[p] = key;
        languageValues[p] = locdescs.get(key);
        p++;
    }
    language = uifactory.addDropdownSingleselect("link.language", formLayout, languageKeys, languageValues, null);
    String langKey = portletLink.getLanguage();
    if (Arrays.asList(languageKeys).contains(langKey)) {
        language.select(langKey, true);
    }
    uifactory.addFormSubmitButton("save", formLayout);
}
Also used : Locale(java.util.Locale) MalformedURLException(java.net.MalformedURLException) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) ValidationError(org.olat.core.gui.components.form.ValidationError) URL(java.net.URL)

Example 2 with ItemValidatorProvider

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

the class EmailProperty method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#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, final User user, String usageIdentifyer, final boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
    tElem = (org.olat.core.gui.components.form.flexible.elements.TextElement) super.addFormItem(locale, user, usageIdentifyer, isAdministrativeUser, formItemContainer);
    // to validate the input a special isValidValue is used.
    if (usageIdentifyer.equals(UserBulkChangeStep00.class.getCanonicalName())) {
        tElem.setItemValidatorProvider(new ItemValidatorProvider() {

            @Override
            public boolean isValidValue(String value, ValidationError validationError, Locale locale2) {
                UserBulkChangeManager ubcMan = CoreSpringFactory.getImpl(UserBulkChangeManager.class);
                Context vcContext = new VelocityContext();
                if (user == null) {
                    vcContext = ubcMan.getDemoContext(locale2);
                } else // should be used if user-argument !=null --> move to right place
                {
                    Long userKey = user.getKey();
                    Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(userKey);
                    ubcMan.setUserContext(identity, vcContext);
                }
                value = value.replace("$", "$!");
                String evaluatedValue = ubcMan.evaluateValueWithUserContext(value, vcContext);
                return EmailProperty.this.isValidValue(user, evaluatedValue, validationError, locale2);
            }
        });
    }
    return tElem;
}
Also used : Locale(java.util.Locale) VelocityContext(org.apache.velocity.VelocityContext) Context(org.apache.velocity.context.Context) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) VelocityContext(org.apache.velocity.VelocityContext) UserBulkChangeStep00(org.olat.admin.user.bulkChange.UserBulkChangeStep00) UserBulkChangeManager(org.olat.admin.user.bulkChange.UserBulkChangeManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Identity(org.olat.core.id.Identity)

Example 3 with ItemValidatorProvider

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

the class DatePropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#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, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.DateChooser dateElem = null;
    Date val = decode(getInternalValue(user));
    dateElem = FormUIFactory.getInstance().addDateChooser(getName(), i18nFormElementLabelKey(), val, formItemContainer);
    dateElem.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
            return DatePropertyHandler.this.isValidValue(user, value, validationError, llocale);
        }
    });
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        dateElem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        dateElem.setMandatory(true);
    }
    dateElem.setExampleKey("form.example.free", new String[] { Formatter.getInstance(locale).formatDate(new Date()) });
    return dateElem;
}
Also used : Locale(java.util.Locale) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Date(java.util.Date)

Example 4 with ItemValidatorProvider

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

the class Generic127CharTextPropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#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, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
    tElem = FormUIFactory.getInstance().addTextElement(getName(), i18nFormElementLabelKey(), 127, getInternalValue(user), formItemContainer);
    tElem.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
            return Generic127CharTextPropertyHandler.this.isValidValue(user, value, validationError, llocale);
        }
    });
    tElem.setLabel(i18nFormElementLabelKey(), null);
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        tElem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        tElem.setMandatory(true);
    }
    return tElem;
}
Also used : Locale(java.util.Locale) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 5 with ItemValidatorProvider

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

the class DatePropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#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, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.DateChooser dateElem = null;
    Date val = decode(getInternalValue(user));
    dateElem = FormUIFactory.getInstance().addDateChooser(getName(), i18nFormElementLabelKey(), val, formItemContainer);
    dateElem.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
            return DatePropertyHandler.this.isValidValue(user, value, validationError, llocale);
        }
    });
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        dateElem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        dateElem.setMandatory(true);
    }
    dateElem.setExampleKey("form.example.free", new String[] { Formatter.getInstance(locale).formatDate(new Date()) });
    return dateElem;
}
Also used : Locale(java.util.Locale) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Date(java.util.Date)

Aggregations

Locale (java.util.Locale)10 ValidationError (org.olat.core.gui.components.form.ValidationError)10 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)10 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)4 UserManager (org.olat.user.UserManager)4 Date (java.util.Date)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2 UserBulkChangeManager (org.olat.admin.user.bulkChange.UserBulkChangeManager)2 UserBulkChangeStep00 (org.olat.admin.user.bulkChange.UserBulkChangeStep00)2 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)2 Identity (org.olat.core.id.Identity)2