add(new Label("label", user.getName() + " (" + user.getLoginName() + ")"));
final Map<Long, List<UserSpaceRole>> spaceRolesMap = getJtrac().loadSpaceRolesMapForUser(userId);
User principal = getPrincipal();
// this flag is used later also for the big "make admin for all spaces" button
boolean isPrincipalSuperUser = principal.isSuperUser();
List<Long> allowedSpaces = new ArrayList<Long>();
if(isPrincipalSuperUser) {
allowedSpaces = new ArrayList(spaceRolesMap.keySet());
} else {
// session user is not an admin, remove spaces that he should not see
for(Space s : principal.getSpacesWhereRoleIsAdmin()) {
long spaceId = s.getId();
if(spaceRolesMap.containsKey(spaceId)) {
allowedSpaces.add(spaceId);
}
}
}
final SimpleAttributeModifier sam = new SimpleAttributeModifier("class", "alt");
add(new ListView("spaces", allowedSpaces) {
protected void populateItem(ListItem listItem) {
long spaceId = (Long) listItem.getModelObject();
List<UserSpaceRole> usrs = spaceRolesMap.get(spaceId);
// space can be null for "all spaces" role (prefixCode used in map = "")
final Space space = usrs.get(0).getSpace();
if(space != null && space.getId() == selectedSpaceId) {
listItem.add(new SimpleAttributeModifier("class", "selected"));
} else if(listItem.getIndex() % 2 == 1) {
listItem.add(sam);
}
if(space == null) {
listItem.add(new Label("name", localize("user_allocate_space.allSpaces")));
listItem.add(new WebMarkupContainer("prefixCode").setVisible(false));
} else {
listItem.add(new Label("name", space.getName()));
listItem.add(new Link("prefixCode") {
public void onClick() {
if(previous instanceof SpaceAllocatePage) { // prevent recursive stack buildup
previous = null;
}
setResponsePage(new SpaceAllocatePage(space.getId(), UserAllocatePage.this, userId));
}
}.add(new Label("prefixCode", space.getPrefixCode())));
}
listItem.add(new RoleDeAllocatePanel("roleDeAllocatePanel", usrs));
}
});
List<Space> spaces = getJtrac().findSpacesNotFullyAllocatedToUser(user.getId());
if(!isPrincipalSuperUser) {
// not super user, show only spaces which can admin
Set<Space> set = new HashSet(spaces);
List<Space> allowed = new ArrayList<Space>();
// also within these spaces may be fully allocated, so trim
for(Space s : principal.getSpacesWhereRoleIsAdmin()) {
if(set.contains(s)) {
allowed.add(s);
}
}
spaces = allowed;