AnsweredAssumed Answered

Open another widget from a custom widget link

Question asked by Grieck on Oct 28, 2016
Latest reply on Dec 2, 2016 by Grieck

Hello, I have a created a widget that loads at startup. This widget creates a couple of "links" on the bottom of the attribute window, next to the "Zoom To". I'm trying to pass data from the selected features attributes to another widget. I have the feature data I want to pass. I just can't get a reference to the other widget and I can't get it to open. I've been trying to follow the Communication with other widget and other examples I've found here but can't get it to work. Any idea's or thoughts would be appreciated. 

 

Shows the custom links in the attribute window

 

Below is MyStartUp widget that creates the links. I would like to call another widget "C" from the this.BClickListener = on(linkB, "click", function(evt){

 

It would also be nice to be able to do it as a function. So I can call the same function in the linkA click event. But, I've struggled with that too.

 

define([
'dojo/_base/declare',
'dojo/dom-construct',
'dojo/query',
'dojo/on',
'dojo/_base/lang',
'jimu/BaseWidget',
'jimu/WidgetManager',
'jimu/PanelManager'
], function(
declare, domConstruct, query, on, lang, BaseWidget, WidgetManager, PanelManager
) {
//To create a widget, you need to derive from BaseWidget.
return declare([BaseWidget], {

// Custom widget code goes here
baseClass: 'MyStartUp',
// this property is set by the framework when widget is loaded.
// name: 'MyStartUp',
// add additional properties here

//methods to communication with app container:
postCreate: function() {
this.inherited(arguments);
console.log('MyStartUp::postCreate');

this.ADomNode = null;
this.AClickListener = null;

this.BDomNode = null;
this.BClickListener = null;

this.map.infoWindow.on("selection-change", lang.hitch(this, function(){
if (this.ADomNode){
domConstruct.destroy(this.ADomNode);
}
if (this.AClickListener){
this.AClickListener.remove();
}
if (this.BDomNode){
domConstruct.destroy(this.BDomNode);
}
if (this.BClickListener){
this.BClickListener.remove();
}
var feature = this.map.infoWindow.getSelectedFeature();
if(feature){
if (feature.attributes.hasOwnProperty("myid")) {
this.ADomNode = domConstruct.create("a",{
"class": "action",
"id": "linkA",
"innerHTML": " A ", //text that appears in the popup for the link
"href": "javascript: void(0);"
}, query(".actionList", this.map.infoWindow.domNode)[0]);

//when the link is clicked register a function that will run
this.AClickListener = on(linkA, "click", function(evt){
console.log(evt);
});

this.BDomNode = domConstruct.create("a",{
"class": "action",
"id": "linkB",
"innerHTML": " B ", //text that appears in the popup for the link
"href": "javascript: void(0);"
}, query(".actionList", this.map.infoWindow.domNode)[0]);

//when the link is clicked register a function that will run
this.BClickListener = on(linkB, "click", function(evt){
console.log(evt);

var wm = WidgetManager.getInstance();
var widgetsConfig = wm.widgetPool.widgets;
var widgetId;
for(var i in widgetsConfig){
if(widgetsConfig[i].name == "B"){
widgetId = widgetsConfig[i].id;
break;
}
}
var widget = wm.getWidgetsByName("AnchorBarController")[0];
widget.setOpenedIds([widgetId]);


if(widgets.length === 0){
this.loadWidgetBInfoNode.innerText = 'Widget B is not configured.';
return;
}

var widgetId = widgets[0].id;
if(this.widgetManager.getWidgetById(widgetId)){
this.loadWidgetBInfoNode.innerText = 'Widget B has been loaded.';
return;
}
this.openWidgetById(widgetId).then(lang.hitch(this, function(widget){
this.loadWidgetBInfoNode.innerText = widget.name + ' is loaded';
}));
});
}
else if (feature.attributes.hasOwnProperty("myid")){
this.BDomNode = domConstruct.create("a",{
"class": "action",
"id": "linkB",
"innerHTML": " B ", //text that appears in the popup for the link
"href": "javascript: void(0);"
}, query(".actionList", this.map.infoWindow.domNode)[0]);

//when the link is clicked register a function that will run
this.BClickListener = on(linkB, "click", function(evt){
console.log(evt);
});
}
}
}
));
}
// startup: function() {
// this.inherited(arguments);
// console.log('MyStartUp::startup');
// },

// onOpen: function(){
// console.log('MyStartUp::onOpen');
// },

// onClose: function(){
// console.log('MyStartUp::onClose');
// },

// onMinimize: function(){
// console.log('MyStartUp::onMinimize');
// },

// onMaximize: function(){
// console.log('MyStartUp::onMaximize');
// },

// onSignIn: function(credential){
// console.log('MyStartUp::onSignIn', credential);
// },

// onSignOut: function(){
// console.log('MyStartUp::onSignOut');
// }

// onPositionChange: function(){
// console.log('MyStartUp::onPositionChange');
// },

// resize: function(){
// console.log('MyStartUp::resize');
// }

//methods to communication between widgets:

});

});

Outcomes