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
define(['dojo/_base/declare',
  'dojo/_base/lang',
  'dojo/dom-class',
  'dojo/dom-style',
  'dojo/on',
  'dojo/mouse',
  'dojo/Evented',
  'dijit/_WidgetBase',
  'dijit/_TemplatedMixin',
  'dijit/popup',
  'dijit/TooltipDialog',
  'dojo/text!./BaseIconItem.html'
  ], function(declare, lang, domClass, domStyle, on, mouse, Evented,
  _WidgetBase, _TemplatedMixin, popup, TooltipDialog, template){
  var PANEL_WIDTH = 350, PANEL_HEIGHT = 480, MIN_MARGIN = 10,
      BACKGROUND_COLOR_COUNT = 6;
  /**
   * @exports themes/LaunchpadTheme/widgets/AnchorBarController/BaseIconItem
   */
  var clazz = declare([_WidgetBase, _TemplatedMixin, Evented], {
    baseClass: 'jimu-anchorbar-iconitem jimu-float-leading',
    templateString: template,
    /**
     * Widget info, read only
     * @type {object} - Include label and uri.
     */
    config: null,
    backgroundIndex: -1,
    /**
     * Whether this widget is opened.
     * @type {Boolean}
     */
    isOpen: false,
    /**
     * The index of this widget in the widget list. It is used to calculate position when
     * opened in panel.
     * @type {Number}
     */
    panelIndex: -1,
 
    /**
     * The size of the icon item.
     * @type {Number}
     */
    size: 40,
 
    postCreate: function() {
      this.inherited(arguments);
 
      this.tooltipDialog = new TooltipDialog({
        'content': this.config.label,
        'class': "launchpad-tooltip"
      });
 
      domClass.add(this.iconItemNode, 'icon-item-background' + this.getBackgroundColorIndex());
 
      this.own(on(this.iconItemNode, mouse.enter, lang.hitch(this, function(){
        if(!window.appInfo.isRunInMobile){
          popup.open({
            parent: this,
            popup: this.tooltipDialog,
            around: this.iconItemNode,
            orient: ['above-centered'],
            onCancel: lang.hitch(this, function(){
              popup.close(this.tooltipDialog);
            })
          });
        }
      })));
 
      this.own(on(this.iconItemNode, mouse.leave, lang.hitch(this, function(){
        if(!window.appInfo.isRunInMobile){
          popup.close(this.tooltipDialog);
        }
      })));
    },
 
    getConfigForPanel: function(){
      var panelConfig = lang.clone(this.config);
      panelConfig.backgroundColor = this.getColor();
      panelConfig.panel.position = this._initPosition();
      panelConfig.panel.position.index = this.panelIndex;
 
      return panelConfig;
    },
 
    /**
     * Calculate initial position of the panel containing this widget.
     * @private
     * @return {object} position object, contains left, right, width and height
     */
    _initPosition: function(){
      return {
        top: window.appInfo.isRunInMobile ? 20 : 120,
        left: MIN_MARGIN,
        width: PANEL_WIDTH,
        height: PANEL_HEIGHT,
        margin: MIN_MARGIN
      };
    },
 
    /**
     * Event handler when user click this node.
     * @private
     */
    _onNodeClick: function(){
      domClass.toggle(this.iconItemStatus, 'selected');
      domClass.toggle(this.iconItemNode, 'selected');
      this.isOpen = domClass.contains(this.iconItemNode, 'selected');
 
      if(!this.isOpen){
        this.panelIndex = -1;
      }
 
      this.emit('nodeClick', {
        target: this
      });
    },
 
    /**
     * Check if this item is a widget group.
     * @return {Boolean} Return true if this is a widget group, or false if this is a single widget.
     */
    isGroup: function(){
      if(this.config.widgets && this.config.widgets.length > 1){
        return true;
      }else{
        return false;
      }
    },
 
    isOpenAtStart: function(){
      return this.config && this.config.openAtStart === true;
    },
 
    setOpened: function(value){
      if(value){
        if(this.iconItemStatus){
          domClass.add(this.iconItemStatus, 'selected');
        }
        if(this.iconItemNode){
          domClass.add(this.iconItemNode, 'selected');
        }
 
        this.isOpen = true;
      }else{
        if(this.iconItemStatus){
          domClass.remove(this.iconItemStatus, 'selected');
        }
        if(this.iconItemNode){
          domClass.remove(this.iconItemNode, 'selected');
        }
        this.isOpen = false;
        this.panelIndex = -1;
      }
    },
 
    getPanelIndex: function(){
      return this.panelIndex;
    },
 
    setPanelIndex: function(theValue){
      this.panelIndex = theValue;
    },
 
    getColor: function(){
      return domStyle.get(this.iconItemNode, 'background-color') || '#FFFFFF';
    },
 
    getBackgroundColorIndex: function(){
      return this.backgroundIndex % BACKGROUND_COLOR_COUNT;
    }
  });
  return clazz;
});