ItEr39S10CUAltaUsuario: implemented adition of Profiles in the User edition interface

This commit is contained in:
Jacobo Aragunde Pérez 2009-12-18 10:50:47 +01:00 committed by Javier Moran Rua
parent 0131f43b50
commit 0f0a180a02
5 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,57 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.web.common.components.finders;
import java.util.List;
import org.navalplanner.business.users.daos.IProfileDAO;
import org.navalplanner.business.users.entities.Profile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
*
* Implements a {@link IFinder} class for providing {@link Profile}
* elements
*
*/
@Repository
public class ProfileFinder extends Finder implements IFinder {
@Autowired
private IProfileDAO dao;
@Override
public String _toString(Object value) {
Profile profile = (Profile) value;
return (profile != null)? profile.getProfileName() : "";
}
@Override
@Transactional(readOnly = true)
public List<Profile> getAll() {
return dao.list(Profile.class);
}
}

View file

@ -104,4 +104,12 @@ public interface IUserModel {
*/
void removeProfile(Profile profile);
/**
* Adds a profile to the list of {@link Profile} objects associated
* with the current User.
*
* @param role The {@link Profile} object to be added.
*/
void addProfile(Profile profile);
}

View file

@ -34,6 +34,7 @@ import org.navalplanner.web.common.Level;
import org.navalplanner.web.common.MessagesForUser;
import org.navalplanner.web.common.OnlyOneVisible;
import org.navalplanner.web.common.Util;
import org.navalplanner.web.common.components.Autocomplete;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Combobox;
@ -63,12 +64,15 @@ public class UserCRUDController extends GenericForwardComposer implements
private Combobox userRolesCombo;
private Autocomplete profileAutocomplete;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
comp.setVariable("controller", this, true);
messagesForUser = new MessagesForUser(messagesContainer);
getVisibility().showOnly(listWindow);
profileAutocomplete = (Autocomplete) createWindow.getFellowIfAny("profileAutocomplete");
userRolesCombo = (Combobox) createWindow.getFellowIfAny("userRolesCombo");
appendAllUserRoles(userRolesCombo);
}
@ -168,6 +172,18 @@ public class UserCRUDController extends GenericForwardComposer implements
return userModel.getProfiles();
}
public void addSelectedProfile() {
Comboitem comboItem = profileAutocomplete.getSelectedItem();
if(comboItem != null) {
addProfile((Profile)comboItem.getValue());
}
}
public void addProfile(Profile profile) {
userModel.addProfile(profile);
Util.reloadBindings(createWindow);
}
public void removeProfile(Profile profile) {
userModel.removeProfile(profile);
Util.reloadBindings(createWindow);

View file

@ -142,4 +142,9 @@ public class UserModel implements IUserModel {
public void removeProfile(Profile profile) {
user.removeProfile(profile);
}
@Override
public void addProfile(Profile profile) {
user.addProfile(profile);
}
}

View file

@ -78,6 +78,13 @@
</rows>
</grid>
<!-- Associated Profiles -->
<hbox align="center">
<autocomplete id="profileAutocomplete"
autodrop="true" constraint=""
finder="ProfileFinder" />
<button label="${i18n:_('Add profile')}"
onClick="controller.addSelectedProfile()" />
</hbox>
<grid id="profilesListing" model="@{controller.profiles}">
<columns sizable="true">
<column label="${i18n:_('Profile name')}" />