ItEr39S19CUAltaGrupoUsuarios: First UI to list and edit Profiles.

Profiles can be edited but not saved, since the edition of roles is
not implemented yet.
This commit is contained in:
Jacobo Aragunde Pérez 2009-12-18 10:50:35 +01:00 committed by Javier Moran Rua
parent ada8a56932
commit e7de013b38
8 changed files with 467 additions and 0 deletions

View file

@ -48,6 +48,10 @@ public class Profile extends BaseEntity {
this.setRoles(roles);
}
public static Profile create() {
return create(new Profile());
}
public static Profile create(String loginName, Set<UserRole> roles) {
return create(new Profile(loginName, roles));
}

View file

@ -0,0 +1,39 @@
/*
* 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.users;
import org.navalplanner.business.users.entities.Profile;
import org.navalplanner.web.common.entrypoints.EntryPoint;
import org.navalplanner.web.common.entrypoints.EntryPoints;
@EntryPoints(page = "/users/profiles.zul", registerAs = "profileCRUD")
public interface IProfileCRUDController {
@EntryPoint("edit")
public abstract void goToEditForm(Profile profile);
@EntryPoint("create")
public abstract void goToCreateForm();
@EntryPoint("list")
public abstract void goToList();
}

View file

@ -0,0 +1,69 @@
/*
* 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.users;
import java.util.List;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.users.entities.Profile;
/**
* Model for UI operations related to {@link Profile}
*
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
*/
public interface IProfileModel {
/**
* Makes some operations needed before edit a {@link Profile}.
*
* @param profile
* The object to be edited
*/
void initEdit(Profile profile);
/**
* Makes some operations needed before create a new {@link Profile}.
*/
void initCreate();
/**
* Get all {@link Profile} elements
*
* @return
*/
List<Profile> getProfiles();
/**
* Gets the current {@link Profile}.
*
* @return A {@link Profile}
*/
Profile getProfile();
/**
* Stores the current {@link Profile}.
*
* @throws ValidationException
* If validation fails
*/
void confirmSave() throws ValidationException;
}

View file

@ -0,0 +1,132 @@
/*
* 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.users;
import static org.navalplanner.web.I18nHelper._;
import java.util.List;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.users.entities.Profile;
import org.navalplanner.web.common.ConstraintChecker;
import org.navalplanner.web.common.IMessagesForUser;
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.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.api.Window;
/**
* Controller for CRUD actions over a {@link Profile}
*
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
*/
@SuppressWarnings("serial")
public class ProfileCRUDController extends GenericForwardComposer implements
IProfileCRUDController {
private Window createWindow;
private Window listWindow;
private IProfileModel profileModel;
private OnlyOneVisible visibility;
private IMessagesForUser messagesForUser;
private Component messagesContainer;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
comp.setVariable("controller", this, true);
messagesForUser = new MessagesForUser(messagesContainer);
getVisibility().showOnly(listWindow);
}
@Override
public void goToCreateForm() {
profileModel.initCreate();
getVisibility().showOnly(createWindow);
Util.reloadBindings(createWindow);
}
@Override
public void goToEditForm(Profile profile) {
profileModel.initEdit(profile);
getVisibility().showOnly(createWindow);
Util.reloadBindings(createWindow);
}
@Override
public void goToList() {
getVisibility().showOnly(listWindow);
Util.reloadBindings(listWindow);
}
public void cancel() {
goToList();
}
public void saveAndExit() {
if (save()) {
goToList();
}
}
public void saveAndContinue() {
if (save()) {
goToEditForm(getProfile());
}
}
public boolean save() {
if(!ConstraintChecker.isValid(createWindow)) {
return false;
}
try {
profileModel.confirmSave();
messagesForUser.showMessage(Level.INFO,
_("Profile saved"));
return true;
} catch (ValidationException e) {
messagesForUser.showInvalidValues(e);
}
return false;
}
public List<Profile> getProfiles() {
return profileModel.getProfiles();
}
public Profile getProfile() {
return profileModel.getProfile();
}
private OnlyOneVisible getVisibility() {
return (visibility == null) ? new OnlyOneVisible(createWindow,
listWindow)
: visibility;
}
}

