Skip to content
Snippets Groups Projects
Commit 6d277ed4 authored by srosse's avatar srosse
Browse files

OO-2785: handle the checkbox property in home user search, coaching tool,...

OO-2785: handle the checkbox property in home user search, coaching tool, import of user in group and course
parent 13965a17
No related branches found
No related tags found
No related merge requests found
......@@ -273,63 +273,71 @@ public class UserSearchController extends BasicController {
} else if (source == searchform) {
if (event == Event.DONE_EVENT) {
// form validation was ok
String login = searchform.login.getValue();
// build user fields search map
Map<String, String> userPropertiesSearch = new HashMap<String, String>();
for (UserPropertyHandler userPropertyHandler : searchform.userPropertyHandlers) {
if (userPropertyHandler == null) continue;
FormItem ui = searchform.propFormItems.get(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if (StringHelper.containsNonWhitespace(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
getLogger().info("Search property:" + userPropertyHandler.getName() + "=" + uiValue);
}
}
if (userPropertiesSearch.isEmpty()) userPropertiesSearch = null;
tableCtr = new TableController(tableConfig, ureq, getWindowControl(), myContent.getTranslator());
listenTo(tableCtr);
List<Identity> users = searchUsers(login, userPropertiesSearch, true);
int maxResults = securityModule.getUserSearchMaxResultsValue();
if(maxResults > 0 && users.size() > maxResults) {
users = users.subList(0, maxResults);
showWarning("error.search.maxResults", Integer.toString(maxResults));
}
if (!users.isEmpty()) {
tdm = new UserTableDataModel(users, ureq.getLocale(), isAdministrativeUser);
// add the data column descriptors
tdm.addColumnDescriptors(tableCtr, null);
// add the action columns
if (useMultiSelect) {
// add multiselect action
tableCtr.addMultiSelectAction(this.actionKeyChoose, ACTION_MULTISELECT_CHOOSE);
} else {
// add single column selec action
tableCtr.addColumnDescriptor(new StaticColumnDescriptor(ACTION_SINGLESELECT_CHOOSE, "table.header.action", myContent
.getTranslator().translate("action.choose")));
}
tableCtr.setTableDataModel(tdm);
tableCtr.setMultiSelect(useMultiSelect);
searchPanel.pushContent(tableCtr.getInitialComponent());
myContent.contextPut("showButton","true");
} else {
getWindowControl().setInfo(translate("error.no.user.found"));
}
doSearch(ureq);
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, Event.CANCELLED_EVENT);
}
}
}
/**
* @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
*/
@Override
protected void doDispose() {
// Child controllers auto-disposed by basic controller
}
private void doSearch(UserRequest ureq) {
String login = searchform.login.getValue();
// build user fields search map
Map<String, String> userPropertiesSearch = new HashMap<>();
for (UserPropertyHandler userPropertyHandler : searchform.userPropertyHandlers) {
if (userPropertyHandler == null) continue;
FormItem ui = searchform.propFormItems.get(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if(userPropertyHandler.getName().startsWith("genericCheckboxProperty")) {
if(!"false".equals(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
} else if (StringHelper.containsNonWhitespace(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
}
if (userPropertiesSearch.isEmpty()) {
userPropertiesSearch = null;
}
tableCtr = new TableController(tableConfig, ureq, getWindowControl(), myContent.getTranslator());
listenTo(tableCtr);
List<Identity> users = searchUsers(login, userPropertiesSearch, true);
int maxResults = securityModule.getUserSearchMaxResultsValue();
if(maxResults > 0 && users.size() > maxResults) {
users = users.subList(0, maxResults);
showWarning("error.search.maxResults", Integer.toString(maxResults));
}
if (!users.isEmpty()) {
tdm = new UserTableDataModel(users, getLocale(), isAdministrativeUser);
// add the data column descriptors
tdm.addColumnDescriptors(tableCtr, null);
// add the action columns
if (useMultiSelect) {
// add multiselect action
tableCtr.addMultiSelectAction(this.actionKeyChoose, ACTION_MULTISELECT_CHOOSE);
} else {
// add single column selec action
tableCtr.addColumnDescriptor(new StaticColumnDescriptor(ACTION_SINGLESELECT_CHOOSE, "table.header.action", myContent
.getTranslator().translate("action.choose")));
}
tableCtr.setTableDataModel(tdm);
tableCtr.setMultiSelect(useMultiSelect);
searchPanel.pushContent(tableCtr.getInitialComponent());
myContent.contextPut("showButton","true");
} else {
getWindowControl().setInfo(translate("error.no.user.found"));
}
}
/**
* Can be overwritten by subclassen to search other users or filter users.
......
......@@ -414,9 +414,12 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController {
if (userPropertyHandler == null) continue;
FormItem ui = propFormItems.get(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if (StringHelper.containsNonWhitespace(uiValue)) {
if(userPropertyHandler.getName().startsWith("genericCheckboxProperty")) {
if(!"false".equals(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
} else if (StringHelper.containsNonWhitespace(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
getLogger().info("Search property:" + userPropertyHandler.getName() + "=" + uiValue);
}
}
if (userPropertiesSearch.isEmpty()) {
......
......@@ -41,6 +41,7 @@ import org.olat.core.util.Util;
import org.olat.user.UserManager;
import org.olat.user.propertyhandlers.EmailProperty;
import org.olat.user.propertyhandlers.UserPropertyHandler;
import org.springframework.beans.factory.annotation.Autowired;
/**
......@@ -60,8 +61,11 @@ public class UserSearchForm extends FormBasicController {
private FormLink searchButton;
protected TextElement login;
protected List<UserPropertyHandler> userPropertyHandlers;
protected Map<String,FormItem> propFormItems;
protected final List<UserPropertyHandler> userPropertyHandlers;
protected final Map<String,FormItem> propFormItems = new HashMap<>();
@Autowired
private UserManager userManager;
/**
......@@ -73,9 +77,8 @@ public class UserSearchForm extends FormBasicController {
public UserSearchForm(UserRequest ureq, WindowControl wControl, boolean isAdminProps, boolean cancelButton, boolean allowReturnKey) {
super(ureq, wControl);
UserManager um = UserManager.getInstance();
Translator decoratedTranslator = um.getPropertyHandlerTranslator(this.getTranslator());
setTranslator(decoratedTranslator);
setTranslator(userManager.getPropertyHandlerTranslator(getTranslator()));
userPropertyHandlers = userManager.getUserPropertyHandlersFor(getClass().getCanonicalName(), isAdminProps);
this.isAdminProps = isAdminProps;
this.cancelButton = cancelButton;
......@@ -97,7 +100,7 @@ public class UserSearchForm extends FormBasicController {
}
boolean filled = !login.isEmpty();
StringBuffer full = new StringBuffer(login.getValue().trim());
StringBuilder full = new StringBuilder(login.getValue().trim());
FormItem lastFormElement = login;
// DO NOT validate each user field => see OLAT-3324
......@@ -151,22 +154,12 @@ public class UserSearchForm extends FormBasicController {
login.setVisible(isAdminProps);
login.setElementCssClass("o_sel_user_search_username");
UserManager um = UserManager.getInstance();
Translator tr = Util.createPackageTranslator(
UserPropertyHandler.class,
getLocale(),
getTranslator());
userPropertyHandlers = um.getUserPropertyHandlersFor(
getClass().getCanonicalName(), isAdminProps);
propFormItems = new HashMap<String,FormItem>();
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
);
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
......
......@@ -60,7 +60,7 @@ public class UserSearchForm extends FormBasicController {
private TextElement login;
private MultipleSelectionElement statusEl;
private List<UserPropertyHandler> userPropertyHandlers;
private Map <String,FormItem>propFormItems;
private final Map<String,FormItem> propFormItems = new HashMap<>();
@Autowired
private UserManager userManager;
......@@ -87,8 +87,7 @@ public class UserSearchForm extends FormBasicController {
login.setVisible(adminProps);
userPropertyHandlers = userManager.getUserPropertyHandlersFor(PROPS_IDENTIFIER, adminProps);
propFormItems = new HashMap<String,FormItem>();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, getClass().getCanonicalName(), false, formLayout);
......@@ -116,12 +115,16 @@ public class UserSearchForm extends FormBasicController {
}
public Map<String,String> getSearchProperties() {
Map<String, String> userPropertiesSearch = new HashMap<String, String>();
Map<String, String> userPropertiesSearch = new HashMap<>();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
FormItem ui = propFormItems.get(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if (StringHelper.containsNonWhitespace(uiValue) && !uiValue.equals("-")) {
if(userPropertyHandler.getName().startsWith("genericCheckboxProperty")) {
if(!"false".equals(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
} else if (StringHelper.containsNonWhitespace(uiValue) && !uiValue.equals("-")) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment