Do definice pracovních skupin byl přidán vyhledávací edit. Doplněna

kontrola členství v komisích/střediscích. 
refs #123 
closes #119
multitenant
Josef Rokos 10 years ago
parent bbad265709
commit 23d2eb58f6

@ -22,5 +22,6 @@ public interface WorkgroupService extends Service<Workgroup> {
public List<Member> getMembers(Workgroup workgroup); public List<Member> getMembers(Workgroup workgroup);
public void loadMembers(Workgroup workgroup); public void loadMembers(Workgroup workgroup);
public void loadParents(Member member); public void loadParents(Member member);
public void loadParentsMembers(Workgroup workgroup);
} }

@ -89,7 +89,7 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
} }
if (member.isPerson()) { if (member.isPerson()) {
return true; return checkParentsMembers(workgroup, (User)member);
} }
Workgroup toAdd = Workgroup.class.cast(member); Workgroup toAdd = Workgroup.class.cast(member);
@ -105,6 +105,23 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
return true; return true;
} }
//check, jestli uzivatel pridavany do komise neni zaroven clenem strediska, jehoz je komise clenem
private boolean checkParentsMembers(Workgroup workgroup, User user) {
if (workgroup.isCentre()) {
return true;
}
for (Workgroup wg : workgroup.getParents()) {
for (JobMapping jm : wg.getMembers()) {
if (jm.getMember().equals(user)) {
return false;
}
}
}
return true;
}
@Override @Override
@Transactional @Transactional
public List<Workgroup> getUserCentres(User user) { public List<Workgroup> getUserCentres(User user) {
@ -291,4 +308,14 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
} }
} }
@Override
@Transactional
public void loadParentsMembers(Workgroup workgroup) {
loadParents(workgroup);
for (Workgroup wg : workgroup.getParents()) {
loadMembers(wg);
}
}
} }

@ -1,6 +1,7 @@
package info.bukova.isspst.ui.workgroups; package info.bukova.isspst.ui.workgroups;
import info.bukova.isspst.Constants; import info.bukova.isspst.Constants;
import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.JobMapping;
import info.bukova.isspst.data.Member; import info.bukova.isspst.data.Member;
import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Role;
@ -8,6 +9,7 @@ import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.services.users.RoleService;
import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupException;
import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.FormViewModel; import info.bukova.isspst.ui.FormViewModel;
@ -22,6 +24,10 @@ import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.event.DropEvent; import org.zkoss.zk.ui.event.DropEvent;
import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zul.Listitem; import org.zkoss.zul.Listitem;
import org.zkoss.zul.Messagebox;
import static ch.lambdaj.Lambda.*;
import static org.hamcrest.Matchers.*;
public class WorkgroupForm extends FormViewModel<Workgroup> { public class WorkgroupForm extends FormViewModel<Workgroup> {
@ -32,11 +38,14 @@ public class WorkgroupForm extends FormViewModel<Workgroup> {
@WireVariable @WireVariable
private WorkgroupService workgroupService; private WorkgroupService workgroupService;
private List<Member> users; private List<Member> users;
private String findUser;
private List<Member> selectedUsers;
@Init(superclass = true) @Init(superclass = true)
public void init() { public void init() {
users = new ArrayList<Member>(); users = new ArrayList<Member>();
users.addAll(userService.getAll()); users.addAll(userService.getAll());
selectedUsers = new ArrayList<Member>();
} }
public List<Member> getUsers() { public List<Member> getUsers() {
@ -147,13 +156,31 @@ public class WorkgroupForm extends FormViewModel<Workgroup> {
if (!u.isPerson()) { if (!u.isPerson()) {
workgroupService.loadMembers((Workgroup) u); workgroupService.loadMembers((Workgroup) u);
} else if (!getDataBean().isCentre()) {
workgroupService.loadParentsMembers(getDataBean());
} }
try {
workgroupService.addMember(getDataBean(), u, roleService.getRoleByAuthority(target)); workgroupService.addMember(getDataBean(), u, roleService.getRoleByAuthority(target));
if (!u.isPerson()) { if (!u.isPerson()) {
users.remove(u); users.remove(u);
} }
} catch (WorkgroupException e) {
String message;
String title;
if (!getDataBean().isCentre()) {
message = StringUtils.localize("WorkgroupFormUserIsCenterMember");
title = StringUtils.localize("WorkgroupFormCannotAddUser");
} else {
message = StringUtils.localize("WorkgroupFormMemberIsCenterMember");
title = StringUtils.localize("WorkgroupFormCannotAddWorkgroup");
}
Messagebox.show(message, title, Messagebox.OK, Messagebox.ERROR);
}
} }
private String getSource(DropEvent event) { private String getSource(DropEvent event) {
@ -172,4 +199,35 @@ public class WorkgroupForm extends FormViewModel<Workgroup> {
return target; return target;
} }
public String getFindUser() {
return findUser;
}
public void setFindUser(String findUser) {
this.findUser = findUser;
}
public List<Member> getSelectedUsers() {
return selectedUsers;
}
public void setSelectedUsers(List<Member> selectedUser) {
this.selectedUsers = selectedUser;
}
@Command
@NotifyChange("selectedUsers")
public void find() {
List<Member> found = filter(having(on(Member.class).getFullName(), startsWith(findUser)), users);
if (!found.isEmpty()) {
if (selectedUsers == null) {
selectedUsers = new ArrayList<Member>();
} else {
selectedUsers.clear();
selectedUsers.add(found.get(0));
}
}
}
} }

@ -277,3 +277,7 @@ RemoveItem=Smazat
Amount=Částka Amount=Částka
WorkgroupFormUserIsCenterMember=Uživatel je členem střediska, jehož je komise členem!
WorkgroupFormMemberIsCenterMember=Některý ze členů přidávané komise je členem tohoto střediska!
WorkgroupFormCannotAddUser=Uživatele nelze přidat
WorkgroupFormCannotAddWorkgroup=Komisi nelze přidat

@ -31,8 +31,10 @@
</grid> </grid>
<label value="Přetáhněte myší:"/> <label value="Přetáhněte myší:"/>
<hlayout> <hlayout>
<vbox>
<textbox value="@bind(vm.findUser)" onChange="@command('find')" instant="true" width="300px"/>
<listbox id="users" model="@bind(vm.users)" height="380px" width="300px" multiple="true" <listbox id="users" model="@bind(vm.users)" height="380px" width="300px" multiple="true"
droppable="true" onDrop="@command('addMember', event=event)"> droppable="true" onDrop="@command('addMember', event=event)" selectedItems="@bind(vm.selectedUsers)">
<listhead> <listhead>
<listheader label="Uživatelé" sort="czech(fullName)"/> <listheader label="Uživatelé" sort="czech(fullName)"/>
</listhead> </listhead>
@ -41,7 +43,7 @@
onDrop="@command('addMember', event=event)" attributes.item="@load(each)"/> onDrop="@command('addMember', event=event)" attributes.item="@load(each)"/>
</template> </template>
</listbox> </listbox>
</vbox>
<tabbox mold="accordion" width="300px"> <tabbox mold="accordion" width="300px">
<tabs children="@load(vm.workgroupRoles)"> <tabs children="@load(vm.workgroupRoles)">

Loading…
Cancel
Save