
package de.ivu.elect.presentation.gruppeimgebiet;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.gruppeimgebiet.boundary.GruppeImGebietBoundaryCreate;
import de.ivu.elect.business.gruppeimgebiet.boundary.GruppeImGebietFactory;
import de.ivu.elect.business.gruppeimgebiet.entity.GruppeImGebiet;
import de.ivu.elect.business.gruppeimgebiet.entity.GruppeImGebietMeta;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.security.UseCaseSecure;
import de.ivu.elect.presentation.View;
import de.ivu.elect.jee.presentation.redirect.Redirect;

@Named(AbstractGruppeImGebietCreateNoScopeView.COMPONENT_NAME)
@View(viewId = AbstractGruppeImGebietCreateNoScopeView.VIEW_ID, useCase = UseCasePermission.GRUPPE_IM_GEBIET_CREATE)
public abstract class AbstractGruppeImGebietCreateNoScopeView extends de.ivu.elect.presentation.AbstractElectCreateView<GruppeImGebiet> {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "gruppeImGebietCreateView";

  public static final String VIEW_ID = "/gruppeimgebiet/gruppe-im-gebiet-create.xhtml";

  public static final String PARENT_VIEW_ID = "/gruppeimgebiet/gruppe-im-gebiet-search.xhtml";

  @Inject
  protected transient GruppeImGebietBoundaryCreate create;

  protected GruppeImGebiet entity;

  @Inject
  protected transient GruppeImGebietMeta entityMeta;

  
  @Inject
  protected transient GruppeImGebietFactory factory;

  public AbstractGruppeImGebietCreateNoScopeView() {
    super();
  }

  @PostConstruct
  public void init() {
    setEntity(factory.create());
  }

  

  public GruppeImGebiet getEntity() {
    return entity;
  }

  protected void setEntity(GruppeImGebiet entity) {
    this.entity = entity;
  }

  @Redirect
  @UseCaseSecure(UseCasePermission.GRUPPE_IM_GEBIET_CREATE)
  public String save() {
    callSave(getEntity());

    addMessageSaveSuccess(getEntity());

    resetStateAfterAction();

    return goBack(getParentViewId());
  }

  protected void callSave(GruppeImGebiet entity) {
    create.save(entity);
  }

  protected void addMessageSaveSuccess(GruppeImGebiet entity) {
    addInfoMessage("entity.create.action.save.success.message", entityMeta.getEinzahlMessage());
  }

  public boolean isBtnSaveRendered() {
    return hasPermission(UseCasePermission.GRUPPE_IM_GEBIET_CREATE);
  }

  @Redirect
  public String reset() {
    resetStateAfterAction();

    init();

    return getViewId();
  }

  public boolean isBtnResetRendered() {
    return true;
  }

  @Redirect
  public String cancel() {
    resetStateAfterAction();

    return goBack(getParentViewId());
  }

  public boolean isBtnCancelRendered() {
    return true;
  }

  protected String getViewId() {
    return VIEW_ID;
  }

  protected String getParentViewId() {
    return PARENT_VIEW_ID;
  }

  protected void resetStateAfterAction() {
    // Do nothing.
  }
}
