[Bug #785] Add improvements in companies list.
it sorts the list by company name. it changes a label by other one to facilitate the understanding. it adds the delete operation of a company with some constraints. FEA : ItEr67S04BugFixing
This commit is contained in:
parent
1b637c7513
commit
e3c615ed80
7 changed files with 204 additions and 20 deletions
|
|
@ -27,6 +27,8 @@ import org.hibernate.criterion.Restrictions;
|
|||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.planner.entities.SubcontractedTaskData;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -136,4 +138,19 @@ public class ExternalCompanyDAO extends GenericDAOHibernate<ExternalCompany, Lon
|
|||
return c.list();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlreadyInUse(ExternalCompany company) {
|
||||
if (company.isNewObject()) {
|
||||
return false;
|
||||
}
|
||||
boolean usedInOrders = !getSession().createCriteria(Order.class).add(
|
||||
Restrictions.eq("customer", company)).list()
|
||||
.isEmpty();
|
||||
boolean usedInSubcontratedTask = !getSession().createCriteria(
|
||||
SubcontractedTaskData.class).add(
|
||||
Restrictions.eq("externalCompany", company)).list().isEmpty();
|
||||
return usedInOrders || usedInSubcontratedTask;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,4 +56,6 @@ public interface IExternalCompanyDAO extends IGenericDAO<ExternalCompany, Long>
|
|||
List<ExternalCompany> getAll();
|
||||
|
||||
List<ExternalCompany> getExternalCompaniesAreClient();
|
||||
|
||||
boolean isAlreadyInUse(ExternalCompany company);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,10 @@ package org.navalplanner.web.externalcompanies;
|
|||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.navalplanner.business.users.entities.User;
|
||||
|
|
@ -36,19 +38,24 @@ 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.Column;
|
||||
import org.zkoss.zul.Comboitem;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
/**
|
||||
* Controller for CRUD actions over a {@link User}
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ExternalCompanyCRUDController extends GenericForwardComposer
|
||||
implements IExternalCompanyCRUDController {
|
||||
|
||||
private static final org.apache.commons.logging.Log LOG = LogFactory
|
||||
.getLog(ExternalCompanyCRUDController.class);
|
||||
|
||||
private IExternalCompanyModel externalCompanyModel;
|
||||
|
||||
private Window createWindow;
|
||||
|
|
@ -75,7 +82,8 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
getVisibility().showOnly(listWindow);
|
||||
appURI = (Textbox) createWindow.getFellow("appURI");
|
||||
ourCompanyLogin = (Textbox) createWindow.getFellow("ourCompanyLogin");
|
||||
ourCompanyPassword = (Textbox) createWindow.getFellow("ourCompanyPassword");
|
||||
ourCompanyPassword = (Textbox) createWindow
|
||||
.getFellow("ourCompanyPassword");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -83,7 +91,8 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
externalCompanyModel.initCreate();
|
||||
createWindow.setTitle(_("Create Company"));
|
||||
getVisibility().showOnly(createWindow);
|
||||
setInteractionFieldsActivation(getCompany().getInteractsWithApplications());
|
||||
setInteractionFieldsActivation(getCompany()
|
||||
.getInteractsWithApplications());
|
||||
clearAutocompleteUser();
|
||||
Util.reloadBindings(createWindow);
|
||||
}
|
||||
|
|
@ -95,6 +104,10 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
}
|
||||
}
|
||||
|
||||
public void goToEditForm(ExternalCompanyDTO dto) {
|
||||
goToEditForm(dto.getCompany());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToEditForm(ExternalCompany company) {
|
||||
externalCompanyModel.initEdit(company);
|
||||
|
|
@ -105,6 +118,41 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
Util.reloadBindings(createWindow);
|
||||
}
|
||||
|
||||
public void confirmRemove(ExternalCompanyDTO dto) {
|
||||
try {
|
||||
int status = Messagebox.show(_(
|
||||
"Confirm deleting {0}. Are you sure?", dto.getCompany()
|
||||
.getName()), _("Delete"), Messagebox.OK
|
||||
| Messagebox.CANCEL, Messagebox.QUESTION);
|
||||
if (Messagebox.OK == status) {
|
||||
goToDelete(dto);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
messagesForUser.showMessage(Level.ERROR, e.getMessage());
|
||||
LOG.error(_("Error on showing removing element: ", dto.getCompany()
|
||||
.getId()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void goToDelete(ExternalCompanyDTO dto) {
|
||||
ExternalCompany company = dto.getCompany();
|
||||
boolean alreadyInUse = externalCompanyModel.isAlreadyInUse(company);
|
||||
if (alreadyInUse) {
|
||||
messagesForUser
|
||||
.showMessage(
|
||||
Level.ERROR,
|
||||
_(
|
||||
"You can not remove the company \"{0}\" because is already in use in some project or in some subcontrated task.",
|
||||
company.getName()));
|
||||
} else {
|
||||
externalCompanyModel.deleteCompany(dto.getCompany());
|
||||
Util.reloadBindings(self);
|
||||
messagesForUser.showMessage(Level.INFO, _("Removed {0}", company
|
||||
.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToList() {
|
||||
getVisibility().showOnly(listWindow);
|
||||
|
|
@ -128,13 +176,12 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
}
|
||||
|
||||
public boolean save() {
|
||||
if(!ConstraintChecker.isValid(createWindow)) {
|
||||
if (!ConstraintChecker.isValid(createWindow)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
externalCompanyModel.confirmSave();
|
||||
messagesForUser.showMessage(Level.INFO,
|
||||
_("Company saved"));
|
||||
messagesForUser.showMessage(Level.INFO, _("Company saved"));
|
||||
return true;
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e);
|
||||
|
|
@ -146,6 +193,14 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
return externalCompanyModel.getCompanies();
|
||||
}
|
||||
|
||||
public List<ExternalCompanyDTO> getCompaniesDTO() {
|
||||
List<ExternalCompanyDTO> result = new ArrayList<ExternalCompanyDTO>();
|
||||
for (ExternalCompany company : getCompanies()) {
|
||||
result.add(new ExternalCompanyDTO(company));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ExternalCompany getCompany() {
|
||||
return externalCompanyModel.getCompany();
|
||||
}
|
||||
|
|
@ -153,17 +208,15 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
public void setCompanyUser(Comboitem selectedItem) {
|
||||
if (selectedItem != null) {
|
||||
externalCompanyModel.setCompanyUser((User) selectedItem.getValue());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
externalCompanyModel.setCompanyUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInteractionFieldsActivation(boolean active) {
|
||||
if(active) {
|
||||
if (active) {
|
||||
enableInteractionFields();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
disableInteractionFields();
|
||||
}
|
||||
}
|
||||
|
|
@ -173,8 +226,10 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
ourCompanyLogin.setDisabled(false);
|
||||
ourCompanyPassword.setDisabled(false);
|
||||
appURI.setConstraint("no empty:" + _("cannot be null or empty"));
|
||||
ourCompanyLogin.setConstraint("no empty:" + _("cannot be null or empty"));
|
||||
ourCompanyPassword.setConstraint("no empty:" + _("cannot be null or empty"));
|
||||
ourCompanyLogin.setConstraint("no empty:"
|
||||
+ _("cannot be null or empty"));
|
||||
ourCompanyPassword.setConstraint("no empty:"
|
||||
+ _("cannot be null or empty"));
|
||||
}
|
||||
|
||||
private void disableInteractionFields() {
|
||||
|
|
@ -188,7 +243,19 @@ public class ExternalCompanyCRUDController extends GenericForwardComposer
|
|||
|
||||
private OnlyOneVisible getVisibility() {
|
||||
return (visibility == null) ? new OnlyOneVisible(createWindow,
|
||||
listWindow)
|
||||
: visibility;
|
||||
listWindow) : visibility;
|
||||
}
|
||||
|
||||
public void sortByDefaultByName() {
|
||||
Column column = (Column) listWindow.getFellowIfAny("columnName");
|
||||
if (column != null) {
|
||||
if (column.getSortDirection().equals("ascending")) {
|
||||
column.sort(false, false);
|
||||
column.setSortDirection("ascending");
|
||||
} else if (column.getSortDirection().equals("descending")) {
|
||||
column.sort(true, false);
|
||||
column.setSortDirection("descending");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2010 Wireless Galicia 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
|
||||
* 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.externalcompanies;
|
||||
|
||||
import org.navalplanner.business.externalcompanies.entities.ExternalCompany;
|
||||
|
||||
/**
|
||||
* DTO for ExternalCompany
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public class ExternalCompanyDTO {
|
||||
|
||||
private ExternalCompany company;
|
||||
|
||||
public ExternalCompany getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public ExternalCompanyDTO(ExternalCompany company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return company.getName();
|
||||
}
|
||||
|
||||
public String getNif() {
|
||||
return company.getNif();
|
||||
}
|
||||
|
||||
public Boolean getClient() {
|
||||
return company.isClient();
|
||||
}
|
||||
|
||||
public Boolean getSubcontractor() {
|
||||
return company.isSubcontractor();
|
||||
}
|
||||
|
||||
public String getCompanyUser() {
|
||||
return (company.getCompanyUser() != null) ? company.getCompanyUser()
|
||||
.getLoginName() : "---";
|
||||
}
|
||||
}
|
||||
|
|
@ -115,4 +115,20 @@ public class ExternalCompanyModel implements IExternalCompanyModel {
|
|||
externalCompany.setCompanyUser(companyUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteCompany(ExternalCompany company) {
|
||||
try {
|
||||
externalCompanyDAO.remove(company.getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public boolean isAlreadyInUse(ExternalCompany company) {
|
||||
return externalCompanyDAO.isAlreadyInUse(company);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,4 +76,19 @@ public interface IExternalCompanyModel {
|
|||
* @param companyUser
|
||||
*/
|
||||
void setCompanyUser(User companyUser);
|
||||
|
||||
/**
|
||||
* Delete the selected {@link ExternalCompany} object.
|
||||
* @param company
|
||||
* The object to be deleted
|
||||
* @return true if the {@link ExternalCompany} has been deleted correctly.
|
||||
*/
|
||||
boolean deleteCompany(ExternalCompany company);
|
||||
|
||||
/**
|
||||
* Check out if the company has been already used.
|
||||
* @param company
|
||||
* @return true if the company has been already used.
|
||||
*/
|
||||
boolean isAlreadyInUse(ExternalCompany company);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,15 @@
|
|||
-->
|
||||
|
||||
<window id="${arg.top_id}" title="${i18n:_('Companies List')}">
|
||||
<newdatasortablegrid id="listing" model="@{controller.companies}" mold="paging"
|
||||
pageSize="10">
|
||||
<newdatasortablegrid id="listing" model="@{controller.companiesDTO}" mold="paging"
|
||||
pageSize="10"
|
||||
onInitRender="controller.sortByDefaultByName();">
|
||||
<columns sizable="true">
|
||||
<newdatasortablecolumn label="${i18n:_('Name')}" sort="auto(lower(name))" />
|
||||
<newdatasortablecolumn id="columnName" label="${i18n:_('Name')}" sort="auto(lower(name))" sortDirection="descending"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Company ID')}" />
|
||||
<newdatasortablecolumn label="${i18n:_('Client')}" />
|
||||
<newdatasortablecolumn label="${i18n:_('Subcontractor')}" />
|
||||
<newdatasortablecolumn label="${i18n:_('Integrated user')}" />
|
||||
<newdatasortablecolumn label="${i18n:_('Associated user')}" />
|
||||
<newdatasortablecolumn label="${i18n:_('Actions')}" />
|
||||
</columns>
|
||||
<rows>
|
||||
|
|
@ -35,13 +36,18 @@
|
|||
<label value="@{company.nif}" />
|
||||
<checkbox checked="@{company.client}" disabled="true" />
|
||||
<checkbox checked="@{company.subcontractor}" disabled="true" />
|
||||
<label value="@{company.companyUser.loginName}" />
|
||||
<label value="@{company.companyUser}" />
|
||||
<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.confirmRemove(self.parent.parent.value)">
|
||||
</button>
|
||||
</hbox>
|
||||
</row>
|
||||
</rows>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue