nnnjjj123
2020-11-17 1b2c1edb61190eeb19f465ff031eaa3b2a1b8dbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
define([
    'require',
    'dojo/_base/array',
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/Deferred',
    'dojo/topic',
    'dstore/Memory',
    'dstore/Trackable',
    'dijit/layout/StackContainer',
    './FeatureGrid',
    '../data/features'
], function (require, arrayUtil, declare, lang, Deferred, topic, Memory, Trackable, StackContainer, FeatureGrid,
        featureData) {
 
    return declare(StackContainer, {
        baseClass: 'featureEditor',
        doLayout: false,
 
        buildRendering: function () {
            this.inherited(arguments);
 
            this.configPanes = {};
 
            this.store = new (declare([ Memory, Trackable ]))({
                data: featureData
            });
 
            this.featureGrid = new FeatureGrid({
                store: this.store,
                featureType: 'grid'
            });
            this.addChild(this.featureGrid);
        },
 
        postCreate: function () {
            this.inherited(arguments);
 
            this.own(
                this.featureGrid.on('configure-module', lang.hitch(this, '_showModuleConfig')),
                this.store.on('add,delete,update', lang.hitch(this, '_onUpdateStore'))
            );
        },
 
        startup: function () {
            this.inherited(arguments);
 
            var self = this;
            var configModuleIds = [];
            var dfd = new Deferred();
            arrayUtil.forEach(featureData, function (feature) {
                if (feature.configModule) {
                    configModuleIds.push('./' + feature.configModule);
                }
            });
 
            require(configModuleIds, function () {
                arrayUtil.forEach(featureData, function (feature) {
                    var ConfigConstructor;
                    var configPane;
 
                    if (feature.configModule !== undefined) {
                        ConfigConstructor = require('./' + feature.configModule);
                        configPane = new ConfigConstructor({
                            moduleName: feature.mid.slice(feature.mid.lastIndexOf('/') + 1),
                            documentationUrl: feature.documentationUrl
                        });
 
                        configPane.on('close', function () {
                            self.selectChild(self.featureGrid);
                        });
 
                        this.addChild(configPane);
                        this.configPanes[feature.mid] = configPane;
                    }
                }, self);
                dfd.resolve();
            });
 
            return dfd.promise;
        },
 
        isSelected: function (moduleId) {
            return !!this.store.filter({ mid: moduleId, selected: true }).fetchSync().length;
        },
 
        filter: function (query) {
            return this.store.filter(query).fetchSync();
        },
 
        getModuleConfig: function (mid) {
            return this.configPanes[mid] && this.configPanes[mid].get('value');
        },
 
        _showModuleConfig: function (event) {
            var configPane = this.configPanes[event.mid];
            if (configPane) {
                this.selectChild(configPane);
            }
        },
 
        _onUpdateStore: function () {
            // Let the Laboratory know that it should update the demo display (grid or generated code)
            topic.publish('/configuration/changed');
        },
 
        _getExpandoColumnAttr: function () {
            return this.configPanes['dgrid/Tree'].get('expandoColumn');
        },
 
        _setFeatureTypeAttr: function (featureType) {
            this.featureGrid.set('featureType', featureType);
            // Make sure the grid is actually the selected child (not one of the option panes)
            this.selectChild(this.featureGrid);
        }
    });
});