use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class RegistrationForm2 method getFirstName.
protected String getFirstName() {
FormItem fi = propFormItems.get("firstName");
TextElement fn = (TextElement) fi;
return fn.getValue().trim();
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class ProfileFormController method formOK.
@Override
protected void formOK(final UserRequest ureq) {
User user = identityToModify.getUser();
// update each user field
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem formItem = formItems.get(userPropertyHandler.getName());
if (formItem.isEnabled()) {
userPropertyHandler.updateUserFromFormItem(user, formItem);
}
}
if (portraitDeleted) {
File img = dps.getLargestPortrait(identityToModify.getName());
if (img != null) {
dps.deletePortrait(identityToModify);
notifyPortraitChanged();
}
}
File uploadedImage = portraitUpload.getUploadFile();
String uploadedFilename = portraitUpload.getUploadFileName();
if (uploadedImage != null) {
dps.setPortrait(uploadedImage, uploadedFilename, identityToModify.getName());
notifyPortraitChanged();
}
if (logoDeleted) {
File img = dps.getLargestLogo(identityToModify.getName());
if (img != null) {
dps.deleteLogo(identityToModify);
notifyPortraitChanged();
}
}
if (logoUpload != null) {
File uploadedLogo = logoUpload.getUploadFile();
String uploadedLogoname = logoUpload.getUploadFileName();
if (uploadedLogo != null) {
dps.setLogo(uploadedLogo, uploadedLogoname, identityToModify.getName());
notifyPortraitChanged();
}
}
// Store the "about me" text.
HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
conf.setTextAboutMe(textAboutMe.getValue());
hpcm.saveConfigTo(identityToModify.getName(), conf);
// fire the appropriate event
fireEvent(ureq, Event.DONE_EVENT);
// update the user profile data
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey()), new SyncerExecutor() {
@Override
public void execute() {
UserManager um = UserManager.getInstance();
identityToModify = (Identity) DBFactory.getInstance().loadObject(identityToModify);
currentEmail = identityToModify.getUser().getProperty("email", null);
identityToModify = updateIdentityFromFormData(identityToModify);
changedEmail = identityToModify.getUser().getProperty("email", null);
emailChanged = false;
if ((currentEmail == null && StringHelper.containsNonWhitespace(changedEmail)) || (currentEmail != null && !currentEmail.equals(changedEmail))) {
if (isAllowedToChangeEmailWithoutVerification(ureq) || !StringHelper.containsNonWhitespace(changedEmail)) {
String key = identityToModify.getUser().getProperty("emchangeKey", null);
TemporaryKey tempKey = rm.loadTemporaryKeyByRegistrationKey(key);
if (tempKey != null) {
rm.deleteTemporaryKey(tempKey);
}
securityManager.deleteInvalidAuthenticationsByEmail(currentEmail);
} else {
emailChanged = true;
// change email address to old address until it is verified
identityToModify.getUser().setProperty("email", currentEmail);
}
}
if (!um.updateUserFromIdentity(identityToModify)) {
getWindowControl().setInfo(translate("profile.unsuccessful"));
// reload user data from db
identityToModify = BaseSecurityManager.getInstance().loadIdentityByKey(identityToModify.getKey());
}
OLATResourceable modRes = OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new MultiUserEvent("changed"), modRes);
if (!emailChanged) {
fireEvent(ureq, Event.FAILED_EVENT);
}
}
});
if (emailChanged) {
removeAsListenerAndDispose(dialogCtr);
String dialogText = "";
if (identityToModify.equals(ureq.getIdentity())) {
dialogText = translate("email.change.dialog.text");
} else {
dialogText = translate("email.change.dialog.text.usermanager");
}
dialogCtr = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), translate("email.change.dialog.title"), dialogText);
listenTo(dialogCtr);
dialogCtr.activate();
}
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class ProfileFormController method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean allOk = true;
formContext.put("username", identityToModify.getName());
User user = identityToModify.getUser();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem formItem = formItems.get(userPropertyHandler.getName());
if (formItem.isEnabled()) {
formItem.clearError();
allOk &= userPropertyHandler.isValid(user, formItem, formContext);
}
}
try {
String aboutMe = textAboutMe.getValue();
if (aboutMe.length() > 10000) {
textAboutMe.setErrorKey("input.toolong", new String[] { "10000" });
allOk = false;
} else {
textAboutMe.clearError();
}
} catch (Exception e) {
textAboutMe.setErrorKey("input.toolong", new String[] { "10000" });
allOk = false;
}
return allOk & super.validateFormLogic(ureq);
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class DateDisplayPropertyHandler method addFormItem.
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
Date date = getDateValue(user);
String dateString = StringHelper.formatLocaleDate(date.getTime(), locale);
FormItem item = FormUIFactory.getInstance().addStaticTextElement(getName(), i18nFormElementLabelKey(), dateString, formItemContainer);
return item;
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
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();
}
}
}
Aggregations