diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/orders/assigntemplates/TemplateFinderPopup.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/orders/assigntemplates/TemplateFinderPopup.java new file mode 100644 index 000000000..e08b84147 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/orders/assigntemplates/TemplateFinderPopup.java @@ -0,0 +1,164 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 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 . + */ +package org.navalplanner.web.orders.assigntemplates; + +import static org.navalplanner.business.i18n.I18nHelper._; + +import org.apache.commons.lang.Validate; +import org.navalplanner.business.templates.entities.OrderElementTemplate; +import org.navalplanner.business.templates.entities.OrderTemplate; +import org.navalplanner.web.common.components.bandboxsearch.BandboxSearch; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.HtmlMacroComponent; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zul.Button; +import org.zkoss.zul.Caption; +import org.zkoss.zul.Popup; + +/** + * @author Óscar González Fernández + * + */ +public class TemplateFinderPopup extends + HtmlMacroComponent { + + private Component finderPlaceholder; + private Popup popup; + private IOnResult onResult; + private BandboxSearch bandboxSearch; + private Button acceptButton; + private Button cancelButton; + private String acceptButtonLabel = _("Accept"); + private String cancelButtonLabel = _("Cancel"); + private Caption caption; + private String captionLabel; + + public interface IOnResult { + public void found(T template); + } + + /** + * @param ref + * this is passed to {@link Popup#open(Component, String)} + * @param position + * this is pased to {@link Popup#open(Component, String)} + * @param onResult + * @see Popup#open(Component, String) + */ + public void openForSubElemenetCreation(Component ref, String position, + IOnResult onResult) { + this.onResult = onResult; + setupPopUp(ref, position, "templatesEligibleForSubElement"); + } + + /** + * @param ref + * this is passed to {@link Popup#open(Component, String)} + * @param position + * this is pased to {@link Popup#open(Component, String)} + * @param onResult + * @see Popup#open(Component, String) + */ + public void openForOrderCreation(Component ref, String position, + IOnResult onResult) { + this.onResult = onResult; + setupPopUp(ref, position, "templatesEligibleForOrder"); + } + + private void setupPopUp(Component ref, String position, + String finderName) { + if (bandboxSearch != null) { + finderPlaceholder.removeChild(bandboxSearch); + } + bandboxSearch = new BandboxSearch(); + bandboxSearch.setFinder(finderName); + finderPlaceholder.appendChild(bandboxSearch); + bandboxSearch.afterCompose(); + popup.open(ref, position); + bandboxSearch.foucusOnInput(); + } + + private void onAccept() { + Object selectedElement = bandboxSearch.getSelectedElement(); + if (selectedElement != null) { + onResult.found((OrderElementTemplate) selectedElement); + } + popup.close(); + } + + private void onCancel() { + popup.close(); + } + + public void setAcceptButtonLabel(String label) { + Validate.notNull(label); + this.acceptButtonLabel = label; + if (acceptButton != null) { + acceptButton.setLabel(label); + } + + } + + public void setCancelButtonLabel(String label) { + Validate.notNull(label); + this.cancelButtonLabel = label; + if (cancelButton != null) { + cancelButton.setLabel(label); + } + } + + public void setCaption(String label) { + Validate.notNull(label); + this.captionLabel = label; + if (caption != null) { + caption.setLabel(label); + } + } + + @Override + public void afterCompose() { + super.afterCompose(); + acceptButton = (Button) getFellow("acceptButton"); + acceptButton.setLabel(acceptButtonLabel); + acceptButton.addEventListener(Events.ON_CLICK, new EventListener() { + + @Override + public void onEvent(Event event) throws Exception { + onAccept(); + } + }); + cancelButton = (Button) getFellow("cancelButton"); + cancelButton.setLabel(cancelButtonLabel); + cancelButton.addEventListener(Events.ON_CLICK, new EventListener() { + + @Override + public void onEvent(Event event) throws Exception { + onCancel(); + } + }); + finderPlaceholder = (Component) getFellow("finderPlaceholder"); + popup = (Popup) getFellow("finderPopup"); + caption = (Caption) getFellow("finderCaption"); + caption.setLabel(captionLabel); + } + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/templates/advances/AdvanceTypesOnConversation.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/templates/advances/AdvanceTypesOnConversation.java new file mode 100644 index 000000000..e8da458df --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/templates/advances/AdvanceTypesOnConversation.java @@ -0,0 +1,28 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 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 . + */ +package org.navalplanner.web.templates.advances; + +/** + * @author Óscar González Fernández + * + */ +public class AdvanceTypesOnConversation { + +} diff --git a/navalplanner-webapp/src/main/resources/metainfo/zk/lang-addon.xml b/navalplanner-webapp/src/main/resources/metainfo/zk/lang-addon.xml index 2c616faab..e8fc093c5 100755 --- a/navalplanner-webapp/src/main/resources/metainfo/zk/lang-addon.xml +++ b/navalplanner-webapp/src/main/resources/metainfo/zk/lang-addon.xml @@ -70,4 +70,10 @@ + + templateFinderPopup + org.navalplanner.web.orders.assigntemplates.TemplateFinderPopup + /common/components/templateFinder.zul + + diff --git a/navalplanner-webapp/src/main/webapp/common/components/templateFinder.zul b/navalplanner-webapp/src/main/webapp/common/components/templateFinder.zul new file mode 100644 index 000000000..caf96f706 --- /dev/null +++ b/navalplanner-webapp/src/main/webapp/common/components/templateFinder.zul @@ -0,0 +1,36 @@ + + + + + + + + +
+ +