13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-form-FieldSet'>/**
</span> * @docauthor Jason Johnston &lt;jason@sencha.com&gt;
 *
 * A container for grouping sets of fields, rendered as a HTML `fieldset` element. The {@link #title}
 * config will be rendered as the fieldset's `legend`.
 *
 * While FieldSets commonly contain simple groups of fields, they are general {@link Ext.container.Container Containers}
 * and may therefore contain any type of components in their {@link #cfg-items}, including other nested containers.
 * The default {@link #layout} for the FieldSet's items is `'anchor'`, but it can be configured to use any other
 * layout type.
 *
 * FieldSets may also be collapsed if configured to do so; this can be done in two ways:
 *
 * 1. Set the {@link #collapsible} config to true; this will result in a collapse button being rendered next to
 *    the {@link #title legend title}, or:
 * 2. Set the {@link #checkboxToggle} config to true; this is similar to using {@link #collapsible} but renders
 *    a {@link Ext.form.field.Checkbox checkbox} in place of the toggle button. The fieldset will be expanded when the
 *    checkbox is checked and collapsed when it is unchecked. The checkbox will also be included in the
 *    {@link Ext.form.Basic#submit form submit parameters} using the {@link #checkboxName} as its parameter name.
 *
 * # Example usage
 *
 *     @example
 *     Ext.create('Ext.form.Panel', {
 *         title: 'Simple Form with FieldSets',
 *         labelWidth: 75, // label settings here cascade unless overridden
 *         url: 'save-form.php',
 *         frame: true,
 *         bodyStyle: 'padding:5px 5px 0',
 *         width: 550,
 *         renderTo: Ext.getBody(),
 *         layout: 'column', // arrange fieldsets side by side
 *         items: [{
 *             // Fieldset in Column 1 - collapsible via toggle button
 *             xtype:'fieldset',
 *             columnWidth: 0.5,
 *             title: 'Fieldset 1',
 *             collapsible: true,
 *             defaultType: 'textfield',
 *             defaults: {anchor: '100%'},
 *             layout: 'anchor',
 *             items :[{
 *                 fieldLabel: 'Field 1',
 *                 name: 'field1'
 *             }, {
 *                 fieldLabel: 'Field 2',
 *                 name: 'field2'
 *             }]
 *         }, {
 *             // Fieldset in Column 2 - collapsible via checkbox, collapsed by default, contains a panel
 *             xtype:'fieldset',
 *             title: 'Show Panel', // title or checkboxToggle creates fieldset header
 *             columnWidth: 0.5,
 *             checkboxToggle: true,
 *             collapsed: true, // fieldset initially collapsed
 *             layout:'anchor',
 *             items :[{
 *                 xtype: 'panel',
 *                 anchor: '100%',
 *                 title: 'Panel inside a fieldset',
 *                 frame: true,
 *                 height: 52
 *             }]
 *         }]
 *     });
 */
Ext.define('Ext.form.FieldSet', {
    extend: 'Ext.container.Container',
    mixins: {
        fieldAncestor: 'Ext.form.FieldAncestor'
    },
    alias: 'widget.fieldset',
    uses: ['Ext.form.field.Checkbox', 'Ext.panel.Tool', 'Ext.layout.container.Anchor', 'Ext.layout.component.FieldSet'],
 
<span id='Ext-form-FieldSet-cfg-title'>    /**
</span>     * @cfg {String} title
     * A title to be displayed in the fieldset's legend. May contain HTML markup.
     */
 
<span id='Ext-form-FieldSet-cfg-checkboxToggle'>    /**
</span>     * @cfg {Boolean} [checkboxToggle=false]
     * Set to true to render a checkbox into the fieldset frame just in front of the legend to expand/collapse the
     * fieldset when the checkbox is toggled.. This checkbox will be included in form submits using
     * the {@link #checkboxName}.
     */
 
<span id='Ext-form-FieldSet-cfg-checkboxName'>    /**
</span>     * @cfg {String} checkboxName
     * The name to assign to the fieldset's checkbox if {@link #checkboxToggle} = true
     * (defaults to '[fieldset id]-checkbox').
     */
 
<span id='Ext-form-FieldSet-cfg-collapsible'>    /**
</span>     * @cfg {Boolean} [collapsible=false]
     * Set to true to make the fieldset collapsible and have the expand/collapse toggle button automatically rendered
     * into the legend element, false to keep the fieldset statically sized with no collapse button.
     * Another option is to configure {@link #checkboxToggle}. Use the {@link #collapsed} config to collapse the
     * fieldset by default.
     */
 
<span id='Ext-form-FieldSet-cfg-collapsed'>    /**
</span>     * @cfg {Boolean} collapsed
     * Set to true to render the fieldset as collapsed by default. If {@link #checkboxToggle} is specified, the checkbox
     * will also be unchecked by default.
     */
    collapsed: false,
 
<span id='Ext-form-FieldSet-cfg-toggleOnTitleClick'>    /**
</span>     * @cfg {Boolean} [toggleOnTitleClick=true]
     * Set to true will add a listener to the titleCmp property for the click event which will execute the
     * {@link #toggle} method. This option is only used when the {@link #collapsible} property is set to true.
     */
    toggleOnTitleClick : true,
 
<span id='Ext-form-FieldSet-property-legend'>    /**
</span>     * @property {Ext.Component} legend
     * The component for the fieldset's legend. Will only be defined if the configuration requires a legend to be
     * created, by setting the {@link #title} or {@link #checkboxToggle} options.
     */
 
<span id='Ext-form-FieldSet-cfg-baseCls'>    /**
</span>     * @cfg {String} [baseCls='x-fieldset']
     * The base CSS class applied to the fieldset.
     */
    baseCls: Ext.baseCSSPrefix + 'fieldset',
 
<span id='Ext-form-FieldSet-cfg-layout'>    /**
</span>     * @cfg {Ext.enums.Layout/Object} layout
     * The {@link Ext.container.Container#layout} for the fieldset's immediate child items.
     */
    layout: 'anchor',
 
<span id='Ext-form-FieldSet-cfg-componentLayout'>    componentLayout: 'fieldset',
</span>
<span id='Ext-form-FieldSet-cfg-autoEl'>    autoEl: 'fieldset',
</span>
<span id='Ext-form-FieldSet-property-childEls'>    childEls: [
</span>        'body'
    ],
 
<span id='Ext-form-FieldSet-cfg-renderTpl'>    renderTpl: [
</span>        '{%this.renderLegend(out,values);%}',
        '&lt;div id=&quot;{id}-body&quot; class=&quot;{baseCls}-body {bodyTargetCls}&quot;&lt;tpl if=&quot;bodyStyle&quot;&gt; style=&quot;{bodyStyle}&quot;&lt;/tpl&gt;&gt;',
            '{%this.renderContainer(out,values);%}',
        '&lt;/div&gt;'
    ],
 
<span id='Ext-form-FieldSet-cfg-stateEvents'>    stateEvents : [ 'collapse', 'expand' ],
</span>
<span id='Ext-form-FieldSet-property-maskOnDisable'>    maskOnDisable: false,
</span>
<span id='Ext-form-FieldSet-method-beforeDestroy'>    beforeDestroy: function(){
</span>        var me = this,
            legend = me.legend;
 
        if (legend) {
            // get rid of the ownerCt since it's not a proper item
            delete legend.ownerCt;
            legend.destroy();
            me.legend = null;
        }
        me.callParent();
    },
 
<span id='Ext-form-FieldSet-method-initComponent'>    initComponent: function() {
</span>        var me = this,
            baseCls = me.baseCls;
                
        me.initFieldAncestor();
 
        me.callParent();
 
        // Fieldsets cannot support managePadding because the managePadding config causes
        // the paddding to be added to the innerCt instead of the fieldset element.  The
        // padding must be on the fieldset element because the horizontal position of the
        // legend is determined by the fieldset element's padding
        // 
        // As a consequence of the inability to support managePadding, manageOverflow
        // cannot be supported either because the correct overflow cannot be calculated
        // without managePadding to adjust for cross-browser differences in the way
        // padding is handled on overflowing elements.
        // See Ext.layout.container.Auto for more info.
        me.layout.managePadding = me.layout.manageOverflow = false;
 
        me.addEvents(
 
<span id='Ext-form-FieldSet-event-beforeexpand'>            /**
</span>             * @event beforeexpand
             * Fires before this FieldSet is expanded. Return false to prevent the expand.
             * @param {Ext.form.FieldSet} f The FieldSet being expanded.
             */
            &quot;beforeexpand&quot;,
 
<span id='Ext-form-FieldSet-event-beforecollapse'>            /**
</span>             * @event beforecollapse
             * Fires before this FieldSet is collapsed. Return false to prevent the collapse.
             * @param {Ext.form.FieldSet} f The FieldSet being collapsed.
             */
            &quot;beforecollapse&quot;,
 
<span id='Ext-form-FieldSet-event-expand'>            /**
</span>             * @event expand
             * Fires after this FieldSet has expanded.
             * @param {Ext.form.FieldSet} f The FieldSet that has been expanded.
             */
            &quot;expand&quot;,
 
<span id='Ext-form-FieldSet-event-collapse'>            /**
</span>             * @event collapse
             * Fires after this FieldSet has collapsed.
             * @param {Ext.form.FieldSet} f The FieldSet that has been collapsed.
             */
            &quot;collapse&quot;
        );
 
        if (me.collapsed) {
            me.addCls(baseCls + '-collapsed');
            me.collapse();
        }
        if (me.title || me.checkboxToggle || me.collapsible) {
            me.addTitleClasses();
            me.legend = Ext.widget(me.createLegendCt());
        }
        me.initMonitor();
    },
 
<span id='Ext-form-FieldSet-method-initPadding'>    initPadding: function(targetEl) {
</span>        var me = this,
            body = me.getProtoBody(),
            padding = me.padding,
            bodyPadding;
 
        if (padding !== undefined) {
            if (Ext.isIEQuirks || Ext.isIE8m) {
                // IE8 and below display fieldset top padding outside the border
                // so we transfer the top padding to the body element.
                padding = me.parseBox(padding);
                bodyPadding = Ext.Element.parseBox(0);
                bodyPadding.top = padding.top;
                padding.top = 0;
                body.setStyle('padding', me.unitizeBox(bodyPadding));
            }
 
            targetEl.setStyle('padding', me.unitizeBox(padding));
        }
    },
 
<span id='Ext-form-FieldSet-method-getProtoBody'>    getProtoBody: function () {
</span>        var me = this,
            body = me.protoBody;
 
        if (!body) {
            me.protoBody = body = new Ext.util.ProtoElement({
                styleProp: 'bodyStyle',
                styleIsText: true
            });
        }
 
        return body;
    },
 
<span id='Ext-form-FieldSet-method-initRenderData'>    /**
</span>     * Initialized the renderData to be used when rendering the renderTpl.
     * @return {Object} Object with keys and values that are going to be applied to the renderTpl
     * @private
     */
    initRenderData: function() {
        var me = this,
            data = me.callParent();
 
        data.bodyTargetCls = me.bodyTargetCls;
        me.protoBody.writeTo(data);
        delete me.protoBody;
 
        return data;
    },
 
<span id='Ext-form-FieldSet-method-getState'>    getState: function () {
</span>        var state = this.callParent();
 
        state = this.addPropertyToState(state, 'collapsed');
 
        return state;
    },
 
<span id='Ext-form-FieldSet-method-afterCollapse'>    afterCollapse: Ext.emptyFn,
</span><span id='Ext-form-FieldSet-method-afterExpand'>    afterExpand: Ext.emptyFn,
</span>
<span id='Ext-form-FieldSet-method-collapsedHorizontal'>    collapsedHorizontal: function () {
</span>        return true;
    },
 
<span id='Ext-form-FieldSet-method-collapsedVertical'>    collapsedVertical: function () {
</span>        return true;
    },
 
<span id='Ext-form-FieldSet-method-createLegendCt'>    createLegendCt: function () {
</span>        var me = this,
            items = [],
            legend = {
                xtype: 'container',
                baseCls: me.baseCls + '-header',
                id: me.id + '-legend',
                autoEl: 'legend',
                items: items,
                ownerCt: me,
                shrinkWrap: true,
                ownerLayout: me.componentLayout
            };
 
        // Checkbox
        if (me.checkboxToggle) {
            items.push(me.createCheckboxCmp());
        } else if (me.collapsible) {
            // Toggle button
            items.push(me.createToggleCmp());
        }
 
        // Title
        items.push(me.createTitleCmp());
 
        return legend;
    },
 
<span id='Ext-form-FieldSet-method-createTitleCmp'>    /**
</span>     * Creates the legend title component. This is only called internally, but could be overridden in subclasses to
     * customize the title component. If {@link #toggleOnTitleClick} is set to true, a listener for the click event
     * will toggle the collapsed state of the FieldSet.
     * @return {Ext.Component}
     * @protected
     */
    createTitleCmp: function() {
        var me  = this,
            cfg = {
                xtype : 'component',
                html  : me.title,
                cls   : me.baseCls + '-header-text',
                id    : me.id + '-legendTitle'
            };
 
        if (me.collapsible &amp;&amp; me.toggleOnTitleClick) {
            cfg.listeners = {
                click : {
                    element: 'el',
                    scope : me,
                    fn : me.toggle
                }
            };
            cfg.cls += ' ' + me.baseCls + '-header-text-collapsible';
        }
 
        return (me.titleCmp = Ext.widget(cfg));
    },
 
<span id='Ext-form-FieldSet-property-checkboxCmp'>    /**
</span>     * @property {Ext.form.field.Checkbox} checkboxCmp
     * Refers to the {@link Ext.form.field.Checkbox} component that is added next to the title in the legend. Only
     * populated if the fieldset is configured with {@link #checkboxToggle}:true.
     */
 
<span id='Ext-form-FieldSet-method-createCheckboxCmp'>    /**
</span>     * Creates the checkbox component. This is only called internally, but could be overridden in subclasses to
     * customize the checkbox's configuration or even return an entirely different component type.
     * @return {Ext.Component}
     * @protected
     */
    createCheckboxCmp: function() {
        var me = this,
            suffix = '-checkbox';
 
        me.checkboxCmp = Ext.widget({
            xtype: 'checkbox',
            hideEmptyLabel: true,
            name: me.checkboxName || me.id + suffix,
            cls: me.baseCls + '-header' + suffix,
            id: me.id + '-legendChk',
            checked: !me.collapsed,
            listeners: {
                change: me.onCheckChange,
                scope: me
            }
        });
        return me.checkboxCmp;
    },
 
<span id='Ext-form-FieldSet-property-toggleCmp'>    /**
</span>     * @property {Ext.panel.Tool} toggleCmp
     * Refers to the {@link Ext.panel.Tool} component that is added as the collapse/expand button next to the title in
     * the legend. Only populated if the fieldset is configured with {@link #collapsible}:true.
     */
 
<span id='Ext-form-FieldSet-method-createToggleCmp'>    /**
</span>     * Creates the toggle button component. This is only called internally, but could be overridden in subclasses to
     * customize the toggle component.
     * @return {Ext.Component}
     * @protected
     */
    createToggleCmp: function() {
        var me = this;
        me.toggleCmp = Ext.widget({
            xtype: 'tool',
            height: 15,
            width: 15,
            type: 'toggle',
            handler: me.toggle,
            id: me.id + '-legendToggle',
            scope: me
        });
        return me.toggleCmp;
    },
 
<span id='Ext-form-FieldSet-method-doRenderLegend'>    doRenderLegend: function (out, renderData) {
</span>        // Careful! This method is bolted on to the renderTpl so all we get for context is
        // the renderData! The &quot;this&quot; pointer is the renderTpl instance!
 
        var me = renderData.$comp,
            legend = me.legend,
            tree;
            
        // Create the Legend component if needed
        if (legend) {
            legend.ownerLayout.configureItem(legend);
            tree = legend.getRenderTree();
            Ext.DomHelper.generateMarkup(tree, out);
        }
    },
 
<span id='Ext-form-FieldSet-method-finishRender'>    finishRender: function () {
</span>        var legend = this.legend;
 
        this.callParent();
 
        if (legend) {
            legend.finishRender();
        }
    },
 
<span id='Ext-form-FieldSet-method-getCollapsed'>    getCollapsed: function () {
</span>        return this.collapsed ? 'top' : false;
    },
 
<span id='Ext-form-FieldSet-method-getCollapsedDockedItems'>    getCollapsedDockedItems: function () {
</span>        var legend = this.legend;
 
        return legend ? [ legend ] : [];
    },
 
<span id='Ext-form-FieldSet-method-setTitle'>    /**
</span>     * Sets the title of this fieldset.
     * @param {String} title The new title.
     * @return {Ext.form.FieldSet} this
     */
    setTitle: function(title) {
        var me = this,
            legend = me.legend,
            baseCls = me.baseCls;
            
        me.title = title;
        if (me.rendered) {
            if (!legend) {
                me.legend = legend = Ext.widget(me.createLegendCt());
                me.addTitleClasses();
                legend.ownerLayout.configureItem(legend);
                legend.render(me.el, 0);
            }
            me.titleCmp.update(title);
        } else if (legend) {
            me.titleCmp.update(title);
        } else {
            me.addTitleClasses();
            me.legend = Ext.widget(me.createLegendCt());
        }
        return me;
    },
    
<span id='Ext-form-FieldSet-method-addTitleClasses'>    addTitleClasses: function(){
</span>        var me = this,
            title = me.title,
            baseCls = me.baseCls;
            
        if (title) {
            me.addCls(baseCls + '-with-title');
        }
        
        if (title || me.checkboxToggle || me.collapsible) {
            me.addCls(baseCls + '-with-header');
        }
    },
 
<span id='Ext-form-FieldSet-method-applyTargetCls'>    applyTargetCls: function(targetCls) {
</span>        this.bodyTargetCls = targetCls;
    },
 
<span id='Ext-form-FieldSet-method-getTargetEl'>    getTargetEl : function() {
</span>        return this.body || this.frameBody || this.el;
    },
 
<span id='Ext-form-FieldSet-method-getDefaultContentTarget'>    getDefaultContentTarget: function() {
</span>        return this.body;
    },
 
<span id='Ext-form-FieldSet-method-expand'>    /**
</span>     * Expands the fieldset.
     * @return {Ext.form.FieldSet} this
     */
    expand : function(){
        return this.setExpanded(true);
    },
 
<span id='Ext-form-FieldSet-method-collapse'>    /**
</span>     * Collapses the fieldset.
     * @return {Ext.form.FieldSet} this
     */
    collapse : function() {
        return this.setExpanded(false);
    },
 
<span id='Ext-form-FieldSet-method-setExpanded'>    /**
</span>     * @private
     * Collapse or expand the fieldset.
     */
    setExpanded: function(expanded) {
        var me = this,
            checkboxCmp = me.checkboxCmp,
            operation = expanded ? 'expand' : 'collapse';
 
        if (!me.rendered || me.fireEvent('before' + operation, me) !== false) {
            expanded = !!expanded;
 
            if (checkboxCmp) {
                checkboxCmp.setValue(expanded);
            }
 
            if (expanded) {
                me.removeCls(me.baseCls + '-collapsed');
            } else {
                me.addCls(me.baseCls + '-collapsed');
            }
            me.collapsed = !expanded;
            if (expanded) {
                delete me.getHierarchyState().collapsed;
            } else {
                me.getHierarchyState().collapsed = true;
            }
            if (me.rendered) {
                // say explicitly we are not root because when we have a fixed/configured height
                // our ownerLayout would say we are root and so would not have it's height
                // updated since it's not included in the layout cycle
                me.updateLayout({ isRoot: false });
                me.fireEvent(operation, me);
            }
        }
        return me;
    },
    
<span id='Ext-form-FieldSet-method-getRefItems'>    getRefItems: function(deep) {
</span>        var refItems = this.callParent(arguments),
            legend = this.legend;
 
        // Prepend legend items to ensure correct order
        if (legend) {
            refItems.unshift(legend);
            if (deep) {
                refItems.unshift.apply(refItems, legend.getRefItems(true));
            }
        }
        return refItems;
    },
 
<span id='Ext-form-FieldSet-method-toggle'>    /**
</span>     * Toggle the fieldset's collapsed state to the opposite of what it is currently.
     */
    toggle: function() {
        this.setExpanded(!!this.collapsed);
    },
 
<span id='Ext-form-FieldSet-method-onCheckChange'>    /**
</span>     * @private
     * Handle changes in the checkbox checked state.
     */
    onCheckChange: function(cmp, checked) {
        this.setExpanded(checked);
    },
 
<span id='Ext-form-FieldSet-method-setupRenderTpl'>    setupRenderTpl: function (renderTpl) {
</span>        this.callParent(arguments);
 
        renderTpl.renderLegend = this.doRenderLegend;
    }
});
</pre>
</body>
</html>