[icinga-checkins] icinga.org: icinga-web/cdoebler/default: * Ext stateful components ready ( ref #184)

git at icinga.org git at icinga.org
Tue Jan 19 16:09:43 CET 2010


Module: icinga-web
Branch: cdoebler/default
Commit: 6be488d5967b8da1e7844fe0420581fd5a1f5aac
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=6be488d5967b8da1e7844fe0420581fd5a1f5aac

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Jan 18 16:28:38 2010 +0100

* Ext stateful components ready (ref #184)
* StateProvider encoding handling through json
* Tabpanel is persistent now
* Cookie write filter merges the data now

---

 .../Cronks/templates/System/CronkPortalSuccess.php |   49 ++++++++++++++++----
 .../AppKitExtApplicationStateFilter.class.php      |   23 ++++++++--
 lib/appkit/js/ext/CronkMgr.js                      |    8 +++
 lib/appkit/js/ext/SessionProvider.js               |   22 ++++++++-
 4 files changed, 87 insertions(+), 15 deletions(-)

diff --git a/app/modules/Cronks/templates/System/CronkPortalSuccess.php b/app/modules/Cronks/templates/System/CronkPortalSuccess.php
index a1ac4b9..eeddbd9 100644
--- a/app/modules/Cronks/templates/System/CronkPortalSuccess.php
+++ b/app/modules/Cronks/templates/System/CronkPortalSuccess.php
@@ -112,21 +112,47 @@ var tabPanel = new Ext.TabPanel({
 	resizeTabs : false,
 	
 	// This component is stateful!
-	/* stateId: 'cronk-tab-panel',
 	stateful: true,
+	stateId: 'cronk-tab-panel',
+	
+	stateEvents: ['add', 'remove', 'tabchange'],
 	
-	stateEvents: ['tabchange'],
 	getState: function() {
-		return {
-			tab: function() {
-				return this.getActiveTab().id;
+		
+		var cout = { };
+		
+		this.items.each(function(item, index, l) {
+			if (item.iscronk && AppKit.Ext.CronkMgr.cronkExist(item.cronkkey)) {
+				var c = AppKit.Ext.CronkMgr.getCronk(item.cronkkey);
+				delete c['cronk'];
+				cout[c.cmpid] = c;
 			}
+		});
+		
+		return {
+			cronks: cout,
+			items: this.items.getCount(),
+			active: this.getActiveTab().id
 		}
 	},
 	
 	applyState: function(state) {
-		Ext.Msg.alert('ok', 'state');
-	}, */
+		if (state.cronks) {
+			Ext.iterate(state.cronks, function(index, item, o) {
+				var config = {};
+				Ext.apply(config, item.config, item.crconf);
+				
+				var cronk = AppKit.Ext.CronkMgr.create(config);
+				
+				this.add(cronk);
+				
+			}, this);
+			
+			this.doLayout();
+			
+			this.setActiveTab(state.active);
+		}
+	},
 	
 	// Here comes the drop zone
 	listeners: {
@@ -135,6 +161,7 @@ var tabPanel = new Ext.TabPanel({
 	}
 });
 
+
 var cronk_list_id = AppKit.Ext.genRandomId('cronk');
 var cronk_search_id = AppKit.Ext.genRandomId('cronk');
 var cronk_status_summary_id = AppKit.Ext.genRandomId('cronk');
@@ -237,10 +264,14 @@ container.render("<?php echo $parentid; ?>");
 
 
 // Adding the first cronk (say hello here)
-if (tabPanel) {
+if (tabPanel && tabPanel.items.getCount() <= 0) {
 	var cHello = AppKit.Ext.CronkMgr.create({
 		title: '<?php echo $tm->_("Welcome"); ?>',
-		crname: 'portalHello'
+		crname: 'portalHello',
+		parentid: undefined,
+		layout: 'fit',
+		loaderUrl: "<?php echo $ro->gen('icinga.cronks.crloader', array('cronk' => null)); ?>",
+		closable: false
 	});
 	
 	tabPanel.add(cHello);
diff --git a/lib/appkit/filters/AppKitExtApplicationStateFilter.class.php b/lib/appkit/filters/AppKitExtApplicationStateFilter.class.php
index a36ff59..191039e 100644
--- a/lib/appkit/filters/AppKitExtApplicationStateFilter.class.php
+++ b/lib/appkit/filters/AppKitExtApplicationStateFilter.class.php
@@ -27,8 +27,7 @@ class AppKitExtApplicationStateFilter extends AgaviFilter implements AgaviIActio
 			// Iterate through the cookies and find extjs cookies
 			foreach ($cookies as $name=>$val) {
 				if(strpos($name, self::EXT_COOKIE_PATTERN) === 0) {
-					$data[ substr($name, 3) ] = $val;
-					
+					$data[ substr($name, 3) ] = ($val);
 					/*
 					 * @todo check why this is not working
 					 */
@@ -40,10 +39,26 @@ class AppKitExtApplicationStateFilter extends AgaviFilter implements AgaviIActio
 				
 			}
 			
+			
+			
 			// Yes, we have data, serialize and push to db
 			if (count($data)) {
-				$data = base64_encode(serialize($data));
-				$this->getContext()->getUser()->setPref(self::DATA_NAMESPACE, $data, true, true);
+				
+				/*
+				 * We need the old data so we didn't loose the existing state
+				 */
+				$save = $this->getContext()->getUser()->getPrefVal(self::DATA_NAMESPACE, null, true);
+				if ($save) {
+					$save = unserialize( base64_decode( $save ) );
+				}
+				else {
+					$save = array ();
+				}
+				
+				$save = array_merge($save, $data);
+				
+				$save = base64_encode(serialize($save));
+				$this->getContext()->getUser()->setPref(self::DATA_NAMESPACE, $save, true, true);
 			}
 		}
 
diff --git a/lib/appkit/js/ext/CronkMgr.js b/lib/appkit/js/ext/CronkMgr.js
index ca45394..6a3b60b 100644
--- a/lib/appkit/js/ext/CronkMgr.js
+++ b/lib/appkit/js/ext/CronkMgr.js
@@ -65,6 +65,14 @@ AppKit.Ext.CronkMgr = function() {
 			return cronks;
 		},
 		
+		getCronk : function(id) {
+			return cronks.get(id);
+		},
+		
+		cronkExist : function(id) {
+			return cronks.containsKey(id);
+		},
+		
 		create : function(config) {
 			
 			var d = {};
diff --git a/lib/appkit/js/ext/SessionProvider.js b/lib/appkit/js/ext/SessionProvider.js
index f27b24e..575cf52 100644
--- a/lib/appkit/js/ext/SessionProvider.js
+++ b/lib/appkit/js/ext/SessionProvider.js
@@ -5,16 +5,34 @@
  * http://www.extjs.com/license
  */
 Ext.state.SessionProvider = Ext.extend(Ext.state.CookieProvider, {
-    readCookies : function(){
+    readCookies : function() {
         if(this.state){
         	
+//        	console.log("--- READ STATE START ---");
+        	
+//        	console.log(this.state);
+        	
             for(var k in this.state){
                 if(typeof this.state[k] == 'string'){
+//                	console.log(this.state[k])
                     this.state[k] = this.decodeValue(this.state[k]);
                 }
             }
+            
+//            console.log("--- READ STATE STOP ---");
+            
         }
         
+        
         return Ext.apply(this.state || {}, Ext.state.SessionProvider.superclass.readCookies.call(this));
-    }
+    },
+
+	encodeValue : function(v) {
+		return Ext.util.JSON.encode(v);
+	},
+	
+	decodeValue : function(v) {
+		return Ext.util.JSON.decode(v);
+	}
+
 });
\ No newline at end of file





More information about the icinga-checkins mailing list