Open Widget Programatically ( Foldable Theme)

952
6
Jump to solution
08-07-2018 05:25 AM
KrishV
by
Occasional Contributor III

Open a widget from another widget 

var widgetCfg = this._getWidgetConfig('Edit');
            var wm = WidgetManager.getInstance();
            wm.loadWidget(widgetCfg).then(lang.hitch(this,function(){

              if (widgetCfg) {  
                //sbc = WidgetManager.getInstance().getWidgetsByName("headerController")[0];  
                printWidget = WidgetManager.getInstance().getWidgetByLabel(widgetCfg.label);  
                if (printWidget) {  
                     
                    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);  
                }  
    
              }

Please let me know, how I can open Edit Widget in Foldable Theme.

Regards,

Krish

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Krish,

   In that case you need this:

var widgetCfg = this._getWidgetConfig('Edit');
var hc = WidgetManager.getInstance().getWidgetsByName("HeaderController")[0];
hc.setOpenedIds([widgetCfg.id]);‍‍‍‍

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Krish,

  Do you have the _getWidgetConfig function defined in your code?

_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;  
},‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

var widgetCfg = this._getWidgetConfig('Edit');
var wm = WidgetManager.getInstance();
wm.loadWidget(widgetCfg).then(lang.hitch(this,function(){
  if (widgetCfg) {  
    editWidget = WidgetManager.getInstance().getWidgetByLabel(widgetCfg.label);  
    if (editWidget) {  
      WidgetManager.getInstance().openWidget(editWidget);  
      PanelManager.getInstance().showPanel(editWidget); 
    } else {  
      setTimeout(function() {  
        editWidget = WidgetManager.getInstance().getWidgetById(widgetCfg.id);  
        WidgetManager.getInstance().openWidget(editWidget);  
        PanelManager.getInstance().showPanel(editWidget);  
      }, 3000);  
    }  
  }
}
KrishV
by
Occasional Contributor III

Hi Robert Scheitlin, GISP‌,

Yes, I have the _getWidgetConfig  function defined. I'm getting error at below line:

PanelManager.getInstance().showPanel(editWidget); 

Error: Fail to startup panel widgets_Edit_Widget_59_panel. TypeError: Cannot set property 'done' of undefined

Regards,

Krish

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Krish,

  If the edit widget part of the foldable themes header controller or is it just in one of the on screen placeholder positions?

0 Kudos
KrishV
by
Occasional Contributor III

It is part of the Header controller. 

above code is working if I open Edit widget after opening app and close it. But when I'm trying this without opening Edit Widget, it is giving error.

Thanks,

Krish

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Krish,

   In that case you need this:

var widgetCfg = this._getWidgetConfig('Edit');
var hc = WidgetManager.getInstance().getWidgetsByName("HeaderController")[0];
hc.setOpenedIds([widgetCfg.id]);‍‍‍‍
KrishV
by
Occasional Contributor III

Yes! After setting below lines, Edit widget is getting opened.

var hc = WidgetManager.getInstance().getWidgetsByName("HeaderController")[0];
hc.setOpenedIds([widgetCfg.id]);

Thank you so much!!

Thanks,

Krish

0 Kudos