Select to view content in your preferred language

show/hide widgets on-the-fly

3975
9
Jump to solution
12-19-2016 02:18 PM
Alexwang
Frequent Contributor

Hello, I have a need to show or hide our widgets based on logged users. I found Robert's post here - https://community.esri.com/thread/174605#comment-598708 . Since we use Launchpad theme, so i simply change "HeaderController" to "AnchorBarController" in the codes, but the Legend Icon didn't appear on the Anchor Bar and didn't open either. Does anybody make the codes work for Lauchpad theme?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Alex.

   The Launchpad theme is pretty different.

      var widgetCfg = this._getWidgetConfig('Draw');
      widgetCfg.visible = true;
      var anchorCfg = this._getWidgetConfig('AnchorBarController');
      var anchorWidget = this.wManager.getWidgetByLabel(anchorCfg.label);

      //This actually open the widget
      anchorWidget._createItem(widgetCfg, anchorWidget.iconList.length + 1);
      anchorWidget.setOpenedIds([widgetCfg.id]);
      //This is need to show the widgets icon in the header
      anchorWidget.resize();
      anchorWidget._makeIconVisible(anchorWidget.iconList.length);

View solution in original post

9 Replies
RobertScheitlin__GISP
MVP Emeritus

Alex.

   The Launchpad theme is pretty different.

      var widgetCfg = this._getWidgetConfig('Draw');
      widgetCfg.visible = true;
      var anchorCfg = this._getWidgetConfig('AnchorBarController');
      var anchorWidget = this.wManager.getWidgetByLabel(anchorCfg.label);

      //This actually open the widget
      anchorWidget._createItem(widgetCfg, anchorWidget.iconList.length + 1);
      anchorWidget.setOpenedIds([widgetCfg.id]);
      //This is need to show the widgets icon in the header
      anchorWidget.resize();
      anchorWidget._makeIconVisible(anchorWidget.iconList.length);
Alexwang
Frequent Contributor

Appreciate it, Robert. Your codes worked. The only thing was that the widget was added at the end of the Anchor bar. I tried to set the index to its original index (widgetCfg.index = 2; ), but it was still added at the end. is there a way to add it as the first one instead of the last one?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

  No not that I am aware of as the anchor bar controller creates all visible widgets at startup and invisible ones are ignored.

0 Kudos
Alexwang
Frequent Contributor

OK, thanks Roberts. Can you do it in an opposite way - to set the Draw widget visible at startup, then hide it later? 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   This will keep the widget index correct:

      var widgetCfg = this._getWidgetConfig('Draw');
      widgetCfg.visible = true;
      var anchorCfg = this._getWidgetConfig('AnchorBarController');
      var anchorWidget = this.wManager.getWidgetByLabel(anchorCfg.label);

      //Save the ids of any opened widgets
      var oids = anchorWidget.getOpenedIds();
      oids.push(widgetCfg.id);
      //This removes all the existing icons
      anchorWidget.clearIconGroupNode();
      //This will recreate all the icons now that one of more visible property has changed
      anchorWidget.postCreate();
      anchorWidget.setOpenedIds(oids);
      //This is need to show the widgets icon in the header
      anchorWidget.resize();
Alexwang
Frequent Contributor

WOW!!! worked perfectly. Thank you so much for your help! I'll never be able to figure it out by myself. 

0 Kudos
Alexwang
Frequent Contributor

Thanks again Robert. I tested that the codes didn't work for on-screen widgets such as Attribute Table Widget. Can you please shed some light one more time?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

  Sorry, I don't have any insight on off panel widgets like the AT widget.

0 Kudos
Alexwang
Frequent Contributor

no problem. Thanks again Robert. 

0 Kudos