9

I have written a GUI extension which adds an additional tab to many of the Item views in the SDL Tridion CME (e.g. Component, Page and Schema etc.). I have also written some JavaScript which loads that tab directly if when the view is loaded with a tab name is specified in the URL.

The result is that if a page is loaded with the tab name added as follows:

http://localhost/WebUI/item.aspx?tcm=64#id=tcm:1-48-64&tab=InfoTab

Rather than the default of

http://localhost/WebUI/item.aspx?tcm=64#id=tcm:1-48-64

The Info Tab will be loaded on top, instead of the General Tab. This is performed with the following code snippet and works very well:

$evt.addEventHandler($display, "start", onDisplayStarted);

// This callback is called when any view has finished loading
function onDisplayStarted() {

    $evt.removeEventHandler($display, "start", onDisplayStarted);
    var tabname = $url.getHashParam("tab");
    if (tabname != '') {
        var tabControl = $controls.getControl($("#MasterTabControl"), "Tridion.Controls.TabControl");
        tabControl.selectItem(tabname);        
    }
}

Now I would like to make a context menu item to open items and link to the tabs using my new functionality. My first thought was to construct the Item URL myself and simply open a new window in my execute method. So I looked at the default functionality in the standard Open.prototype_execute() functionality of the GUI. This is stored in the navigation.js file of the CME, and is performed by the Tridion.Cme.Commands.Open.prototype._execute method. The code is a lot more complicated than I had anticipated as it deals with shared items, and permissions etc.

Rather than just copying all of this code to my own function, I was wondering if there is a way to elegantly extend the existing Open.prototype_execute() function and append my “&tab=MyTab” to the $cme.Popups.OPEN_ITEM_OPTIONS.URL constant for my own functions.

Any advice would be greatly appreciated.

7

You can extend the Open command through the use of the <ext:commandextensions> section in your editor configuration -- see this question for an example: How to Extend “CheckOut” Command in SDL Tridion 2011 SP1?

In this case, I would overwrite the _openInEditor method instead. It already takes a list of URL parameters, which then end up as hashtags in the URL.

So you would just need to add your own before calling the base method:

Examples.ExampleOpenCommand._openInEditor = function ExampleOpenCommand$_openInEditor(itemToOpenUri, urlParams)
{
   urlParams.tab = "InfoTab";
   this.callBase("Tridion.Cme.Commands.Open", "_openInEditor", [itemToOpenUri, urlParams]);
}

Disclaimer: any method that starts with an underscore is considered private. So it could be changed without warning in the future. It still seems like the best solution to me in this case, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.