]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/grid/ResourceGrid.js
ui: drop various translations of fixed strings
[pve-manager.git] / www / manager6 / grid / ResourceGrid.js
CommitLineData
e5c95a12
DM
1Ext.define('PVE.grid.ResourceGrid', {
2 extend: 'Ext.grid.GridPanel',
3 alias: ['widget.pveResourceGrid'],
4
4dce154f 5 border: false,
df6345f9
DC
6 defaultSorter: {
7 property: 'type',
f6710aac 8 direction: 'ASC',
df6345f9 9 },
ad4a19f6 10 userCls: 'proxmox-tags-full',
8058410f 11 initComponent: function() {
f79de803 12 let me = this;
e5c95a12 13
f79de803 14 let rstore = PVE.data.ResourceStore;
e5c95a12 15
f79de803 16 let store = Ext.create('Ext.data.Store', {
e5c95a12 17 model: 'PVEResources',
df6345f9 18 sorters: me.defaultSorter,
f79de803
TL
19 proxy: {
20 type: 'memory',
21 },
e5c95a12
DM
22 });
23
f79de803
TL
24 let textfilter = '';
25 let textfilterMatch = function(item) {
26 for (const field of ['name', 'storage', 'node', 'type', 'text']) {
27 let v = item.data[field];
28 if (v && v.toLowerCase().indexOf(textfilter) >= 0) {
29 return true;
e5c95a12 30 }
f79de803
TL
31 }
32 return false;
e5c95a12
DM
33 };
34
f79de803 35 let updateGrid = function() {
e5c95a12 36 var filterfn = me.viewFilter ? me.viewFilter.filterfn : null;
2a4971d8 37
e5c95a12
DM
38 store.suspendEvents();
39
f79de803
TL
40 let nodeidx = {};
41 let gather_child_nodes;
42 gather_child_nodes = function(node) {
43 if (!node || !node.childNodes) {
e5c95a12
DM
44 return;
45 }
f79de803
TL
46 for (let child of node.childNodes) {
47 let orgNode = rstore.data.get(child.data.id);
48 if (orgNode) {
49 if ((!filterfn || filterfn(child)) && (!textfilter || textfilterMatch(child))) {
50 nodeidx[child.data.id] = orgNode;
e5c95a12
DM
51 }
52 }
53 gather_child_nodes(child);
54 }
55 };
56 gather_child_nodes(me.pveSelNode);
57
58 // remove vanished items
f79de803
TL
59 let rmlist = [];
60 store.each(olditem => {
61 if (!nodeidx[olditem.data.id]) {
e5c95a12
DM
62 rmlist.push(olditem);
63 }
64 });
e5c95a12
DM
65 if (rmlist.length) {
66 store.remove(rmlist);
67 }
68
69 // add new items
f79de803
TL
70 let addlist = [];
71 for (const [_key, item] of Object.entries(nodeidx)) {
72 // getById() use find(), which is slow (ExtJS4 DP5)
73 let olditem = store.data.get(item.data.id);
74 if (!olditem) {
75 addlist.push(item);
76 continue;
77 }
78 let changes = false;
79 for (let field of PVE.data.ResourceStore.fieldNames) {
80 if (field !== 'id' && item.data[field] !== olditem.data[field]) {
81 changes = true;
82 olditem.beginEdit();
83 olditem.set(field, item.data[field]);
e5c95a12
DM
84 }
85 }
f79de803
TL
86 if (changes) {
87 olditem.endEdit(true);
88 olditem.commit(true);
89 }
e5c95a12 90 }
e5c95a12
DM
91 if (addlist.length) {
92 store.add(addlist);
93 }
e5c95a12 94 store.sort();
e5c95a12 95 store.resumeEvents();
7a3691ac 96 store.fireEvent('refresh', store);
e5c95a12
DM
97 };
98
e5c95a12
DM
99 Ext.apply(me, {
100 store: store,
df6345f9 101 stateful: true,
ac419eb9 102 stateId: 'grid-resource',
e5c95a12 103 tbar: [
2a4971d8 104 '->',
e5c95a12
DM
105 gettext('Search') + ':', ' ',
106 {
107 xtype: 'textfield',
108 width: 200,
109 value: textfilter,
110 enableKeyEvents: true,
111 listeners: {
f79de803 112 buffer: 500,
e5c95a12 113 keyup: function(field, e) {
f79de803
TL
114 textfilter = field.getValue().toLowerCase();
115 updateGrid();
f6710aac
TL
116 },
117 },
118 },
e5c95a12
DM
119 ],
120 viewConfig: {
f6710aac 121 stripeRows: true,
e5c95a12
DM
122 },
123 listeners: {
685b7aa4 124 itemcontextmenu: PVE.Utils.createCmdMenu,
e5c95a12
DM
125 itemdblclick: function(v, record) {
126 var ws = me.up('pveStdWorkspace');
127 ws.selectById(record.data.id);
128 },
cd79166d
DC
129 afterrender: function() {
130 updateGrid();
131 },
e5c95a12 132 },
f79de803 133 columns: rstore.defaultColumns(),
e5c95a12 134 });
e5c95a12 135 me.callParent();
76630375 136 me.mon(rstore, 'load', () => updateGrid());
f6710aac 137 },
e5c95a12 138});