ItEr35S08CUAsignacionCalendarioLaboralRecursoItEr25S09: Added controller and model to manage Configuration.
This commit is contained in:
parent
8cde179bb3
commit
ebc8691103
5 changed files with 314 additions and 1 deletions
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <mrego@igalia.com>
|
||||
*/
|
||||
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<BaseCalendar> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <mrego@igalia.com>
|
||||
*/
|
||||
@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<BaseCalendar> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
|
||||
/**
|
||||
* Contract for {@link ConfigurationModel}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IConfigurationModel {
|
||||
|
||||
/*
|
||||
* Non conversational steps
|
||||
*/
|
||||
List<BaseCalendar> getCalendars();
|
||||
|
||||
/*
|
||||
* Initial conversation steps
|
||||
*/
|
||||
void init();
|
||||
|
||||
/*
|
||||
* Intermediate conversation steps
|
||||
*/
|
||||
BaseCalendar getDefaultCalendar();
|
||||
void setDefaultCalendar(BaseCalendar calendar);
|
||||
|
||||
/*
|
||||
* Final conversation steps
|
||||
*/
|
||||
void confirm();
|
||||
void cancel();
|
||||
|
||||
}
|
||||
63
navalplanner-webapp/src/main/webapp/common/configuration.zul
Normal file
63
navalplanner-webapp/src/main/webapp/common/configuration.zul
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<!--
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?page title="${i18n:_('Navalpro: Configuration')}"?>
|
||||
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
|
||||
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
|
||||
<?page id="List"?>
|
||||
<?init class="org.zkoss.zk.ui.util.Composition" arg0="/common/layout/template.zul"?>
|
||||
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_v01.css"?>
|
||||
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_zk.css"?>
|
||||
<?link rel="stylesheet" type="text/css" href="/resources/css/resources.css"?>
|
||||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||
<zk>
|
||||
|
||||
<window id="configurationWindow" self="@{define(content)}"
|
||||
apply="org.navalplanner.web.common.ConfigurationController">
|
||||
|
||||
<hbox>
|
||||
<label value="${i18n:_('Defautl calendar')}" />
|
||||
<bandbox id="defaultCalendarBandbox"
|
||||
value="@{configurationController.defaultCalendar.name}">
|
||||
<bandpopup>
|
||||
<listbox width="200px"
|
||||
model="@{configurationController.calendars}"
|
||||
onSelect="configurationController.setDefaultCalendar(self.selectedItem);">
|
||||
<listhead>
|
||||
<listheader label="Name" />
|
||||
</listhead>
|
||||
<listitem self="@{each='calendar'}" value="@{calendar}">
|
||||
<listcell label="@{calendar.name}" />
|
||||
</listitem>
|
||||
</listbox>
|
||||
</bandpopup>
|
||||
</bandbox>
|
||||
</hbox>
|
||||
|
||||
<hbox>
|
||||
<button label="${i18n:_('Save')}"
|
||||
onClick="configurationController.save()" />
|
||||
<button label="${i18n:_('Cancel')}"
|
||||
onClick="configurationController.cancel()" />
|
||||
</hbox>
|
||||
|
||||
</window>
|
||||
|
||||
</zk>
|
||||
Loading…
Add table
Reference in a new issue