Skip to content

Commit

Permalink
adds 3 new widget types: loading, layout and layer.
Browse files Browse the repository at this point in the history
adds 3 new entry points within the Controller when widgets can be created.
use the widget's key internally when no id is available
  • Loading branch information
tmcgee committed Dec 4, 2016
1 parent 0028d0f commit 27f4cd7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
6 changes: 6 additions & 0 deletions viewer/js/viewer/_ConfigMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ define([
initConfigSuccess: function (config) {
this.config = config;

// in _WidgetsMixin
this.createWidgets(['loading']);

if (config.isDebug) {
window.app = this; //dev only
}
Expand All @@ -44,6 +47,9 @@ define([
// in _LayoutMixin
this.initLayout();

// in _WidgetsMixin
this.createWidgets(['layout']);

// in _MapMixin
this.initMapAsync().then(
lang.hitch(this, 'initMapComplete'),
Expand Down
5 changes: 4 additions & 1 deletion viewer/js/viewer/_MapMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ define([
}

if (this.map) {
// in _WidgetsMixin
this.createWidgets(['map', 'layer']);

this.map.on('resize', function (evt) {
var pnt = evt.target.extent.getCenter();
setTimeout(function () {
Expand All @@ -205,7 +208,7 @@ define([
this.createPanes();

// in _WidgetsMixin
this.initWidgets();
this.createWidgets();
}

},
Expand Down
53 changes: 37 additions & 16 deletions viewer/js/viewer/_WidgetsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@ define([
identifyLayerInfos: [],
layerControlLayerInfos: [],

initWidgets: function () {
widgets: {},
widgetTypes: ['titlePane', 'contentPane', 'floating', 'domNode', 'invisible', 'map', 'layer', 'layout', 'loading'],

createWidgets: function (widgetTypes) {
var widgets = [],
paneWidgets;

widgetTypes = widgetTypes || this.widgetTypes;
for (var key in this.config.widgets) {
if (this.config.widgets.hasOwnProperty(key)) {
var widget = lang.clone(this.config.widgets[key]);
if (widget.include) {
widget.widgetKey = widget.widgetKey || widget.id || key;
if (widget.include && (!this.widgets[widget.widgetKey]) && (array.indexOf(widgetTypes, widget.type) >= 0)) {
widget.position = (typeof (widget.position) !== 'undefined') ? widget.position : 10000;
widgets.push(widget);
this.widgets[key] = true; // will be replaced by actual widget once created
}
}
}
Expand Down Expand Up @@ -79,7 +85,7 @@ define([
widgetLoader: function (widgetConfig, position) {
var parentId, pnl;

var widgetTypes = ['titlePane', 'contentPane', 'floating', 'domNode', 'invisible', 'map'];
var widgetTypes = this.widgetTypes;
// add any user-defined widget types
widgetTypes = widgetTypes.concat(this.config.widgetTypes || []);
// only proceed for valid widget types
Expand All @@ -96,8 +102,8 @@ define([
}

// build a titlePane or floating widget as the parent
if ((widgetConfig.type === 'titlePane' || widgetConfig.type === 'contentPane' || widgetConfig.type === 'floating') && (widgetConfig.id && widgetConfig.id.length > 0)) {
parentId = widgetConfig.id + '_parent';
if ((widgetConfig.type === 'titlePane' || widgetConfig.type === 'contentPane' || widgetConfig.type === 'floating')) {
parentId = widgetConfig.widgetKey + '_parent';
if (widgetConfig.type === 'titlePane') {
pnl = this._createTitlePaneWidget(parentId, widgetConfig);
} else if (widgetConfig.type === 'contentPane') {
Expand All @@ -117,7 +123,31 @@ define([
},

createWidget: function (widgetConfig, options, WidgetClass) {
var key = widgetConfig.widgetKey;
if (!key) {
return;
}

// set any additional options
options = this._setWidgetOptions(widgetConfig, options);

// create the widget
var pnl = options.parentWidget;
var widgets = this.widgets;
if ((widgetConfig.type === 'titlePane' || widgetConfig.type === 'contentPane' || widgetConfig.type === 'floating')) {
widgets[key] = new WidgetClass(options, put('div')).placeAt(pnl.containerNode);
} else if (widgetConfig.type === 'domNode') {
widgets[key] = new WidgetClass(options, widgetConfig.srcNodeRef);
} else {
widgets[key] = new WidgetClass(options);
}
// start up the widget
if (widgets[key] && widgets[key].startup && !widgets[key]._started) {
widgets[key].startup();
}
},

_setWidgetOptions: function (widgetConfig, options) {
if (widgetConfig.id) {
options.id = widgetConfig.id + '_widget';
}
Expand Down Expand Up @@ -153,20 +183,11 @@ define([
if (options.identifyLayerInfos) {
options.layerInfos = this.identifyLayerInfos;
}
return options;
},

// create the widget
var pnl = options.parentWidget;
if ((widgetConfig.type === 'titlePane' || widgetConfig.type === 'contentPane' || widgetConfig.type === 'floating')) {
this[widgetConfig.id] = new WidgetClass(options, put('div')).placeAt(pnl.containerNode);
} else if (widgetConfig.type === 'domNode') {
this[widgetConfig.id] = new WidgetClass(options, widgetConfig.srcNodeRef);
} else {
this[widgetConfig.id] = new WidgetClass(options);
}

// start up the widget
if (this[widgetConfig.id] && this[widgetConfig.id].startup && !this[widgetConfig.id]._started) {
this[widgetConfig.id].startup();
}
},

Expand Down

0 comments on commit 27f4cd7

Please sign in to comment.