Hello.
I have a WAB application at version 2.16. There is a custom widget, which is set "visible: false," in the application's config.json. I would like to change it as visible if the log in user is in a permitted group. According to this discussion, Show hide layers widget based on Portal Named user level , I add the following codes to this custom widget.js postCreate module. But the code never hits to postCreate module. Where should I put those lines of codes?
thanks so much.
postCreate: function () {
console.log('postCreate');
var widgetCfg = this._getWidgetConfig('MyCustomWidget');
widgetCfg.visible = true;
if(window._layoutManager.params.urlParams.mode === 'config'){
topic.publish('builder/widgetChanged', widgetCfg);
}else{
topic.publish('widgetChanged', widgetCfg);
}
},
Solved! Go to Solution.
Helen,
OK I did some simple testing and I had to issue enabling a widget that had it's visibility set to false from inside the MapManager.js. Here is my code (simplified test no user authentication just set a widget to be visible after 5 seconds).
....
_showMap: function(appConfig) {
// console.timeEnd('before map');
console.time('Load Map');
//for now, we can't create both 2d and 3d map
if (appConfig.map['3D']) {
if (appConfig.map.itemId) {
this._show3DWebScene(appConfig);
} else {
this._show3DLayersMap(appConfig);
}
} else {
if (appConfig.map.itemId) {
this._show2DWebMap(appConfig);
} else {
console.log('No webmap found. Please set map.itemId in config.json.');
}
}
setTimeout(
lang.hitch(this, this._checkWidgetVisibility), 5000
);
},
_checkWidgetVisibility: function(){
var widgetCfg = this._getWidgetConfig('Draw');
widgetCfg.visible = true;
if(window._layoutManager.params.urlParams.mode === 'config'){
topic.publish('builder/widgetChanged', widgetCfg);
}else{
topic.publish('widgetChanged', widgetCfg);
}
},
_getWidgetConfig: function(widgetName){
var widgetCnfg = null;
array.some(this.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(this.appConfig.widgetOnScreen.widgets, function(aWidget) {
if(aWidget.name == widgetName) {
widgetCnfg = aWidget;
return true;
}
return false;
});
}
return widgetCnfg;
},
....
Like I already said in that thread. I can't tell you exactly where to put this as i am not aware of your exact workflow.
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.
Thanks Robert. There is a custom widget, which is set "visible: false," in the application's config.json. I would like the custom widget show up when the application loads if the log in user is in a permitted group. The permission is already checked before the map and widget load in the application. I have tried to put the "topic.publish
"
code in the jimu.js\layoutManagers\BaseLayoutManager.js postCreate. The _onWidgetChanged is still not fired in \\tst-gis6\c$\inetpub\wwwroot\iMapWAB\jimu.js\ConfigManager.js.
Helen,
The permission is already checked before the map and widget load in the application
Thanks so much, Robert.
topic.publish('widgetChanged', widgetCfg);
" Helen,
OK I did some simple testing and I had to issue enabling a widget that had it's visibility set to false from inside the MapManager.js. Here is my code (simplified test no user authentication just set a widget to be visible after 5 seconds).
....
_showMap: function(appConfig) {
// console.timeEnd('before map');
console.time('Load Map');
//for now, we can't create both 2d and 3d map
if (appConfig.map['3D']) {
if (appConfig.map.itemId) {
this._show3DWebScene(appConfig);
} else {
this._show3DLayersMap(appConfig);
}
} else {
if (appConfig.map.itemId) {
this._show2DWebMap(appConfig);
} else {
console.log('No webmap found. Please set map.itemId in config.json.');
}
}
setTimeout(
lang.hitch(this, this._checkWidgetVisibility), 5000
);
},
_checkWidgetVisibility: function(){
var widgetCfg = this._getWidgetConfig('Draw');
widgetCfg.visible = true;
if(window._layoutManager.params.urlParams.mode === 'config'){
topic.publish('builder/widgetChanged', widgetCfg);
}else{
topic.publish('widgetChanged', widgetCfg);
}
},
_getWidgetConfig: function(widgetName){
var widgetCnfg = null;
array.some(this.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(this.appConfig.widgetOnScreen.widgets, function(aWidget) {
if(aWidget.name == widgetName) {
widgetCnfg = aWidget;
return true;
}
return false;
});
}
return widgetCnfg;
},
....
thank you so much, Robert. that is exactly what I want. I call "_checkWidgetVisibility
" without setting time out.