diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/LenientDecimalBox.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/LenientDecimalBox.java new file mode 100644 index 000000000..9dbafdbd0 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/LenientDecimalBox.java @@ -0,0 +1,46 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2011 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 + * 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 . + */ +package org.libreplan.web.common; + +import java.math.BigDecimal; +import java.text.DecimalFormatSymbols; + +import org.zkoss.util.Locales; +import org.zkoss.zk.ui.WrongValueException; +import org.zkoss.zul.Decimalbox; + +/** + * Same behavior as a {@link Decimalbox}, but it always interprets , and + * . as decimals separators. So you can use both freely as decimal + * separators. + * + * @author Óscar González Fernández + * + */ +public class LenientDecimalBox extends Decimalbox { + + public LenientDecimalBox() { + super(); + } + + public LenientDecimalBox(BigDecimal value) throws WrongValueException { + super(value); + } + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRow.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRow.java index 0281e6045..7fc22740f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRow.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRow.java @@ -60,6 +60,7 @@ import org.libreplan.business.workingday.EffortDuration; import org.libreplan.business.workingday.EffortDuration.IEffortFrom; import org.libreplan.business.workingday.ResourcesPerDay; import org.libreplan.web.common.EffortDurationBox; +import org.libreplan.web.common.LenientDecimalBox; import org.libreplan.web.common.Util; import org.libreplan.web.planner.allocation.ResourceAllocationController.DerivedAllocationColumn; import org.zkoss.zk.au.out.AuWrongValue; @@ -283,7 +284,7 @@ public abstract class AllocationRow { private EffortDurationBox effortInput = new EffortDurationBox(); - private final Decimalbox intendedResourcesPerDayInput = new Decimalbox(); + private final Decimalbox intendedResourcesPerDayInput = new LenientDecimalBox(); private ResourcesPerDay editedValue; diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java index ac6087051..b744e3a4a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java @@ -40,6 +40,7 @@ import org.libreplan.business.resources.entities.ResourceEnum; import org.libreplan.web.I18nHelper; import org.libreplan.web.common.EffortDurationBox; import org.libreplan.web.common.IMessagesForUser; +import org.libreplan.web.common.LenientDecimalBox; import org.libreplan.web.common.Util; import org.libreplan.web.common.components.AllocationSelector; import org.libreplan.web.common.components.NewAllocationSelector; @@ -141,7 +142,7 @@ public class ResourceAllocationController extends GenericForwardComposer { @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); - allResourcesPerDay = new Decimalbox(); + allResourcesPerDay = new LenientDecimalBox(); allResourcesPerDay.setWidth("80px"); initAllocationLabels(); makeReadyInputsForCalculationTypes(); diff --git a/libreplan-webapp/src/main/resources/metainfo/zk/lang-addon.xml b/libreplan-webapp/src/main/resources/metainfo/zk/lang-addon.xml index 770a161bb..befabeaab 100755 --- a/libreplan-webapp/src/main/resources/metainfo/zk/lang-addon.xml +++ b/libreplan-webapp/src/main/resources/metainfo/zk/lang-addon.xml @@ -88,6 +88,12 @@ /common/components/templateFinder.zul + + LenientDecimalBox + org.libreplan.web.common.LenientDecimalBox + webcommon.LenientDecimalBox + + LimitingResourcesPanel org.libreplan.web.limitingresources.LimitingResourcesPanel diff --git a/libreplan-webapp/src/main/resources/web/js/webcommon/LenientDecimalBox.js b/libreplan-webapp/src/main/resources/web/js/webcommon/LenientDecimalBox.js new file mode 100644 index 000000000..2fc932af5 --- /dev/null +++ b/libreplan-webapp/src/main/resources/web/js/webcommon/LenientDecimalBox.js @@ -0,0 +1,14 @@ +zk.$package("webcommon"); + +webcommon.LenientDecimalBox = zk.$extends(zul.inp.Decimalbox,{ + + coerceFromString_: function (b) { + if(!b) { + return null; + } + //replace decimal comma with dot + b = b.replace(',','.'); + //process normally + return this.$supers('coerceFromString_', arguments); + } +}); diff --git a/libreplan-webapp/src/main/resources/web/js/webcommon/zk.wpd b/libreplan-webapp/src/main/resources/web/js/webcommon/zk.wpd index 475fab65f..ef9d9cff0 100644 --- a/libreplan-webapp/src/main/resources/web/js/webcommon/zk.wpd +++ b/libreplan-webapp/src/main/resources/web/js/webcommon/zk.wpd @@ -1,2 +1,3 @@ +