[icinga-checkins] icinga.org: icinga-web/master: * Grid filter are persistent now

git at icinga.org git at icinga.org
Fri Jan 29 15:07:28 CET 2010


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

Author: Marius Hein <mhein at sasquatch.local.itsocks.de>
Date:   Wed Jan 27 15:43:31 2010 +0100

* Grid filter are persistent now

---

 .../System/ViewProc/AjaxGridLayoutSuccess.php      |   26 ++++--
 .../System/ViewProc/js/IcingaGridFilterHandler.js  |   92 ++++++++++++++++----
 lib/appkit/js/ext/grid/MetaGridCreator.js          |   42 ++++++---
 3 files changed, 118 insertions(+), 42 deletions(-)

diff --git a/app/modules/Cronks/templates/System/ViewProc/AjaxGridLayoutSuccess.php b/app/modules/Cronks/templates/System/ViewProc/AjaxGridLayoutSuccess.php
index a88b7ab..3234c54 100644
--- a/app/modules/Cronks/templates/System/ViewProc/AjaxGridLayoutSuccess.php
+++ b/app/modules/Cronks/templates/System/ViewProc/AjaxGridLayoutSuccess.php
@@ -13,7 +13,7 @@
 		
 		MetaGrid.setStoreUrl("<?php echo $ro->gen('icinga.cronks.viewProc.json', array('template' => $rd->getParameter('template'))); ?>");
 		MetaGrid.setParameters(<?php echo json_encode($rd->getParameters()); ?>);
-		
+		MetaGrid.setParameters({storeDisableAutoload: true});
 		var grid = MetaGrid.createGrid();
 		
 		// Magick includes (Grid filters)
@@ -34,17 +34,19 @@
 				});
 			
 				if (bFilters == true) {
-				
-					IcingaGridFilterWindow.setGrid(grid);
-					IcingaGridFilterWindow.setFilterCfg( MetaGrid.getFilterCfg() );
+					
+					var fw = new IcingaGridFilterWindow();
+					
+					fw.setGrid(grid);
+					fw.setFilterCfg( MetaGrid.getFilterCfg() );
 				
 					// Distribute destroy events
 					grid.on('destroy', function() {
-						IcingaGridFilterWindow.destroyHandler();
+						fw.destroyHandler();
 					});
 					
 					grid.on('refresh', function() {
-						IcingaGridFilterWindow.destroyHandler();	
+						fw.destroyHandler();	
 					});
 					
 				
@@ -56,13 +58,13 @@
 								items: [{ 
 									text: '<?php echo $tm->_("Modify"); ?>', 
 									iconCls: 'silk-application-form',
-									handler: IcingaGridFilterWindow.startHandler,
+									handler: fw.startHandler,
 									scope: this
 								},{ 
 									text: '<?php echo $tm->_("Remove"); ?>', 
 									iconCls: 'silk-cancel',
 									handler: function(b, e) {
-										IcingaGridFilterWindow.removeFilters();
+										fw.removeFilters();
 									},
 									scope: this
 								}]
@@ -121,6 +123,14 @@
 		//Insert the grid in the parent
 		var cmp = Ext.getCmp("<?php echo $parentid; ?>");
 		
+		// Check if the store is loaded by whatever ...
+		// If no load with defautl params!
+		grid.on('render', function(g) {
+			if (this.storeIsLoaded() == false) {
+				this.initStore();
+			}
+		}, MetaGrid);
+		
 		// Add to parent component
 		cmp.insert(0, grid);
 		
diff --git a/app/modules/Cronks/templates/System/ViewProc/js/IcingaGridFilterHandler.js b/app/modules/Cronks/templates/System/ViewProc/js/IcingaGridFilterHandler.js
index d7ec81d..79f5b14 100644
--- a/app/modules/Cronks/templates/System/ViewProc/js/IcingaGridFilterHandler.js
+++ b/app/modules/Cronks/templates/System/ViewProc/js/IcingaGridFilterHandler.js
@@ -36,12 +36,18 @@ var IcingaGridFilterWindow = function() {
 					'fLabel' : item[2]
 				});
 				
+				if (oGrid.filter_types) {
+					delete oGrid.filter_types[ item[1] ];
+				}
+				
 				oCombo.getStore().add([ r ]);
 			}
 		});
 		
 		oWindow().doLayout();
 		
+		oGrid.fireEvent('activate');
+		
 		return true;
 	});
 	
@@ -64,6 +70,38 @@ var IcingaGridFilterWindow = function() {
 					
 					remove: function(oc, oremove) {
 						oc.doLayout();
+					},
+					
+					render: function(oc) {
+						if (oGrid.filter_types) {
+							var i = 0;
+							Ext.iterate(oGrid.filter_types, function(key, item) {
+								var r = new Ext.data.Record(item);
+								selectRestrictionHandler(oCombo, r, i);
+								i++;
+							})
+						}
+						
+						if (oGrid.filter_params) {
+							Ext.iterate(oGrid.filter_params, function (key, val) {
+								key = key.replace(/^f\[|\]$/g, "");
+								var c = oCoPanel.findBy(function(ti) {
+									if (ti.hiddenName == key || ti.name == key) {
+										return true;
+									}
+									
+									return false; 
+								});
+								
+								if (c[0]) {
+									c[0].setValue(val);
+								}
+							});
+						}
+					},
+					hide: function(oc) {
+						oGrid.filter_params = getFormValues(false);
+						oGrid.fireEvent('activate');
 					}
 				},
 				
@@ -72,7 +110,7 @@ var IcingaGridFilterWindow = function() {
 						text: '<?php echo $tm->_("Apply"); ?>',
 						iconCls: 'silk-accept',
 						handler: function(b, e) {
-							IcingaGridFilterWindow.applyFilters();
+							pub.applyFilters();
 						}
 					},{
 						text: '<?php echo $tm->_("Discard"); ?>',
@@ -84,7 +122,7 @@ var IcingaGridFilterWindow = function() {
 						text: '<?php echo $tm->_("Reset"); ?>',
 						iconCls: 'silk-delete',
 						handler: function(b, y) {
-							IcingaGridFilterWindow.resetFilterForm();
+							pub.resetFilterForm();
 						}
 					}]
 				}
@@ -140,18 +178,7 @@ var IcingaGridFilterWindow = function() {
 				displayField: 'fLabel',
 				
 				listeners: {
-					select: function(oCombo, record, index) {
-						var type = record.data['fType'];
-						
-						// Reset the combo
-						oCombo.setValue('');
-						
-						// Add a new field construct
-						addResctriction(type);
-						
-						// Remove the selected item from the store
-						oCombo.getStore().removeAt(index);
-					}
+					select: selectRestrictionHandler
 				}
 			});
 		
@@ -165,6 +192,23 @@ var IcingaGridFilterWindow = function() {
 		
 	}
 	
