
package de.ivu.elect.presentation.wahlvorschlagsperson;

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

import de.ivu.elect.business.wahlvorschlagsperson.boundary.WahlvorschlagsPersonBoundaryCreate;
import de.ivu.elect.business.wahlvorschlagsperson.boundary.WahlvorschlagsPersonFactory;
import de.ivu.elect.business.wahlvorschlagsperson.entity.WahlvorschlagsPerson;
import de.ivu.elect.business.wahlvorschlagsperson.entity.WahlvorschlagsPersonMeta;
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(AbstractWahlvorschlagsPersonCreateNoScopeView.COMPONENT_NAME)
@View(viewId = AbstractWahlvorschlagsPersonCreateNoScopeView.VIEW_ID, useCase = UseCasePermission.WAHLVORSCHLAGS_PERSON_CREATE)
public abstract class AbstractWahlvorschlagsPersonCreateNoScopeView extends de.ivu.elect.presentation.AbstractElectCreateView<WahlvorschlagsPerson> {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "wahlvorschlagsPersonCreateView";

  public static final String VIEW_ID = "/wahlvorschlagsperson/wahlvorschlags-person-create.xhtml";

  public static final String PARENT_VIEW_ID = "/wahlvorschlagsperson/wahlvorschlags-person-search.xhtml";

  @Inject
  protected transient WahlvorschlagsPersonBoundaryCreate create;

  protected WahlvorschlagsPerson entity;

  @Inject
  protected transient WahlvorschlagsPersonMeta entityMeta;

  
  @Inject
  protected transient WahlvorschlagsPersonFactory factory;

  public AbstractWahlvorschlagsPersonCreateNoScopeView() {
    super();
  }

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

  

  public WahlvorschlagsPerson getEntity() {
    return entity;
  }

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

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

    addMessageSaveSuccess(getEntity());

    resetStateAfterAction();

    return goBack(getParentViewId());
  }

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

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

  public boolean isBtnSaveRendered() {
    return hasPermission(UseCasePermission.WAHLVORSCHLAGS_PERSON_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.
  }
}
