use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class UserSearchFlexiController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
// insert a autocompleter search
Roles roles = ureq.getUserSession().getRoles();
boolean autoCompleteAllowed = securityModule.isUserAllowedAutoComplete(roles);
boolean ajax = Windows.getWindows(ureq).getWindowManager().isAjaxEnabled();
if (ajax && autoCompleteAllowed) {
// auto complete
String velocityAutoCRoot = Util.getPackageVelocityRoot(FlexiAutoCompleterController.class);
String autoCPage = velocityAutoCRoot + "/autocomplete.html";
autoCompleterContainer = FormLayoutContainer.createCustomFormLayout("autocompletionsearch", getTranslator(), autoCPage);
autoCompleterContainer.setRootForm(mainForm);
layoutCont.add(autoCompleterContainer);
layoutCont.add("autocompletionsearch", autoCompleterContainer);
setupAutoCompleter(ureq, autoCompleterContainer, null, isAdministrativeUser, 60, 3, null);
}
// user search form
backLink = uifactory.addFormLink("btn.back", formLayout);
backLink.setIconLeftCSS("o_icon o_icon_back");
searchFormContainer = FormLayoutContainer.createDefaultFormLayout("usersearchPanel", getTranslator());
searchFormContainer.setRootForm(mainForm);
searchFormContainer.setElementCssClass("o_sel_usersearch_searchform");
searchFormContainer.setFormTitle(translate("header.normal"));
layoutCont.add(searchFormContainer);
layoutCont.add("usersearchPanel", searchFormContainer);
loginEl = uifactory.addTextElement("login", "search.form.login", 128, "", searchFormContainer);
loginEl.setVisible(isAdministrativeUser);
propFormItems = new HashMap<>();
for (UserPropertyHandler userPropertyHandler : userSearchFormPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, UserSearchForm.class.getCanonicalName(), false, searchFormContainer);
// DO NOT validate email field => see OLAT-3324, OO-155, OO-222
if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
TextElement textElement = (TextElement) fi;
textElement.setItemValidatorProvider(null);
}
propFormItems.put(userPropertyHandler.getName(), fi);
}
FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
buttonGroupLayout.setRootForm(mainForm);
searchFormContainer.add(buttonGroupLayout);
// Don't use submit button, form should not be marked as dirty since this is
// not a configuration form but only a search form (OLAT-5626)
searchButton = uifactory.addFormLink("submit.search", buttonGroupLayout, Link.BUTTON);
layoutCont.contextPut("noList", "false");
layoutCont.contextPut("showButton", "false");
// add the table
FlexiTableColumnModel tableColumnModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
int colPos = 0;
if (isAdministrativeUser) {
tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.user.login", colPos++, true, "login"));
}
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<>();
// followed by the users fields
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = UserManager.getInstance().isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
if (visible) {
resultingPropertyHandlers.add(userPropertyHandler);
tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++, true, userPropertyHandler.getName()));
}
}
tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("select", translate("select"), "select"));
Translator myTrans = userManager.getPropertyHandlerTranslator(getTranslator());
userTableModel = new UserSearchFlexiTableModel(Collections.<Identity>emptyList(), resultingPropertyHandlers, isAdministrativeUser, getLocale(), tableColumnModel);
tableEl = uifactory.addTableElement(getWindowControl(), "users", userTableModel, 250, false, myTrans, formLayout);
tableEl.setCustomizeColumns(false);
tableEl.setMultiSelect(true);
tableEl.setSelectAllEnable(true);
layoutCont.put("userTable", tableEl.getComponent());
}
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class UserSearchForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_user_search_form");
login = uifactory.addTextElement("login", "search.form.login", 128, "", formLayout);
login.setVisible(isAdminProps);
login.setElementCssClass("o_sel_user_search_username");
Translator tr = Util.createPackageTranslator(UserPropertyHandler.class, getLocale(), getTranslator());
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, getClass().getCanonicalName(), false, formLayout);
fi.setTranslator(tr);
// DO NOT validate email field => see OLAT-3324, OO-155, OO-222
if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
TextElement textElement = (TextElement) fi;
textElement.setItemValidatorProvider(null);
}
fi.setElementCssClass("o_sel_user_search_".concat(userPropertyHandler.getName().toLowerCase()));
propFormItems.put(userPropertyHandler.getName(), fi);
}
FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
formLayout.add(buttonGroupLayout);
// Don't use submit button, form should not be marked as dirty since this is
// not a configuration form but only a search form (OLAT-5626)
searchButton = uifactory.addFormLink("submit.search", buttonGroupLayout, Link.BUTTON);
searchButton.setElementCssClass("o_sel_user_search_button");
if (cancelButton) {
uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
}
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class UsermanagerUserSearchForm method findIdentitiesFromSearchForm.
/**
* @return List of identities that match the criterias from the search form
*/
private List<Identity> findIdentitiesFromSearchForm() {
// get user attributes from form
String login = searchform.getStringValue("login");
// when searching for deleted users, add wildcard to match with backup prefix
if (searchform.getStatus().equals(Identity.STATUS_DELETED)) {
login = "*" + login;
}
Integer status = null;
// get user fields from form
// build user fields search map
Map<String, String> userPropertiesSearch = new HashMap<String, String>();
for (UserPropertyHandler userPropertyHandler : searchform.getPropertyHandlers()) {
if (userPropertyHandler == null)
continue;
FormItem ui = searchform.getItem(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if (userPropertyHandler.getName().startsWith("genericCheckboxProperty") && ui instanceof MultipleSelectionElement) {
if (!"false".equals(uiValue)) {
// ignore false for the search
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
} else if (StringHelper.containsNonWhitespace(uiValue)) {
// when searching for deleted users, add wildcard to match with backup prefix
if (userPropertyHandler instanceof EmailProperty && searchform.getStatus().equals(Identity.STATUS_DELETED)) {
uiValue = "*" + uiValue;
}
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
}
if (userPropertiesSearch.isEmpty())
userPropertiesSearch = null;
// get group memberships from form
List<SecurityGroup> groupsList = new ArrayList<SecurityGroup>();
if (searchform.getRole("admin")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
groupsList.add(group);
}
if (searchform.getRole("author")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
groupsList.add(group);
}
if (searchform.getRole("groupmanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
groupsList.add(group);
}
if (searchform.getRole("usermanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
groupsList.add(group);
}
if (searchform.getRole("oresmanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
groupsList.add(group);
}
if (searchform.getRole("poolmanager")) {
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_POOL_MANAGER);
groupsList.add(group);
}
status = searchform.getStatus();
SecurityGroup[] groups = groupsList.toArray(new SecurityGroup[groupsList.size()]);
// no permissions in this form so far
PermissionOnResourceable[] permissionOnResources = null;
String[] authProviders = searchform.getAuthProviders();
// get date constraints from form
Date createdBefore = searchform.getBeforeDate();
Date createdAfter = searchform.getAfterDate();
Date userLoginBefore = searchform.getUserLoginBefore();
Date userLoginAfter = searchform.getUserLoginAfter();
// now perform power search
List<Identity> myIdentities = securityManager.getIdentitiesByPowerSearch((login.equals("") ? null : login), userPropertiesSearch, true, groups, permissionOnResources, authProviders, createdAfter, createdBefore, userLoginAfter, userLoginBefore, status);
return myIdentities;
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class NewUserForm method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
// validate if username does match the syntactical login requirements
String loginName = usernameTextElement.getValue();
if (usernameTextElement.isEmpty() || !UserManager.getInstance().syntaxCheckOlatLogin(loginName)) {
usernameTextElement.setErrorKey("new.error.loginname.empty", new String[] {});
return false;
}
// Check if login is still available
Identity identity = BaseSecurityManager.getInstance().findIdentityByName(loginName);
if (identity != null) {
usernameTextElement.setErrorKey("new.error.loginname.choosen", new String[] {});
return false;
}
usernameTextElement.clearError();
// validate special rules for each user property
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
// we assume here that there are only textElements for the user properties
FormItem formItem = flc.getFormComponent(userPropertyHandler.getName());
if (!userPropertyHandler.isValid(null, formItem, null) || formItem.hasError()) {
return false;
}
formItem.clearError();
}
// special test on email address: validate if email is already used
String email = emailTextElement.getValue();
if (!UserManager.getInstance().isEmailAllowed(email)) {
emailTextElement.setErrorKey("new.error.email.choosen", new String[] {});
return false;
}
// password fields depend on form configuration
if (showPasswordFields && psw1TextElement != null && psw2TextElement != null && authCheckbox.isSelected(0)) {
String pwd = psw1TextElement.getValue();
if (psw1TextElement.isEmpty("new.form.mandatory") || psw1TextElement.hasError()) {
return false;
}
if (!UserManager.getInstance().syntaxCheckOlatPassword(pwd)) {
psw1TextElement.setErrorKey("form.checkPassword", new String[] {});
return false;
}
psw1TextElement.clearError();
if (psw2TextElement.isEmpty("new.form.mandatory") || psw2TextElement.hasError()) {
return false;
}
// validate that both passwords are the same
if (!pwd.equals(psw2TextElement.getValue())) {
psw2TextElement.setErrorKey("new.error.password.nomatch", new String[] {});
return false;
}
psw2TextElement.clearError();
}
// all checks passed
return true;
}
use of org.olat.core.gui.components.form.flexible.FormItem in project openolat by klemens.
the class NewUserForm method doCreateAndPersistIdentity.
private Identity doCreateAndPersistIdentity() {
String lang = languageSingleSelection.getSelectedKey();
String username = usernameTextElement.getValue();
String pwd = null;
// use password only when configured to do so
if (showPasswordFields && authCheckbox.isSelected(0)) {
pwd = psw1TextElement.getValue();
if (!StringHelper.containsNonWhitespace(pwd)) {
// treat white-space passwords as no-password. This is fine, a password can be set later on
pwd = null;
}
}
// Create new user and identity and put user to users group
// Create transient user without firstName,lastName, email
UserManager um = UserManager.getInstance();
User newUser = um.createUser(null, null, null);
// Now add data from user fields (firstName,lastName and email are mandatory)
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem propertyItem = this.flc.getFormComponent(userPropertyHandler.getName());
userPropertyHandler.updateUserFromFormItem(newUser, propertyItem);
}
// Init preferences
newUser.getPreferences().setLanguage(lang);
newUser.getPreferences().setInformSessionTimeout(true);
// Save everything in database
Identity ident = securityManager.createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(username, null, pwd, newUser);
return ident;
}
Aggregations