Open a widget from another widget

7361
14
Jump to solution
07-28-2016 02:22 AM
Labels (1)
Naveen_KumarKairamkonda
Occasional Contributor


How to open a widget from another widget. I have a scenario like, After getting the resulted location in map(Search widget) it should open the Identify widget. Which of the files need to be edited in both widgets.

Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ibrahim,

So it turns out that the code to open the draw widget in the TabTheme should be:

     _openDrawWidget: function() {
          var drawWidget, sbc;
          var widgetCfg = this._getWidgetConfig('Draw');
          if (widgetCfg) {
              sbc = WidgetManager.getInstance().getWidgetsByName("SidebarController")[0];
              sbc._resizeToMax();
              sbc.setOpenedIds([widgetCfg.id]);
          }
      }

View solution in original post

14 Replies
RobertScheitlin__GISP
MVP Emeritus
Naveen_KumarKairamkonda
Occasional Contributor

Hi Robert,

  I'm using Tab theme for this application.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

d ibrahim,

So the first link I posted is the one you want to look at then as that poster was working with the TabTheme as well.

0 Kudos
Naveen_KumarKairamkonda
Occasional Contributor

Hi Robert,

  I'm implementing the code which is in 1st link, Could you define the _getWidgetConfig('Print') function.

Thanks for suggesting me...

0 Kudos
deepthip
New Contributor

Hi Robert,

Even I am looking for that _getWidgetConfig('Print') function.

could u please share _getWidgetConfig('Print') function code and if any userdefined functions inside the _getWidgetConfig('Print') please attach the code for that functions also.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

d ibrahim,

Looking at that thread again I realize that it is dealing with the LaunchPad theme and not the Tab theme so you need to use:

Add these Require statements to your code:

'jimu/WidgetManager',
'jimu/PanelManager

WidgetManager, 
PanelManager

Then these new functions:

            _getWidgetConfig: function(widgetName){
              var widgetCnfg = null;
              array.some(WidgetManager.getInstance().appConfig.widgetPool.widgets, function(aWidget) {
                if(aWidget.name == widgetName) {
                  widgetCnfg = aWidget;
                  return true;
                }
                return false;
              });
              if(!widgetCnfg){
                /*Check OnScreen widgets if not found in widgetPool*/
                array.some(WidgetManager.getInstance().appConfig.widgetOnScreen.widgets, function(aWidget) {
                  if(aWidget.name == widgetName) {
                    widgetCnfg = aWidget;
                    return true;
                  }
                  return false;
                });
              }
              return widgetCnfg;
            },

            _openPrintWidget: function() {
                var printWidget, sbc;
                var widgetCfg = this._getWidgetConfig('Print');
                if (widgetCfg) {
                    sbc = WidgetManager.getInstance().getWidgetsByName("SidebarController")[0];
                    printWidget = WidgetManager.getInstance().getWidgetByLabel(widgetCfg.label);
                    if (printWidget) {
                        sbc.setOpenedIds([widgetCfg.id]);
                        sbc._resizeToMax();
                        WidgetManager.getInstance().openWidget(printWidget);
                        PanelManager.getInstance().showPanel(printWidget);
                    } else {
                        sbc.setOpenedIds([widgetCfg.id]);
                        sbc._resizeToMax();
                        setTimeout(function() {
                            printWidget = WidgetManager.getInstance().getWidgetById(widgetCfg.id);
                            WidgetManager.getInstance().openWidget(printWidget);
                            PanelManager.getInstance().showPanel(printWidget);
                        }, 3000);
                    }
                }
            }

Then call the _openPrintWidget function

this._openPrintWidget();
Ángel_DanielSuárez_Calero
New Contributor III

Hi Robert, I tried this code in the tab theme and this work correctly , but I tried in a "SidebarTheme7" and it doesn´t work correctly. The "sbc" is undefined. I don´t understand this, because the widget that contains the widgets in my "SidebarTheme7" is "SidebarController".  Need I a other function for my theme?

I attached my theme in this link : https://drive.google.com/open?id=1_Zw0huZZrP9y5UZA_brFb4KAbgQHH6wv 

Thanks for all! 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Angel,

   So you have:

sbc = WidgetManager.getInstance().getWidgetsByName("SidebarTheme7")[0];

in your code?

0 Kudos
Ángel_DanielSuárez_Calero
New Contributor III

No, I have this in my code :  

sbc = WidgetManager.getInstance().getWidgetsByName("SidebarController")[0];

Thanks! 

0 Kudos