The Common Opener allows you to open any ALI object from anywhere within the portal. (To retrieve an URL as a String or HTMLAnchor object, use ASURL.)
The PTCommonOpener class is included in every page generated by the ALI application, and can be called from any piece of UI or from within a portlet. Portlets can also call functions remotely through the PRC. The most commonly used function in this class is getOpenerURLOpenObjID.
function
getOpenerURLOpenObjID (_nClassID, _nObjectID, _strOptQSArgs, _nOpenerMode)
This JavaScript creates a URL that calls the Opener ActivitySpace and its corresponding OpenObject Control (the only MVC module in the Opener ActivitySpace). The URL includes all necessary parameters for the Control. As noted above, the Common Opener function is available from any portal page. The getOpenerURLOpenObjID function has four required parameters:
nClassID refers to the numeric ID for the type of object being opened (e.g., User = 1, Portlet = 43, Content Source = 35). A full list of object types can be found in the PTCLASSDESCRIPTION table in the com.plumtree.portaluiinfrastructure.classtypedescriptors package.
nObjectID is the identifier for the specific object being opened. Every object has a unique identifier (ObjectID) stored within the database (e.g., for the Users object type: Administrator = 1, Guest = 2, Default Profile = 3, etc.). The ObjectID can be retrieved through the com.plumtree.server package and usually through a QueryResult.
strOptQSArgs allows you to add arguments to the query string that are not included by default. This argument may be empty.
nOpenerMode defines the mode in which the object will be opened, which controls the actions that can be performed on the object (i.e., Create = 0, Edit = 1, View = 2, View Meta Data = 3).
As noted above, the getOpenerURLOpenObjID function returns a URL. To open the URL you must pass it to another function. PTCommonOpener includes two handy functions for opening URLs: openInSameWindow and openInNewWindow.
Call either of these functions in a standard OnClick event. The example below opens the User Editor ActivitySpace as the Administrator user in View mode.
<INPUT
value="Opener Click" type="Button" name="btnSubmit"
onClick="PTCommonOpener.openInSameWindow(PTCommonOpener.getOpenerURLOpenObjID(1,1,'null',2));"/>
You can execute custom functionality whenever the Common Opener is used to open an object or direct to an ActivitySpace through the IOpenerActions PEI. For more details on PTCommonOpener and its functions, see the Common Opener API documentation. To download the samples referenced on this page, see the ALI Scripting Framework Samples in dev2dev code share.
As noted earlier, PTCommonOpener functions can be called from within any ALI-based portal page. You can also use these functions in a custom editor or browsing page by making a call to the Opener ActivitySpace. The Common Opener functionality can be implemented in a variety of ways; the method explained here is the easiest and most commonly used.
Note: To use the following method, first import the package that contains the Opener ActivitySpace (com.plumtree.portaluiinfrastructure.classtypedescriptors.classframework).
Within the DisplayJavaScript method in the View class of your custom ActivitySpace, make a call to GetOpenerJavascript as shown in the code snippet below. This function requires one parameter: the ActivitySpace that contains the JavaScript function (inherited from the top level AActivitySpace object (m_asOwner)). The HTMLScript element returned contains Common Opener JavaScript functions.
public
HTMLScript DisplayJavascript()
{
HTMLScript myScript;
myScript = new HTMLScript("text/javaScript");
myScript = PTOpenerLinks.GetOpenerJavascript(m_asOwner);
return myScript;
}
This code creates a new HTMLScript element, initializes it, and makes a call to GetOpenerJavascript.
Other methods for generating JavaScript code on the server are described in the API documentation for PTOpenerLinks in the portaluiinfrastructure package.
Next: Using ASURL and Redirect