diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationController.java new file mode 100644 index 000000000..99ca7390d --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationController.java @@ -0,0 +1,88 @@ +/* + * 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.common; + +import static org.navalplanner.web.I18nHelper._; + +import java.util.List; + +import org.navalplanner.business.calendars.entities.BaseCalendar; +import org.navalplanner.business.common.entities.Configuration; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.util.GenericForwardComposer; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.Messagebox; +import org.zkoss.zul.api.Bandbox; +import org.zkoss.zul.api.Window; + +/** + * Controller for {@link Configuration} entity. + * + * @author Manuel Rego Casasnovas + */ +public class ConfigurationController extends GenericForwardComposer { + + private Window configurationWindow; + private Bandbox defaultCalendarBandbox; + + private IConfigurationModel configurationModel; + + @Override + public void doAfterCompose(Component comp) throws Exception { + super.doAfterCompose(comp); + comp.setVariable("configurationController", this, true); + configurationModel.init(); + } + + public BaseCalendar getDefaultCalendar() { + return configurationModel.getDefaultCalendar(); + } + + public List getCalendars() { + return configurationModel.getCalendars(); + } + + public void setDefaultCalendar(Listitem item) { + BaseCalendar calendar = (BaseCalendar) item.getValue(); + configurationModel.setDefaultCalendar(calendar); + + Util.reloadBindings(defaultCalendarBandbox); + defaultCalendarBandbox.closeDropdown(); + } + + public void save() throws InterruptedException { + configurationModel.confirm(); + Messagebox.show(_("Changes saved"), _("Information"), Messagebox.OK, + Messagebox.INFORMATION); + } + + public void cancel() throws InterruptedException { + configurationModel.cancel(); + Messagebox.show(_("Changes has been canceled"), _("Information"), + Messagebox.OK, Messagebox.INFORMATION); + reloadWindow(); + } + + private void reloadWindow() { + Util.reloadBindings(configurationWindow); + } + +} \ No newline at end of file diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationModel.java new file mode 100644 index 000000000..621e2c67c --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationModel.java @@ -0,0 +1,105 @@ +/* + * 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.common; + +import java.util.List; + +import org.navalplanner.business.calendars.daos.IBaseCalendarDAO; +import org.navalplanner.business.calendars.entities.BaseCalendar; +import org.navalplanner.business.common.daos.IConfigurationDAO; +import org.navalplanner.business.common.entities.Configuration; +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; + +/** + * @author Manuel Rego Casasnovas + */ +@Service +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +public class ConfigurationModel implements IConfigurationModel { + + /** + * Conversation state + */ + private Configuration configuration; + + @Autowired + private IConfigurationDAO configurationDAO; + + @Autowired + private IBaseCalendarDAO baseCalendarDAO; + + @Override + @Transactional(readOnly = true) + public List getCalendars() { + return baseCalendarDAO.getBaseCalendars(); + } + + @Override + public BaseCalendar getDefaultCalendar() { + if (configuration == null) { + return null; + } + return configuration.getDefaultCalendar(); + } + + @Override + @Transactional(readOnly = true) + public void init() { + this.configuration = getCurrentConfiguration(); + } + + private Configuration getCurrentConfiguration() { + Configuration configuration = configurationDAO.getConfiguration(); + if (configuration == null) { + configuration = Configuration.create(); + } + forceLoad(configuration); + return configuration; + } + + private void forceLoad(Configuration configuration) { + configuration.getDefaultCalendar().getName(); + } + + @Override + public void setDefaultCalendar(BaseCalendar calendar) { + if (configuration != null) { + configuration.setDefaultCalendar(calendar); + } + } + + @Override + @Transactional + public void confirm() { + configurationDAO.save(configuration); + } + + @Override + @Transactional(readOnly = true) + public void cancel() { + configuration = getCurrentConfiguration(); + } + +} \ No newline at end of file diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java index 3cb5fa3ca..06445c5e8 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java @@ -184,7 +184,8 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { subItem(_("Manage criteria"), "/resources/criterions/criterions-V2.zul"), subItem(_("Calendars"), "/calendars/calendars.zul"), - subItem(_("Label types"), "/labels/labelTypes.zul")); + subItem(_("Label types"), "/labels/labelTypes.zul"), + subItem(_("Configuration"), "/common/configuration.zul")); topItem(_("Quality management"), "/", true); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/IConfigurationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/IConfigurationModel.java new file mode 100644 index 000000000..374e980b7 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/IConfigurationModel.java @@ -0,0 +1,56 @@ +/* + * 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.common; + +import java.util.List; + +import org.navalplanner.business.calendars.entities.BaseCalendar; + +/** + * Contract for {@link ConfigurationModel}. + * + * @author Manuel Rego Casasnovas + */ +public interface IConfigurationModel { + + /* + * Non conversational steps + */ + List getCalendars(); + + /* + * Initial conversation steps + */ + void init(); + + /* + * Intermediate conversation steps + */ + BaseCalendar getDefaultCalendar(); + void setDefaultCalendar(BaseCalendar calendar); + + /* + * Final conversation steps + */ + void confirm(); + void cancel(); + +} diff --git a/navalplanner-webapp/src/main/webapp/common/configuration.zul b/navalplanner-webapp/src/main/webapp/common/configuration.zul new file mode 100644 index 000000000..6bdf74937 --- /dev/null +++ b/navalplanner-webapp/src/main/webapp/common/configuration.zul @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + +