Show TOC

Accessing the "preview" ContractLocate this document in the navigation structure

This contract allows you to display a preview of a CHIP. This can be used to display a list of available CHIPs in a catalog, for example.

The preview does not display any live data, but it contains a link to the same target application as the corresponding live CHIP.

As a prerequisite, you have to consume the preview contract in the CHIP definition XML.

The preview property is then available in the CHIP API object. It provides the following methods:

  • chip.preview.getTitle()

    You can use this method to get the CHIP title. The CHIP may display this in the UI that it shows in preview mode.

  • chip.preview.getDescription()

    You can use this method to get the CHIP description. The CHIP may display this in the UI that it shows in preview mode.

  • chip.preview.isEnabled()

    You can use this method to find out whether the preview mode of CHIPs is enabled.

  • chip.preview.setPreviewIcon()

    This method defines the preview icon to be used for this CHIP.

  • chip.preview.setPreviewTitle()

    This method defines the preview title to be used for this CHIP. It is necessary to explicitly set a title, otherwise no title will be displayed in the preview.

    We recommend to use the same title for the preview as for the live CHIP. To achieve this, set the preview title to the return value of the oChipApi.preview.getTitle() method.

    If you want to define a separate title for the preview, you should additionally use the bag contract to store the title in a translatable bag property.

  • chip.preview.setTargetUrl()

    You can use this method to define the URL of the underlying application for this CHIP.

Example:

Code Example
onInit: function() {
  var oChipApi = this.getView().getViewData().chip;

  if(oChipApi.preview.isEnabled()) {
    // Determine target URL e.g. from CHIP configuration
    var sUrl = ... // typically #<SemanticObject>-<Action>?Parameter1=Value1&Parameter2=Value2, e.g. #DaysSalesOutstanding-Display?kpiId=KPI&variantId=VARIANT
    oChipApi.preview.setTargetUrl(sUrl);
    // Note: do NOT use to display live data etc.!
    //   You may use oChipApi.preview.getTitle() and oChipApi.preview.getDescription() to display on the UI
    oChipApi.preview.setPreviewIcon(oChipApi.configuration.getParameterValueAsString("icon")); //sample: set preview icon from CHIP configuration
    oChipApi.preview.setPreviewTitle(oChipApi.preview.getTitle());
 }
}

In this example, the CHIP instance checks whether preview mode is enabled in its onInit method. If preview mode is enabled, it computes and sets the target URL in the preview contract. In addition, it ensures that rendering is done in preview mode. For example, it makes sure not to use any live data and uses title and description accessed using the preview contract for its UI. If the embedding application does not render the CHIP in preview mode, it provides an icon and a title to be displayed by the embedding application for preview purposes.