Show hide layers widget based on Portal Named user level

1753
7
Jump to solution
09-25-2018 05:30 AM
Labels (1)
AbdulMateen
New Contributor

In my web appbuilder application , i have 6 customize widgets and 12 layers, Is there anyway to show hide widget icon, layers based on the portal named user level.

Portal users with level 2 must be able to see widget icon when clicks open the widget also some layers only visible to level 2 user.The level 1 user will see only default widgets.

I tried to use widgetmanager .getwidgets or loaded  ,it gets only builtin widgets not the customize widget.

what is the best efficient way.

Thanks

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Abdul,

   No the OnScreenWidgetIcon.js is not the appropriate place.

You need this code somewhere in your app that will be used to control the visibility of on screen widgets. Like some other widget that will always be added to your app.

var widgetCfg = this._getWidgetConfig('Share');
widgetCfg.visible = true;
if(window._layoutManager.params.urlParams.mode === 'config'){
  topic.publish('builder/widgetChanged', widgetCfg);
}else{
  topic.publish('widgetChanged', widgetCfg);
}

In my link I provided the headercontroller widget was used to run code to turn on widgets inside itself passed on privilege. 

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Emeritus

Abdul,

See this thread where I provided an answer for that.  Both these threads assume you have the code to determine the user access level already and you just need to show or hide the widgets.

How can I toggle the visibility of a widget?  

https://community.esri.com/thread/187702-showhide-widgets-on-the-fly?commentID=654968&et=watches.ema... 

0 Kudos
AbdulMateen
New Contributor

Thanks for your prompt reply,

In application config.json file default widget settings visible:false & below is hiding widget icon fine

"placeholderIndex": 1,
"id": "_5",
"name": "ManageLookup",
"version": "2.9",
"closeable": true,
"visible": false,
"IsController": false,

All settings are configured inside ofpanel widget and below code on start up

startup:function(){

//After verifying with users level

var widgetCfg = this._getWidgetConfig('Managebuffer');
widgetCfg.visible = true;

}

still above code does not show widget icon ,and widget is not inside the "HeaderController"

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Then my first link provides the answer to that.

0 Kudos
AbdulMateen
New Contributor

Thanks Robert i checked the link,

it is hiding showing widget icon avaialble inside the headercontroller, but i need to show hide icon onscreenwidget icon.below code still does not hide icon 

do i need to put below code inside OnScreenWidgetIcon.js file

  1. _getWidgetConfig: function(widgetName){  
  2.   var widgetCnfg = null;  
  3.   array.some(this.wManager.appConfig.widgetPool.widgets, function(aWidget) {  
  4.     if(aWidget.name == widgetName) {  
  5.       widgetCnfg = aWidget;  
  6.       return true;  
  7.     }  
  8.     return false;  
  9.   });  
  10.   if(!widgetCnfg){  
  11.     /*Check OnScreen widgets if not found in widgetPool*/  
  12.     array.some(this.wManager.appConfig.widgetOnScreen.widgets, function(aWidget) {  
  13.       if(aWidget.name == widgetName) {  
  14.         widgetCnfg = aWidget;  
  15.         return true;  
  16.       }  
  17.       return false;  
  18.     });  
  19.   }  
  20.   return widgetCnfg;  
  21. },  
postCreate: function(){       this.inherited(arguments);          var widgetCfg = this._getWidgetConfig('Managebuffer');         this.iconNode = html.create('img', {         src: this.widgetCfg.icon       }, this.domNode);       if(this.widgetCfg.label === 'Managebuffer'){         html.setStyle(this.domNode, 'display', 'none');       }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Abdul,

   No the OnScreenWidgetIcon.js is not the appropriate place.

You need this code somewhere in your app that will be used to control the visibility of on screen widgets. Like some other widget that will always be added to your app.

var widgetCfg = this._getWidgetConfig('Share');
widgetCfg.visible = true;
if(window._layoutManager.params.urlParams.mode === 'config'){
  topic.publish('builder/widgetChanged', widgetCfg);
}else{
  topic.publish('widgetChanged', widgetCfg);
}

In my link I provided the headercontroller widget was used to run code to turn on widgets inside itself passed on privilege. 

AbdulMateen
New Contributor

Thanks Robert,

This is what i was looking for, worked like  a charm

if(window._layoutManager.params.urlParams.mode === 'config'){
  topic.publish('builder/widgetChanged', widgetCfg);
}else{
  topic.publish('widgetChanged', widgetCfg);
}
0 Kudos
AbdulMateen
New Contributor

Thanks Robert i checked the link,

it is hiding showing widget icon avaialble inside the headercontroller, but i need to show hide icon onscreenwidget icon.below code still does not hide icon 

do i need to put below code inside OnScreenWidgetIcon.js file

  1. _getWidgetConfig: function(widgetName){  
  2.   var widgetCnfg = null;  
  3.   array.some(this.wManager.appConfig.widgetPool.widgets, function(aWidget) {  
  4.     if(aWidget.name == widgetName) {  
  5.       widgetCnfg = aWidget;  
  6.       return true;  
  7.     }  
  8.     return false;  
  9.   });  
  10.   if(!widgetCnfg){  
  11.     /*Check OnScreen widgets if not found in widgetPool*/  
  12.     array.some(this.wManager.appConfig.widgetOnScreen.widgets, function(aWidget) {  
  13.       if(aWidget.name == widgetName) {  
  14.         widgetCnfg = aWidget;  
  15.         return true;  
  16.       }  
  17.       return false;  
  18.     });  
  19.   }  
  20.   return widgetCnfg;  
  21. },  
postCreate: function(){       this.inherited(arguments);          var widgetCfg = this._getWidgetConfig('Managebuffer');         this.iconNode = html.create('img', {         src: this.widgetCfg.icon       }, this.domNode);       if(this.widgetCfg.label === 'Managebuffer'){         html.setStyle(this.domNode, 'display', 'none');       }
0 Kudos