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
<!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-selection-CheckboxModel'>/**
</span> * A selection model that renders a column of checkboxes that can be toggled to
 * select or deselect rows. The default mode for this selection model is MULTI.
 *
 * The selection model will inject a header for the checkboxes in the first view
 * and according to the {@link #injectCheckbox} configuration.
 */
Ext.define('Ext.selection.CheckboxModel', {
    alias: 'selection.checkboxmodel',
    extend: 'Ext.selection.RowModel',
 
<span id='Ext-selection-CheckboxModel-cfg-mode'>    /**
</span>     * @cfg {&quot;SINGLE&quot;/&quot;SIMPLE&quot;/&quot;MULTI&quot;} mode
     * Modes of selection.
     * Valid values are `&quot;SINGLE&quot;`, `&quot;SIMPLE&quot;`, and `&quot;MULTI&quot;`.
     */
    mode: 'MULTI',
 
<span id='Ext-selection-CheckboxModel-cfg-injectCheckbox'>    /**
</span>     * @cfg {Number/String} [injectCheckbox=0]
     * The index at which to insert the checkbox column.
     * Supported values are a numeric index, and the strings 'first' and 'last'.
     */
    injectCheckbox: 0,
 
<span id='Ext-selection-CheckboxModel-cfg-checkOnly'>    /**
</span>     * @cfg {Boolean} checkOnly
     * True if rows can only be selected by clicking on the checkbox column.
     */
    checkOnly: false,
    
<span id='Ext-selection-CheckboxModel-cfg-showHeaderCheckbox'>    /**
</span>     * @cfg {Boolean} showHeaderCheckbox
     * Configure as `false` to not display the header checkbox at the top of the column.
     * When {@link Ext.data.Store#buffered} is set to `true`, this configuration will
     * not be available because the buffered data set does not always contain all data. 
     */
    showHeaderCheckbox: undefined,
    
<span id='Ext-selection-CheckboxModel-cfg-checkSelector'>    /**
</span>     * @cfg {String} [checkSelector=&quot;x-grid-row-checker&quot;]
     * The selector for determining whether the checkbox element is clicked. This may be changed to
     * allow for a wider area to be clicked, for example, the whole cell for the selector.
     */
    checkSelector: '.' + Ext.baseCSSPrefix + 'grid-row-checker',
 
<span id='Ext-selection-CheckboxModel-property-headerWidth'>    headerWidth: 24,
</span>
<span id='Ext-selection-CheckboxModel-property-checkerOnCls'>    // private
</span>    checkerOnCls: Ext.baseCSSPrefix + 'grid-hd-checker-on',
    
<span id='Ext-selection-CheckboxModel-method-constructor'>    constructor: function(){
</span>        var me = this;
        me.callParent(arguments);   
        
        // If mode is single and showHeaderCheck isn't explicity set to
        // true, hide it.
        if (me.mode === 'SINGLE' &amp;&amp; me.showHeaderCheckbox !== true) {
            me.showHeaderCheckbox = false;
        } 
    },
 
<span id='Ext-selection-CheckboxModel-method-beforeViewRender'>    beforeViewRender: function(view) {
</span>        var me = this,
            owner;
            
        me.callParent(arguments);
 
        // if we have a locked header, only hook up to the first
        if (!me.hasLockedHeader() || view.headerCt.lockedCt) {
            if (me.showHeaderCheckbox !== false) {
                view.headerCt.on('headerclick', me.onHeaderClick, me);
            }
            me.addCheckbox(view, true);
            owner = view.ownerCt;
            // Listen to the outermost reconfigure event
            if (view.headerCt.lockedCt) {
                owner = owner.ownerCt;
            }
            me.mon(owner, 'reconfigure', me.onReconfigure, me);
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-bindComponent'>    bindComponent: function(view) {
</span>        var me = this;
        me.sortable = false;
        me.callParent(arguments);
    },
 
<span id='Ext-selection-CheckboxModel-method-hasLockedHeader'>    hasLockedHeader: function(){
</span>        var views     = this.views,
            vLen      = views.length,
            v;
 
        for (v = 0; v &lt; vLen; v++) {
            if (views[v].headerCt.lockedCt) {
                return true;
            }
        }
        return false;
    },
 
<span id='Ext-selection-CheckboxModel-method-addCheckbox'>    /**
</span>     * Add the header checkbox to the header row
     * @private
     * @param {Boolean} initial True if we're binding for the first time.
     */
    addCheckbox: function(view, initial){
        var me = this,
            checkbox = me.injectCheckbox,
            headerCt = view.headerCt;
 
        // Preserve behaviour of false, but not clear why that would ever be done.
        if (checkbox !== false) {
            if (checkbox == 'first') {
                checkbox = 0;
            } else if (checkbox == 'last') {
                checkbox = headerCt.getColumnCount();
            }
            Ext.suspendLayouts();
            if (view.getStore().buffered) {
                me.showHeaderCheckbox = false;
            }
            headerCt.add(checkbox,  me.getHeaderConfig());
            Ext.resumeLayouts();
        }
 
        if (initial !== true) {
            view.refresh();
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-onReconfigure'>    /**
</span>     * Handles the grid's reconfigure event.  Adds the checkbox header if the columns have been reconfigured.
     * @private
     * @param {Ext.panel.Table} grid
     * @param {Ext.data.Store} store
     * @param {Object[]} columns
     */
    onReconfigure: function(grid, store, columns) {
        if(columns) {
            this.addCheckbox(this.views[0]);
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-toggleUiHeader'>    /**
</span>     * Toggle the ui header between checked and unchecked state.
     * @param {Boolean} isChecked
     * @private
     */
    toggleUiHeader: function(isChecked) {
        var view     = this.views[0],
            headerCt = view.headerCt,
            checkHd  = headerCt.child('gridcolumn[isCheckerHd]'),
            cls = this.checkerOnCls;
 
        if (checkHd) {
            if (isChecked) {
                checkHd.addCls(cls);
            } else {
                checkHd.removeCls(cls);
            }
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-onHeaderClick'>    /**
</span>     * Toggle between selecting all and deselecting all when clicking on
     * a checkbox header.
     */
    onHeaderClick: function(headerCt, header, e) {
        if (header.isCheckerHd) {
            e.stopEvent();
            var me = this,
                isChecked = header.el.hasCls(Ext.baseCSSPrefix + 'grid-hd-checker-on');
                
            // Prevent focus changes on the view, since we're selecting/deselecting all records
            me.preventFocus = true;
            if (isChecked) {
                me.deselectAll();
            } else {
                me.selectAll();
            }
            delete me.preventFocus;
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-getHeaderConfig'>    /**
</span>     * Retrieve a configuration to be used in a HeaderContainer.
     * This should be used when injectCheckbox is set to false.
     */
    getHeaderConfig: function() {
        var me = this,
            showCheck = me.showHeaderCheckbox !== false;     
 
        return {
            isCheckerHd: showCheck,
            text : '&amp;#160;',
            clickTargetName: 'el',
            width: me.headerWidth,
            sortable: false,
            draggable: false,
            resizable: false,
            hideable: false,
            menuDisabled: true,
            dataIndex: '',
            cls: showCheck ? Ext.baseCSSPrefix + 'column-header-checkbox ' : '',
            renderer: Ext.Function.bind(me.renderer, me),
            editRenderer: me.editRenderer || me.renderEmpty,
            locked: me.hasLockedHeader()
        };
    },
 
<span id='Ext-selection-CheckboxModel-method-renderEmpty'>    renderEmpty: function() {
</span>        return '&amp;#160;';
    },
 
<span id='Ext-selection-CheckboxModel-method-refresh'>    // After refresh, ensure that the header checkbox state matches
</span>    refresh: function() {
        this.callParent(arguments);
        this.updateHeaderState();
    },
 
<span id='Ext-selection-CheckboxModel-method-renderer'>    /**
</span>     * Generates the HTML to be rendered in the injected checkbox column for each row.
     * Creates the standard checkbox markup by default; can be overridden to provide custom rendering.
     * See {@link Ext.grid.column.Column#renderer} for description of allowed parameters.
     */
    renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
        var baseCSSPrefix = Ext.baseCSSPrefix;
        metaData.tdCls = baseCSSPrefix + 'grid-cell-special ' + baseCSSPrefix + 'grid-cell-row-checker';
        return '&lt;div class=&quot;' + baseCSSPrefix + 'grid-row-checker&quot;&gt;&amp;#160;&lt;/div&gt;';
    },
    
<span id='Ext-selection-CheckboxModel-method-processSelection'>    processSelection: function(view, record, item, index, e){
</span>        var me = this,
            checker = e.getTarget(me.checkSelector),
            mode;
            
        // checkOnly set, but we didn't click on a checker.
        if (me.checkOnly &amp;&amp; !checker) {
            return;
        }
 
        if (checker) {
            mode = me.getSelectionMode();
            // dont change the mode if its single otherwise
            // we would get multiple selection
            if (mode !== 'SINGLE') {
                me.setSelectionMode('SIMPLE');
            }
            me.selectWithEvent(record, e);
            me.setSelectionMode(mode);
        } else {
            me.selectWithEvent(record, e);
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-onSelectChange'>    /**
</span>     * Synchronize header checker value as selection changes.
     * @private
     */
    onSelectChange: function() {
        this.callParent(arguments);
        if (!this.suspendChange) {
            this.updateHeaderState();
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-onStoreLoad'>    /**
</span>     * @private
     */
    onStoreLoad: function() {
        this.callParent(arguments);
        this.updateHeaderState();
    },
 
<span id='Ext-selection-CheckboxModel-method-onStoreAdd'>    onStoreAdd: function() {
</span>        this.callParent(arguments);
        this.updateHeaderState();
    },
 
<span id='Ext-selection-CheckboxModel-method-onStoreRemove'>    onStoreRemove: function() {
</span>        this.callParent(arguments);
        this.updateHeaderState();
    },
    
<span id='Ext-selection-CheckboxModel-method-onStoreRefresh'>    onStoreRefresh: function(){
</span>        this.callParent(arguments);    
        this.updateHeaderState();
    },
    
<span id='Ext-selection-CheckboxModel-method-maybeFireSelectionChange'>    maybeFireSelectionChange: function(fireEvent) {
</span>        if (fireEvent &amp;&amp; !this.suspendChange) {
            this.updateHeaderState();
        }
        this.callParent(arguments);
    },
    
<span id='Ext-selection-CheckboxModel-method-resumeChanges'>    resumeChanges: function(){
</span>        this.callParent();
        if (!this.suspendChange) {
            this.updateHeaderState();
        }
    },
 
<span id='Ext-selection-CheckboxModel-method-updateHeaderState'>    /**
</span>     * @private
     */
    updateHeaderState: function() {
        // check to see if all records are selected
        var me = this,
            store = me.store,
            storeCount = store.getCount(),
            views = me.views,
            hdSelectStatus = false,
            selectedCount = 0,
            selected, len, i;
            
        if (!store.buffered &amp;&amp; storeCount &gt; 0) {
            selected = me.selected;
            hdSelectStatus = true;
            for (i = 0, len = selected.getCount(); i &lt; len; ++i) {
                if (!me.storeHasSelected(selected.getAt(i))) {
                    break;
                }
                ++selectedCount;
            }
            hdSelectStatus = storeCount === selectedCount;
        }
            
        if (views &amp;&amp; views.length) {
            me.toggleUiHeader(hdSelectStatus);
        }
    }
});
</pre>
</body>
</html>