ItEr49S04ValidacionEProbasFuncionaisItEr48S04: [Bug #359] Fixed bug. Just allow to remove advance types not used.
This commit is contained in:
parent
67c9aa462e
commit
c1ad372bdb
7 changed files with 113 additions and 74 deletions
|
|
@ -24,6 +24,7 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.advance.entities.AdvanceAssignment;
|
||||
import org.navalplanner.business.advance.entities.AdvanceType;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -61,4 +62,11 @@ public class AdvanceTypeDAO extends GenericDAOHibernate<AdvanceType, Long>
|
|||
public Collection<? extends AdvanceType> getAll() {
|
||||
return list(AdvanceType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlreadyInUse(AdvanceType advanceType) {
|
||||
return !getSession().createCriteria(AdvanceAssignment.class).add(
|
||||
Restrictions.eq("advanceType", advanceType)).list().isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,4 +40,6 @@ public interface IAdvanceTypeDAO extends IGenericDAO<AdvanceType, Long>{
|
|||
|
||||
public Collection<? extends AdvanceType> getAll();
|
||||
|
||||
public boolean isAlreadyInUse(AdvanceType advanceType);
|
||||
|
||||
}
|
||||
|
|
@ -35,9 +35,17 @@ import org.navalplanner.web.common.OnlyOneVisible;
|
|||
import org.navalplanner.web.common.Util;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Checkbox;
|
||||
import org.zkoss.zul.Constraint;
|
||||
import org.zkoss.zul.api.Window;
|
||||
import org.zkoss.zul.Hbox;
|
||||
import org.zkoss.zul.Label;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.RowRenderer;
|
||||
|
||||
/**
|
||||
* Controller for CRUD actions over a {@link AdvanceType}
|
||||
|
|
@ -58,10 +66,6 @@ public class AdvanceTypeCRUDController extends GenericForwardComposer {
|
|||
|
||||
private Component listWindow;
|
||||
|
||||
private Window confirmRemove;
|
||||
|
||||
private boolean confirmingRemove = false;
|
||||
|
||||
private IAdvanceTypeModel advanceTypeModel;
|
||||
|
||||
private OnlyOneVisible visibility;
|
||||
|
|
@ -168,43 +172,23 @@ public class AdvanceTypeCRUDController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public void confirmRemove(AdvanceType advanceType) {
|
||||
advanceTypeModel.prepareForRemove(advanceType);
|
||||
showConfirmingWindow();
|
||||
}
|
||||
|
||||
public void cancelRemove() {
|
||||
confirmingRemove = false;
|
||||
confirmRemove.setVisible(false);
|
||||
Util.reloadBindings(confirmRemove);
|
||||
}
|
||||
|
||||
public boolean isConfirmingRemove() {
|
||||
return confirmingRemove;
|
||||
}
|
||||
|
||||
private void hideConfirmingWindow() {
|
||||
confirmingRemove = false;
|
||||
Util.reloadBindings(confirmRemove);
|
||||
}
|
||||
|
||||
private void showConfirmingWindow() {
|
||||
confirmingRemove = true;
|
||||
try {
|
||||
Util.reloadBindings(confirmRemove);
|
||||
confirmRemove.doModal();
|
||||
} catch (Exception e) {
|
||||
int status = Messagebox.show(_(
|
||||
"Confirm deleting {0}. Are you sure?", advanceType
|
||||
.getUnitName()), "Remove", Messagebox.OK
|
||||
| Messagebox.CANCEL, Messagebox.QUESTION);
|
||||
if (Messagebox.OK == status) {
|
||||
advanceTypeModel.prepareForRemove(advanceType);
|
||||
advanceTypeModel.remove(advanceType);
|
||||
}
|
||||
Util.reloadBindings(listWindow);
|
||||
messagesForUser.showMessage(Level.INFO, _("Removed {0}",
|
||||
advanceType.getUnitName()));
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(AdvanceType advanceType) {
|
||||
advanceTypeModel.remove(advanceType);
|
||||
hideConfirmingWindow();
|
||||
Util.reloadBindings(listWindow);
|
||||
messagesForUser.showMessage(
|
||||
Level.INFO, _("Removed {0}", advanceType.getUnitName()));
|
||||
}
|
||||
|
||||
public void goToCreateForm() {
|
||||
advanceTypeModel.prepareForCreate();
|
||||
getVisibility().showOnly(createWindow);
|
||||
|
|
@ -264,4 +248,69 @@ public class AdvanceTypeCRUDController extends GenericForwardComposer {
|
|||
return advanceTypeModel.isImmutable();
|
||||
}
|
||||
|
||||
public boolean isImmutableOrAlreadyInUse(AdvanceType advanceType) {
|
||||
return advanceTypeModel.isImmutableOrAlreadyInUse(advanceType);
|
||||
}
|
||||
|
||||
public RowRenderer getAdvanceTypeRenderer() {
|
||||
return new RowRenderer() {
|
||||
|
||||
@Override
|
||||
public void render(Row row, Object data) throws Exception {
|
||||
AdvanceType advanceType = (AdvanceType) data;
|
||||
|
||||
appendLabelName(row, advanceType);
|
||||
appendCheckboxEnabled(row, advanceType);
|
||||
appendCheckboxPredefined(row, advanceType);
|
||||
appendOperations(row, advanceType);
|
||||
}
|
||||
|
||||
private void appendLabelName(Row row, AdvanceType advanceType) {
|
||||
row.appendChild(new Label(advanceType.getUnitName()));
|
||||
}
|
||||
|
||||
private void appendCheckboxEnabled(Row row, AdvanceType advanceType) {
|
||||
Checkbox checkbox = new Checkbox();
|
||||
checkbox.setChecked(advanceType.getActive());
|
||||
checkbox.setDisabled(true);
|
||||
row.appendChild(checkbox);
|
||||
}
|
||||
|
||||
private void appendCheckboxPredefined(Row row,
|
||||
AdvanceType advanceType) {
|
||||
Checkbox checkbox = new Checkbox();
|
||||
checkbox.setChecked(advanceType.isImmutable());
|
||||
checkbox.setDisabled(true);
|
||||
row.appendChild(checkbox);
|
||||
}
|
||||
|
||||
private void appendOperations(Row row, final AdvanceType advanceType) {
|
||||
Hbox hbox = new Hbox();
|
||||
|
||||
hbox.appendChild(Util.createEditButton(new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
goToEditForm(advanceType);
|
||||
}
|
||||
}));
|
||||
|
||||
Button removeButton = Util
|
||||
.createRemoveButton(new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
confirmRemove(advanceType);
|
||||
}
|
||||
});
|
||||
removeButton.setDisabled(advanceTypeModel
|
||||
.isImmutableOrAlreadyInUse(advanceType));
|
||||
hbox.appendChild(removeButton);
|
||||
|
||||
row.appendChild(hbox);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,4 +184,17 @@ public class AdvanceTypeModel implements IAdvanceTypeModel {
|
|||
return advanceType.isImmutable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public boolean isImmutableOrAlreadyInUse(AdvanceType advanceType) {
|
||||
if (advanceType == null) {
|
||||
return false;
|
||||
}
|
||||
if (advanceType.isImmutable()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return advanceTypeDAO.isAlreadyInUse(advanceType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,4 +125,6 @@ public interface IAdvanceTypeModel {
|
|||
Boolean getPercentage();
|
||||
|
||||
boolean isImmutable();
|
||||
|
||||
boolean isImmutableOrAlreadyInUse(AdvanceType advanceType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,32 +20,14 @@
|
|||
|
||||
<window id="${arg.top_id}" title="${i18n:_('Advance type list')}">
|
||||
<newdatasortablegrid id="listing" model="@{controller.advanceTypes}" mold="paging"
|
||||
pageSize="10" fixedLayout="true">
|
||||
pageSize="10" fixedLayout="true"
|
||||
rowRenderer="@{controller.advanceTypeRenderer}" >
|
||||
<columns>
|
||||
<newdatasortablecolumn label="${i18n:_('Name')}" sort="auto(unitName)"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Enabled')}"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Predefined')}"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Operations')}"/>
|
||||
|
||||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='advanceType'}" value="@{advanceType}">
|
||||
<label value="@{advanceType.unitName}"/>
|
||||
<checkbox checked="@{advanceType.active}" disabled="true" />
|
||||
<checkbox checked="@{advanceType.immutable}" disabled="true" />
|
||||
<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')}" disabled="@{advanceType.immutable}" onClick="controller.confirmRemove(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">
|
||||
|
|
|
|||
|
|
@ -39,22 +39,5 @@
|
|||
<edition top_id="editWindow" title="${i18n:_('Edit advance type data')}"
|
||||
save_button_label="${i18n:_('Save')}" cancel_button_label="${i18n:_('Cancel')}"
|
||||
save_and_continue_button_label="${i18n:_('Save & Continue')}" />
|
||||
<window visible="@{controller.confirmingRemove}"
|
||||
id="confirmRemove" title="${i18n:_('Confirm')}" sizable="true"
|
||||
position="center">
|
||||
<vbox align = "center">
|
||||
<hbox align = "center">
|
||||
<label value = "Confirm deleting"/>
|
||||
<label value ="@{controller.advanceType.unitName}"/>
|
||||
<label value = "?"/>
|
||||
</hbox>
|
||||
<hbox align = "center">
|
||||
<button label="${i18n:_('Yes')}"
|
||||
onClick="controller.remove(controller.advanceType);" />
|
||||
<button label="${i18n:_('No')}"
|
||||
onClick="controller.cancelRemove();" />
|
||||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
||||
</window>
|
||||
</zk>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue