[fusion-commits] r1966 - trunk/lib

svn_fusion at osgeo.org svn_fusion at osgeo.org
Sun Nov 8 22:15:36 EST 2009


Author: liuar
Date: 2009-11-08 22:15:36 -0500 (Sun, 08 Nov 2009)
New Revision: 1966

Modified:
   trunk/lib/fusion.js
Log:
Fixed http://trac.osgeo.org/fusion/ticket/300
pre-create a session to avoid the unauthorized dialog, which is a defect of safari and chrome. 

Modified: trunk/lib/fusion.js
===================================================================
--- trunk/lib/fusion.js	2009-11-06 16:05:28 UTC (rev 1965)
+++ trunk/lib/fusion.js	2009-11-09 03:15:36 UTC (rev 1966)
@@ -227,7 +227,8 @@
         initialize : function(options) {
             options = options || {};
             var sessionIdParam = this.getQueryParam('Session');
-            this.sessionId = sessionIdParam || (options.sessionId || null);
+			// Override the pre-created sessionId by user specified sessionId(if exist)
+			this.sessionId = sessionIdParam || options.sessionId || this.sessionId;
         
             if (options.applicationDefinitionURL) {
                 this.applicationDefinitionURL = options.applicationDefinitionURL;            
@@ -252,11 +253,11 @@
             this.sScriptLang = "";
 
             /*
-                     * if the application has been loaded from the same host as
-                     * fusion is installed in, then technically we don't need to
-                     * use the redirect script because we conform to the 
-                     * Same Origin Policy for XmlHttpRequest to work.
-                     */
+			 * if the application has been loaded from the same host as
+			 * fusion is installed in, then technically we don't need to
+			 * use the redirect script because we conform to the 
+			 * Same Origin Policy for XmlHttpRequest to work.
+			 */
             var test = window.location.protocol+'//'+window.location.host;
             var configUrl = 'config.json';
             //if (this.fusionURL.indexOf(test,0) == 0) {
@@ -1147,7 +1148,7 @@
     
         var fusionURL = r + Fusion.getFusionURL() + configUrl; 
     
-        var xhr = new XMLHttpRequest(); 
+        var xhr = getXmlHttpRequest(); 
         xhr.open("GET", fusionURL, false); 
         xhr.send(null); 
     
@@ -1174,7 +1175,7 @@
         } 
         Fusion.configuration.mapguide.mapAgentUrl = s + 'mapagent/mapagent.fcgi'; 
         return Fusion.configuration.mapguide.mapAgentUrl; 
-    } 
+    }
     
     var addElement = function(element) { 
         if (!element) { 
@@ -1188,29 +1189,50 @@
         } 
     
         document.writeln('<script src="' + src + '"><\/script>'); 
-    } 
+    }
 
-	if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("Firefox")>0){
-		var appDefUrl = Fusion.getQueryParam('ApplicationDefinition'); 
-		if(appDefUrl){
-			
-			var xhr = new XMLHttpRequest(); 
-			var mapAgentUrl = getAgentUrl(); 
-			xhr.open("GET", mapAgentUrl + "?OPERATION=GETRESOURCECONTENT&VERSION=1.0.0&LOCALE=en&CLIENTAGENT=MapGuide+Developer&RESOURCEID=" + appDefUrl + "&FORMAT=text%2Fxml", false); 
-			xhr.send(null); 
-			var appDefXML = xhr.responseXML.documentElement; 
-			
-			if(appDefXML){
-				var googleElement = appDefXML.getElementsByTagName("GoogleScript")[0]; 
-				var yahooElement = appDefXML.getElementsByTagName("YahooScript")[0]; 
-				var veElement = appDefXML.getElementsByTagName("VirtualEarthScript")[0]; 
+	var getXmlHttpRequest = function(){	
+        try { return new XMLHttpRequest(); }
+		catch (e) { try { return new ActiveXObject('Msxml2.XMLHTTP'); } 
+		catch (e) { try { return new ActiveXObject('Microsoft.XMLHTTP'); }
+		catch (e) { return  null; }}}
+	}
+	
+	/**
+	 * Function: createSessionId
+	 *
+	 * Pre-create a session to avoid the 401 Unauthorized dialog
+	 *
+	 */
+	var createSessionId = function(){
+		var xhr = getXmlHttpRequest();
+		xhr.open("GET", Fusion.fusionURL+"layers/MapGuide/php/CreateSession.php",false);
+		xhr.send(null); 
+		var o;
+		eval('o='+xhr.responseText);
+		Fusion.sessionId = o.sessionId;
+	}
+	
+	createSessionId();	
+	var appDefUrl = Fusion.getQueryParam('ApplicationDefinition'); 
+	if(appDefUrl){
+		var xhr = new getXmlHttpRequest(); 
+		var mapAgentUrl = getAgentUrl(); 
+		xhr.open("GET", mapAgentUrl + "?OPERATION=GETRESOURCECONTENT&VERSION=1.0.0&LOCALE=en&CLIENTAGENT=MapGuide+Developer&RESOURCEID=" + appDefUrl + "&FORMAT=text%2Fxml&SESSION="+ Fusion.sessionId, false); 
+		xhr.send(null); 
+		var appDefXML = xhr.responseXML.documentElement; 
+		
+		if(appDefXML){
+			var googleElement = appDefXML.getElementsByTagName("GoogleScript")[0]; 
+			var yahooElement = appDefXML.getElementsByTagName("YahooScript")[0]; 
+			var veElement = appDefXML.getElementsByTagName("VirtualEarthScript")[0]; 
 
-				addElement(googleElement); 
-				addElement(yahooElement); 
-				addElement(veElement);
-			}
+			addElement(googleElement); 
+			addElement(yahooElement); 
+			addElement(veElement);
 		}
 	}
+	
     
 })();
 



More information about the fusion-commits mailing list