[pve-devel] r4898 - in pve-manager/pve2/www/manager: . data

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Jul 14 12:33:35 CEST 2010


Author: dietmar
Date: 2010-07-14 10:33:35 +0000 (Wed, 14 Jul 2010)
New Revision: 4898

Added:
   pve-manager/pve2/www/manager/data/SearchStore.js
Modified:
   pve-manager/pve2/www/manager/Makefile.am
   pve-manager/pve2/www/manager/PVECache.js
Log:
namespace cleanups


Modified: pve-manager/pve2/www/manager/Makefile.am
===================================================================
--- pve-manager/pve2/www/manager/Makefile.am	2010-07-14 10:28:06 UTC (rev 4897)
+++ pve-manager/pve2/www/manager/Makefile.am	2010-07-14 10:33:35 UTC (rev 4898)
@@ -7,6 +7,7 @@
 	data/ObjectReader.js				\
 	data/ObjectStore.js				\
 	data/UpdateStore.js				\
+	data/SearchStore.js				\
 	grid/ObjectView.js				\
 	PVECache.js 					\
 	Workspace.js 					\

Modified: pve-manager/pve2/www/manager/PVECache.js
===================================================================
--- pve-manager/pve2/www/manager/PVECache.js	2010-07-14 10:28:06 UTC (rev 4897)
+++ pve-manager/pve2/www/manager/PVECache.js	2010-07-14 10:33:35 UTC (rev 4898)
@@ -1,270 +1,5 @@
 Ext.ns("PVE");
 
-PVE.SearchStore = Ext.extend(Ext.data.Store, {
-
-    constructor: function(config) {
-	var obj = this;
-
-	config = config || {};
-
-	if (!config.storelist)
-	    throw "no storage list specified";
-
-	var text_filter = '';
-
-	var text_filter_fn = function(item) {
-	    if (text_filter) {
-		var match = false;
-		Ext.each(['name', 'storage', 'node'], function(field) {
-		    var v = item.data[field];
-		    if (v !== undefined) {
-			v = v.toLowerCase();
-			if (v.indexOf(text_filter) >= 0) {
-			    match = true;
-			    return false;
-			}
-		    }
-		});
-		return !match;
-	    } 
-	    return false;
-	};
-
-	var item_filter_fn;
-
-	var group_filter = [];
-
-	var filterFn = function(item, itype) {
-
-	    if (item_filter_fn && !item_filter_fn(item, itype)) {
-		return true;
-	    }
-
-	    for (var i = 0, len = group_filter.length; i < len; i++) {
-		var filter = group_filter[i];
-		var field = filter.field;
-		if (field === 'itype') {
-		    if (itype != filter.value)
-			return true;
-		} else if (item.data[field] != filter.value)
-		    return true;
-	    }
-
-	    return text_filter_fn(item);
-	};
-
-	var load_info = {};
-
-	var task_search = null;
-
-	var run_search_task = function(delay) {
-
-	    if (!task_search) {
-	    
-		task_search = new Ext.util.DelayedTask(function() {
-
-		    console.log("text filter " + text_filter);
-
-		    obj.suspendEvents();
-
-		    obj.removeAll();
-	
-		    Ext.each(config.storelist, function(store) {
-			obj.initStore(store, store.itype);
-		    });
-
-		    obj.applySort();
-
-		    obj.resumeEvents();
-
-		    obj.fireEvent('datachanged', obj);
-		
-		    obj.fireEvent('load', obj);
-	
-		});
-	    }
-
-	    task_search.delay(delay);
-	};
-
-	var basefields = PVE.Utils.base_fields;
-
-	var myfields = ['objectid', 'itype', 'itemid'].concat(basefields);;
-	
-	var reader =  new Ext.data.ArrayReader({
-	    fields: myfields,
-	    idIndex: 0
-	});
-
-	Ext.apply(config, {
-
-	    reader: reader,
-
-	    sortInfo: {
-		field: 'itype',
-		direction: 'DESC'
-	    },	
-	    
-	    getTextFilter: function() {
-		return text_filter;
-	    },
-
-	    setTextFilter: function(text) {
-
-		if (text_filter === text)
-		    return;
-
-		text_filter = text.toLowerCase();
-
-		run_search_task(200);
-	    },
-
-	    setGroupFilter: function(viewname, filterinfo) {
-
-		item_filter_fn = PVE.Utils.default_views[viewname].filterfn;
-
-		group_filter = filterinfo;
-
-		run_search_task(10);
-	    },
-
-	    createRec: function(item, uid, itype) {
-	    
-		var info = Ext.apply({}, item.data);
-
-		Ext.apply(info, {
-		    itype: itype,
-		    id: uid,
-		    text: item.id,
-		    itemid: item.id,
-		    leaf: true
-		});		    
-	    
-		var rec = new obj.reader.recordType(info, uid);
-	    
-		return rec;
-	    },
- 
-	    initStore: function(basestore, itype) {
- 
-		console.log("basestore init " + itype);
-
-		load_info[itype] = true;
-
-		basestore.each(function(item) {
-
-		    if (filterFn(item, itype))
-			return true;
-
-		    var uid = itype + "." + item.id;
-
-		    //console.log("add item " + uid);
-
-		    var rec = obj.createRec(item, uid, itype);
-		    obj.add(rec);
-		});
-	    },
-
-	    updateStore: function(basestore, itype) {
-	    
-		//console.log("basestore load " + itype);
-	    
-		if (!load_info[itype]) {
-		    
-		    //console.log("basestore first load " + itype);
-		
-		    obj.suspendEvents();
-	    
-		    obj.initStore(basestore, itype);
-		
-		    obj.applySort();
-
-		    obj.resumeEvents();
-		
-		    obj.fireEvent('datachanged', obj);
- 	    
-		} else {
-	
-		    // update tree
-		    //console.log("basestore update start");
-
-		    obj.suspendEvents();
-
-		    // remove vanished or changed items
-		    var rmlist = [];
-		    obj.each(function(item) {
-		    
-			if (item.data.itype !== itype)
-			    return true;
-		
-			var newitem = basestore.getById(item.data.itemid);
-
-			if (!newitem)
-			    rmlist.push(item);
-		    });
-
-		    if (rmlist.length) 
-			obj.remove(rmlist); //fixme:
-		
-		    var addlist = [];
-		    basestore.each(function(newitem) {
-
-			if (filterFn(newitem, itype))
-			    return true;
-
-			var uid = itype + "." + newitem.id;
-
-			var item = obj.getById(uid);
-			if (!item) {
-			    //console.log("add item " + uid);
-			    var rec = obj.createRec(newitem, uid, itype);
-			    addlist.push(rec);
-			} else {
-			    var changes = false;
-			    for (var i = 0, len = basefields.length; i < len; i++) {
-				field = basefields[i];
-				if (field != 'id' && item[field] != newitem.data[field]) {
-				    item.beginEdit()
-				    item.set(field,newitem.data[field]);
-				    changes = true;
-				    //item[field] = newitem.data[field];
-				}
-			    };
-			    if (changes)
-				item.commit(true);
-			}
-		    });
-
-		    if (addlist.length) 
-			obj.add(addlist);
-
-		    obj.applySort();
-
-		    obj.resumeEvents();
-
-		    obj.fireEvent('datachanged', obj);
-	 
-		    //console.log("basestore update end " + itype);
-		}
-	    }
-	});
-
-	PVE.SearchStore.superclass.constructor.call(this, config);
-	    
-	Ext.each(config.storelist, function(store)  {
-	    var update_store = function() {
-		obj.updateStore(store, store.itype);
-	    };
-
-	    store.on('load', update_store);
-
-	    obj.on('destroy', function () {
-		store.un('load', update_store);
-	    });
-	});      
-    }
-});
-
 PVE.Cache = function() {
 
     var defaults = {};
@@ -335,7 +70,7 @@
 	pvecache.ststore
     ];
 
