Refactor users list to use a RowRenderer
Add several methods in Util class to make easier renderers implementation. FEA: ItEr76S27ResourceBinding
This commit is contained in:
parent
521aa36bfc
commit
42baf46926
5 changed files with 79 additions and 30 deletions
|
|
@ -299,12 +299,6 @@ public class User extends BaseEntity implements IHumanIdentifiable{
|
|||
return loginName;
|
||||
}
|
||||
|
||||
public String getAuthenticationType() {
|
||||
if (isLibrePlanUser())
|
||||
return "Database";
|
||||
return "LDAP";
|
||||
}
|
||||
|
||||
public Worker getWorker() {
|
||||
return worker;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
* Copyright (C) 2010-2011 Igalia, S.L.
|
||||
* Copyright (C) 2010-2012 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
@ -49,8 +49,11 @@ import org.zkoss.zul.Combobox;
|
|||
import org.zkoss.zul.Comboitem;
|
||||
import org.zkoss.zul.Datebox;
|
||||
import org.zkoss.zul.Decimalbox;
|
||||
import org.zkoss.zul.Hbox;
|
||||
import org.zkoss.zul.Intbox;
|
||||
import org.zkoss.zul.Label;
|
||||
import org.zkoss.zul.Radio;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.Timebox;
|
||||
import org.zkoss.zul.api.Checkbox;
|
||||
|
|
@ -691,4 +694,30 @@ public class Util {
|
|||
return currencySymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the <code>text</code> as a {@link Label} into the specified
|
||||
* {@link Row}.
|
||||
*/
|
||||
public static void appendLabel(Row row, String text) {
|
||||
row.appendChild(new Label(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a edit button and a remove button to the {@link Row} inside a
|
||||
* {@link Hbox} and adds the <code>ON_CLICK</code> event over the
|
||||
* {@link Row} for the edit operation.<br />
|
||||
*
|
||||
* The edit button will call the <code>editButtonListener</code> when
|
||||
* clicked and the remove button the <code>removeButtonListener</code>.
|
||||
*/
|
||||
public static void appendOperationsAndOnClickEvent(Row row,
|
||||
EventListener editButtonListener, EventListener removeButtonListener) {
|
||||
Hbox hbox = new Hbox();
|
||||
hbox.appendChild(Util.createEditButton(editButtonListener));
|
||||
hbox.appendChild(Util.createRemoveButton(removeButtonListener));
|
||||
row.appendChild(hbox);
|
||||
|
||||
row.addEventListener(Events.ON_CLICK, editButtonListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,32 @@ public class UserCRUDController extends BaseCRUDController<User> implements
|
|||
|
||||
private IURLHandlerRegistry URLHandlerRegistry;
|
||||
|
||||
private RowRenderer usersRenderer = new RowRenderer() {
|
||||
|
||||
@Override
|
||||
public void render(Row row, Object data) throws Exception {
|
||||
final User user = (User) data;
|
||||
row.setValue(user);
|
||||
|
||||
Util.appendLabel(row, user.getLoginName());
|
||||
Util.appendLabel(row, user.isDisabled() ? _("Yes") : _("No"));
|
||||
Util.appendLabel(row, user.isAdministrator() ? _("Yes") : _("No"));
|
||||
Util.appendLabel(row, getAuthenticationType(user));
|
||||
|
||||
Util.appendOperationsAndOnClickEvent(row, new EventListener() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
goToEditForm(user);
|
||||
}
|
||||
}, new EventListener() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
confirmDelete(user);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
|
|
@ -260,4 +286,23 @@ public class UserCRUDController extends BaseCRUDController<User> implements
|
|||
};
|
||||
}
|
||||
|
||||
public String getAuthenticationType() {
|
||||
User user = getUser();
|
||||
if (user != null) {
|
||||
return getAuthenticationType(user);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getAuthenticationType(User user) {
|
||||
if (user.isLibrePlanUser()) {
|
||||
return _("Database");
|
||||
}
|
||||
return _("LDAP");
|
||||
}
|
||||
|
||||
public RowRenderer getUsersRenderer() {
|
||||
return usersRenderer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Authentication type')}" />
|
||||
<label value="@{controller.user.authenticationType}" />
|
||||
<label value="@{controller.authenticationType}" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||
Desenvolvemento Tecnolóxico de Galicia
|
||||
Copyright (C) 2010-2011 Igalia, S.L.
|
||||
Copyright (C) 2010-2012 Igalia, S.L.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
<window id="${arg.top_id}" title="${i18n:_('Users List')}">
|
||||
<newdatasortablegrid id="listing" model="@{controller.users}" mold="paging"
|
||||
pageSize="10" sclass="clickable-rows">
|
||||
pageSize="10" sclass="clickable-rows"
|
||||
rowRenderer="@{controller.usersRenderer}">
|
||||
<columns sizable="true">
|
||||
<newdatasortablecolumn label="${i18n:_('User login name')}" sort="auto(loginName)" />
|
||||
<newdatasortablecolumn label="${i18n:_('Disabled')}" />
|
||||
|
|
@ -29,26 +30,6 @@
|
|||
<newdatasortablecolumn label="${i18n:_('Authentication type')}" />
|
||||
<newdatasortablecolumn label="${i18n:_('Actions')}" />
|
||||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='user'}" value="@{user}" onClick="controller.goToEditForm(self.value);">
|
||||
<label value="@{user.loginName}" />
|
||||
<checkbox checked="@{user.disabled}" disabled="true" />
|
||||
<checkbox checked="@{user.administrator}" disabled="true" />
|
||||
<label value="@{user.authenticationType}" />
|
||||
<hbox>
|
||||
<button sclass="icono" image="/common/img/ico_editar1.png"
|
||||
hoverImage="/common/img/ico_editar.png"
|
||||
tooltiptext="${i18n:_('Edit')}"
|
||||
onClick="controller.goToEditForm(self.parent.parent.value);">
|
||||
</button>
|
||||
<button sclass="icono" image="/common/img/ico_borrar1.png"
|
||||
hoverImage="/common/img/ico_borrar.png"
|
||||
tooltiptext="${i18n:_('Delete')}"
|
||||
onClick="controller.confirmDelete(self.parent.parent.value);">
|
||||
</button>
|
||||
</hbox>
|
||||
</row>
|
||||
</rows>
|
||||
</newdatasortablegrid>
|
||||
<button id="show_create_form" onClick="controller.goToCreateForm();"
|
||||
label="${i18n:_('Create')}" sclass="create-button global-action" >
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue