Add option to unbound resource from user edition

FEA: ItEr76S27ResourceBinding
This commit is contained in:
Manuel Rego Casasnovas 2012-05-09 12:41:12 +02:00
parent 9d7b1754b4
commit cc92ce809d
4 changed files with 33 additions and 2 deletions

View file

@ -3,7 +3,7 @@
* *
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia * 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 * 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 * it under the terms of the GNU Affero General Public License as published by
@ -33,6 +33,7 @@ import org.libreplan.business.users.entities.UserRole;
* Model for UI operations related to {@link User} * Model for UI operations related to {@link User}
* *
* @author Jacobo Aragunde Perez <jaragunde@igalia.com> * @author Jacobo Aragunde Perez <jaragunde@igalia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/ */
public interface IUserModel { public interface IUserModel {
@ -129,4 +130,6 @@ public interface IUserModel {
boolean isLDAPRolesBeingUsed(); boolean isLDAPRolesBeingUsed();
void unboundResource();
} }

View file

@ -53,6 +53,7 @@ import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Row; import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer; import org.zkoss.zul.RowRenderer;
import org.zkoss.zul.Textbox; import org.zkoss.zul.Textbox;
import org.zkoss.zul.api.Groupbox;
/** /**
* Controller for CRUD actions over a {@link User} * Controller for CRUD actions over a {@link User}
@ -77,6 +78,8 @@ public class UserCRUDController extends BaseCRUDController<User> implements
private Combobox userRolesCombo; private Combobox userRolesCombo;
private Groupbox boundResourceGroupbox;
private Autocomplete profileAutocomplete; private Autocomplete profileAutocomplete;
private IURLHandlerRegistry URLHandlerRegistry; private IURLHandlerRegistry URLHandlerRegistry;
@ -118,6 +121,8 @@ public class UserCRUDController extends BaseCRUDController<User> implements
profileAutocomplete = (Autocomplete) editWindow.getFellowIfAny("profileAutocomplete"); profileAutocomplete = (Autocomplete) editWindow.getFellowIfAny("profileAutocomplete");
userRolesCombo = (Combobox) editWindow.getFellowIfAny("userRolesCombo"); userRolesCombo = (Combobox) editWindow.getFellowIfAny("userRolesCombo");
appendAllUserRoles(userRolesCombo); appendAllUserRoles(userRolesCombo);
boundResourceGroupbox = (Groupbox) editWindow
.getFellowIfAny("boundResourceGroupbox");
final EntryPointsHandler<IUserCRUDController> handler = URLHandlerRegistry final EntryPointsHandler<IUserCRUDController> handler = URLHandlerRegistry
.getRedirectorFor(IUserCRUDController.class); .getRedirectorFor(IUserCRUDController.class);
@ -376,4 +381,9 @@ public class UserCRUDController extends BaseCRUDController<User> implements
} }
} }
public void unboundResource() {
userModel.unboundResource();
Util.reloadBindings(boundResourceGroupbox);
}
} }

View file

@ -71,6 +71,8 @@ public class UserModel implements IUserModel {
private String clearNewPassword; private String clearNewPassword;
private Worker unboundWorker;
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<User> getUsers() { public List<User> getUsers() {
@ -116,6 +118,11 @@ public class UserModel implements IUserModel {
user.validate(); user.validate();
userDAO.save(user); userDAO.save(user);
if (unboundWorker != null) {
unboundWorker.setUser(null);
workerDAO.save(unboundWorker);
}
} }
@Override @Override
@ -126,6 +133,7 @@ public class UserModel implements IUserModel {
@Override @Override
public void initCreate() { public void initCreate() {
this.user = User.create(); this.user = User.create();
this.unboundWorker = null;
} }
@Override @Override
@ -134,6 +142,7 @@ public class UserModel implements IUserModel {
Validate.notNull(user); Validate.notNull(user);
this.user = getFromDB(user); this.user = getFromDB(user);
this.setClearNewPassword(null); this.setClearNewPassword(null);
this.unboundWorker = null;
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@ -250,4 +259,10 @@ public class UserModel implements IUserModel {
.getLdapSaveRolesDB(); .getLdapSaveRolesDB();
} }
@Override
public void unboundResource() {
unboundWorker = user.getWorker();
user.setWorker(null);
}
} }

View file

@ -93,7 +93,7 @@
</grid> </grid>
</groupbox> </groupbox>
<groupbox closable="false"> <groupbox closable="false" id="boundResourceGroupbox">
<caption label="${i18n:_('Bound resource')}" /> <caption label="${i18n:_('Bound resource')}" />
<grid fixedLayout="false" span="true"> <grid fixedLayout="false" span="true">
<columns> <columns>
@ -114,6 +114,9 @@
<button label="${i18n:_('Go to worker edition window')}" <button label="${i18n:_('Go to worker edition window')}"
onClick="controller.goToWorkerEdition();" onClick="controller.goToWorkerEdition();"
visible="@{controller.bound}" /> visible="@{controller.bound}" />
<button label="${i18n:_('Unbound resource')}"
onClick="controller.unboundResource();"
visible="@{controller.bound}" />
</groupbox> </groupbox>
<!-- Associated UserRoles --> <!-- Associated UserRoles -->