-    pvecache.searchstore = new PVE.SearchStore({ storelist: pvecache.storelist });
+    pvecache.searchstore = new PVE.data.SearchStore({ storelist: pvecache.storelist });
 
     return pvecache;
 

Added: pve-manager/pve2/www/manager/data/SearchStore.js
===================================================================
--- pve-manager/pve2/www/manager/data/SearchStore.js	                        (rev 0)
+++ pve-manager/pve2/www/manager/data/SearchStore.js	2010-07-14 10:33:35 UTC (rev 4898)
@@ -0,0 +1,266 @@
+Ext.ns("PVE.data");
+
+PVE.data.SearchStore = Ext.extend(Ext.data.Store, {
+
+    constructor: function(config) {
+	var self = this;
+
+	config = config || {};
+
+	if (!config.storelist)
+	    throw "no storage list specified";
+
+	var text_filter = '';
+
+	var text_filter_fn = function(item) {
+	    if (text_filter) {
+		var match = false;
+		Ext.each(['name', 'storage', 'node'], function(field) {
+		    var v = item.data[field];
+		    if (v !== undefined) {
+			v = v.toLowerCase();
+			if (v.indexOf(text_filter) >= 0) {
+			    match = true;
+			    return false;
+			}
+		    }
+		});
+		return !match;
+	    } 
+	    return false;
+	};
+
+	var item_filter_fn;
+
+	var group_filter = [];
+
+	var filterFn = function(item, itype) {
+
+	    if (item_filter_fn && !item_filter_fn(item, itype)) {
+		return true;
+	    }
+
+	    for (var i = 0, len = group_filter.length; i < len; i++) {
+		var filter = group_filter[i];
+		var field = filter.field;
+		if (field === 'itype') {
+		    if (itype != filter.value)
+			return true;
+		} else if (item.data[field] != filter.value)
+		    return true;
+	    }
+
+	    return text_filter_fn(item);
+	};
+
+	var load_info = {};
+
+	var task_search = null;
+
+	var run_search_task = function(delay) {
+
+	    if (!task_search) {
+	    
+		task_search = new Ext.util.DelayedTask(function() {
+
+		    console.log("text filter " + text_filter);
+
+		    self.suspendEvents();
+
+		    self.removeAll();
+	
+		    Ext.each(config.storelist, function(store) {
+			self.initStore(store, store.itype);
+		    });
+
+		    self.applySort();
+
+		    self.resumeEvents();
+
+		    self.fireEvent('datachanged', self);
+		
+		    self.fireEvent('load', self);
+	
+		});
+	    }
+
+	    task_search.delay(delay);
+	};
+
+	var basefields = PVE.Utils.base_fields;
+
+	var myfields = ['objectid', 'itype', 'itemid'].concat(basefields);;
+	
+	var reader =  new Ext.data.ArrayReader({
+	    fields: myfields,
+	    idIndex: 0
+	});
+
+	Ext.apply(config, {
+
+	    reader: reader,
+
+	    sortInfo: {
+		field: 'itype',
+		direction: 'DESC'
+	    },	
+	    
+	    getTextFilter: function() {
+		return text_filter;
+	    },
+
+	    setTextFilter: function(text) {
+
+		if (text_filter === text)
+		    return;
+
+		text_filter = text.toLowerCase();
+
+		run_search_task(200);
+	    },
+
+	    setGroupFilter: function(viewname, filterinfo) {
+
+		item_filter_fn = PVE.Utils.default_views[viewname].filterfn;
+
+		group_filter = filterinfo;
+
+		run_search_task(10);
+	    },
+
+	    createRec: function(item, uid, itype) {
+	    
+		var info = Ext.apply({}, item.data);
+
+		Ext.apply(info, {
+		    itype: itype,
+		    id: uid,
+		    text: item.id,
+		    itemid: item.id,
+		    leaf: true
+		});		    
+	    
+		var rec = new self.reader.recordType(info, uid);
+	    
+		return rec;
+	    },
+ 
+	    initStore: function(basestore, itype) {
+ 
+		console.log("basestore init " + itype);
+
+		load_info[itype] = true;
+
+		basestore.each(function(item) {
+
+		    if (filterFn(item, itype))
+			return true;
+
+		    var uid = itype + "." + item.id;
+
+		    //console.log("add item " + uid);
+
+		    var rec = self.createRec(item, uid, itype);
+		    self.add(rec);
+		});
+	    },
+
+	    updateStore: function(basestore, itype) {
+	    
+		//console.log("basestore load " + itype);
+	    
+		if (!load_info[itype]) {
+		    
+		    //console.log("basestore first load " + itype);
+		
+		    self.suspendEvents();
+	    
+		    self.initStore(basestore, itype);
+		
+		    self.applySort();
+
+		    self.resumeEvents();
+		
+		    self.fireEvent('datachanged', self);
+ 	    
+		} else {
+	
+		    // update tree
+		    //console.log("basestore update start");
+
+		    self.suspendEvents();
+
+		    // remove vanished or changed items
+		    var rmlist = [];
+		    self.each(function(item) {
+		    
+			if (item.data.itype !== itype)
+			    return true;
+		
+			var newitem = basestore.getById(item.data.itemid);
+
+			if (!newitem)
+			    rmlist.push(item);
+		    });
+
+		    if (rmlist.length) 
+			self.remove(rmlist); //fixme:
+		
+		    var addlist = [];
+		    basestore.each(function(newitem) {
+
+			if (filterFn(newitem, itype))
+			    return true;
+
+			var uid = itype + "." + newitem.id;
+
+			var item = self.getById(uid);
+			if (!item) {
+			    //console.log("add item " + uid);
+			    var rec = self.createRec(newitem, uid, itype);
+			    addlist.push(rec);
+			} else {
+			    var changes = false;
+			    for (var i = 0, len = basefields.length; i < len; i++) {
+				field = basefields[i];
+				if (field != 'id' && item[field] != newitem.data[field]) {
+				    item.beginEdit()
+				    item.set(field,newitem.data[field]);
+				    changes = true;
+				    //item[field] = newitem.data[field];
+				}
+			    };
+			    if (changes)
+				item.commit(true);
+			}
+		    });
+
+		    if (addlist.length) 
+			self.add(addlist);
+
+		    self.applySort();
+
+		    self.resumeEvents();
+
+		    self.fireEvent('datachanged', self);
+	 
+		    //console.log("basestore update end " + itype);
+		}
+	    }
+	});
+
+	PVE.data.SearchStore.superclass.constructor.call(self, config);
+	    
+	Ext.each(config.storelist, function(store)  {
+	    var update_store = function() {
+		self.updateStore(store, store.itype);
+	    };
+
+	    store.on('load', update_store);
+
+	    self.on('destroy', function () {
+		store.un('load', update_store);
+	    });
+	});      
+    }
+});




More information about the pve-devel mailing list