package de.ivu.elect.presentation.internet;

import javax.annotation.Nullable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.internet.entity.InternetWidget;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.jee.faces.PreConditionCheck;
import de.ivu.elect.jee.presentation.dynamicform.FormBuilder;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.hilfe.OnlineHilfeId;
import de.ivu.elect.presentation.internet.form.InternetWidgetViewFormBuilder;

@RequestScoped
@Named(AbstractInternetWidgetEditNoScopeView.COMPONENT_NAME)
@View(viewId = AbstractInternetWidgetEditNoScopeView.VIEW_ID, useCase = UseCasePermission.INTERNET_WIDGET_EDIT)
@OnlineHilfeId("749")
public class InternetWidgetEditView extends AbstractInternetWidgetEditView {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient InternetWidgetViewFormBuilder viewFormBuilder;

  public InternetWidgetEditView() {
    super();
  }

  @Nullable
  @PreConditionCheck
  public String checkCondition() {
    if (isEntitySet()) {
      return null;
    }

    return cancel();
  }

  @Override
  protected boolean isGebietBearbeitenRechtPruefen() {
    return false;
  }

  @Override
  public void addProperties(FormBuilder formBuilder, InternetWidget internetWidget) {
    viewFormBuilder.addProperties(formBuilder, internetWidget);
  }

  @Nullable
  @Override
  public String goBack() {
    if (viewStack.contains(InternetWidgetCreateView.VIEW_ID)) {
      return InternetWidgetSearchView.VIEW_ID; // sonst geht's zuück zum Anlegen View...
    }
    return super.goBack();
  }

}
