~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/ext/source/widgets/grid/CheckboxSelectionModel.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 2.2
 
3
 * Copyright(c) 2006-2008, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.grid.CheckboxSelectionModel
 
11
 * @extends Ext.grid.RowSelectionModel
 
12
 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
 
13
 * @constructor
 
14
 * @param {Object} config The configuration options
 
15
 */
 
16
Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
 
17
    /**
 
18
     * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the checkbox column
 
19
     * (defaults to '<div class="x-grid3-hd-checker"> </div>').  The default CSS class of 'x-grid3-hd-checker'
 
20
     * displays a checkbox in the header and provides support for automatic check all/none behavior on header click.
 
21
     * This string can be replaced by any valid HTML fragment, including a simple text string (e.g., 'Select Rows'), but
 
22
     * the automatic check all/none behavior will only work if the 'x-grid3-hd-checker' class is supplied.
 
23
     */
 
24
    header: '<div class="x-grid3-hd-checker">&#160;</div>',
 
25
    /**
 
26
     * @cfg {Number} width The default width in pixels of the checkbox column (defaults to 20).
 
27
     */
 
28
    width: 20,
 
29
    /**
 
30
     * @cfg {Boolean} sortable True if the checkbox column is sortable (defaults to false).
 
31
     */
 
32
    sortable: false,
 
33
 
 
34
    // private
 
35
    menuDisabled:true,
 
36
    fixed:true,
 
37
    dataIndex: '',
 
38
    id: 'checker',
 
39
 
 
40
    // private
 
41
    initEvents : function(){
 
42
        Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
 
43
        this.grid.on('render', function(){
 
44
            var view = this.grid.getView();
 
45
            view.mainBody.on('mousedown', this.onMouseDown, this);
 
46
            Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
 
47
 
 
48
        }, this);
 
49
    },
 
50
 
 
51
    // private
 
52
    onMouseDown : function(e, t){
 
53
        if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
 
54
            e.stopEvent();
 
55
            var row = e.getTarget('.x-grid3-row');
 
56
            if(row){
 
57
                var index = row.rowIndex;
 
58
                if(this.isSelected(index)){
 
59
                    this.deselectRow(index);
 
60
                }else{
 
61
                    this.selectRow(index, true);
 
62
                }
 
63
            }
 
64
        }
 
65
    },
 
66
 
 
67
    // private
 
68
    onHdMouseDown : function(e, t){
 
69
        if(t.className == 'x-grid3-hd-checker'){
 
70
            e.stopEvent();
 
71
            var hd = Ext.fly(t.parentNode);
 
72
            var isChecked = hd.hasClass('x-grid3-hd-checker-on');
 
73
            if(isChecked){
 
74
                hd.removeClass('x-grid3-hd-checker-on');
 
75
                this.clearSelections();
 
76
            }else{
 
77
                hd.addClass('x-grid3-hd-checker-on');
 
78
                this.selectAll();
 
79
            }
 
80
        }
 
81
    },
 
82
 
 
83
    // private
 
84
    renderer : function(v, p, record){
 
85
        return '<div class="x-grid3-row-checker">&#160;</div>';
 
86
    }
 
87
});
 
 
b'\\ No newline at end of file'