/*
 *  Copyright 2013-2050 Emmanuel BRUN (contact@amapj.fr)
 * 
 *  This file is part of AmapJ.
 *  
 *  AmapJ 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.

 *  AmapJ 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 AmapJ.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 
 */
 package fr.amapj.view.views.appinstance;

import java.util.List;

import com.vaadin.ui.ComboBox;

import fr.amapj.model.engine.db.DbManager;
import fr.amapj.service.services.appinstance.AppInstanceDTO;
import fr.amapj.service.services.appinstance.AppInstanceService;
import fr.amapj.view.engine.popup.formpopup.FormPopup;
import fr.amapj.view.engine.popup.formpopup.genericmodel.StringItem;

/**
 * Suppression d'une ou plusieurs instances
 *
 */
@SuppressWarnings("serial")
public class PopupDeleteAppInstance extends FormPopup
{

	private List<AppInstanceDTO> dtos;
	private StringItem item = new StringItem();

	/**
	 * 
	 */
	public PopupDeleteAppInstance(List<AppInstanceDTO> dtos)
	{
		popupTitle = "Suppression des instances";
		this.dtos = dtos;
		setModel(item);
	}
	
	
	protected void addFields()
	{
		String str = "ATTENTION<br/> ! Vous allez supprimer "+dtos.size()+" bases<br/><br/>";
		str = str +"Liste des bases <br/>";
		
		for (AppInstanceDTO appInstanceDTO : dtos)
		{
			str = str+ appInstanceDTO.nomInstance+"<br/>";
		}
					
		addHtml(str);
		addHtml("Merci de saisir JE CONFIRME ci dessous");
		
		addTextField("", "value");
	}
	
	protected String checkScreen()
	{
		if (item.value.equals("JE CONFIRME")==false)
		{
			return "Confirmation obligatoire";
		}
		return null;
	}

	
	@Override
	protected void performSauvegarder()
	{
		for (AppInstanceDTO dto : dtos)
		{
			new AppInstanceService().delete(dto.id);
		}
	}

	
}
