Open Print widget

6070
18
Jump to solution
06-06-2016 07:39 AM
TomLeMahieu
Deactivated User

I'm trying to open the Print widget from another widget.  If the widget has already been loaded I have no problem. If the print widget hasn't been loaded, it creates the widget and it creates the panel, but nothing shows. How do I show the panel?

Console:

     widget [widgets/Print/Widget] created.

     PanelManager.js:83 panel [widgets_Print_Widget_35_panel] created.

Code:

      _openPrintWidget: function () {

        if (this.wManager) {

            var widgetCfg = this._getWidgetConfig('Print');

            if(widgetCfg){

                var printWidget = this.wManager.getWidgetByLabel(widgetCfg.label);

                if(printWidget){

                    this.wManager.openWidget(printWidget);

                    this.pManager.showPanel(printWidget);

                } else {

                    this.wManager.loadWidget(widgetCfg).then(lang.hitch(this, function(widget){

                        if(widget){

                            this.wManager.openWidget(widget);

                            this.pManager.showPanel(widgetCfg);

                        }

                    }));

                }           

            }

        }

      },

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Tom,

Sorry about that. I have tested this code and it works fine:

        var widgetsConfig = this.appConfig.widgetPool.widgets;
        var widgetId;
        for(var i in widgetsConfig){
          if(widgetsConfig.name == "Print"){
            widgetId = widgetsConfig.id;
            break;
          } 
        }
        var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0];
        abc.setOpenedIds([widgetId]);

View solution in original post

0 Kudos
18 Replies
RobertScheitlin__GISP
MVP Emeritus

Tom,

  What theme are you working with, is the print widget in one of the themes controller widgets?

Here is some change to your code that sets the postion of the panel:

_openPrintWidget: function () {
        if (this.wManager) {
            var widgetCfg = this._getWidgetConfig('Print');
            if(widgetCfg){
                var printWidget = this.wManager.getWidgetByLabel(widgetCfg.label);
                if(printWidget){
                    this.wManager.openWidget(printWidget);
                    this.pManager.showPanel(printWidget);
                } else {
                    this.wManager.loadWidget(widgetCfg).then(lang.hitch(this, function(widget){
                        if(widget){
                            this.wManager.openWidget(widget);
                            this.pManager.showPanel(myWidget).then(lang.hitch(this, function(panel){ 
                                panel.setPosition({ top: 120, left: 10, width: 350, height: 480, margin: 10, index: 0 }); 
                                this.pManager.normalizePanel(panel); 
                            }))
                        }
                    }));
                }         
            }
        }
      },
0 Kudos
TomLeMahieu
Deactivated User

Robert,

Thanks for your help.  Something still isn’t right. 

If I load the Print widget, close it and then open if from another widget, it works fine. 

If I don’t load the Print widget and then open it from another widget using the openPrintWidget  code you provided, then the Print Widget panel appears, but it stays blank and I get the following error:

widget [widgets/Print/Widget] created.

panel [widgets_Print_Widget_35_panel] created.

Error:

“PanelManager.js:148 fail to startup panel widgets_Print_Widget_35_panel. TypeError: Cannot read property 'id' of null”

Any ideas?

Tom

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tom,

  Can you provide more info?

  • What theme are you using?
  • Is the print widget in a a themes controller widget?
0 Kudos
TomLeMahieu
Deactivated User

Robert,

I'm using the Launchpad theme and the Print widget is not part of a controller widget.

Tom

Sent from my iPhone

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tom,

  Just to double check Your print widget is added to one of the on screen widget placeholders then and not the Anchorbar controller?

0 Kudos
TomLeMahieu
Deactivated User

Robert,

I'm assuming this is the anchorbar widget in which case the print widget belongs to it.

Tom

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tom,

  Yes that is the AnchorBarController.

var controller = WidgetManager.getInstance().getWidgetsByName('AnchorBarController');

var widgetCfg = this._getWidgetConfig('Print');

controller.openWidget(widgetCfg);

0 Kudos
TomLeMahieu
Deactivated User

Hmmmm...when I use the 3 lines above, the first line defines the controller as an array with 1 item.  The second line defines widgetCfg but the third line gives me the error:

"controller.openWidget is not a function"

Am I missing something?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tom,

Sorry about that. I have tested this code and it works fine:

        var widgetsConfig = this.appConfig.widgetPool.widgets;
        var widgetId;
        for(var i in widgetsConfig){
          if(widgetsConfig.name == "Print"){
            widgetId = widgetsConfig.id;
            break;
          } 
        }
        var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0];
        abc.setOpenedIds([widgetId]);
0 Kudos