use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class ProfileFormController method updateIdentityFromFormData.
public Identity updateIdentityFromFormData(Identity identity) {
identityToModify = identity;
User user = identityToModify.getUser();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem formItem = formItems.get(userPropertyHandler.getName());
if (formItem.isEnabled()) {
userPropertyHandler.updateUserFromFormItem(user, formItem);
}
}
return identityToModify;
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class ProfileFormController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
User user = identityToModify.getUser();
// show a form element for each property handler
boolean first = true;
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null) {
continue;
}
// add spacer if necessary (i.e. when group name changes)
String group = userPropertyHandler.getGroup();
String formId = "group." + group;
FormLayoutContainer groupContainer = (FormLayoutContainer) formLayout.getFormComponent(formId);
if (groupContainer == null) {
groupContainer = FormLayoutContainer.createDefaultFormLayout(formId, getTranslator());
groupContainer.setFormTitle(translate("form.group." + group));
if (first) {
groupContainer.setFormContextHelp("Configuration");
first = false;
}
formItems.put(formId, groupContainer);
formLayout.add(groupContainer);
}
// add input field to container
FormItem formItem = userPropertyHandler.addFormItem(getLocale(), user, usageIdentifier, isAdministrativeUser, groupContainer);
String propertyName = userPropertyHandler.getName();
formItems.put(propertyName, formItem);
if (formItem instanceof TextElement) {
// it's a text field, so get the value of this property into the text field
TextElement textElement = (TextElement) formItem;
textElement.setValue(user.getProperty(propertyName, getLocale()));
} else if (formItem instanceof MultipleSelectionElement) {
// it's a checkbox, so set the box to checked if the corresponding property is set to "true"
MultipleSelectionElement checkbox = (MultipleSelectionElement) formItem;
String value = user.getProperty(propertyName, getLocale());
if (value != null) {
checkbox.select(propertyName, value.equals("true"));
} else {
// assume "false" if the property is not present
checkbox.select(propertyName, false);
}
}
// special case for email field
if (userPropertyHandler.getName().equals("email")) {
String key = user.getProperty("emchangeKey", null);
TemporaryKey tempKey = rm.loadTemporaryKeyByRegistrationKey(key);
if (tempKey != null) {
XStream xml = XStreamHelper.createXStreamInstance();
@SuppressWarnings("unchecked") HashMap<String, String> mails = (HashMap<String, String>) xml.fromXML(tempKey.getEmailAddress());
formItem.setExampleKey("email.change.form.info", new String[] { mails.get("changedEMail") });
}
if (!userModule.isEmailMandatory()) {
formItem.setMandatory(false);
}
}
}
// add the "about me" text field.
FormLayoutContainer groupContainer = FormLayoutContainer.createDefaultFormLayout("group.about", getTranslator());
groupContainer.setFormTitle(translate("form.group.about"));
groupContainer.setElementCssClass("o_user_aboutme");
formLayout.add(groupContainer);
HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
textAboutMe = uifactory.addRichTextElementForStringData("form.text", "form.text", conf.getTextAboutMe(), 10, -1, false, null, null, groupContainer, ureq.getUserSession(), getWindowControl());
textAboutMe.setMaxLength(10000);
// upload image
groupContainer = FormLayoutContainer.createDefaultFormLayout("portraitupload", getTranslator());
groupContainer.setFormTitle(translate("ul.header"));
formLayout.add(groupContainer);
File portraitFile = dps.getLargestPortrait(identityToModify.getName());
// Init upload controller
Set<String> mimeTypes = new HashSet<>();
mimeTypes.add("image/gif");
mimeTypes.add("image/jpg");
mimeTypes.add("image/jpeg");
mimeTypes.add("image/png");
portraitUpload = uifactory.addFileElement(getWindowControl(), "ul.select", "ul.select", groupContainer);
portraitUpload.setMaxUploadSizeKB(10000, null, null);
portraitUpload.setPreview(ureq.getUserSession(), true);
portraitUpload.addActionListener(FormEvent.ONCHANGE);
portraitUpload.setHelpTextKey("ul.select.fhelp", null);
portraitUpload.setDeleteEnabled(true);
if (portraitFile != null) {
portraitUpload.setInitialFile(portraitFile);
}
portraitUpload.limitToMimeType(mimeTypes, null, null);
if (logoEnabled) {
// upload image
groupContainer = FormLayoutContainer.createDefaultFormLayout("logoupload", getTranslator());
groupContainer.setFormTitle(translate("logo.header"));
formLayout.add(groupContainer);
File logoFile = dps.getLargestLogo(identityToModify.getName());
logoUpload = uifactory.addFileElement(getWindowControl(), "logo.select", "logo.select", groupContainer);
logoUpload.setMaxUploadSizeKB(10000, null, null);
logoUpload.setPreview(ureq.getUserSession(), true);
logoUpload.addActionListener(FormEvent.ONCHANGE);
logoUpload.setHelpTextKey("ul.select.fhelp", null);
logoUpload.setDeleteEnabled(true);
if (logoFile != null) {
logoUpload.setInitialFile(logoFile);
}
logoUpload.limitToMimeType(mimeTypes, null, null);
}
// Create submit and cancel buttons
FormLayoutContainer buttonLayoutWrappper = FormLayoutContainer.createDefaultFormLayout("buttonLayoutWrappper", getTranslator());
formLayout.add(buttonLayoutWrappper);
FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayoutInner", getTranslator());
buttonLayoutWrappper.add(buttonLayout);
uifactory.addFormSubmitButton("save", buttonLayout);
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class GenericSelectionPropertyHandler 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, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
FormItem newItem = null;
if (isMultiselect) {
MultipleSelectionElement mse = FormUIFactory.getInstance().addCheckboxesHorizontal(getName(), i18nFormElementLabelKey(), formItemContainer, selectionKeys, getTranslatedValues(selectionKeys, locale));
for (String sKey : getSelectedKeys(user)) {
mse.select(sKey, true);
}
newItem = mse;
} else {
String[] allKeys = new String[selectionKeys.length + 1];
System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
allKeys[0] = NO_SEL_KEY;
SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, getTranslatedValues(allKeys, locale), null);
// make pre-selection of the formItem
String internalValue = getInternalValue(user);
if (isValidValue(user, internalValue, null, null) && internalValue != null)
sse.select(internalValue, true);
newItem = sse;
}
// enable/disable according to settings
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
newItem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
newItem.setMandatory(true);
}
return newItem;
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class UsrPropContextEditController method formInnerEvent.
@Override
@SuppressWarnings("unused")
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source instanceof FormToggle) {
int activeCount = 0;
FormToggle sourceToggle = (FormToggle) source;
UserPropertyHandler handler = (UserPropertyHandler) sourceToggle.getUserObject();
if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_MAND)) {
context.setAsMandatoryUserProperty(handler, sourceToggle.isOn());
} else if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_ADMN)) {
context.setAsAdminstrativeUserOnly(handler, sourceToggle.isOn());
} else if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_USR)) {
context.setAsUserViewReadOnly(handler, sourceToggle.isOn());
} else if (sourceToggle.getName().startsWith(FT_NAME_PREFIX_INCL)) {
if (sourceToggle.isOn()) {
// activate the toggles on this row
List<FormItem> rowFormItems = rowToggleButtonsMap.get(handler.getName());
for (FormItem item : rowFormItems) {
item.setEnabled(true);
item.setVisible(true);
}
context.addPropertyHandler(handler);
includedPropertiesCount++;
} else {
// this is removing property from context
// deactivate the toggles on this row
List<FormItem> rowFormItems = rowToggleButtonsMap.get(handler.getName());
for (FormItem item : rowFormItems) {
item.setEnabled(false);
item.setVisible(false);
}
context.removePropertyHandler(handler);
includedPropertiesCount--;
if (!UsrPropCfgManager.canBeOptionalInContext(handler, contextName)) {
showInfo("upc.deact_infotext");
}
}
}
// something was toggled, save changes!
usrPropCfgMng.saveUserPropertiesConfig();
contTableFlc.contextPut("activePropCount", includedPropertiesCount);
} else if (source instanceof FormLink) {
// a link, (up/down)
UserPropertyHandler handler = (UserPropertyHandler) source.getUserObject();
if (source.getName().startsWith(FT_NAME_PREFIX_MUP)) {
context.moveHandlerUp(handler);
usrPropCfgMng.saveUserPropertiesConfig();
buildPropertyHandlerListFromContext();
} else if (source.getName().startsWith(FT_NAME_PREFIX_MDN)) {
context.moveHandlerDown(handler);
usrPropCfgMng.saveUserPropertiesConfig();
buildPropertyHandlerListFromContext();
}
}
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class RegistrationForm2 method getFirstName.
protected String getFirstName() {
FormItem fi = propFormItems.get("firstName");
TextElement fn = (TextElement) fi;
return fn.getValue().trim();
}
Aggregations