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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations