diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/components/bandboxsearch/BandboxSearch.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/components/bandboxsearch/BandboxSearch.java index 3ac4e6989..220cc9001 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/components/bandboxsearch/BandboxSearch.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/components/bandboxsearch/BandboxSearch.java @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2011 Igalia, S.L. + * Copyright (C) 2010-2012 Igalia, 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 @@ -294,6 +294,10 @@ public class BandboxSearch extends HtmlMacroComponent { } + public void setBandboxEventListener(String event, EventListener listener) { + bandbox.addEventListener(event, listener); + } + public void foucusOnInput() { bandbox.setFocus(true); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/orders/ProjectDetailsController.java b/libreplan-webapp/src/main/java/org/libreplan/web/orders/ProjectDetailsController.java index bebb0795e..4e53a2667 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/orders/ProjectDetailsController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/orders/ProjectDetailsController.java @@ -2,7 +2,7 @@ * This file is part of LibrePlan * * Copyright (C) 2010-2011 Wireless Galicia, S.L. - * Copyright (C) 2011 Igalia, S.L. + * Copyright (C) 2011-2012 Igalia, S.L. * * This program is free software: you can redistribute it and/or modify @@ -49,6 +49,7 @@ 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.util.GenericForwardComposer; +import org.zkoss.zul.Checkbox; import org.zkoss.zul.ComboitemRenderer; import org.zkoss.zul.Constraint; import org.zkoss.zul.Datebox; @@ -91,6 +92,8 @@ public class ProjectDetailsController extends GenericForwardComposer { private Datebox deadline; + private Checkbox generateCode; + @Autowired private IOrderDAO orderDAO; @@ -277,23 +280,32 @@ public class ProjectDetailsController extends GenericForwardComposer { bdExternalCompanies.close(); } }); - bdProjectTemplate.setListboxEventListener(Events.ON_SELECT, + bdProjectTemplate.setBandboxEventListener(Events.ON_BLUR, new EventListener() { @Override public void onEvent(Event event) { - calculateDeadlineDate(); + if (bdProjectTemplate.getSelectedElement() == null) { + generateCode.setDisabled(false); + } else { + setCodeAutogenerated(true); + generateCode.setDisabled(true); + generateCode.setChecked(true); + calculateProjectDates(); + } } }); } - public void calculateDeadlineDate() { - if ((bdProjectTemplate.getSelectedElement() == null) - || (((OrderTemplate) bdProjectTemplate.getSelectedElement()) - .getDeadlineAsDaysFromBeginning() == null) - || (initDate.getValue() == null)) { + public void calculateProjectDates() { + OrderTemplate template = (OrderTemplate) bdProjectTemplate.getSelectedElement(); + if (template == null) { return; } - int days = ((OrderTemplate) bdProjectTemplate.getSelectedElement()).getDeadlineAsDaysFromBeginning(); - deadline.setValue( new LocalDate(initDate.getValue()).plusDays(days).toDateTimeAtStartOfDay().toDate()); + initDate.setValue(new LocalDate().plusDays(template.getStartAsDaysFromBeginning()).toDateTimeAtStartOfDay().toDate()); + if (template.getDeadlineAsDaysFromBeginning() != null ) { + deadline.setValue( new LocalDate(initDate.getValue()).plusDays(template.getDeadlineAsDaysFromBeginning()).toDateTimeAtStartOfDay().toDate()); + } else { + deadline.setText(""); } + } } \ No newline at end of file diff --git a/libreplan-webapp/src/main/webapp/orders/_projectDetails.zul b/libreplan-webapp/src/main/webapp/orders/_projectDetails.zul index bd53ebffb..e8ce5e176 100644 --- a/libreplan-webapp/src/main/webapp/orders/_projectDetails.zul +++ b/libreplan-webapp/src/main/webapp/orders/_projectDetails.zul @@ -2,6 +2,7 @@ This file is part of LibrePlan Copyright (C) 2010-2011 Wireless Galicia, S.L. + Copyright (C) 2012 Igalia, 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 @@ -43,7 +44,7 @@ -