String userGroupKey = role.getPermission(UserModule.AUTH_USER).getValue();
userGroups.add(userGroupKey);
}
ZeroView view = new ZeroView(getMessages(), request.getLocale());
view.addWidget(new JavascriptWidget("hidePopup('v2js_user_warning')"));
view.addWidget(new SimpleWidget(ZeroView.DIV_CONTENT, "user_userlist"));
FormWidget filter = (FormWidget) getWidgetManager(session).getWidget("USERLIST_FILTER");
if (filter == null) {
filter = new FormWidget("USERLIST_FILTER", getLocale(request));
filter.setColumnCount(3);
filter.setShowLabelAtTop(true);
filter.addField(new StringField("username", "base.user.table.username", ""));
ComboBoxField groupField = new ComboBoxField("userGroup", "base.user.label.usergroupkey", "");
groupField.addOption("", "*");
for (UserGroup userGroup : getUserGroups()) {
groupField.addOption(userGroup.getId(), userGroup.getGroupKey());
}
filter.addField(groupField);
ComboBoxField deletedField = new ComboBoxField("deleted", "base.user.label.deleted", "");
deletedField.addOption("", "NOT DELETED");
deletedField.addOption("D", "DELETED");
deletedField.addOption("A", "ALL");
filter.addField(deletedField);
filter.setForm("UserFilterForm");
getWidgetManager(session).register(filter);
}
view.addWidget(filter);
List<ZeroUser> userList = null;
if (userGroups.contains("*")) {
userList = userDao.findAll();
} else {
userList = new ArrayList<ZeroUser>();
for (String userGroup : userGroups) {
userList.addAll(userDao.findByGroup(userGroup));
}
}
HtmlTableWidget userListComponent = (HtmlTableWidget) getWidgetManager(session).getWidget("USERLIST");
if (userListComponent == null) {
DefaultTableModelColumn usernameColumn = new DefaultTableModelColumn("base.user.table.username", "username");
usernameColumn.setStyleClass("emphasize");
usernameColumn.setRenderer(new TableColumnRenderer() {
public String getTemplate() {
return "v2js_widgets_username";
}
public Object getData(Object obj) {
JSONObject jLink = new JSONObject();
jLink.element("username", ((ZeroUser) obj).getUsername());
jLink.element("deleted", ((ZeroUser) obj).isDeleted());
return jLink;
}
});
/* usernameColumn.addClickListener(new TableClickListener() {
public void fireClicked(TableClickEvent event) {
log.debug("fireClicked: " + event.getWidget().getModel().getData(event.getColumn(), event.getRow()));
}
});*/
UserTableModel model = new UserTableModel(userList, getMessages(), request.getLocale());
if (user.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {
model.setSelectable(true);
DefaultTableModelColumn editColumn = new DefaultTableModelColumn("", "");
editColumn.setRenderer(new TableColumnRenderer() {
public String getTemplate() {
return "v2js_widgets_tablelink";
}
public Object getData(Object obj) {
if (obj instanceof User) {
JSONObject jLink = new JSONObject();
jLink.element("url", "user/userEdit.do?selected=" + ((ZeroUser) obj).getId());
jLink.element("text", "Edit");
return jLink;
}
return "";
}
});
model.addColumn(editColumn);
}
if (user.checkAuthorisation(UserModule.AUTH_LOGIN_AS)) {
model.setSelectable(true);
DefaultTableModelColumn loginColumn = new DefaultTableModelColumn("", "");
loginColumn.setRenderer(new TableColumnRenderer() {
public String getTemplate() {
return null;
}
public Object getData(Object obj) {
if (obj instanceof User) {
return new HtmlSnippet("<a href=\"user/loginAsUser.do?selected=" + ((ZeroUser) obj).getId() + "\">Login</a>");
}
return "";
}
});
model.addColumn(loginColumn);
}
model.addColumn(usernameColumn);
model.addColumn(new DefaultTableModelColumn("base.user.table.firstname", "person.firstname"));
model.addColumn(new DefaultTableModelColumn("base.user.table.lastname", "person.lastname"));
model.addColumn(new DefaultTableModelColumn("base.user.table.email", "person.email"));
model.addColumn(new DefaultTableModelColumn("base.user.table.phone", "person.phone"));
model.addColumn(new DefaultTableModelColumn("base.user.label.usergroupkey", "userGroup.groupKey"));
model.addColumn(new DefaultTableModelColumn("base.user.label.locked", "locked"));
if (user.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {
DefaultTableModelColumn sendPwdColumn = new DefaultTableModelColumn("", "");
sendPwdColumn.setRenderer(new TableColumnRenderer() {
public String getTemplate() {
return "v2js_widgets_tablelink";
}
public Object getData(Object obj) {
if (obj instanceof User) {
JSONObject jLink = new JSONObject();
jLink.element("url", "user/userSendPwd.do?selected=" + ((ZeroUser) obj).getId());
jLink.element("text", "Send Password");
return jLink;
}
return "";
}
});
model.addColumn(sendPwdColumn);
}
model.setSort(1);
userListComponent = new HtmlTableWidget("USERLIST", model, request.getLocale());
userListComponent.setRowsPerPage(20);
getWidgetManager(session).register(userListComponent);
} else {
((DefaultTableModel<ZeroUser>) userListComponent.getModel()).setCollection(userList);
}
view.addWidget(userListComponent);
if (user.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {
view.getJson().element("edit", true);
}
return new ModelAndView(view, null);
}