liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
///////////////////////////////////////////////////////////////////////////
// Copyright © 2014 - 2018 Esri. All Rights Reserved.
//
// Licensed under the Apache License Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///////////////////////////////////////////////////////////////////////////
 
define([
  'dojo/_base/declare',
  'dojo/_base/lang',
  'dojo/on',
  'dojo/query',
  'dojo/_base/html',
  'dojo/topic',
  'dijit/_TemplatedMixin',
  'dojo/text!./Panel.html',
  'jimu/BaseWidgetPanel',
  'jimu/utils'
], function (
  declare,
  lang,
  on,
  query,
  html,
  topic,
  _TemplatedMixin,
  template,
  BaseWidgetPanel,
  utils
) {
  /* global jimuConfig */
  return declare([BaseWidgetPanel, _TemplatedMixin], {
 
    baseClass: 'jimu-panel jimu-pocket-panel',
 
    templateString: template,
 
    postCreate: function () {
      this.inherited(arguments);
      this.own(on(this.maxNode, "click", lang.hitch(this, "_onMaxBtnClicked")));
    },
 
    startup: function () {
      //get the configured widget info
      var configs;
      configs = this.getAllWidgetConfigs();
      if (Array.isArray(this.config.widgets)) {
        configs = this.config.widgets;
      } else {
        configs = [this.config];
      }
      //if widget is configured remove the message
      if (configs.length > 0) {
        html.empty(this.containerNode);
      }
      //on startup call setPosition so that all the positions of controls get updated
      this._setPosition();
      this.inherited(arguments);
    },
 
    /**
     * This function is used to change the position of the panel & its size
     * depending upon the modes(desktop/mobile)
     */
    resize: function () {
      this._setPosition();
    },
 
    /**
     * This function is used to destroy the run-time files(position.css) created by
     * pocket theme when user switches from this theme to another theme like
     * foldable, dart etc..
     */
    destroy: function () {
      var styleLink, domNodes;
      //On destroy disable the position css applied to shift the controls,
      //so that it will not impact other themes
      styleLink = document.getElementById(this.baseClass + 'positionCSS');
      if (styleLink) {
        styleLink.disabled = true;
      }
      domNodes = query(".esriControlsBR");
      if (window.isRTL) {
        html.setStyle(domNodes[0], { "left": "0px" });
      } else {
        html.setStyle(domNodes[0], { "right": "0px" });
      }
      this.inherited(arguments);
    },
 
    /**
     * This function returns value true/false based the execution of app
     * whether it is running in mobile mode or not
     */
    _isShowingPanelOfMobileMode: function () {
      if (window.appInfo.isRunInMobile && window.innerWidth <= 760) {
        return true;
      }
      return false;
    },
 
    /**
     * This function is used to maximize the panel when user
     * clicks on max button which is available/active only in mobile mode
     */
    _onMaxBtnClicked: function (evt) {
      evt.stopPropagation();
      if (this._isShowingPanelOfMobileMode()) {
        if (this.windowState === 'maximized') {
          this.panelManager.normalizePanel(this);
        } else {
          this.panelManager.maximizePanel(this);
        }
        this._setPosition();
      }
    },
 
    /**
     * This function is used to set the positions of the widgets and styles of the panel.
     * This will consider all layouts, states, mobile mode etc.
     */
    _setPosition: function () {
      var style, currentPanel, isInMobileMode, titleNodeHeight;
      style = utils.getPositionStyle(this.position);
      //domNode & titleNode use to get null once theme is changed,
      //hence used getPanelById method to get current panel
      currentPanel = this.panelManager.getPanelById(this.id);
      isInMobileMode = this._isShowingPanelOfMobileMode();
      //If app is running in mobile set positions according to mobile else desktop
      //also based on layout shift the controls if required
      if (isInMobileMode) {
        style.width = '100%';
        style.right = '0';
        style.left = '0';
        style.bottom = '0';
        //Based on state set the map positions also as in mobile only 50% of map will be visible
        if (this.windowState === 'maximized') {
          style.height = '100%';
          style.width = '100%';
          style.top = '0';
          topic.publish('changeMapPosition', { bottom: "0" });
        } else {
          style.height = '50%';
          style.width = '100%';
          style.top = '50%';
          topic.publish('changeMapPosition', { bottom: "50%" });
        }
        html.setStyle(currentPanel.domNode, style);
        html.place(currentPanel.domNode, jimuConfig.layoutId);
        //In mobile mode show title node,
        //so that user can change the state of panel using maximize button
        html.setStyle(currentPanel.titleNode, "display", "block");
        titleNodeHeight = currentPanel.titleNode.offsetHeight;
        html.setStyle(currentPanel.containerNode, {
          height: "calc(100% - " + titleNodeHeight + "px)"
        });
      } else {
        style.height = 'auto';
        if (currentPanel.titleNode) {
          html.setStyle(currentPanel.titleNode, "display", "none");
        }
        html.setStyle(currentPanel.containerNode, { height: "100%" });
        topic.publish('changeMapPosition', { bottom: "0px" });
        html.place(currentPanel.domNode, jimuConfig.mapId);
        html.setStyle(currentPanel.domNode, style);
      }
      //Update the attribution and logo positions
      this._setAttributionAndLogoPosition(style);
      //Add remove styles to shift the controls based on layout
      //Condition 1. Layout 1 & not RTL
      //Condition 2. Layout 1 and RTL
      if ((style.right === "auto" && !window.isRTL) ||
        (style.right === "15px" && window.isRTL)) {
        this._setPositionStyles(true);
      } else {
        this._setPositionStyles(false);
      }
    },
 
    /**
     * This function is used to set the attribution and logo positions
     */
    _setAttributionAndLogoPosition: function (style) {
      var domNodes;
      domNodes = query(".esriControlsBR");
      //In default layout move logo before panel
      if (domNodes && domNodes.length > 0 && style.left === "auto") {
        html.setStyle(domNodes[0], { "right": "380px" });
      } else if (domNodes && domNodes.length > 0) {
        //If Default layout and in RTL mode
        //else if & else is for mobile mode and other layouts
        if ((style.right === "auto" && window.isRTL)) {
          html.setStyle(domNodes[0], { "left": "380px" });
        } else if ((style.right !== "auto" && window.isRTL)) {
          html.setStyle(domNodes[0], { "left": "0px" });
        } else {
          html.setStyle(domNodes[0], { "right": "0px" });
        }
      }
    },
 
    /**
     * This function is used to add or remove the styles to shift controls
     */
    _setPositionStyles: function (shiftPositions) {
      var styleLink, info;
      styleLink = document.getElementById(this.baseClass + 'positionCSS');
      if (shiftPositions) {
        if (styleLink) {
          styleLink.disabled = false;
        } else {
          info = utils.getUriInfo(this.uri);
          utils.loadStyleLink(this.baseClass + 'positionCSS',
            info.folderUrl + "positions.css", null);
        }
      } else if (styleLink) {
        styleLink.disabled = true;
      }
    }
  });
});