
package de.ivu.elect.presentation.person;

import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.person.boundary.BerufEdit;
import de.ivu.elect.business.person.entity.Beruf;
import de.ivu.elect.business.person.entity.BerufProperties;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.security.UseCaseSecure;
import de.ivu.elect.jee.presentation.dynamicform.FormBuilder;
import de.ivu.elect.jee.presentation.redirect.Redirect;
import de.ivu.elect.presentation.hilfe.OnlineHilfeId;
import de.ivu.elect.presentation.security.AbstractGebietSecurityFilter;

@OnlineHilfeId("492")
@Named(AbstractBerufSearchView.COMPONENT_NAME)
public class BerufSearchView extends AbstractBerufSearchView {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient BerufEdit berufEdit;

  public BerufSearchView() {
    super();
  }

  @Override
  protected AbstractGebietSecurityFilter<Beruf> getGebietSecurityFilter() {
    return KEIN_GEBIET_SECURITY_FILTER;
  }

  @Override
  public void presetSearchParameters() {
    // Do nothing.
  }

  @Override
  public void addProperties(FormBuilder formBuilder) {
    BerufProperties properties = getSearchParameters().getBeruf().getProperties();
    formBuilder.addProperty(properties.getNameProperty()).withRequired(false);
    formBuilder.addProperty(properties.getCodeProperty()).withRequired(false);
    formBuilder.addProperty(properties.getHerkunftProperty()).withRequired(false);
    formBuilder.addProperty(properties.getGeschlechtMitLeererAuswahlProperty()).withRequired(false);
  }

  public boolean isBtnAlleBerufeLoeschenRendered() {
    return hasPermission(UseCasePermission.BERUF_DELETE);
  }

  public boolean isBtnAlleBerufeLoeschenDisabled() {
    return isEmptySearchResultDisplayed();
  }

  @Redirect
  @UseCaseSecure(UseCasePermission.BERUF_DELETE)
  public String alleBerufeLoeschen() {
    berufEdit.delete(getSearchResult());

    addInfoMessage("entity.edit.action.delete.all.success.message", entityMeta.getMehrzahlMessage());

    resetSearchResult();

    return VIEW_ID;
  }
}
