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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
define(['dojo/_base/declare',
  'dojo/_base/lang',
  'dojo/_base/array',
  'dojo/_base/html',
  'dijit/_WidgetBase',
  'dijit/_Container',
  './dijit/LoadingIndicator',
  './BaseWidgetFrame',
  './utils'],
function (declare, lang, array, html, _WidgetBase, _Container, LoadingIndicator,
    BaseWidgetFrame, utils) {
  return declare([_WidgetBase, _Container], {
    baseClass: 'jimu-panel jimu-container',
    started: false,
    state: 'closed',
    windowState: 'normal',
 
    moveTopOnActive: true,
 
    /**************
    *animations, can be:
    * string:
          For open animation: fadeIn, wipeIn ...
          For close animation: fadeOut, wipeOut ...
    * array: array of the above effects, will be played one by one
    * function: an animation function
    ***************/
    openAnimation: null,
    closeAnimation: null,
 
    // onPositionChangeAnimation: null,
 
    //
    animationDuration: 0,
 
    startup: function(){
      this.inherited(arguments);
 
      this.loadAllWidgetsInOrder();
      this.started = true;
    },
 
    loadAllWidgetsInOrder: function(){
      var configs = this.getAllWidgetConfigs();
      if(Array.isArray(this.config.widgets)){
        configs = this.config.widgets;
      }else{
        configs = [this.config];
      }
      array.forEach(configs, function(widgetConfig){
        var frame, loading;
        if(widgetConfig.visible === false){
          return;
        }
        loading = new LoadingIndicator();
        frame = this.createFrame(widgetConfig);
        this.addChild(frame);
        frame.setLoading(loading);
 
        this.widgetManager.loadWidget(widgetConfig).then(lang.hitch(this, function(widget){
          frame.setWidget(widget);
          widget.startup();
        }));
      }, this);
    },
 
    getAllWidgetConfigs: function(){
      var configs = [];
      if(Array.isArray(this.config.widgets)){
        configs = this.config.widgets;
      }else{
        configs = [this.config];
      }
      return configs;
    },
 
    getWidgetById: function(widgetId){
      var frames = this.getChildren();
      for(var i = 0; i < frames.length; i++){
        if(frames[i].getWidget() && frames[i].getWidget().id === widgetId){
          return frames[i].getWidget();
        }
      }
    },
 
    getWidgets: function(){
      return this.getChildren().map(function(f){
        return f.getWidget();
      });
    },
 
    createFrame: function(widgetSetting){
      /*jshint unused: false*/
      return new BaseWidgetFrame();
    },
 
    setPosition: function(position, containerNode){
      this.position = position;
      var style = utils.getPositionStyle(this.position);
      style.position = 'absolute';
 
      if(!containerNode){
        if(position.relativeTo === 'map'){
          containerNode = window.jimuConfig.mapId;
        }else{
          containerNode = window.jimuConfig.layoutId;
        }
      }
 
      if(this.started){
        this.resize();
      }else{
        if(this.openAnimation){//hiden panel to play animation
          style.display = 'none';
        }
      }
 
      html.place(this.domNode, containerNode);
      html.setStyle(this.domNode, style);
    },
 
    getPosition: function(){
      return this.position;
    },
 
    setState: function(state){
      this.state = state;
      // console.log('Panel', this.id, 'state:', state);
    },
 
    setWindowState: function(state){
      this.windowState = state;
    },
 
    resize: function(){
      this.getChildren().forEach(function(frame){
        frame.resize();
      });
    },
 
    onPositionChange: function(position){
      this.setPosition(position);
    },
 
    onOpen: function(){
      array.forEach(this.getChildren(), function(frame){
        if(frame.getWidget()){
          this.widgetManager.openWidget(frame.getWidget());
        }
      }, this);
    },
 
    onClose: function(){
      array.forEach(this.getChildren(), function(frame){
        if(frame.getWidget()){
          this.widgetManager.closeWidget(frame.getWidget());
        }
      }, this);
    },
 
    onMaximize: function(){
      array.forEach(this.getChildren(), function(frame){
        if(frame.getWidget()){
          this.widgetManager.maximizeWidget(frame.getWidget());
        }
      }, this);
    },
 
    onMinimize: function(){
      array.forEach(this.getChildren(), function(frame){
        if(frame.getWidget()){
          this.widgetManager.minimizeWidget(frame.getWidget());
        }
      }, this);
    },
 
    onNormalize: function(){
      array.forEach(this.getChildren(), function(frame){
        if(frame.getWidget()){
          this.widgetManager.normalizeWidget(frame.getWidget());
        }
      }, this);
    },
 
    onActive: function(){
      // summary:
      //    this function will be called when panel is clicked.
    },
 
    onDeActive: function(){
      // summary:
      //    this function will be called when another panel is clicked.
    },
 
    //update the config without reload the widget
    updateConfig: function(_config){
      this._updateConfig(_config);
    },
 
    reloadWidget: function(widgetConfig){
      if(!this.isWidgetInPanel(widgetConfig)){
        return;
      }
 
      this._updateConfig(widgetConfig);
 
      this.getChildren().forEach(function(frame){
        if(frame.getWidget() && frame.getWidget().id === widgetConfig.id){
          frame.getWidget().destroy();
          frame.setLoading(new LoadingIndicator());
          this.widgetManager.loadWidget(widgetConfig).then(lang.hitch(this, function(widget){
            frame.setWidget(widget);
            widget.startup();
            if(this.state === 'closed'){
              this.widgetManager.closeWidget(widget);
            }
          }));
        }
      }, this);
    },
 
    isWidgetInPanel: function(widgetConfig){
      if(array.some(this.getAllWidgetConfigs(), function(wc){
        if(widgetConfig.id === wc.id){
          return true;
        }
      })){
        //the widget is in the panel
        return true;
      }else{
        return false;
      }
    },
 
    _updateConfig: function(widgetConfig) {
      if(Array.isArray(this.config.widgets)){
        var index = -1;
        for(var i = 0; i < this.config.widgets.length; i++){
          if(this.config.widgets[i].id === widgetConfig.id){
            index = i;
          }
        }
        if(index > 0){
          this.config.widgets[index] = widgetConfig;
        }
      }else{
        this.config = widgetConfig;
      }
    },
 
    destroy: function(){
      this.getChildren().forEach(function(frame){
        try{
          if(frame.domNode){
            frame.destroy();
          }
        }catch(error){
          console.error('destroy widget frame error.' + error.stack);
        }
      });
      this.inherited(arguments);
    }
  });
});