Manage entity 'Calendar Exception Type'.
* Adds a new entry at Administration->Data Type->Exception Day Types for managing 'Calendar Exception Types' * Adds a new field 'duration' to entity CalendarExceptionType * Modifies Calendar managing, so when a CalendarExceptionType is selected its field duration is set to the number of hours assigned to selected CalendarExceptionType FEA: ItEr61S06ExceptionTypeEntity
This commit is contained in:
parent
04fe46a0ab
commit
fd6f652f54
16 changed files with 766 additions and 16 deletions
|
|
@ -22,18 +22,24 @@ package org.navalplanner.business.calendars.daos;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.calendars.entities.CalendarException;
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.common.daos.IntegrationEntityDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* DAO for {@link CalendarExceptionType}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
|
|
@ -50,4 +56,56 @@ public class CalendarExceptionTypeDAO extends
|
|||
return (list.size() == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CalendarExceptionType> getAll() {
|
||||
return list(CalendarExceptionType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCalendarExceptions(CalendarExceptionType type) {
|
||||
return !getCalendarExceptions(type).isEmpty();
|
||||
}
|
||||
|
||||
private List<CalendarException> getCalendarExceptions(CalendarExceptionType type) {
|
||||
Criteria c = getSession().createCriteria(CalendarException.class);
|
||||
c.add(Restrictions.eq("type.id", type.getId()));
|
||||
return c.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean existsByNameAnotherTransaction(String name) {
|
||||
return existsByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByName(String name) {
|
||||
try {
|
||||
findByName(name);
|
||||
return true;
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public CalendarExceptionType findByName(String name) throws InstanceNotFoundException {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
throw new InstanceNotFoundException(null, CalendarExceptionType.class.getName());
|
||||
}
|
||||
|
||||
CalendarExceptionType calendarExceptionType = (CalendarExceptionType) getSession().createCriteria(
|
||||
CalendarExceptionType.class).add(
|
||||
Restrictions.eq("name", name.trim()).ignoreCase())
|
||||
.uniqueResult();
|
||||
|
||||
if (calendarExceptionType == null) {
|
||||
throw new InstanceNotFoundException(name, CalendarExceptionType.class.getName());
|
||||
} else {
|
||||
return calendarExceptionType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,31 @@
|
|||
|
||||
package org.navalplanner.business.calendars.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
|
||||
/**
|
||||
* Contract for {@link CalendarExceptionTypeDAO}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*/
|
||||
public interface ICalendarExceptionTypeDAO extends
|
||||
IIntegrationEntityDAO<CalendarExceptionType> {
|
||||
|
||||
boolean existsByName(CalendarExceptionType type);
|
||||
|
||||
List<CalendarExceptionType> getAll();
|
||||
|
||||
boolean hasCalendarExceptions(CalendarExceptionType type);
|
||||
|
||||
boolean existsByNameAnotherTransaction(String name);
|
||||
|
||||
CalendarExceptionType findByName(String name) throws InstanceNotFoundException;
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,19 @@
|
|||
|
||||
package org.navalplanner.business.calendars.entities;
|
||||
|
||||
import static org.navalplanner.business.i18n.I18nHelper._;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.navalplanner.business.calendars.daos.ICalendarExceptionTypeDAO;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.EffortDuration.Granularity;
|
||||
|
||||
/**
|
||||
* Type of an exception day.
|
||||
|
|
@ -32,6 +41,20 @@ import org.navalplanner.business.common.Registry;
|
|||
*/
|
||||
public class CalendarExceptionType extends IntegrationEntity {
|
||||
|
||||
private String name;
|
||||
|
||||
private String color;
|
||||
|
||||
// Beware. Not Assignable was intended to mean not over assignable. This
|
||||
// name is kept in order to not break legacy data
|
||||
private Boolean notAssignable = Boolean.TRUE;
|
||||
|
||||
private EffortDuration duration = EffortDuration.zero();
|
||||
|
||||
public static CalendarExceptionType create() {
|
||||
return create(new CalendarExceptionType());
|
||||
}
|
||||
|
||||
public static CalendarExceptionType create(String name, String color,
|
||||
Boolean notAssignable) {
|
||||
return create(new CalendarExceptionType(name, color, notAssignable));
|
||||
|
|
@ -43,17 +66,11 @@ public class CalendarExceptionType extends IntegrationEntity {
|
|||
code);
|
||||
}
|
||||
|
||||
private String name;
|
||||
private String color;
|
||||
|
||||
// Beware. Not Assignable was intended to mean not over assignable. This
|
||||
// name is kept in order to not break legacy data
|
||||
private Boolean notAssignable;
|
||||
|
||||
/**
|
||||
* Constructor for hibernate. Do not use!
|
||||
*/
|
||||
public CalendarExceptionType() {
|
||||
protected CalendarExceptionType() {
|
||||
|
||||
}
|
||||
|
||||
public CalendarExceptionType(String name, String color,
|
||||
|
|
@ -67,10 +84,18 @@ public class CalendarExceptionType extends IntegrationEntity {
|
|||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If more hours can be assigned on this day.
|
||||
*/
|
||||
|
|
@ -78,8 +103,53 @@ public class CalendarExceptionType extends IntegrationEntity {
|
|||
return BooleanUtils.isFalse(notAssignable);
|
||||
}
|
||||
|
||||
public void setOverAssignable(Boolean overAssignable) {
|
||||
this.notAssignable = !overAssignable;
|
||||
}
|
||||
|
||||
public String getOverAssignableStr() {
|
||||
return isOverAssignable() ? _("Yes") : _("No");
|
||||
}
|
||||
|
||||
public EffortDuration getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public String getDurationStr() {
|
||||
EnumMap<Granularity, Integer> values = duration.decompose();
|
||||
Integer hours = values.get(Granularity.HOURS);
|
||||
Integer minutes = values.get(Granularity.MINUTES);
|
||||
Integer seconds = values.get(Granularity.SECONDS);
|
||||
return hours + ":" + minutes + ":" + seconds ;
|
||||
}
|
||||
|
||||
public void setDuration(EffortDuration duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ICalendarExceptionTypeDAO getIntegrationEntityDAO() {
|
||||
return Registry.getCalendarExceptionTypeDAO();
|
||||
}
|
||||
|
||||
@AssertTrue(message = "name is already used")
|
||||
public boolean checkConstraintUniqueName() {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ICalendarExceptionTypeDAO calendarExceptionTypeDAO = getIntegrationEntityDAO();
|
||||
if (isNewObject()) {
|
||||
return !calendarExceptionTypeDAO.existsByNameAnotherTransaction(
|
||||
name);
|
||||
} else {
|
||||
try {
|
||||
CalendarExceptionType calendarExceptionType = calendarExceptionTypeDAO.findByName(name);
|
||||
return calendarExceptionType.getId().equals(getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
package org.navalplanner.business.calendars.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Defines the default {@link CalendarExceptionType}.
|
||||
|
|
@ -46,4 +49,14 @@ public enum PredefinedCalendarExceptionTypes {
|
|||
return calendarExceptionType;
|
||||
}
|
||||
|
||||
public static boolean contains(CalendarExceptionType exceptionType) {
|
||||
PredefinedCalendarExceptionTypes[] predefinedExceptionTypes = PredefinedCalendarExceptionTypes.values();
|
||||
for (PredefinedCalendarExceptionTypes each: predefinedExceptionTypes) {
|
||||
if (each.getCalendarExceptionType().getName().equals(exceptionType.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,4 +243,8 @@ public class EffortDuration implements Comparable<EffortDuration> {
|
|||
return hours;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getHours() + ":" + getMinutes() + ":" + getSeconds();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,10 +78,11 @@
|
|||
|
||||
<property name="code" access="property" not-null="true" unique="true"/>
|
||||
|
||||
<property name="name" access="field" unique="true" />
|
||||
<property name="color" access="field"/>
|
||||
<property name="notAssignable" access="field"/>
|
||||
<property name="name" unique="true" />
|
||||
<property name="color" />
|
||||
<property name="notAssignable" />
|
||||
|
||||
<property name="duration" type="org.navalplanner.business.workingday.hibernate.EffortDurationType"/>
|
||||
</class>
|
||||
|
||||
<!-- CalendarData -->
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ 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.event.Events;
|
||||
import org.zkoss.zk.ui.event.SelectEvent;
|
||||
import org.zkoss.zk.ui.util.Clients;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Button;
|
||||
|
|
@ -136,10 +137,34 @@ public abstract class BaseCalendarEditionController extends
|
|||
private EffortDurationPicker addEffortDurationPickerAtWorkableTimeRow(
|
||||
Component comp) {
|
||||
EffortDurationPicker result = ensureOnePickerOn(comp);
|
||||
result.setValue(EffortDuration.zero());
|
||||
setEffortDurationPicker(getSelectedExceptionType());
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setEffortDurationPicker(CalendarExceptionType exceptionType) {
|
||||
EffortDurationPicker durationPicker = getEffortDurationPicker();
|
||||
EffortDuration effortDuration = exceptionType != null ? exceptionType
|
||||
.getDuration() : EffortDuration.zero();
|
||||
durationPicker.setValue(effortDuration);
|
||||
}
|
||||
|
||||
private EffortDurationPicker getEffortDurationPicker() {
|
||||
Component container = self.getFellowIfAny("exceptionDayWorkableTimeRow");
|
||||
List<EffortDurationPicker> existent = ComponentsFinder
|
||||
.findComponentsOfType(EffortDurationPicker.class,
|
||||
container.getChildren());
|
||||
return !existent.isEmpty() ? (EffortDurationPicker) existent
|
||||
.iterator().next() : null;
|
||||
}
|
||||
|
||||
private CalendarExceptionType getSelectedExceptionType() {
|
||||
Comboitem selectedItem = exceptionTypes.getSelectedItem();
|
||||
if (selectedItem != null) {
|
||||
return (CalendarExceptionType) selectedItem.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private EffortDurationPicker ensureOnePickerOn(Component comp) {
|
||||
Component container = comp.getFellow("exceptionDayWorkableTimeRow");
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -155,13 +180,36 @@ public abstract class BaseCalendarEditionController extends
|
|||
}
|
||||
}
|
||||
|
||||
private Combobox exceptionTypes;
|
||||
|
||||
private void prepareExceptionTypeCombo() {
|
||||
Combobox exceptionTypes = (Combobox) window
|
||||
.getFellow("exceptionTypes");
|
||||
fillExceptionTypesComboAndMakrSelectedItem(exceptionTypes);
|
||||
exceptionTypes = (Combobox) window.getFellow("exceptionTypes");
|
||||
fillExceptionTypesComboAndMarkSelectedItem(exceptionTypes);
|
||||
addSelectListener(exceptionTypes);
|
||||
}
|
||||
|
||||
private void fillExceptionTypesComboAndMakrSelectedItem(
|
||||
private void addSelectListener(final Combobox exceptionTypes) {
|
||||
exceptionTypes.addEventListener(Events.ON_SELECT, new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
Comboitem selectedItem = getSelectedItem((SelectEvent) event);
|
||||
if (selectedItem != null) {
|
||||
setEffortDurationPicker(getValue(selectedItem));
|
||||
}
|
||||
}
|
||||
|
||||
private Comboitem getSelectedItem(SelectEvent event) {
|
||||
return (Comboitem) event.getSelectedItems().iterator().next();
|
||||
}
|
||||
|
||||
private CalendarExceptionType getValue(Comboitem item) {
|
||||
return (CalendarExceptionType) item.getValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fillExceptionTypesComboAndMarkSelectedItem(
|
||||
Combobox exceptionTypes) {
|
||||
exceptionTypes.getChildren().clear();
|
||||
CalendarExceptionType type = baseCalendarModel
|
||||
|
|
|
|||
|
|
@ -263,6 +263,7 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
|
|||
subItem(_("Data Types"),"/advance/advanceTypes.zul", "04-avances.html#id1",
|
||||
subItem(_("Advances"),"/advance/advanceTypes.zul", "04-avances.html#id1"),
|
||||
subItem(_("Criteria"),"/resources/criterions/criterions.zul","02-criterios.html#id1"),
|
||||
subItem(_("Exception Days"),"/excetiondays/exceptionDays.zul",""),
|
||||
subItem(_("Labels"), "/labels/labelTypes.zul","10-etiquetas.html"),
|
||||
subItem(_("Unit Measures"), "/materials/unitTypes.zul", "11-materiales.html#administraci-n-de-materiais"),
|
||||
subItem(_("Work Hours"),"/costcategories/typeOfWorkHours.zul","14-custos.html#administraci-n-de-horas-traballadas"),
|
||||
|
|
|
|||
|
|
@ -135,6 +135,9 @@ public class EffortDurationPicker extends Hbox {
|
|||
}
|
||||
|
||||
public void setValue(EffortDuration effortDuration) {
|
||||
if (effortDuration == null) {
|
||||
effortDuration = EffortDuration.zero();
|
||||
}
|
||||
updateUIWithValuesFrom(effortDuration);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,237 @@
|
|||
package org.navalplanner.web.exceptionDays;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.calendars.entities.PredefinedCalendarExceptionTypes;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
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.navalplanner.web.common.components.EffortDurationPicker;
|
||||
import org.navalplanner.web.common.components.NewDataSortableGrid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.zkoss.util.InvalidValueException;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.MouseEvent;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Checkbox;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class CalendarExceptionTypeCRUDController extends GenericForwardComposer {
|
||||
|
||||
private static final org.apache.commons.logging.Log LOG = LogFactory
|
||||
.getLog(CalendarExceptionTypeCRUDController.class);
|
||||
|
||||
@Autowired
|
||||
private ICalendarExceptionTypeModel calendarExceptionTypeModel;
|
||||
|
||||
private Window listWindow;
|
||||
|
||||
private Window editWindow;
|
||||
|
||||
private Textbox tbName;
|
||||
|
||||
private Textbox tbColor;
|
||||
|
||||
private Checkbox cbNotOverAssignable;
|
||||
|
||||
private EffortDurationPicker edpDuration;
|
||||
|
||||
private OnlyOneVisible visibility;
|
||||
|
||||
private IMessagesForUser messagesForUser;
|
||||
|
||||
private Component messagesContainer;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
messagesForUser = new MessagesForUser(messagesContainer);
|
||||
comp.setVariable("controller", this, true);
|
||||
initializeEditWindowComponents();
|
||||
showListWindow();
|
||||
}
|
||||
|
||||
private void initializeEffortDurationPicker() {
|
||||
final CalendarExceptionType exceptionType = getExceptionDayType();
|
||||
edpDuration = (EffortDurationPicker) editWindow
|
||||
.getFellowIfAny("edpDuration");
|
||||
edpDuration.bind(new Util.Getter<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration get() {
|
||||
return exceptionType != null ? exceptionType.getDuration() : null;
|
||||
}
|
||||
}, new Util.Setter<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public void set(EffortDuration value) {
|
||||
if (exceptionType != null) {
|
||||
exceptionType.setDuration(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeEditWindowComponents() {
|
||||
tbName = (Textbox) editWindow.getFellowIfAny("tbName");
|
||||
tbColor = (Textbox) editWindow.getFellowIfAny("tbColor");
|
||||
cbNotOverAssignable = (Checkbox) editWindow
|
||||
.getFellowIfAny("cbNotOverAssignable");
|
||||
}
|
||||
|
||||
private void showListWindow() {
|
||||
showWindow(listWindow);
|
||||
}
|
||||
|
||||
private void showWindow(Window window) {
|
||||
getVisibility().showOnly(window);
|
||||
}
|
||||
|
||||
private OnlyOneVisible getVisibility() {
|
||||
if (visibility == null) {
|
||||
visibility = new OnlyOneVisible(listWindow, editWindow);
|
||||
}
|
||||
return visibility;
|
||||
}
|
||||
|
||||
private void showEditWindow() {
|
||||
initializeEffortDurationPicker();
|
||||
editWindow.setTitle(_("Edit Exception Day Type"));
|
||||
showWindow(editWindow);
|
||||
}
|
||||
|
||||
public void goToCreateForm() {
|
||||
calendarExceptionTypeModel.initCreate();
|
||||
showCreateWindow();
|
||||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
private void showCreateWindow() {
|
||||
initializeEffortDurationPicker();
|
||||
editWindow.setTitle(_("Create Exception Day Type"));
|
||||
showWindow(editWindow);
|
||||
}
|
||||
|
||||
public CalendarExceptionType getExceptionDayType() {
|
||||
return calendarExceptionTypeModel.getExceptionDayType();
|
||||
}
|
||||
|
||||
public List<CalendarExceptionType> getExceptionDayTypes() {
|
||||
return calendarExceptionTypeModel.getExceptionDayTypes();
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
clearFields();
|
||||
showListWindow();
|
||||
}
|
||||
|
||||
private void clearFields() {
|
||||
tbName.setRawValue("");
|
||||
tbColor.setRawValue("");
|
||||
cbNotOverAssignable.setChecked(Boolean.TRUE);
|
||||
}
|
||||
|
||||
private boolean save() {
|
||||
try {
|
||||
calendarExceptionTypeModel.confirmSave();
|
||||
messagesForUser.showMessage(Level.INFO, _("Calendar Exception Type saved"));
|
||||
return true;
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAndExit() {
|
||||
boolean couldSave = save();
|
||||
if (couldSave) {
|
||||
clearFields();
|
||||
showListWindow();
|
||||
Util.reloadBindings(listWindow);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAndContinue() {
|
||||
save();
|
||||
}
|
||||
|
||||
public void showRemoveConfirmationMessage(MouseEvent event) {
|
||||
Button button = (Button) event.getTarget();
|
||||
Component comp = (Component) event.getTarget();
|
||||
CalendarExceptionType exceptionType = (CalendarExceptionType) ((Row) button
|
||||
.getParent().getParent()).getValue();
|
||||
|
||||
if (PredefinedCalendarExceptionTypes.contains(exceptionType)) {
|
||||
throw new WrongValueException(comp, "Cannot remove a predefined Exception Day Type");
|
||||
} else {
|
||||
showRemoveConfirmationMessage(exceptionType);
|
||||
}
|
||||
}
|
||||
|
||||
public void showRemoveConfirmationMessage(
|
||||
CalendarExceptionType exceptionType) {
|
||||
try {
|
||||
int status = Messagebox
|
||||
.show(_("Delete item {0}. Are you sure?",
|
||||
exceptionType.getName()), _("Delete"),
|
||||
Messagebox.OK | Messagebox.CANCEL,
|
||||
Messagebox.QUESTION);
|
||||
if (Messagebox.OK == status) {
|
||||
confirmDelete(exceptionType);
|
||||
Util.reloadBindings(listWindow);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error(_("Error on showing delete confirm"), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void confirmDelete(CalendarExceptionType exceptionType) {
|
||||
try {
|
||||
calendarExceptionTypeModel.confirmDelete(exceptionType);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidValueException e) {
|
||||
NewDataSortableGrid listExceptionDayTypes = (NewDataSortableGrid) listWindow
|
||||
.getFellowIfAny("listExceptionDayTypes");
|
||||
Row row = findRowByValue(listExceptionDayTypes, exceptionType);
|
||||
throw new WrongValueException(row, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Row findRowByValue(Grid grid, Object value) {
|
||||
final List<Row> rows = grid.getRows().getChildren();
|
||||
for (Row row: rows) {
|
||||
if (row.getValue().equals(value)) {
|
||||
return row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void goToEditForm(CalendarExceptionType exceptionType) {
|
||||
calendarExceptionTypeModel.initEdit(exceptionType);
|
||||
showEditWindow();
|
||||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package org.navalplanner.web.exceptionDays;
|
||||
|
||||
import static org.navalplanner.business.i18n.I18nHelper._;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.business.calendars.daos.ICalendarExceptionTypeDAO;
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.web.common.concurrentdetection.OnConcurrentModification;
|
||||
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;
|
||||
import org.zkoss.util.InvalidValueException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@OnConcurrentModification(goToPage = "/exceptionDays/exceptionDays.zul")
|
||||
public class CalendarExceptionTypeModel implements ICalendarExceptionTypeModel {
|
||||
|
||||
@Autowired
|
||||
private ICalendarExceptionTypeDAO calendarExceptionTypeDAO;
|
||||
|
||||
private CalendarExceptionType calendarExceptionType;
|
||||
|
||||
@Override
|
||||
public void initCreate() {
|
||||
calendarExceptionType = CalendarExceptionType.create();
|
||||
}
|
||||
|
||||
public void initEdit() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalendarExceptionType getExceptionDayType() {
|
||||
return calendarExceptionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly=true)
|
||||
public List<CalendarExceptionType> getExceptionDayTypes() {
|
||||
return calendarExceptionTypeDAO.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void confirmSave() throws ValidationException {
|
||||
calendarExceptionTypeDAO.save(calendarExceptionType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void confirmDelete(CalendarExceptionType exceptionType) throws InstanceNotFoundException, InvalidValueException {
|
||||
if (calendarExceptionTypeDAO.hasCalendarExceptions(exceptionType)) {
|
||||
throw new InvalidValueException(_("Cannot remove {0}, since it is being used by some Exception Day", exceptionType.getName()));
|
||||
}
|
||||
if (!exceptionType.isNewObject()) {
|
||||
calendarExceptionTypeDAO.remove(exceptionType.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void initEdit(CalendarExceptionType exceptionType) {
|
||||
Validate.notNull(exceptionType);
|
||||
this.calendarExceptionType = getFromDB(exceptionType);
|
||||
}
|
||||
|
||||
private CalendarExceptionType getFromDB(CalendarExceptionType exceptionType) {
|
||||
return getFromDB(exceptionType.getId());
|
||||
}
|
||||
|
||||
private CalendarExceptionType getFromDB(Long id) {
|
||||
try {
|
||||
CalendarExceptionType result = calendarExceptionTypeDAO.find(id);
|
||||
return result;
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package org.navalplanner.web.exceptionDays;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.zkoss.util.InvalidValueException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
public interface ICalendarExceptionTypeModel {
|
||||
|
||||
void initCreate();
|
||||
|
||||
void initEdit(CalendarExceptionType exceptionType);
|
||||
|
||||
List<CalendarExceptionType> getExceptionDayTypes();
|
||||
|
||||
CalendarExceptionType getExceptionDayType();
|
||||
|
||||
void confirmSave();
|
||||
|
||||
void confirmDelete(CalendarExceptionType exceptionType)
|
||||
throws InstanceNotFoundException, InvalidValueException;
|
||||
|
||||
}
|
||||
|
|
@ -23,6 +23,12 @@
|
|||
<extends>label</extends>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<component-name>effortDurationPicker</component-name>
|
||||
<component-class>org.navalplanner.web.common.components.EffortDurationPicker</component-class>
|
||||
<extends>hbox</extends>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<component-name>calendarhighlighteddays</component-name>
|
||||
<component-class>org.navalplanner.web.common.components.CalendarHighlightedDays</component-class>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
<!--
|
||||
This file is part of NavalPlan
|
||||
|
||||
Copyright (C) 2009-2010 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.id}">
|
||||
<tabbox>
|
||||
<tabs>
|
||||
<tab label="${i18n:_('Edit')}"></tab>
|
||||
</tabs>
|
||||
<tabpanels>
|
||||
<tabpanel>
|
||||
<grid fixedLayout="true">
|
||||
<columns>
|
||||
<column width="200px" />
|
||||
<column />
|
||||
</columns>
|
||||
|
||||
<rows>
|
||||
<row>
|
||||
<label value="${i18n:_('Name')}"/>
|
||||
<textbox id="tbName"
|
||||
value="@{controller.exceptionDayType.name}"
|
||||
width="300px" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Color')}" />
|
||||
<textbox id="tbColor"
|
||||
value="@{controller.exceptionDayType.color}"
|
||||
width="300px"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Over assignable')}" />
|
||||
<checkbox id="cbNotOverAssignable"
|
||||
checked="@{controller.exceptionDayType.overAssignable}" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Duration')}" />
|
||||
<effortDurationPicker id="edpDuration" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</tabpanel>
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
|
||||
<!-- Control buttons -->
|
||||
<button onClick="controller.saveAndExit()"
|
||||
label="${i18n:_('Save')}"
|
||||
sclass="save-button global-action"/>
|
||||
<button onClick="controller.saveAndContinue()"
|
||||
label="${i18n:_('Save and Continue')}"
|
||||
sclass="save-button global-action"/>
|
||||
<button onClick="controller.cancel()"
|
||||
label="${i18n:_('Cancel')}"
|
||||
sclass="cancel-button global-action"/>
|
||||
|
||||
</window>
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<!--
|
||||
This file is part of NavalPlan
|
||||
|
||||
Copyright (C) 2009-2010 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.id}" title="${i18n:_('Exception Day Types List')}">
|
||||
|
||||
<newdatasortablegrid id="listExceptionDayTypes"
|
||||
model="@{controller.exceptionDayTypes}"
|
||||
mold="paging" pageSize="10"
|
||||
fixedLayout="true">
|
||||
|
||||
<columns>
|
||||
<newdatasortablecolumn label="${i18n:_('Name')}" sort="auto(lower(name))" sortDirection="ascending" />
|
||||
<newdatasortablecolumn label="${i18n:_('Color')}"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Over assignable')}" />
|
||||
<newdatasortablecolumn label="${i18n:_('Duration')}" />
|
||||
|
||||
<newdatasortablecolumn label="${i18n:_('Operations')}" />
|
||||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='exceptionDayType'}" value="@{exceptionDayType}">
|
||||
<label value="@{exceptionDayType.name}" />
|
||||
<label value="@{exceptionDayType.color}" />
|
||||
<label value="@{exceptionDayType.overAssignableStr}" />
|
||||
<label value="@{exceptionDayType.durationStr}" />
|
||||
|
||||
<!-- Operation -->
|
||||
<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 sclass="icono" image="/common/img/ico_borrar1.png"
|
||||
hoverImage="/common/img/ico_borrar.png"
|
||||
tooltiptext="${i18n:_('Delete')}"
|
||||
onClick="controller.showRemoveConfirmationMessage(event)"/>
|
||||
</hbox>
|
||||
</row>
|
||||
</rows>
|
||||
</newdatasortablegrid>
|
||||
|
||||
<button label="${i18n:_('Create')}" onClick="controller.goToCreateForm()"
|
||||
sclass="create-button global-action"/>
|
||||
|
||||
</window>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<!--
|
||||
This file is part of NavalPlan
|
||||
|
||||
Copyright (C) 2009-2010 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/>.
|
||||
-->
|
||||
|
||||
<?page id="exceptionDayTypesList" title="${i18n:_('NavalPlan: Exception Days')}" ?>
|
||||
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
|
||||
<?init class="org.zkoss.zk.ui.util.Composition" arg0="/common/layout/template.zul"?>
|
||||
|
||||
<?link rel="stylesheet" type="text/css" href="/common/css/navalplan.css"?>
|
||||
<?link rel="stylesheet" type="text/css" href="/common/css/navalplan_zk.css"?>
|
||||
|
||||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||
|
||||
<?component name="list" inline="true" macroURI="_listExceptionDayTypes.zul"?>
|
||||
<?component name="edit" inline="true" macroURI="_editExceptionDayType.zul"?>
|
||||
|
||||
<zk>
|
||||
<window self="@{define(content)}"
|
||||
apply="org.navalplanner.web.exceptionDays.CalendarExceptionTypeCRUDController">
|
||||
<vbox id="messagesContainer"/>
|
||||
<list id="listWindow"/>
|
||||
<edit id="editWindow"/>
|
||||
</window>
|
||||
</zk>
|
||||
Loading…
Add table
Reference in a new issue