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);
}
}));
}
}
}
},
Solved! Go to Solution.
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]);
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); })) } })); } } } },
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
Tom,
Can you provide more info?
Robert,
I'm using the Launchpad theme and the Print widget is not part of a controller widget.
Tom
Sent from my iPhone
Tom,
Just to double check Your print widget is added to one of the on screen widget placeholders then and not the Anchorbar controller?
Robert,
I'm assuming this is the anchorbar widget in which case the print widget belongs to it.
Tom
Tom,
Yes that is the AnchorBarController.
var controller = WidgetManager.getInstance().getWidgetsByName('AnchorBarController');
var widgetCfg = this._getWidgetConfig('Print');
controller.openWidget(widgetCfg);
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?
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]);