From 27f4cd741b586ef734c9c8b1b159d6f461346748 Mon Sep 17 00:00:00 2001 From: Tim McGee Date: Sun, 4 Dec 2016 10:14:53 +0800 Subject: [PATCH 1/2] adds 3 new widget types: loading, layout and layer. adds 3 new entry points within the Controller when widgets can be created. use the widget's key internally when no id is available --- viewer/js/viewer/_ConfigMixin.js | 6 ++++ viewer/js/viewer/_MapMixin.js | 5 ++- viewer/js/viewer/_WidgetsMixin.js | 53 +++++++++++++++++++++---------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/viewer/js/viewer/_ConfigMixin.js b/viewer/js/viewer/_ConfigMixin.js index 0113fc381..430a22f8f 100644 --- a/viewer/js/viewer/_ConfigMixin.js +++ b/viewer/js/viewer/_ConfigMixin.js @@ -31,6 +31,9 @@ define([ initConfigSuccess: function (config) { this.config = config; + // in _WidgetsMixin + this.createWidgets(['loading']); + if (config.isDebug) { window.app = this; //dev only } @@ -44,6 +47,9 @@ define([ // in _LayoutMixin this.initLayout(); + // in _WidgetsMixin + this.createWidgets(['layout']); + // in _MapMixin this.initMapAsync().then( lang.hitch(this, 'initMapComplete'), diff --git a/viewer/js/viewer/_MapMixin.js b/viewer/js/viewer/_MapMixin.js index 924777ecc..48ebcc95c 100644 --- a/viewer/js/viewer/_MapMixin.js +++ b/viewer/js/viewer/_MapMixin.js @@ -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 () { @@ -205,7 +208,7 @@ define([ this.createPanes(); // in _WidgetsMixin - this.initWidgets(); + this.createWidgets(); } }, diff --git a/viewer/js/viewer/_WidgetsMixin.js b/viewer/js/viewer/_WidgetsMixin.js index fc7bd0fbd..0a634928c 100644 --- a/viewer/js/viewer/_WidgetsMixin.js +++ b/viewer/js/viewer/_WidgetsMixin.js @@ -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 } } } @@ -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 @@ -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') { @@ -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'; } @@ -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(); } }, From ec1020463387450c3f260b2d300a77e1e4a0ba64 Mon Sep 17 00:00:00 2001 From: Tim McGee Date: Sun, 4 Dec 2016 10:53:30 +0800 Subject: [PATCH 2/2] remove some braces that should not have been there. --- viewer/js/viewer/_WidgetsMixin.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/viewer/js/viewer/_WidgetsMixin.js b/viewer/js/viewer/_WidgetsMixin.js index 0a634928c..aca984f74 100644 --- a/viewer/js/viewer/_WidgetsMixin.js +++ b/viewer/js/viewer/_WidgetsMixin.js @@ -186,11 +186,6 @@ define([ return options; }, - } - - } - }, - _createTitlePaneWidget: function (parentId, widgetConfig) { var tp, options = lang.mixin({