[pve-devel] r5776 - in pve-manager/pve2/www/new: . data form
svn-commits at proxmox.com
svn-commits at proxmox.com
Fri Apr 1 14:27:25 CEST 2011
Author: dietmar
Date: 2011-04-01 14:27:25 +0200 (Fri, 01 Apr 2011)
New Revision: 5776
Added:
pve-manager/pve2/www/new/form/ViewSelector.js
Modified:
pve-manager/pve2/www/new/Makefile.am
pve-manager/pve2/www/new/ResourceTree.js
pve-manager/pve2/www/new/data/PVEProxy.js
Log:
try to hide private date, implement ViewSelector.js
Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am 2011-04-01 09:33:13 UTC (rev 5775)
+++ pve-manager/pve2/www/new/Makefile.am 2011-04-01 12:27:25 UTC (rev 5776)
@@ -7,6 +7,7 @@
data/UpdateStore.js \
data/ResourceStore.js \
form/RealmComboBox.js \
+ form/ViewSelector.js \
window/LoginWindow.js \
ResourceTree.js \
Workspace.js
Modified: pve-manager/pve2/www/new/ResourceTree.js
===================================================================
--- pve-manager/pve2/www/new/ResourceTree.js 2011-04-01 09:33:13 UTC (rev 5775)
+++ pve-manager/pve2/www/new/ResourceTree.js 2011-04-01 12:27:25 UTC (rev 5776)
@@ -1,100 +1,121 @@
Ext.define('PVE.ResourceTree', {
extend: 'Ext.tree.TreePanel',
- requires: ['Ext.tree.*', 'PVE.Utils', 'PVE.data.ResourceStore'],
+ requires: ['Ext.tree.*', 'PVE.Utils',
+ 'PVE.form.ViewSelector', 'PVE.data.ResourceStore'],
alias: ['widget.pveResourceTree'],
- statics: {
- updateCount: 0
- },
-
- // private
- updateTree: function() {
+ initComponent : function() {
var self = this;
-
- var rootnode = self.store.node;
- //rootnode.collapse();
- //rootnode.removeAll(true);
- var index = self.dataIndex;
-
var rstore = PVE.data.ResourceStore;
+
+ var pdata = {
+ view: {},
+ dataIndex: {},
+ updateCount: 0
+ };
- // remove vanished or changed items
- for (var key in index) {
- if (!index.hasOwnProperty(key))
- continue;
+ var store = Ext.create('Ext.data.TreeStore', {
+ model: 'PVETree',
+ root: {
+ expanded: true,
+ id: 'root',
+ text: "Datacenter 1",
+ }
+ });
- var olditem = index[key];
+ var updateTree = function() {
- var changed = false;
- // getById() use find(), which is slow (ExtJS4 DP5)
- //var item = rstore.getById(olditem.data.id);
- var item = rstore.data.get(olditem.data.id);
+ var rootnode = self.store.node;
- if (!item || changed) {
- console.log("REM UID: " + key);
- delete index[key];
- olditem.remove(true);
- }
- }
+ var index = pdata.dataIndex;
- // add new items
- rstore.each(function(item) {
- var olditem = index[item.id];
- if (olditem)
- return;
- var itype = item.data.type;
- console.log("ADD UID: " + item.id);
- item.data.text = item.id;
- item.data.leaf = true;
- item.data.cls = 'x-tree-icon-parent';
+ // remove vanished or changed items
+ for (var key in index) {
+ if (!index.hasOwnProperty(key))
+ continue;
- var ni = Ext.apply({}, item.data);
- var nn = Ext.ModelMgr.create(ni, 'PVETree');
- rootnode.appendChild(nn);
- index[item.id] = nn;
- });
+ var olditem = index[key];
- if (!PVE.ResourceTree.updateCount) {
- rootnode.collapse();
- rootnode.expand();
- }
+ var changed = false;
+ // getById() use find(), which is slow (ExtJS4 DP5)
+ //var item = rstore.getById(olditem.data.id);
+ var item = rstore.data.get(olditem.data.id);
- PVE.ResourceTree.updateCount++;
- },
+ if (!item || changed) {
+ console.log("REM UID: " + key);
+ delete index[key];
+ olditem.remove(true);
+ }
+ }
- initComponent : function() {
- var self = this;
+ // add new items
+ rstore.each(function(item) {
+ var olditem = index[item.id];
+ if (olditem)
+ return;
- self.dataIndex = {};
+ var itype = item.data.type;
+ console.log("ADD UID: " + item.id);
+ item.data.text = item.id;
+ item.data.leaf = true;
+ item.data.cls = 'x-tree-icon-parent';
- var rstore = PVE.data.ResourceStore;
-
- rstore.on("load", self.updateTree, self);
+ var ni = Ext.apply({}, item.data);
+ var nn = Ext.ModelMgr.create(ni, 'PVETree');
+ rootnode.appendChild(nn);
+ index[item.id] = nn;
+ });
- var store = Ext.create('Ext.data.TreeStore', {
- model: 'PVETree',
- root: {
- expanded: true,
- id: 'root',
- text: "Datacenter 1",
+ if (!pdata.updateCount) {
+ rootnode.collapse();
+ rootnode.expand();
}
- });
+ pdata.updateCount++;
+ };
+
Ext.apply(self, {
store: store,
title: 'Resource Tree',
- tbar: [ 'TEST' ],
+ tbar: [
+ {
+ xtype: 'pveViewSelector',
+ listeners: {
+ select: function(combo, records) {
+ if (records && records.length) {
+ var view = combo.getViewSettings();
+ self.setView(view);
+ }
+ }
+ }
+ }
+ ],
listeners: {
destroy: function() {
- rstore.un("load", self.updateTree, self)
+ rstore.un("load", updateTree)
}
},
+
+ setView: function(view) {
+ var self = this;
+
+ console.log("NEW VIEW " + view);
+ pdata.view = view;
+
+ var rootnode = self.store.node;
+ //rootnode.collapse();
+ rootnode.removeAll(true);
+ pdata.dataIndex = {};
+ updateTree();
+ },
+
});
PVE.ResourceTree.superclass.initComponent.call(self);
+ rstore.on("load", updateTree);
rstore.startUpdate();
}
Modified: pve-manager/pve2/www/new/data/PVEProxy.js
===================================================================
--- pve-manager/pve2/www/new/data/PVEProxy.js 2011-04-01 09:33:13 UTC (rev 5775)
+++ pve-manager/pve2/www/new/data/PVEProxy.js 2011-04-01 12:27:25 UTC (rev 5776)
@@ -32,4 +32,12 @@
}
});
+ Ext.regModel('LocalKeyValue', {
+ fields: [ 'key', 'value' ],
+ proxy: {
+ type: 'memory',
+ reader: 'array'
+ }
+ });
+
});
Added: pve-manager/pve2/www/new/form/ViewSelector.js
===================================================================
--- pve-manager/pve2/www/new/form/ViewSelector.js (rev 0)
+++ pve-manager/pve2/www/new/form/ViewSelector.js 2011-04-01 12:27:25 UTC (rev 5776)
@@ -0,0 +1,72 @@
+Ext.define('PVE.form.ViewSelector', {
+ extend: 'Ext.form.ComboBox',
+ requires: ['Ext.data.Store'],
+ alias: ['widget.pveViewSelector'],
+
+ initComponent: function() {
+ var self = this;
+
+ var default_views = {
+ server: {
+ text: 'Server View',
+ groups: ['node']
+ },
+ folder: {
+ text: 'Folder View',
+ groups: ['type']
+ },
+ storage: {
+ text: 'Storage View',
+ groups: ['node'],
+ filterfn: function(n, type) {
+ return type === 'storage';
+ }
+ }
+ };
+
+ var groupdef = [];
+ Ext.Object.each(default_views, function(viewname, value) {
+ groupdef.push([viewname, value.text]);
+ });
+
+ var store = Ext.create('Ext.data.Store', {
+ model: 'LocalKeyValue',
+ data: groupdef,
+ autoload: true,
+ autoDestory: true
+ });
+
+ Ext.apply(self, {
+ hideLabel: true,
+ store: store,
+ value: groupdef[0][0],
+ editable: false,
+ queryMode: 'local',
+ allowBlank: false,
+ forceSelection: true,
+ autoSelect: false,
+ triggerAction: 'all',
+ valueField: 'key',
+ displayField: 'value',
+
+ getViewSettings: function() {
+ var view = this.getValue();
+ return Ext.clone(default_views[view] || default_views.server);
+ },
+
+ getState: function() {
+ return { value: this.getValue() };
+ },
+ applyState : function(state) {
+ if (state && state.value) {
+ this.setValue(state.value);
+ }
+ },
+ stateEvents: [ 'select' ],
+ stateful: true,
+ stateId: 'pveviewselection'
+ });
+
+ PVE.form.ViewSelector.superclass.initComponent.call(self);
+ }
+});
\ No newline at end of file
More information about the pve-devel
mailing list