[pve-devel] r5809 - pve-manager/pve2/www/new/grid
svn-commits at proxmox.com
svn-commits at proxmox.com
Tue Apr 12 11:12:53 CEST 2011
Author: dietmar
Date: 2011-04-12 11:12:53 +0200 (Tue, 12 Apr 2011)
New Revision: 5809
Modified:
pve-manager/pve2/www/new/grid/ResourceGrid.js
Log:
try to implement filter
Modified: pve-manager/pve2/www/new/grid/ResourceGrid.js
===================================================================
--- pve-manager/pve2/www/new/grid/ResourceGrid.js 2011-04-12 07:48:39 UTC (rev 5808)
+++ pve-manager/pve2/www/new/grid/ResourceGrid.js 2011-04-12 09:12:53 UTC (rev 5809)
@@ -30,11 +30,28 @@
updateCount: 0
};
- var updateGrid = function() {
+ var textfilter = '';
+ var textfilter_match = function(item) {
+ var match = false;
+ Ext.each(['name', 'storage', 'node', 'type'], function(field) {
+ var v = item.data[field];
+ if (v !== undefined) {
+ v = v.toLowerCase();
+ if (v.indexOf(textfilter) >= 0) {
+ match = true;
+ return false;
+ }
+ }
+ });
+ return match;
+ };
+
+ var updateGrid = function(removeAll) {
+
var filterfn = null;
- console.log("START GRID UPDATE");
+ console.log("START GRID UPDATE " + removeAll);
store.suspendEvents();
@@ -46,6 +63,9 @@
for (; i < len; i++) {
n = cs[i];
+ //if (textfilter && !textfilter_match(n))
+ //continue;
+
var orgnode = rstore.data.get(n.data.id);
if (orgnode)
nodeidx[n.data.id] = rstore.data.get(n.data.id);
@@ -60,10 +80,11 @@
var item = nodeidx[olditem.data.id];
if (!item) {
//console.log("GRID REM UID: " + olditem.data.id);
- rmlist.push(item);
+ rmlist.push(olditem);
}
});
- if (rmlist.length)
+
+ if (rmlist.length)
store.remove(rmlist);
// add new items
@@ -100,6 +121,7 @@
olditem.commit(true);
}
};
+
if (addlist.length) {
store.cacheRecords(addlist);
store.guaranteeRange(0, 50);
@@ -108,6 +130,7 @@
store.sort();
store.resumeEvents();
+
store.fireEvent('datachanged', store);
console.log("END GRID UPDATE");
@@ -118,10 +141,38 @@
pdata.updateCount++;
};
+
+ var filter_task = new Ext.util.DelayedTask(function(){
+ console.log("run filter " + textfilter);
+ updateGrid(true);
+ });
+
+ var load_cb = function() { updateGrid(false); };
+
Ext.apply(me, {
title: 'Search',
store: store,
- viewConfig: {
+ tbar: [
+ {
+ text: "Create VM"
+ },
+ '->',
+ 'Search:', ' ',
+ {
+ xtype: 'textfield',
+ width: 200,
+ value: textfilter,
+ enableKeyEvents: true,
+ listeners: {
+ keyup: function(field, e) {
+ var v = field.getValue();
+ textfilter = v;
+ filter_task.delay(500);
+ }
+ }
+ }
+ ],
+ viewConfig: {
invalidateScrollerOnRefresh: false,
stripeRows: true,
trackOver: false
@@ -132,7 +183,7 @@
},
listeners: {
destroy: function() {
- rstore.un("load", updateGrid)
+ rstore.un("load", load_cb)
}
},
columns: coldef
@@ -141,6 +192,6 @@
me.callParent();
updateGrid();
- rstore.on("load", updateGrid);
+ rstore.on("load", load_cb);
}
});
\ No newline at end of file
More information about the pve-devel
mailing list