Options
All
  • Public
  • Public/Protected
  • All
Menu

Sample Viewer Type

The following code sample illustrates an extension that registers a simple custom viewer type:

(function (parameters) {
  function CustomViewer(card) {
    this._card = card;

    this.id = this._card.instanceId;
    this.unsupportedTabTitle = this._card.title + " (Unsupported)";
    this.type = this._card.viewerType;

    this.cardLoaded = function (api, card, target) {
      this._target = target;
    };

    this.cardLoadItem = function (item, options) {
      this._updateItemName(item.label);
      return Promise.resolve(true);
    };

    this._updateItemName = function (name) {
      this._target.innerText = name;
    };
  }

  return {
    id: "relativity.review.test.customviewers",
    name: "Custom Viewers Test Extension",
    viewers: [
      {
        id: "review.custom",
        viewerType: "custom",
        title: "Custom",
        loader: {
          custom: {
            loadCard: function (card, target) {
              return Promise.resolve();
            },
            unloadCard: function (card, target) {
              return Promise.resolve();
            },
          },
        },
        createInstance: function (card) {
          return new CustomViewer(card);
        },
        supportsItem: function (api, queueItem, fileTypeId) {
          return Promise.resolve(fileTypeId === 1143); // Supports emails
        },
      },
    ],
  };
})(params);