
package de.ivu.elect.presentation.ui;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

@RequestScoped
@Named("pageMenuRemoteCommand")
public class PageMenuRemoteCommand implements Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient PageMenuState pageMenuState;

  public PageMenuRemoteCommand() {
    super();
  }

  public void setWidth() {
    try {
      String widthAsString = getParameterAsString("width");

      pageMenuState.setWidth(Long.parseLong(widthAsString));
    } catch (Exception ignored) {
      // ignorieren
    }
  }

  public void collapse() {
    try {
      String collapseAsString = getParameterAsString("collapse");
      pageMenuState.setCollapsed(Boolean.parseBoolean(collapseAsString));
    } catch (Exception ignored) {
      // ignorieren
    }

  }

  private String getParameterAsString(String parameterName) {
    return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(parameterName);
  }
}
