use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class ProfileFormController method updateFromFormData.
/**
* Stores the data from the form into a) the user's home page configuration
* and b) the user's properties.
*
* @param config The user's home page configuration (i.e. flags for publicly
* visible fields).
* @param identity The user's identity
*/
public void updateFromFormData() {
User user = identityToModify.getUser();
// For each user property...
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
// ...get the value from the form field and store it into the user
// property...
FormItem formItem = formItems.get(userPropertyHandler.getName());
if (formItem.isEnabled()) {
userPropertyHandler.updateUserFromFormItem(user, formItem);
}
}
// Store the "about me" text.
HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
conf.setTextAboutMe(textAboutMe.getValue());
hpcm.saveConfigTo(identityToModify.getName(), conf);
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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 OpenOLAT.
the class AttributeEasyRowAdderController method event.
@Override
protected void event(final UserRequest ureq, final Controller source, final Event event) {
if (event instanceof FormEvent) {
final FormEvent fe = (FormEvent) event;
final FormItem sourceItem = fe.getFormItemSource();
final String compName = sourceItem.getName();
if (columnAddRow.contains(compName)) {
// add link clicked
final int clickPos = ((Integer) sourceItem.getUserObject()).intValue();
addRowAt(clickPos + 1);
} else if (columnRemoveRow.contains(compName)) {
// remove link clicked
final int clickPos = ((Integer) sourceItem.getUserObject()).intValue();
removeRowAt(clickPos);
}
}
}
Aggregations