This repository was archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection_index.js
More file actions
68 lines (58 loc) · 1.43 KB
/
collection_index.js
File metadata and controls
68 lines (58 loc) · 1.43 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
/*globals Ext */
/*jslint glovar: true, undef: true, nomen: true */
Ext.namespace('Ext.ux.data');
Ext.ux.data.CollectionIndex = function(coll, name, fn) {
if(typeof name == 'function') {
fn = name;
name = null;
}
this.collection = coll;
this.mapFn = fn;
this.map = {};
if(name) {
coll.maps = coll.maps || {};
coll.maps[name] = this.map;
}
coll.on('add', this.onAdd, this);
coll.on('replace', this.onReplace, this);
coll.on('remove', this.onRemove, this);
coll.on('clear', this.onClear, this);
this.refreshIndex();
};
Ext.ux.data.CollectionIndex.prototype = {
onAdd: function(index, o, key) { this.index(o); },
onReplace: function(key, old, o) { this.index(o); },
index: function(o) {
var key = this.mapFn(o);
if(key) {
this.map[key] = o;
}
},
refreshIndex: function() {
this.collection.each(function(item) {
this.index(item);
}, this);
},
onRemove: function(o, key) {
key = this.mapFn(o);
if(key) {
delete this.map[key];
}
},
onClear: function() {
this.map = {};
}
};
Ext.override(Ext.FormPanel, {
createForm_without_collection_index: Ext.FormPanel.prototype.createForm,
createForm: function() {
var form = this.createForm_without_collection_index();
var index = new Ext.ux.data.CollectionIndex(form.items,
function(o) {
return o.dataIndex;
}
);
form.fields = index.map;
return form;
}
});