[pve-devel] r5802 - pve-manager/pve2/www/new

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Apr 8 07:25:09 CEST 2011


Author: dietmar
Date: 2011-04-08 07:25:09 +0200 (Fri, 08 Apr 2011)
New Revision: 5802

Modified:
   pve-manager/pve2/www/new/StateProvider.js
   pve-manager/pve2/www/new/index.pl
Log:
bug fixes


Modified: pve-manager/pve2/www/new/StateProvider.js
===================================================================
--- pve-manager/pve2/www/new/StateProvider.js	2011-04-07 13:49:26 UTC (rev 5801)
+++ pve-manager/pve2/www/new/StateProvider.js	2011-04-08 05:25:09 UTC (rev 5802)
@@ -2,10 +2,16 @@
 PVE.StopPageUnload = false;
 PVE.PageUnloadMessFn = function (){
     var mess = "Are you sure you want to navigate away from this page?";
-    return PVE.StopPageUnload ? mess : undefined;
+    if (PVE.StopPageUnload)
+	return mess;
 }
 window.onbeforeunload = PVE.PageUnloadMessFn;
 
+/* This state provider keeps part of the state inside
+ * the browser history, the rest is stored using HTML5
+ * localStorage Feature
+*/
+
 Ext.define('PVE.StateProvider', {
     extend: 'Ext.state.Provider',
 
@@ -23,19 +29,11 @@
 	    'ltab'
 	];
 
-	var urlstate = Ext.urlDecode(Ext.History.getToken());
-
 	Ext.Array.each(list, function(name) {
-	    if (typeof urlstate[name] != "undefined") {
-		var value = { value: urlstate[name] };
-  		window.localStorage.setItem(name, Ext.encode(value));
-	    }
-	    var text = window.localStorage.getItem(name);
-	    var value = Ext.decode(text);
-	    self.UIState[name] = value ? value.value : null;
+	    self.UIState[name] = null;
 	});
 
-	Ext.History.on('change', function(token) {
+	var history_change_cb = function(token) {
 	    //console.log("HC " + token);
 	    if (!token) {
 		PVE.StopPageUnload = true;
@@ -48,35 +46,54 @@
 		if (typeof newstate[name] == "undefined")
 		    return;
 
-		var newvalue = { value: newstate[name] };
+		var oldvalue = { value: self.UIState[name] };
+ 		var newvalue = { value: newstate[name] };
  		var newtext = Ext.encode(newvalue);
-		var oldtext = window.localStorage.getItem(name);
+		var oldtext = Ext.encode(oldvalue);
 		if (newtext != oldtext) {
- 		    window.localStorage.setItem(name, newtext);
-		    self.UIState[name] = newstate[name];
+ 		    self.UIState[name] = newstate[name];
 		    //console.log("changed " + name + " " + newtext);
 		    self.fireEvent("statechange", self, name, newvalue);
 		}
 	    });
-	});
+	};
+
+	var start_token = Ext.History.getToken();
+	if (start_token)
+	    history_change_cb(start_token);
+
+	Ext.History.on('change', history_change_cb);
     },
 
     get: function(name, defaultValue){
 	var self = this;
-	var text = window.localStorage.getItem(name);
-	//console.log("GET " + name + " " + text +  " " + Ext.decode(text));
-        if (typeof text == "undefined")
-	    return defaultValue;
+	var data;
 
-	var value = Ext.decode(text);
+	if (typeof self.UIState[name] != "undefined") {
+	    data = { value: self.UIState[name] };
+	} else {
+	    var text = window.localStorage.getItem(name);
+            if (typeof text == "undefined") {
+		data = defaultValue;
+	    } else {
+		data = Ext.decode(text);
+	    }
+	}
 
-	return value;
+	//console.log("GET " + name + " " + text +  " " + data);
+
+	return data;
     },
 
     clear: function(name){
 	var self = this;
 
-	window.localStorage.removeItem(name); 
+	if (typeof self.UIState[name] != "undefined") {
+	    self.UIState[name] = null;
+	} else {
+	    window.localStorage.removeItem(name); 
+	}
+
         self.fireEvent("statechange", self, name, null);
     },
 

Modified: pve-manager/pve2/www/new/index.pl
===================================================================
--- pve-manager/pve2/www/new/index.pl	2011-04-07 13:49:26 UTC (rev 5801)
+++ pve-manager/pve2/www/new/index.pl	2011-04-08 05:25:09 UTC (rev 5802)
@@ -64,7 +64,6 @@
     'PVE.Workspace']);
 
 Ext.History.fieldid = 'x-history-field';
-Ext.History.iframeId = 'x-history-frame';
 
 Ext.onReady(function() {
     Ext.History.init();
@@ -95,7 +94,6 @@
     <!-- Fields required for history management -->
     <form id="history-form" class="x-hidden">
     <input type="hidden" id="x-history-field"/>
-    <iframe id="x-history-frame"></iframe>
     </form>
   </body>
 </html>




More information about the pve-devel mailing list