zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
/*
关闭
最大化(包含还原)    toggle逻辑
最小化(包含还原)
伸缩(上下,左右)        配合父容器的布局,改变伸缩逻辑和图片样式.
    伸缩的时候,重要的是控制好minWidth/minHeight,在父容器内进行一个比较小的占位
    当确定为collapse的时候,不要对子元素进行doLayout(提高性能!)
    
*/
 
/**
    @name Edo.containers.Panel
    @class 
    @typeName panel
    @description 实现header头容器
    @extend Edo.containers.Box
    @example 
 
 
*/ 
Edo.containers.Panel = function(){
    Edo.containers.Panel.superclass.constructor.call(this);
    
    //titleclick
};
Edo.containers.Panel.extend(Edo.containers.Box,{
    /**
        @name Edo.containers.Panel#collapseHeight
        @property        
        @default 26
    */ 
    collapseHeight: 26,
    /**
        @name Edo.containers.Panel#collapseWidth
        @property        
        @default 26
    */ 
    collapseWidth: 26,
    /**
        @name Edo.containers.Panel#minHeight
        @property        
        @default 22
    */
    minHeight: 22,          //当折叠后,此容器不调用measure和doLayout,不操作子元素    
    /**
        @name Edo.containers.Panel#headerHeight
        @property 
        @type Number
        @default 25
        @description 头部高度
    */
    headerHeight: 25,    
    /**
        @name Edo.containers.Panel#title      
        @property 
        @type String
        @description 标题文本
    */ 
    title: '',
    /**
        @name Edo.containers.Panel#titleIcon
        @property 
        @type String
        @description 标题图标
    */
    titleIcon: '',
    
    titleCollapse: false,
    
    titlebar: null,
    
    elCls: 'e-panel e-box e-div',
 
    getInnerHtml: function(sb){        
        var h = this.headerHeight;
        if(!isBorderBox){
            h -= 1;
        }
        sb[sb.length] = '<div class="e-panel-header" style="height:'+h+'px;line-height:'+h+'px;"><div class="e-panel-title">'+this.doTitle()+'</div><div class="e-titlebar"></div></div>';
        Edo.containers.Panel.superclass.getInnerHtml.call(this, sb);
    },
    initEvents: function(){
        Edo.containers.Panel.superclass.initEvents.call(this);
        
        this.on('click', this._onClick, this);
    },
    createChildren: function(el){                
        Edo.containers.Panel.superclass.createChildren.call(this, el);
        this.scrollEl = this.el.lastChild;
        
        this.headerCt = this.el.firstChild;
        this.titleCt = this.headerCt.firstChild;
        this.titlebarCt = this.headerCt.lastChild; 
        
        if(this.titlebar){        
            this.titlebar.render(this.titlebarCt);
        }       
    }, 
    measure: function(){
        Edo.containers.Panel.superclass.measure.call(this);
        this.realHeight += this.headerHeight;
        this.measureSize();
    },
    getLayoutBox: function(){          
        var box = Edo.containers.Panel.superclass.getLayoutBox.call(this);        
        var hd = this.headerHeight;
        box.y += hd;
        box.height -= hd;
        
        box.right = box.x + box.width;
        box.bottom = box.y + box.height;
        return box;
    },
    doTitle: function(){
        var title = "";
        if(this.titleIcon) title += '<div style="float:left;margin-right:3px;" class="e-panel-titleicon '+this.titleIcon+'"></div>';
        if(this.title) title += '<div style="float:left;">'+this.title+'</div>';
        if(this.titleCt) this.titleCt.innerHTML = title;
        return title;
    },
    _setTitle: function(value){
        if(this.title != value){
            this.title = value;
            this.doTitle();
            this.changeProperty('title', value);
        }
    },
    _setTitleIcon: function(value){
        if(this.titleIcon != value){
            this.titleIcon = value;
            this.doTitle();
            this.changeProperty('titleIcon', value);
        }
    },
    _setHeaderHeight: function(value){
        value = parseInt(value);        
        if(isNaN(value)) throw new Error('headerHeight must is Number type');
        if(this.headerHeight != value){
            this.headerHeight = value;
            
            this.collapseHeight = value + this.border[0];
            this.relayout('headerHeight', value);
        }
    },
    syncSize: function(){    //设置组件尺寸,并设置容器子元素的所有尺寸!
        var h = this.headerHeight;
        if(!isBorderBox){
            h -= 1;
        }
        if(this.el){
            this.headerCt.style.height = h + 'px';
            this.headerCt.style.lineHeight = h + 'px';
        }
        Edo.containers.Panel.superclass.syncSize.call(this);        
    },
    _setTitlebar: function(value){
        if(!(value instanceof Array)) value = [value];
        value.each(function(o){
            var c = o.cls;
            Edo.apply(o,{
                type: 'button',
                simpleButton: true,                
                height: 15,
                width: 15,
                minHeight: 15,
                minWidth: 15,
                cls: c,
                overCls: o.overCls || c+'-over',
                focusCls: o.focusCls || c+'-focus',
                pressedCls: o.pressedCls || c+'-pressed'
            });
        });
        
        if(this.titlebar){
            this.titlebar.destory();            
        }
        
        this.titlebar = Edo.create({            
            type: 'ct',
            layout: 'horizontal',
            horizontalGap: 1,
            height: 15,
            children: value,
            onclick: function(e){
                e.stop();
            }
        });
        this.titlebar.owner = this;
        
        if(this.titlebarCt){
            this.titlebar.render(this.titlebarCt);
        }
    },
    _onClick: function(e){        
        if(e.within(this.headerCt) && this.titleCollapse){
            this.toggle();
        }
    }
    
////    setCollapseProperty: function(value){
////        this.collapseProperty = value;
////        if(this.el){
////            if(value == 'width'){
////                //e-collapse-width
////                Edo.util.Dom.addClass(this.titleCt, 'e-collapse-width');
////                Edo.util.Dom.addClass(this.scrollEl, 'e-collapse-width');
////            }else{
////                Edo.util.Dom.removeClass(this.titleCt, 'e-collapse-width');
////                Edo.util.Dom.removeClass(this.scrollEl, 'e-collapse-width');
////            }
////        }
////    } 
});
 
Edo.containers.Panel.regType('panel', 'dialog');
 
Edo.containers.Dialog = Edo.containers.Panel;