package nc.noumea.mairie.organigramme.viewmodel; /* * #%L * Logiciel de Gestion des Organigrammes de la Ville de Nouméa * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2015 Mairie de Nouméa * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ import java.io.Serializable; import java.util.HashMap; import java.util.Map; import nc.noumea.mairie.organigramme.core.viewmodel.AbstractPopupViewModel; import nc.noumea.mairie.organigramme.core.ws.IAdsWSConsumer; import nc.noumea.mairie.organigramme.dto.EntiteDto; import nc.noumea.mairie.organigramme.dto.ReturnMessageDto; import nc.noumea.mairie.organigramme.dto.TransitionDto; import nc.noumea.mairie.organigramme.services.OrganigrammeService; import nc.noumea.mairie.organigramme.services.ReturnMessageService; import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.AfterCompose; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.ContextParam; import org.zkoss.bind.annotation.ContextType; import org.zkoss.bind.annotation.GlobalCommand; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.select.Selectors; import org.zkoss.zk.ui.select.annotation.VariableResolver; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zkplus.spring.DelegatingVariableResolver; import org.zkoss.zul.Window; @VariableResolver(DelegatingVariableResolver.class) @Init(superclass = true) public class PopupTransitoireFichesPosteViewModel extends AbstractPopupViewModel<TransitionDto> implements Serializable { private static final long serialVersionUID = 1L; @WireVariable IAdsWSConsumer adsWSConsumer; @WireVariable OrganigrammeService organigrammeService; @WireVariable ReturnMessageService returnMessageService; @AfterCompose public void afterCompose(@ContextParam(ContextType.VIEW) Component view) { setPopup((Window) Selectors.iterable(view, "#popupTransitoireFichesPoste").iterator().next()); } @GlobalCommand @NotifyChange({ "entity" }) public void ouvrePopupTransitoireFichesPoste(@BindingParam("entity") EntiteDto entity) throws InstantiationException, IllegalAccessException { setEntity(new TransitionDto()); // On va chercher en base la valeur de la NFA si elle est renseignée // EntiteDto entityBdd = adsWSConsumer.getEntite(entity.getIdEntite()); getEntity().setEntiteDto(entity); getPopup().doModal(); } @Command public void saveTransitoireFichesPoste() { getEntity().setFdpInactive(false); getEntity().setFdpTransitoire(true); ReturnMessageDto returnMessageDto = adsWSConsumer.transiteFichesPosteFromEntity(getEntity()); if (!returnMessageService.gererReturnMessage(returnMessageDto, true)) { return; } getPopup().detach(); final Map<String, Object> mapEntite = new HashMap<String, Object>(); mapEntite.put("entiteCible", getEntity().getEntiteDto()); BindUtils.postGlobalCommand(null, null, "refreshArbreFichesPoste", mapEntite); } @Command public void saveInactiveFichesPoste() { getEntity().setFdpInactive(true); getEntity().setFdpTransitoire(false); ReturnMessageDto returnMessageDto = adsWSConsumer.transiteFichesPosteFromEntity(getEntity()); if (!returnMessageService.gererReturnMessage(returnMessageDto, true)) { return; } getPopup().detach(); final Map<String, Object> mapEntite = new HashMap<String, Object>(); mapEntite.put("entiteCible", getEntity().getEntiteDto()); BindUtils.postGlobalCommand(null, null, "refreshArbreFichesPoste", mapEntite); } }