[icinga-checkins] icinga.org: icinga-web/master: * Moved persistent implementation to grid object

git at icinga.org git at icinga.org
Thu Jan 20 15:46:05 CET 2011


Module: icinga-web
Branch: master
Commit: ffc89e5eae568bf885831bc3bd20d823e1bae73e
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=ffc89e5eae568bf885831bc3bd20d823e1bae73e

Author: Marius Hein <marius.hein at netways.de>
Date:   Thu Jan 20 15:45:16 2011 +0100

* Moved persistent implementation to grid object
* Implemented basic stateful col model (ref #988)

---

 app/modules/Cronks/lib/js/grid/GridPanel.js       |   89 ++++++++++++++++++++-
 app/modules/Cronks/lib/js/grid/MetaGridCreator.js |   59 +-------------
 2 files changed, 89 insertions(+), 59 deletions(-)

diff --git a/app/modules/Cronks/lib/js/grid/GridPanel.js b/app/modules/Cronks/lib/js/grid/GridPanel.js
index 1c4bd73..e26ec93 100755
--- a/app/modules/Cronks/lib/js/grid/GridPanel.js
+++ b/app/modules/Cronks/lib/js/grid/GridPanel.js
@@ -163,7 +163,94 @@ Cronk.grid.GridPanel = Ext.extend(Ext.grid.GridPanel, {
 	
 	setFilter : function(f) {
 		this.filter = f;
-	}
+	},
+	
+	stateEvents: ['activate', 'columnmove ', 'columnresize', 'groupchange', 'sortchange'],
+	
+	getPersistentColumnModel : function() {
+		
+		o = {};
+		Ext.iterate(this.colModel.config, function(col, colId) {
+			o[colId] = {};
+			Ext.copyTo(o[colId], col, [
+				'hidden',
+				'width',
+				'dataIndex',
+				'id',
+				'sortable'
+			]);
+		}, this);
+		
+		return o;
+	},
+	
+	applyPersistentColumnModel : function(data) {
+		var cm = this.colModel;
+		
+		Ext.iterate(data, function(colId, col) {
+			
+			if (Ext.isDefined(col.dataIndex)){
+				var org = cm.getColumnById(colId);
+				
+				// Column was not moved arropund
+				if (org.dataIndex == col.dataIndex) {
+					cm.setHidden(colId, col.hidden);
+					cm.setColumnWidth(colId, col.width);
+				}
+			}
+			
+		}, this);
+	},
+	
+	getState: function() {
+		var store = this.getStore();
+	
+		var o = {
+			filter_params: this.filter_params || {},
+			filter_types: this.filter_types || {},
+			store_origin_params: ("originParams" in store) ? store.originParams : {},
+			colModel: this.getPersistentColumnModel()
+		};
+		
+		return o;
+	},
+	
+	applyState: function(state) {
+		var reload = false;
+		var store = this.getStore();
+		
+		if (Ext.isObject(state.colModel)) {
+			this.applyPersistentColumnModel(state.colModel);
+		}
+		
+		if (state.filter_types) {
+			this.filter_types = state.filter_types;
+		}
+		
+		if (state.store_origin_params) {
+			store.originParams = state.store_origin_params;
+			this.applyParamsToStore(store.originParams, store);
+			reload = true;
+		}
+		
+		if (state.filter_params) {
+			this.filter_params = state.filter_params;
+			this.applyParamsToStore(this.filter_params, store);
+			reload = true;
+		}
+		
+		if (reload == true) {
+			store.reload();
+		}
+					
+		return true;
+	},
+	
+	applyParamsToStore : function(params) {
+		for (var i in params) {
+			this.store.setBaseParam(i, params[i]);
+		}
+	},
 	
 });
 
diff --git a/app/modules/Cronks/lib/js/grid/MetaGridCreator.js b/app/modules/Cronks/lib/js/grid/MetaGridCreator.js
index 299d61a..46e187f 100755
--- a/app/modules/Cronks/lib/js/grid/MetaGridCreator.js
+++ b/app/modules/Cronks/lib/js/grid/MetaGridCreator.js
@@ -265,55 +265,7 @@ Cronk.grid.MetaGridCreator = function(meta) {
 		if (pub.stateuid) {
 			Ext.apply(grid_config, {
 				stateful: Ext.isDefined(pub.initialstate) ? false : true,
-				
-				stateId: pub.stateuid,
-				
-				stateEvents: ['activate'],
-				
-				getState: function() {
-					var store = this.getStore();
-				
-					var o = {
-						filter_params: this.filter_params || {},
-						filter_types: this.filter_types || {},
-						store_origin_params: ("originParams" in store) ? store.originParams : {}
-					};
-					
-					var e = true;
-
-					for (var i in o.filter_params) { e=false; break; }
-					for (var i in o.filter_types) { e=false; break; }
-					for (var i in o.store_origin_params) { e=false; break; }
-
-					if (e == false) {
-						return o;
-					}
-				},
-				
-				applyState: function(state) {
-					var reload = false;
-					var store = this.getStore();
-					
-					if (state.filter_types) {
-						this.filter_types =  pub.filter_types = state.filter_types;
-					}
-					
-					if (state.store_origin_params) {
-						store.originParams = state.store_origin_params;
-						pub.applyParamsToStore(store.originParams, store) && (!reload && (reload=true));
-					}
-					
-					if (state.filter_params) {
-						this.filter_params = pub.filter_params = state.filter_params;
-						
-						pub.applyParamsToStore(this.filter_params, store) && (!reload && (reload=true));
-					}
-					
-					(reload == true) && (store.reload());
-					
-//					log(store.originParams);			
-					return true;
-				}
+				stateId: pub.stateuid
 			});
 		}
 		
@@ -471,15 +423,6 @@ Cronk.grid.MetaGridCreator = function(meta) {
 			this.store_url = url;
 		},
 		
-		applyParamsToStore : function(params, store) {
-			var retval = false;
-			for (var i in params) {
-				store.setBaseParam(i, params[i]);
-				(!retval) && (retval = true);
-			}
-			return retval;
-		},
-		
 		getMetaMapping : function() {
 			return Ext.data.Record.create(this.mapping_array);
 		},





More information about the icinga-checkins mailing list