[pve-devel] r5989 - in pve-manager/pve2/www/new: data data/reader grid
svn-commits at proxmox.com
svn-commits at proxmox.com
Tue May 17 15:25:32 CEST 2011
Author: dietmar
Date: 2011-05-17 15:25:32 +0200 (Tue, 17 May 2011)
New Revision: 5989
Modified:
pve-manager/pve2/www/new/data/DiffStore.js
pve-manager/pve2/www/new/data/ObjectStore.js
pve-manager/pve2/www/new/data/reader/JsonObject.js
pve-manager/pve2/www/new/grid/ObjectGrid.js
Log:
use DiffStore
Modified: pve-manager/pve2/www/new/data/DiffStore.js
===================================================================
--- pve-manager/pve2/www/new/data/DiffStore.js 2011-05-17 11:16:47 UTC (rev 5988)
+++ pve-manager/pve2/www/new/data/DiffStore.js 2011-05-17 13:25:32 UTC (rev 5989)
@@ -8,14 +8,14 @@
constructor: function(config) {
var me = this;
- config = config || {};
+ var config = config || {};
if (!config.rstore)
throw "no rstore specified";
if (!config.rstore.model)
throw "no rstore model specified";
- rstore = config.rstore;
+ var rstore = config.rstore;
Ext.apply(config, {
model: rstore.model,
@@ -57,7 +57,9 @@
rstore.each(function(item) {
cond_add_item(item.data, item.getId());
});
-
+
+ me.filter();
+
me.resumeEvents();
me.fireEvent('datachanged', me);
});
Modified: pve-manager/pve2/www/new/data/ObjectStore.js
===================================================================
--- pve-manager/pve2/www/new/data/ObjectStore.js 2011-05-17 11:16:47 UTC (rev 5988)
+++ pve-manager/pve2/www/new/data/ObjectStore.js 2011-05-17 13:25:32 UTC (rev 5989)
@@ -14,7 +14,10 @@
proxy: {
type: 'pve',
url: config.url,
- reader: 'jsonobject'
+ reader: {
+ type: 'jsonobject',
+ rows: config.rows
+ }
}
});
Modified: pve-manager/pve2/www/new/data/reader/JsonObject.js
===================================================================
--- pve-manager/pve2/www/new/data/reader/JsonObject.js 2011-05-17 11:16:47 UTC (rev 5988)
+++ pve-manager/pve2/www/new/data/reader/JsonObject.js 2011-05-17 13:25:32 UTC (rev 5989)
@@ -27,9 +27,21 @@
root = {};
}
- Ext.Object.each(root, function(key, value) {
- data.push({key: key, value: value });
- });
+ if (me.rows) {
+ Ext.Object.each(me.rows, function(key, rowdef) {
+ if (Ext.isDefined(root[key])) {
+ data.push({key: key, value: root[key]});
+ } else if (Ext.isDefined(rowdef.defaultValue)) {
+ data.push({key: key, value: rowdef.defaultValue});
+ } else if (rowdef.required) {
+ data.push({key: key, value: undefined});
+ }
+ });
+ } else {
+ Ext.Object.each(root, function(key, value) {
+ data.push({key: key, value: value });
+ });
+ }
}
catch (ex) {
Ext.Error.raise({
Modified: pve-manager/pve2/www/new/grid/ObjectGrid.js
===================================================================
--- pve-manager/pve2/www/new/grid/ObjectGrid.js 2011-05-17 11:16:47 UTC (rev 5988)
+++ pve-manager/pve2/www/new/grid/ObjectGrid.js 2011-05-17 13:25:32 UTC (rev 5989)
@@ -45,45 +45,37 @@
me.rstore = Ext.create('PVE.data.ObjectStore', {
url: me.url,
- interval: me.interval
+ interval: me.interval,
+ rows: me.rows
});
}
var rstore = me.rstore;
- var store = Ext.create('Ext.data.Store', {
- model: 'KeyValue',
- proxy: 'memory',
- sorters: {
- property: 'key'
- }
- });
+ var store = Ext.create('PVE.data.DiffStore', { rstore: rstore });
- var cond_add_item = function(data, olditem) {
- if (olditem) {
- olditem.beginEdit()
- olditem.set('value', data.value);
- olditem.endEdit(true);
- olditem.commit();
- } else {
- var newrec = Ext.ModelMgr.create(
- data, store.model, data.key);
- store.add(newrec);
- }
- };
-
if (rows) {
Ext.Object.each(rows, function(key, rowdef) {
if (Ext.isDefined(rowdef.defaultValue)) {
- var data = { key: key, value: rowdef.defaultValue };
- cond_add_item(data);
+ store.add({ key: key, value: rowdef.defaultValue });
} else if (rowdef.required) {
- var data = { key: key, value: undefined };
- cond_add_item(data);
+ store.add({ key: key, value: undefined });
}
});
}
+ store.filters.add(new Ext.util.Filter({
+ filterFn: function(item) {
+ if (rows) {
+ var rowdef = rows[item.data.key];
+ if (!rowdef || (rowdef.visible === false)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }));
+
me.mon(rstore, 'load', function(s, records, success) {
if (!success) {
@@ -91,50 +83,7 @@
return;
} else {
me.setLoading(false);
- }
-
- store.suspendEvents();
-
- // remove vanished items
- store.each(function(olditem) {
- var item = rstore.data.get(olditem.data.key);
- if (!item) {
- if (!(rows && rows[olditem.data.key] &&
- Ext.isDefined(rows[olditem.data.key].defaultValue))) {
- store.remove(olditem);
- }
- }
- });
-
- // add/update items
- if (rows) {
- Ext.Object.each(rows, function(key, rowdef) {
- var olditem = (store.snapshot || store.data).get(key);
- var item = rstore.data.get(key);
- if (!item) {
- if (!Ext.isDefined(rowdef.defaultValue))
- return;
- var data = { key: key, value: rowdef.defaultValue };
- cond_add_item(data, olditem);
- } else
- cond_add_item(item.data, olditem);
- });
- } else {
- rstore.each(function(item) {
- var olditem = (store.snapshot || store.data).get(item.data.key);
- cond_add_item(item.data, olditem);
- });
- }
-
- store.filterBy(function(item) {
- if (rows && rows[item.data.key] &&
- (rows[item.data.key].visible === false))
- return false;
- return true;
- });
-
- store.resumeEvents();
- store.fireEvent('datachanged', store);
+ }
});
Ext.applyIf(me, {
More information about the pve-devel
mailing list