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
/**
    @name Edo.containers.FieldSet
    @class 
    @typeName fieldset
    @description 
    @extend Edo.containers.Container
    @example 
 
 
*/ 
Edo.containers.FieldSet = function(){    
    Edo.containers.FieldSet.superclass.constructor.call(this);    
    
};
Edo.containers.FieldSet.extend(Edo.containers.Container, {
    /**
        @name Edo.containers.FieldSet#defaultWidth
        @property        
        @default 80
    */ 
    defaultWidth: 80,   
    /**
        @name Edo.containers.FieldSet#defaultHeight
        @property
        @default 30
    */ 
    defaultHeight: 20,
    /**
        @name Edo.containers.FieldSet#collapseHeight
        @property
        @default 18
    */ 
    collapseHeight: 18,        
    /**
        @name Edo.containers.FieldSet#legend
        @property
        @type {String} 
        @description 头部文本
    */
    legend: '',
     
    /**
        @name Edo.containers.Box#padding
        @property
        @type [top, right, bottom, left]
        @default [3,5,5,5]
        @description 内边距宽度
    */
    padding: [3,5,5,5],    
    
    elCls: 'e-fieldset e-div',
    
    getInnerHtml: function(sb){        
        sb[sb.length] = '<fieldset class="e-fieldset-fieldset"><legend class="e-fieldset-legend">';        
        sb[sb.length] = '<span class="'+(this.enableCollapse ? 'e-fieldset-icon' : '')+'">';
        sb[sb.length] = this.legend || '&#160;';
        sb[sb.length] = '</span></legend><div class="e-fieldset-body" style="';        
        sb[sb.length] = this.doScrollPolicy();
        sb[sb.length] = '"></div></fieldset>';
    },
    createChildren: function(el){        
        Edo.containers.FieldSet.superclass.createChildren.call(this, el);        
        
        this.fieldset = this.el.firstChild;
        this.scrollEl = this.fieldset.lastChild;
        this.legendEl = this.fieldset.firstChild;        
        this.titleEl = this.legendEl.lastChild;
    },
    initEvents:  function(){
        Edo.containers.FieldSet.superclass.initEvents.call(this);
        Edo.util.Dom.on(this.legendEl, 'click', this._onLegendClick, this);       
    },
    _onLegendClick: function(e){   
    
        if(this.enableCollapse){                 
            this.toggle();            
        }
    },
    syncSize: function(){
        Edo.containers.FieldSet.superclass.syncSize.apply(this, arguments);
        
        Edo.util.Dom.setSize(this.fieldset, this.realWidth, this.realHeight);
    },    
    measure: function(){
        Edo.containers.FieldSet.superclass.measure.call(this);
        
        this.realWidth += 2;
        this.realHeight += 20;
        
        var p = this.padding;                
        this.realWidth += p[3] + p[1];
        this.realHeight += p[0] + p[2];
        
        this.measureSize();
    },
    getLayoutBox: function(){
        var box = Edo.containers.FieldSet.superclass.getLayoutBox.call(this);
        box.x += 1;
        box.y += 1;
        box.width -= 2;
        box.height -= 20;
        
        var p = this.padding;
        box.width = box.width - p[3] - p[1];
        box.height = box.height - p[0] - p[2];
        box.x += p[3];
        box.y += p[0];
        
        box.right = box.x + box.width;
        box.bottom = box.y + box.height;
        return box;             //这里的逻辑没问题!!!
    },
    _setLegend: function(value){
        if(this.legend !== value){
            this.legend = value;
            if(this.el){                
                this.titleEl.innerText = value;
            }
            this.changeProperty('legend', value);
        }
    },
    _setPadding: function(value){
        value = this._toArray(value);
        if(!this._checkTheSame(this.padding, value)){                    
            this.padding = value;            
            this.relayout('padding', value);
            this.changeProperty('padding', value);
        }
    },    
    destroy : function(){        
        Edo.util.Dom.clearEvent(this.legendEl);
        this.legendEl = null;
        
        Edo.containers.Container.superclass.destroy.call(this);
    }
});
 
Edo.containers.FieldSet.regType('fieldset');