Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds 3 new widget types: loading, layout and layer. #643

Merged
merged 2 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
56 changes: 36 additions & 20 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,21 +183,7 @@ define([
if (options.identifyLayerInfos) {
options.layerInfos = this.identifyLayerInfos;
}

// 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();
}
return options;
},

_createTitlePaneWidget: function (parentId, widgetConfig) {
Expand Down