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.ArrayList; import java.util.HashMap; import java.util.List; 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.DuplicationDto; import nc.noumea.mairie.organigramme.dto.EntiteDto; import nc.noumea.mairie.organigramme.dto.ReturnMessageDto; import nc.noumea.mairie.organigramme.enums.Statut; import nc.noumea.mairie.organigramme.query.EntiteDtoQueryListModel; 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 PopupDeplacerFichesPosteViewModel extends AbstractPopupViewModel<DuplicationDto> 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, "#popupDeplacerFichesPoste").iterator().next()); } @GlobalCommand @NotifyChange({ "entity", "entiteDtoQueryListModel" }) public void ouvrePopupDeplacerFichesPoste(@BindingParam("entity") EntiteDto entity) throws InstantiationException, IllegalAccessException { setEntity(new DuplicationDto()); // 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 saveDeplacerFichesPoste() { ReturnMessageDto returnMessageDto = adsWSConsumer.deplaceFichesPosteFromEntityToOtherEntity(getEntity().getEntiteDto().getIdEntite(), getEntity().getEntiteDtoCible().getIdEntite()); if (!returnMessageService.gererReturnMessage(returnMessageDto, true)) { return; } getPopup().detach(); final Map<String, Object> mapEntite = new HashMap<String, Object>(); mapEntite.put("entiteCible", getEntity().getEntiteDtoCible()); BindUtils.postGlobalCommand(null, null, "refreshArbreFichesPoste", mapEntite); } public EntiteDtoQueryListModel getEntiteDtoQueryListModel() { List<EntiteDto> listeEntiteDtoAPlat = new ArrayList<EntiteDto>(); if (this.entity != null && this.entity.getEntiteDto() != null) { List<Statut> listeStatut = new ArrayList<Statut>(); listeStatut.add(Statut.ACTIF); listeEntiteDtoAPlat = adsWSConsumer.getAllEntiteAPlat(listeStatut); listeEntiteDtoAPlat.remove(this.entity.getEntiteDto()); } return new EntiteDtoQueryListModel(listeEntiteDtoAPlat); } }