The Relativity Review API exposes functionality for creating and managing the right-click context menus in the document viewer. It also supports extending the functionality available in context menus. Relativity Extensions provides a framework used when making these customizations.
This page contains the following information:
To add menu items for a specific viewer type, use the IExtensionConfig.viewerContextMenus function. Pass viewer type (ViewerType) property to this function. To create a Relativity extension, see Building an extension.
In an extension script, use viewerContextMenus
function to create and return an array of context menu items of type IContextMenuItemConfig.
The following extension script includes these examples for working with menu items:
click
event on the menu items.viewerType
(ViewerType) argument passed to the viewerContextMenus
function.permissionCheck
property must be type IPermissionCheckRequest.(function (params) {
var config = {
id: "examplecompany.testextension",
name: "Example Company Test Extension",
viewerContextMenus: function (api, viewerType) {
var menuItems = [];
// Example 1
// Add this menu item to all viewers and set up its click event handler.
var menuItem1 = {
text: "Selected",
order: 10,
onClickCallback: function (reviewData, api) {
alert("View Type: " + viewerType);
},
};
menuItems.push(menuItem1);
// Example 2
// Add this menu item only to native viewers and set up its click event handler.
if (viewerType === "native") {
menuItems.push({
text: "Native Context",
order: 10,
onClickCallback: function (reviewData, api) {
alert("Native Viewer");
},
});
}
// Example 3
// Call other APIs when this menu item is clicked.
if (viewerType === "native" || viewerType === "text") {
menuItems.push({
text: "Search for Text",
onClickCallback: function (reviewData, api) {
var selected = reviewData.getSelectedText();
if (selected) {
api.highlights.setRecentSearchTerm(
reviewData.getSelectedText(),
"literal"
);
} else {
alert("No text selected.");
}
},
});
}
// Example 4
// Include permission checks for menu items.
menuItems.push({
text: "No Permission To See This",
onClickCallback: function (reviewData, api) {
alert("You shouldn't be allowed to do this!!!");
},
permissionCheck: {
permissionName: "HasPermission",
artifactTypeId: 1000007,
},
});
return menuItems;
},
};
return config;
})(params);
Additional configurations for context menu items include:
Add child items - use childItems
(IContextMenuItemConfig.childItems) property on the IContextMenuItemConfig interface to add child menu items. These child items are added to an existing menu item. They are displayed on the right when a user hovers over the parent menu item.
Change menus on the fly - use the onBuildCallback
(IContextMenuItemConfig.onBuildCallback) function to change menu items on the fly. This callback is invoked when the IContextMenu is built for each item. It can access review data like documentId
or workspaceId
.
For example, you can change a menu on the fly by disabling a menu item based on a specific condition. See ContextMenuOption object properties for information about changing child items or the name of an option in this function.
The following extension script illustrates how to use the childItems
, the disabled
, and the onBuildCallback
properties of IContextMenuItemConfig object:
(function(params) {
var config = {
id: "examplecompany.testextension",
name: "Example Company Test Extension",
lifecycle: function(api) {
...
},
cards: [ .. ],
viewerContextMenus: function(api, viewerType) {
var menuItems = [];
// Example 1
var menuItem1 = {
text: "Selected",
order: 10,
onClickCallback: function(reviewData, api) {
alert('View Type: ' + viewerType);
},
onBuildCallback: function(contextMenuOption, reviewData, api) {
if (api.viewer.mainCollection.activeType === "production") {
contextMenuOption.disabled = true;
}
else {
contextMenuOption.items = [{
name: ...
}];
}
console.log("ReviewData Information - ");
console.log("WorkspaceId - " + reviewData.workspaceId);
console.log("DocumentId - " +
reviewData.queuePointer.item.artifactId);
console.log("Cursor - " +
reviewData.cursor.x + "," + reviewData.cursor.y);
console.log("SelectedText - " + reviewData.getSelectedText());
console.log("getSelectedAnnotations() - " +
reviewData.getSelectedAnnotations());
console.log("getAnnotationsAtCursor() - " +
reviewData.getAnnotationsAtCursor());
}
// Return the contextMenuOption if any modifications were made.
return contextMenuOption;
};
// Example 2
var menuItem2 = {
text: "Parent",
order: 12,
childItems: [
{
text: "Child 1",
order: 15,
onClickCallback: function(reviewData, api) {
alert("I'm child 1");
},
},
{
text: "Child 2",
order: 16,
onClickCallback: function(reviewData, api) {
alert("I'm child 2");
},
}
],
};
menuItems.push(menuItem1);
menuItems.push(menuItem2);
return menuItems;
}
};
return config;
}(params))