/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */
package imgmap;

import ilog.views.chart.faces.servlet.IlvFacesChartSelectAction;
import ilog.views.chart.servlet.IlvDefaultIMapAttributes;

/**
 * A custom <code>IlvDefaultIMapAttributes</code> subclass that overrides
 * getTarget() to return the PIECHART frame and adds javascript extra
 * attributes.
 */

public class SliceIMapAttributes extends IlvDefaultIMapAttributes {
  String action;

  String onClickLink;

  /**
   * Creates a <code>SliceIMapAttributes</code> instance.
   * 
   * @param id
   *          The slice ID.
   * @param title
   *          The title of the map area.
   * @param onClickLnk
   *          The link to visit if the map area is clicked.
   */
  public SliceIMapAttributes(String id, String title, String onClickLnk) {
    super("javascript:void(0)", title);
    this.action = buildAction(id);
    this.onClickLink = onClickLnk;
  }

  /**
   * Builds the href from the id of the slice. This href trigger a default
   * server side action registered on the chart servlet support that translate
   * the servlet action into a JSF action and will invoke the listener passed as
   * parameter.
   * 
   * @param id
   *          The id of the slice.
   * @return The href The href of the map area.
   * @see ilog.views.chart.faces.servlet.IlvFacesChartSelectAction
   */
  private String buildAction(String id) {
    // This JavaScript action references a default servlet action registered on
    // the faces chart servlet support.
    // This action will translate the servlet action into a JSF action and will
    // invoke the listener passed as parameter
    return "chartView.performAction('" + IlvFacesChartSelectAction.ACTION_NAME + "'" + ", new Array('" + id
        + "','0','0','0','0','0','0','0','#{imapBean.explode}','0','#{imapBean.finder}'), true); ";

  }

  /**
   * Returns the link target.
   */
  Override
  public String getTarget() {
    return "PIECHART";
  }

  /**
   * Returns the extra attributes of the map area.
   */
  Override
  public String getExtraAttributes() {
    // Fix JV-5589 && JV-5864
    return "onClick=\"" + action + " setTimeout(parent.frames['SLICELINK'].location=" + "'" + onClickLink + "',0);\"";
  }
}