/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.gui.controladores.esquemaoperacional;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Button;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;

import com.rjconsultores.ventaboletos.entidad.ParamConexion;
import com.rjconsultores.ventaboletos.service.ParamConexionService;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;

/**
 * 
 * @author Administrador
 */
@Controller("editarParamConexionController")
@Scope("prototype")
public class EditarParamConexionController extends MyGenericForwardComposer {

	@Autowired
	private ParamConexionService paramConexionService;
	private ParamConexion paramConexion;
	private MyListbox paramConexionList;
	private static Logger log = Logger.getLogger(EditarParamConexionController.class);
	private Textbox txtNome;
	private Textbox descconstante;
	private Textbox valorconstante;
	private Button btnApagar;
	private Button btnSalvar;

	public Button getBtnApagar() {
		return btnApagar;
	}

	public void setBtnApagar(Button btnApagar) {
		this.btnApagar = btnApagar;
	}

	public Textbox getTxtNome() {
		return txtNome;
	}

	public void setTxtNome(Textbox txtNome) {
		this.txtNome = txtNome;
	}

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);

		paramConexion = (ParamConexion) Executions.getCurrent().getArg().get("paramConexion");
		paramConexionList = (MyListbox) Executions.getCurrent().getArg().get("paramConexionList");

		if (paramConexion.getParamConexionId() != null) {
			txtNome.setDisabled(Boolean.TRUE);
			descconstante.setDisabled(Boolean.TRUE);
		}

		txtNome.focus();

	}

	public void onClick$btnSalvar(Event ev) throws InterruptedException {
		valorconstante.getValue();

		paramConexionService.actualizacion(paramConexion);
		paramConexionList.updateItem(paramConexion);

		Messagebox.show(
				Labels.getLabel("editarParamConexionController.MSG.suscribirOK"),
				Labels.getLabel("editarParamConexionController.window.title"),
				Messagebox.OK, Messagebox.INFORMATION);

		closeWindow();

	}

	public ParamConexion getParamConexion() {
		return paramConexion;
	}

}
