forked from maxvyaznikov/RowToolbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExt.ux.grid.features.RowToolbar.js
More file actions
152 lines (128 loc) · 5.26 KB
/
Ext.ux.grid.features.RowToolbar.js
File metadata and controls
152 lines (128 loc) · 5.26 KB
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
/*
Copyright 2013 Siterra Ltd. (www.siterra.org)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
Ext.define('Ext.ux.grid.features.RowToolbar', {
extend: 'Ext.grid.feature.Feature',
alias: 'feature.rowtoolbar',
rowToolbarCls: 'app-grid-feature-rowtoolbar',
/* @param renderTimeout (int)
* Timeout for delay before render items. Required, because we have no events to call
* our render after data loads and grid rendered. It can be edit, then computer is too
* slow to render so fast.
*/
renderTimeout: 1,
toolbar: {},
init: function() {
this.toolbar = Ext.applyIf(this.toolbar, {
xclass: 'Ext.toolbar.Toolbar',
padding: '0 16 0 0',
cls: 'grid-feature-rowtoolbar-instance',
baseCls: '',
baseId: Ext.id() + '-rowtoolbar',
/* @optional
* @param isDisabledForRecord (function)
* Function gives a record to check enable item or not for it
* inputs
* @param record
* @return boolean
*/
/* @optional
* @param isVisibleForRecord (function)
* Function gives a record to check visibility of item
* inputs
* @param record
* @return boolean
*/
/* @optional
* @param hiddenItemsSavePosition (boolean)
* With this flag is true and element is hidden, then it's width
* doesn't 0. Visibility doesn't influence on positioning othe items.
*/
listeners: {
scope: this,
afterrender: function(tbar) {
Ext.each(tbar.items.items, function(item) {
if (item.isDisabledForRecord) {
var is_disabled = item.isDisabledForRecord(item, tbar.record);
item.setDisabled(is_disabled);
}
if (item.isVisibleForRecord) {
var is_visible = item.isVisibleForRecord(item, tbar.record);
if (item.hiddenItemsSavePosition) {
item.getEl().dom.style.visibility = (is_visible ? 'visible' : 'hidden');
} else {
item.setVisible(is_visible);
}
}
}, this);
}
}
/* @variable renderedItems
* Keeps rendered components created with help of this toolbar config
*/
/* each renderedItem has
* @variable record
* what links to it's own record in store
* Keeps rendered components created with help of this toolbar config
*/
});
},
renderItems: function() {
this.toolbar.renderedItems = [];
var els = Ext.query('.'+ this.toolbar.baseId +'-wrap', this.grid.getEl().dom);
Ext.each(els, function(el) {
// clone toolbar config for each row
var tb_clone = Ext.clone(this.toolbar);
tb_clone.items = Ext.clone(this.items);
// find record in store for current row
var row = Ext.get(el).up('.x-grid-row');
if (row) {
tb_clone.record = this.grid.getView().getRecord(row);
}
// create and render toolbar for current row
tb_clone = Ext.create(tb_clone);
el.innerHTML = '';
tb_clone.render(el);
// remember an item
this.toolbar.renderedItems.push(tb_clone);
}, this);
},
getRowToolbar: function() {
var tpl =
'<tr class="'+ this.rowToolbarCls +'">'+
'<td class="'+ this.rowToolbarCls +'" colspan="{[ this.embedColSpan() ]}">'+
'<div class="'+ this.toolbar.baseId +'-wrap '+ this.rowToolbarCls +'-btn"></div>'+
'</td>'+
'</tr>';
return tpl;
},
embedColSpan: function() {
return '{rowToolbarColspan}';
},
getAdditionalData: function(data, idx, record, orig) {
var colspan = this.view.headerCt.getColumnCount();
return {
rowToolbarCls: this.rowToolbarCls,
rowToolbarColspan: colspan
};
},
mutateMetaRowTpl: function(metaRowTpl) {
metaRowTpl.push(this.getRowToolbar());
},
getMetaRowTplFragments: function() {
// render toolbar after some time
Ext.defer(this.renderItems, this.renderTimeout, this);
return {
embedColSpan: this.embedColSpan
};
}
});