Options
All
  • Public
  • Public/Protected
  • All
Menu

Window Service

Window Service

The Relativity Review Interface exposes APIs for creating and managing pop-up windows. Use these APIs to open cards and viewers in separate windows. Additionally, use to them to create pop-up windows as part of Review Extensions. The Review API exposes the Window Service API, which you can use for several of these tasks. For Window Service reference content, see IReviewInterfaceApi.window.

This page contains the following information:

Create pop-up windows using the Window Service API

To create a pop-up window, use the IWindowService.create function. Pass this function an argument of type IApplicationWindowConfig. Set the IApplicationWindowConfig.name property on the config object. This string property is required, must be unique, and can't contain any spaces. Except for the name property, all other properties on IApplicationWindowConfig are optional.

If successful, the IWindowService.create function returns an instance of IApplicationWindow. This instance provides access to the underlying window object of the pop-up window and other window properties. You can also use this instance to subscribe to different window events or to close the window.

The following example illustrates how to create a pop-up window:

reviewapi.on("apiready", function () {
  var config = {
    name: "test-window",
    isPopup: true,
    title: "Test Window",
    url: "https://www.relativity.com",
    features: "width=600,height=600,resizable=yes",
  };

  var appWindow = reviewapi.window.create(config);
  var isWindowOpen = appWindow.isOpen === true;

  // Access the DOM functions and properties via the "window" property.
  var body = appWindow.window.document.querySelector("body");
  body.innerHTML = "<h1>Review Pop-up Window</h1>";
});

Subscribe to window events

To subscribe to window events, use the IApplicationWindow. The ApplicationWindowEventType enum includes these events:

  • canclose - an event raised when a window is about to close. Use this event to prompt users about unsaved changes.
  • close - an event raised when a window is being closed.
  • resized - an event raised after a window has been resized.

The following code sample illustrates how to subscribe to an event:

reviewapi.on("apiready", function () {
  var config = {
    name: "test-window",
    isPopup: true,
    title: "Test Window",
    url: "https://www.relativity.com",
    features: "width=600,height=600,resizable=yes",
  };

  var appWindow = reviewapi.window.create(config);
  var isWindowOpen = appWindow.isOpen === true;

  // Subscribe to events.
  appWindow.on("canclose", function () {
    /* 
      For example, use this event as a check for unsaved changes.
    */

    // Returning false prompts the user about unsaved changes and prevents the window from closing. Returning true closes the window.
    return false;
  });

  appWindow.on("close", function () {
    // Perform any clean up tasks after the window closes.
    var isWindowClosed = appWindow.isOpen === false;
  });

  appWindow.on("resized", function (e) {
    var newHeight = e.target.innerHeight;
    var newWidth = e.target.innerWidth;
  });

  // Resizing the window triggers a "resized" event.
  appWindow.window.resizeTo(700, 800);

  // Closing the pop-up window triggers the "canclose" and then "close" events.
  appWindow.close();
});

Access the main and Relativity windows

For cross-window communication, you can use the following IApplicationWindow instances created when the Review API initializes:

Access a pop-up window by name

To access a specific IApplicationWindow, use the IWindowService.getWindow helper function. This function takes the window name used when creating the pop-up window. If it finds a pop-up window with this name, the function returns a corresponding IApplicationWindow object. If it doesn't find one, the function returns undefined.

The following code sample creates two pop-up windows. It then uses the IWindowService.getWindow function to retrieve the IApplicationWindow:

reviewapi.on("apiready", function () {
  var config1 = {
    name: "test-window1",
    isPopup: true,
    title: "Test Window 1",
    url: "https://www.relativity.com",
    features: "width=600,height=600,resizable=yes",
  };
  var appWindow1 = reviewapi.window.create(config1);

  var config2 = {
    name: "test-window2",
    isPopup: true,
    title: "Test Window 2",
    url: "https://www.google.com",
    features: "width=600,height=600,resizable=yes",
  };
  var appWindow2 = reviewapi.window.create(config2);

  // Get a window by its name.
  var appWindow = reviewapi.window.getWindow("test-window1");
  // appWindow.title === "Test Window 1"
});

Close all pop-up windows

To close all pop-up windows, use the IWindowService.closeAll function on the Window Service API (IWindowService). For example, you might use this function when a when user navigates away from the Review Interface into a document list.

The following code sample creates multiple windows and closes them all using this helper function:

reviewapi.on("apiready", function () {
  var config1 = {
    name: "test-window1",
    isPopup: true,
    title: "Test Window 1",
    url: "https://www.relativity.com",
    features: "width=600,height=600,resizable=yes",
  };
  var appWindow1 = reviewapi.window.create(config1);

  var config2 = {
    name: "test-window2",
    isPopup: true,
    title: "Test Window 2",
    url: "https://www.google.com",
    features: "width=600,height=600,resizable=yes",
  };
  var appWindow2 = reviewapi.window.create(config2);

  // Close all windows.
  reviewapi.window.closeAll();
});