File: AxisGrid.js

package info (click to toggle)
icinga-web 1.11.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 83,356 kB
  • ctags: 41,251
  • sloc: php: 240,553; xml: 145,830; sql: 9,243; sh: 1,325; makefile: 617; perl: 328; python: 194
file content (189 lines) | stat: -rw-r--r-- 5,524 bytes parent folder | download | duplicates (2)
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
/*
This file is part of Ext JS 3.4

Copyright (c) 2011-2013 Sencha Inc

Contact:  http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as
published by the Free Software Foundation and appearing in the file LICENSE included in the
packaging of this file.

Please review the following information to ensure the GNU General Public License version 3.0
requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department
at http://www.sencha.com/contact.

Build date: 2013-04-03 15:07:25
*/
/**
 * @class pivot.AxisGrid
 * @extends Ext.grid.EditorGridPanel
 * Grid used to control the dimensions in a PivotGrid axis
 */
pivot.AxisGrid = Ext.extend(Ext.grid.EditorGridPanel, {
    border: false,
    style: 'border-top-width: 1px',
    flex: 1,
    clicksToEdit: 1,

    /**
     * @cfg {Array} fields The array of field names to control. Required
     */
    
    /**
     * @cfg {Boolean} hasWidthField True to add a column for 'width' (e.g. for left axes)
     */
    hasWidthField: false,
    
    /**
     * The Record used internally to manage the field name, sort direction and width of each dimension
     * @property record
     * @type Ext.data.Record
     */
    record: Ext.data.Record.create([
        {name: 'field',     type: 'string'},
        {name: 'direction', type: 'string'},
        {name: 'width',     type: 'int'}
    ]),

    initComponent: function() {
        this.store = new Ext.data.Store({
            data  : this.dimensionData || [], 
            reader: new Ext.data.JsonReader({}, this.record)
        });

        var columns = [{
            header   : 'Dimension',
            dataIndex: 'field',
            editor   : this.buildDimensionEditor(),
            width    : this.hasWidthField ? 110 : 160
        }, {
            header   : 'Sort Direction',
            dataIndex: 'direction',
            editor   : this.buildDirectionEditor(),
            width    : 80
        }];

        if (this.hasWidthField) {
            columns.push({
                header   : 'Width',
                dataIndex: 'width',
                editor   : new Ext.form.NumberField(),
                width    : 50
            });
        }

        columns.push({
            xtype: 'actioncolumn',
            width: 30,
            icon   : '../shared/icons/fam/delete.gif',
            scope  : this,
            handler: this.onRemoveDimension,
            tooltip: 'Delete this axis',
            editable: false
        });

        Ext.applyIf(this, {
            bbar: [{
                text   : 'Add Dimension',
                icon   : '../shared/icons/fam/add.gif',
                scope  : this,
                handler: this.onAddDimension
            }],
            columns: columns
        });
        pivot.AxisGrid.superclass.initComponent.apply(this, arguments);
    },

    /**
     * @private
     * Adds a new row to the store and auto-focusses its first editor
     */
    onAddDimension: function() {
        this.store.add(new this.record({
            field    : this.fields[0],
            direction: "ASC",
            width    : 80
        }));

        this.startEditing(this.store.getCount() - 1, 0);
    },

    /**
     * @private
     */
    onRemoveDimension: function(grid, rowIndex, colIndex) {
        var store  = this.store,
            record = this.store.getAt(rowIndex);
        
        store.remove(record);
    },

    /**
     * @private
     * @return {Ext.form.ComboBox} The editor
     */
    buildDimensionEditor: function() {
        return new Ext.form.ComboBox({
            mode : 'local',
            store: this.getFieldStore(),
            editable      : false,
            valueField    : 'name',
            displayField  : 'name',
            triggerAction : 'all',
            forceSelection: true
        });
    },

    /**
     * @private
     * @return {Ext.data.Store} The store
     */
    getFieldStore: function() {
        /**
         * @property fieldStore
         * @type Ext.data.JsonStore
         * The store bound to the combo for selecting the field
         */
        if (this.fieldStore == undefined) {
            var fields = [],
                length = this.fields.length,
                i;

            for (i = 0; i < length; i++) {
                fields[i] = [this.fields[i]];
            }

            this.fieldStore = new Ext.data.ArrayStore({
                fields: ['name'],
                data  : fields
            });
        }
        return this.fieldStore; 
    },

    /**
     * @private
     * Creates a local combo with options for ASC and DESC
     * @return {Ext.form.ComboBox} The editor
     */
    buildDirectionEditor: function() {
        return new Ext.form.ComboBox({
            name          : 'name',
            mode          : 'local',
            editable      : false,
            forceSelection: true,
            triggerAction : 'all',
            displayField  : 'name',
            valueField    : 'name',
            value         : 'ASC',
            store: new Ext.data.JsonStore({
                fields : ['name'],
                data   : [{name : 'ASC'}, {name : 'DESC'}]
            })
        });
    }
});