View file

@ -0,0 +1,82 @@
/*
* 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.users;
import java.util.List;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.users.daos.IProfileDAO;
import org.navalplanner.business.users.entities.Profile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Model for UI operations related to {@link Profile}
*
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
*/
@Service
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ProfileModel implements IProfileModel {
private Profile profile;
@Autowired
private IProfileDAO profileDAO;
@Override
@Transactional
public void confirmSave() throws ValidationException {
profileDAO.save(profile);
}
@Override
@Transactional(readOnly=true)
public List<Profile> getProfiles() {
return profileDAO.list(Profile.class);
}
@Override
public Profile getProfile() {
return profile;
}
@Override
@Transactional(readOnly = true)
public void initCreate() {
profile = Profile.create();
}
@Override
public void initEdit(Profile profile) {
try {
this.profile = profileDAO.find(profile.getId());
}
catch (InstanceNotFoundException e) {
initCreate();
}
}
}

View file

@ -0,0 +1,58 @@
<!--
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/>.
-->
<?taglib uri="/WEB-INF/tld/i18n.tld" prefix="i18n" ?>
<window id="${arg.top_id}" title="${i18n:_('Edit profile')}">
<tabbox>
<tabs>
<tab label="${i18n:_('Profile data')}"></tab>
</tabs>
<tabpanels>
<tabpanel>
<vbox>
<!-- Type of work hour details -->
<grid fixedLayout="false">
<columns>
<column width="200px" />
<column />
</columns>
<rows>
<row>
<label value="${i18n:_('Name')}:" />
<textbox id="name"
value="@{controller.profile.profileName}" width="300px"
constraint="no empty:${i18n:_('cannot be null or empty')}"/>
</row>
</rows>
</grid>
</vbox>
</tabpanel>
</tabpanels>
</tabbox>
<button onClick="controller.saveAndExit();"
label="${i18n:_('Save')}" sclass="save-button global-action" />
<button onClick="controller.saveAndContinue();"
label="${i18n:_('Save &amp; Continue')}" sclass="saveandcontinue-button global-action" />
<button onClick="controller.cancel();"
label="${i18n:_('Cancel')}" sclass="cancel-button global-action" />
</window>

View file

@ -0,0 +1,45 @@
<!--
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/>.
-->
<window id="${arg.top_id}" title="${i18n:_('Profiles listing')}">
<newdatasortablegrid id="listing" model="@{controller.profiles}" mold="paging"
pageSize="10">
<columns sizable="true">
<newdatasortablecolumn label="${i18n:_('Profile name')}" sort="auto(profileName)" />
<newdatasortablecolumn label="${i18n:_('Actions')}" />
</columns>
<rows>
<row self="@{each='profile'}" value="@{profile}">
<label value="@{profile.profileName}" />
<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>
</hbox>
</row>
</rows>
</newdatasortablegrid>
<button id="show_create_form" onClick="controller.goToCreateForm();"
label="${i18n:_('Create')}" sclass="create-button global-action" >
</button>
</window>

View file

@ -0,0 +1,38 @@
<!--
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/>.
-->
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?page id="work_report_admin"?>
<?init class="org.zkoss.zk.ui.util.Composition" arg0="/common/layout/template.zul"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_v01.css"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_zk.css"?>
<?link rel="stylesheet" type="text/css" href="/resources/css/resources.css"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?component name="list" inline="true" macroURI="_listProfiles.zul"?>
<?component name="edition" inline="true" macroURI="_editProfile.zul"?>
<zk>
<window self="@{define(content)}"
apply="org.navalplanner.web.users.ProfileCRUDController">
<vbox id="messagesContainer"></vbox>
<list top_id="listWindow" />
<edition top_id="createWindow" />
</window>
</zk>