Button opens new widget, but closes open one thats in a different panel?

146
3
Jump to solution
11-16-2021 11:20 AM
EricRuberson1
New Contributor III

We added an on screen widget and made the button invisible per client request; they want it to open from somewhere else. Client has 2 sets of layers they want showing, in separate layer lists/table of contents (TOC) widgets. We got that working, basically by adding a second widget and configuring it to the second set of layers. 

We added a button to the bottom of the second TOC widget. 

So right now you can click the first TOC widget icon, see its layers listed, then click the second TOC widget icon, and it's layers also get listed, but it has a 'launch report' button at the bottom which launches our custom widget. The problem is once you click that button, after succesfully launching the custom widget, it closes the 2nd TOC list and switches back to the 1st TOC widget, since they shared the same panel.

How we made the button work:

1) added code to the 2nd TOC's html file

<a style="float:left; margin-right:10px; font-weight: bold; font-size: large;" href="#" data-dojo-attach-point="btnLaunchReport">Launch Report</a>

 

2) added code to the TOC's widget.js file

//under bindEvents
this.own(on(this.btnLaunchReport,
            'click',
            lang.hitch(this, this._reportWidget)));

//new function

      _reportWidget: function() {
        
        var widgetCfg = this._getWidgetConfig('reportWidget');

        widgetCfg.visible = true;

        var headerCfg = this._getWidgetConfig('HeaderController');

        var headerWidget = this.widgetManager.getWidgetByLabel(headerCfg.label);
        

        //This is need to show the widgets icon in the header

        headerWidget.resize();

        //This actually open the widget

        headerWidget.setOpenedIds([widgetCfg.id]);
        console.log(widgetCfg.id);

      },

 

this initially gave us errors saying that the config object was missing so we added code (lines 10-12, and 15) to the header controller widget.js below. 

//this is in themes/FoldableTheme/widgets/HeaderController
//we tweaked the original setOpenedIds function to look for our widget's config if it gets here and cant find one

      setOpenedIds: function(ids) {
        console.log("This is the ID test " + ids);
        if (ids.length === 0) {
          return;
        }
        var config = this.getConfigById(ids[0]);
        if(ids[0] == "_49"){ // set to our widget ID number
          config = this._getWidgetConfig('reportWidget');
        }

        if (!config) {
          console.log("No config found for " + ids[0]);
          return;
        }
        if(this.openedId){
          this._switchNodeToClose(this.openedId);

        }
        this.openedId = ids[0];
        if (config.widgets && config.openType === 'openAll') {
          this._switchNodeToOpen(config.id);
        } else if (!config.widgets) {
          if(this._getIconNodeById(config.id)){
            this._switchNodeToOpen(config.id);
          }else{
            this._showIconContent(config);
          }
        }
      },

It worked, successfully launching the custom widget, but side effect is it closes the TOC widget which shows all the layers, so the user would have to open it again. Minor bug but still a bug. It also launches an error in the console "TypeError:can't access property "className", b is null in the _showIconContent line, which implies that the code is hitting the header controller widget again after launching the custom report widget. So I'm not sure what's going on there.

 

I'm sure we're doing it wrong. Any help would be appreciated.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

@EricRuberson1 

You can only have one on screen widget open at at time in the foldable theme as well. So in all you can have one on screen widget (what you picture above) and on header controller widget open at the same time.

 

Now there are other themes like the launchpad theme that can have as many widgets as you want open at the same time.

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

@EricRuberson1 

Sounds like you are talking about the limitation that the Foldable theme has for only ONE widget to be open at a time from the header controller. It's just how it is, when you open another widget that is in the header controller widget it will close any other widget that are opened from the header controller.

0 Kudos
EricRuberson1
New Contributor III

Robert, 

Does this count even if it opens from over in this area, and not from the buttons located within the header controller?

EricRuberson1_0-1637173040049.png

 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

@EricRuberson1 

You can only have one on screen widget open at at time in the foldable theme as well. So in all you can have one on screen widget (what you picture above) and on header controller widget open at the same time.

 

Now there are other themes like the launchpad theme that can have as many widgets as you want open at the same time.

View solution in original post

0 Kudos