+	function selectRestrictionHandler(oCombo, record, index) {
+		var type = record.data['fType'];
+		
+		// Reset the combo
+		oCombo.setValue('');
+		
+		// Add a new field construct
+		addResctriction(type);
+		
+		// Remove the selected item from the store
+		oCombo.getStore().removeAt(index);
+		
+		var tmp = oGrid.filter_types || {};
+		tmp[ record.data['fType'] ] = record.data;
+		oGrid.filter_tyes = tmp;
+	}
+	
 	function addResctriction(type) {
 		
 		if (oFilter[type]) {
@@ -179,7 +223,7 @@ var IcingaGridFilterWindow = function() {
 			
 	}
 	
-	function getFormValues() {
+	function getFormValues(raw) {
 		var data = oCoPanel.getForm().getValues();
 		
 		var o = {};
@@ -223,6 +267,15 @@ var IcingaGridFilterWindow = function() {
 		setGrid : function(g) {
 			oGrid = g;
 			oOrgBaseParams = oGrid.getStore().baseParams;
+			
+			oGrid.on('activate', function() {
+				oGrid.filter_params = getFormValues(false);
+				return true;
+			});
+			
+			if (oGrid.filter_params) {
+				this.applyFilters(oGrid.filter_params);
+			}
 		},
 		
 		setMeta : function(meta) {
@@ -250,8 +303,8 @@ var IcingaGridFilterWindow = function() {
 		 * If a restriction was made, this method applies the restrictins
 		 * to the store
 		 */
-		applyFilters : function() {
-			var data = getFormValues();
+		applyFilters : function(owd) {
+			var data = owd || getFormValues();
 
 			oGrid.getStore().baseParams = {};
 			Ext.apply(oGrid.getStore().baseParams, oOrgBaseParams);
@@ -261,7 +314,6 @@ var IcingaGridFilterWindow = function() {
 //			console.log(oGrid.getStore().baseParams);
 			
 			oGrid.getStore().reload();
-			oGrid.fireEvent('activate');
 			
 			oWindow().hide();
 		},
@@ -273,14 +325,16 @@ var IcingaGridFilterWindow = function() {
 		removeFilters : function() {
 			oGrid.getStore().baseParams = oOrgBaseParams;
 			oGrid.getStore().reload();
+			oGrid.fireEvent('activate');
 		},
 		
 		resetFilterForm : function() {
 			oFilterHandler.removeAllComponents();
+			oGrid.fireEvent('activate');
 		}
 		
 	};
 
 	return pub;
 	
-}();
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/lib/appkit/js/ext/grid/MetaGridCreator.js b/lib/appkit/js/ext/grid/MetaGridCreator.js
index 90f99ac..773144f 100644
--- a/lib/appkit/js/ext/grid/MetaGridCreator.js
+++ b/lib/appkit/js/ext/grid/MetaGridCreator.js
@@ -32,6 +32,9 @@ AppKit.Ext.grid.MetaGridCreator = function(meta) {
 	// Stateuid
 	this.stateuid = undefined;
 	
+	// Store is loaded
+	this.storeloaded = false;
+	
 	this.constructor.call(this, meta);
 };
 
@@ -142,25 +145,21 @@ AppKit.Ext.grid.MetaGridCreator.prototype = {
 				
 				getState: function() {
 					
-//					console.log('GET STATE');
-//					console.log(this.getStore().baseParams);
-					
-					return {
-						params: this.getStore().baseParams
+					var o = {
+						filter_params: this.filter_params || {},
+						filter_types: this.filter_types || {}
 					};
+					
+					return o;
 				},
 				
 				applyState: function(state) {
+					if (state.filter_params) {
+						this.filter_params = state.filter_params;
+					}
 					
-					if (state.params) {
-						this.getStore().baseParams = {};
-						Ext.apply(this.getStore().baseParams, state.params);
-						
-						this.getStore().on('load', function() {
-							this.reload();
-						}, null, { single: true } );
-						
-						return true;
+					if (state.filter_types) {
+						this.filter_types = state.filter_types;
 					}
 					
 					return true;
@@ -308,6 +307,11 @@ AppKit.Ext.grid.MetaGridCreator.prototype = {
 			}
 		}
 		
+		this.meta_store.on('beforeload', function() {
+			this.storeloaded = true;
+			return true;
+		}, this, { single: true });
+		
 		return this.meta_store;
 	},
 	
@@ -378,6 +382,14 @@ AppKit.Ext.grid.MetaGridCreator.prototype = {
 	},
 	
 	setParameters : function(p) {
-		this.params = p;
+		Ext.apply(this.params, p);
+	},
+	
+	storeIsLoaded : function() {
+		return this.storeloaded
+	},
+	
+	initStore : function() {
+		this.getMetaStore().load();
 	}
 };





More information about the icinga-checkins mailing list