How to handle loading of a view in Tridion's CME

偶尔善良 提交于 2019-12-08 16:47:12

问题


I have an extension to the Tridion 2011 Content Manager Explorer where I want to execute a specific piece of JavaScript only for a specific view.

I do this with the following JavaScript fragment:

var onDisplayStarted = function () {
    $evt.removeEventHandler($display, "start", onDisplayStarted);

    if ($display.getView().getId() == "PublishPopup") {
      ...
    }
};
$evt.addEventHandler($display, "start", onDisplayStarted);

This code has worked well in the past and it definitely triggers when the PublishPopup opens and ensures my code only executes in that specific view.

But unfortunately I sometimes get the following error message in the JavaScript console while loading the DashboardView:

Uncaught TypeError: Object # has no method 'getId'

The error doesn't cause any problems, most likely since errors in event handlers are handled correctly by Tridion's UI framework. But I'd still prefer to not have the error showing in the JavaScript console.

I understand how to detect if the getId method exists:

if ($display.getView().getId && $display.getView().getId() == "PublishPopup") {

But that would just mean that the code doesn't execute ever. And although it seems to work fine in the PublishPopup right now, I'd rather know the proper way to handle this type of "my code should execute once the view has initialized" sequence.

Does anyone know a better way to handle this?


回答1:


Well, there are two different views, which are loaded at the same time - Dashboard View and Tridion Dashboard View. Tridion Dashboard View is what you see when you click on SDL Tridion tab in Ribbon Toolbar. Indeed, this view doesn't have getId method (which is strange, btw). That's why you have this issue.

Nevertheless, the whole idea behind the file groups in configuraton file is to minimize amount of the javascript, loaded for each view and to minimize un-needed javascript processing. So I would recommend to split your javascript file into pieces and load them only oт necessity.




回答2:


Do you have code in your configuration to only include your extension on the popup window? For example:

<cfg:extension target="Tridion.Web.UI.Editors.CME.Views.Popups.Publish">

I typically use that configuration to only run script on a specific view within the cme.

My js file then looks like this:

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

function onDisplayStarted() {

        $log.message("stuff here");
}


来源:https://stackoverflow.com/questions/12901161/how-to-handle-loading-of-a-view-in-tridions-cme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!