2

I need to change the "title" for each document shown in ICN Viewer, dynamically, at runtime. I'll read the new viewer tab title from the document properties.

Environment: ICN 2.0.3 CM8.5 WAS 8.5.5

Code so far:

  1. I found a PARTIAL solution by hooking "ecm.model.desktop, onChange":

     aspect.after(ecm.model.desktop, 'onChange', function() {
        var contentViewer = dijit.byId('contentViewer');
        if (contentViewer) {
           var viewerTabTitleDef = new ViewerTabTitleDef ();
           contentViewer.mainTabContainer.getChildren().forEach(function(child) {
              viewerTabTitleDef.changeTitle(viewerTabTitleDef.self,
                 child.controlButton, child.contentViewerPane.viewerItem.item);
           });
           ...
    
  2. I was able to extend this for subsequent documents opened in the same viewer, and optimized by "removing()" the handler after this initial call. Here is the complete code:

     var kill = aspect.after(ecm.model.desktop, 'onChange', function() {
    
        var contentViewer = dijit.byId('contentViewer');
        // "contentViewer" will be "unknown" unless viewer invoked
        console.log('onChange: contentViewer', contentViewer);  
    
        if (contentViewer) {
           console.log("new ViewerTabTitleDef()...");
           kill.remove();
           var viewerTabTitleDef = new ViewerTabTitleDef ();
           contentViewer.mainTabContainer.getChildren().forEach(function(child) {
               // For initially opened tabs
               console.log('initially opened: child', child);
               viewerTabTitleDef.changeTitle(viewerTabTitleDef.self, child.controlButton, child.contentViewerPane.viewerItem.item);
           });
           aspect.after(contentViewer.mainTabContainer, 'addChild', function(child) {
               // For tabs added after the viewer was opened
               console.log('subsequently opened: child', child);
               viewerTabTitleDef.changeTitle(viewerTabTitleDef, child.controlButton, child.contentViewerPane.viewerItem.item);
           }, true);
        } // end if contentViewer
    
     });  // end aspect.after(onChange desktop)
    
  3. Current problem: how can I change the label for a split tab (either vertical or horizontal)?

So far, I have NOT been able to find any event for any ICN/ECM widget or object variable that I can trigger on.

halfer
  • 19,824
  • 17
  • 99
  • 186
paulsm4
  • 114,292
  • 17
  • 138
  • 190

2 Answers2

1

It seems you want to show a different tab-title (instead of the document title) in the navigator viewer whenever a doc is opened.

How about this?

Every document you open in the viewer is wrapped in a ecm.widget.viewer.model.ViewerItem which exposes the getHtmlName that returns the name used in the tab.

Your solution would be to implement your own getHtmlName.

Unfortunately though, the ViewerItem is constructed in the ecm.widget.viewer.ContentViewer#_open and then passed to the ecm.widget.viewer.ContentViewer#_openTab. So you'll either violate best practice by mingling with IBM private methods, or you'll go for a generic approach and just replace the ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ivo Jonker
  • 306
  • 3
  • 9
  • Excellent suggestion: thank you. I'll let you know how it goes; I'll be sure to "accept" if it works! – paulsm4 May 18 '18 at 17:54
  • Good luck! You could start with this arbitrary example that presents the document id as title: `require(["ecm/widget/viewer/model/ViewerItem"],function(ContentViewer){ ContentViewer.prototype.getHtmlName=function (){ return this.item.id; } });` – Ivo Jonker May 22 '18 at 05:57
0

(I am posting the answer on behalf of the question author, to move it to the answer section).

Many thanks to Ivo Jonker, for his suggestion to modify the widget prototype's "getHtmlName()" method. It worked!

Specifically:

  1. I'm invoking this code from an ICN plugin. I set event handlers in my plugin's base .js file, but it actually gets invoked in the new, separate viewer window.

  2. The original prototype looked like this:

     getHtmlName: function() {
         var methodName = "getHtmlName";
         this.logEntry(methodName);
    
         var displayName = this.item.getDisplayValue("{NAME}");
         if (displayName == "") {
             displayName = this.item.name;
         }
    
         var htmlName = entities.encode(displayName);
         this.logExit(methodName);
         return htmlName;
     },
    
  3. Per Ivo's suggestion, I overrode the prototype method like this:

         myPluginDojo.viewerTabTitleDef = viewerTabTitleDef;
         ...
         ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName = function () {
             console.log("NEW getHtmlName()...");
             var displayName = myPluginDojo.viewerTabTitleDef.getTitle(this.item);
             return displayName;
         };
    
halfer
  • 19,824
  • 17
  • 99
  • 186
  • [/help/referencing](/help/referencing) you need to blockquote. – starball Jul 07 '23 at 16:49
  • Ah, I see what you mean @starball - since the material comes from the question author, and it was re-posted by me, then it needs to be `>` quoted in its entirety. I don't agree with that - the idea here is that the first line indicates that the whole post can be taken to be in the question author's voice. – halfer Jul 07 '23 at 20:40
  • (If they were to repost it themselves I'd be happy to delete the CW copy, but unfortunately the question author is keen to oppose a number of community standards, and is not minded to collaborate to such a degree). – halfer Jul 07 '23 at 20:42