[fusion-commits] r3037 - sandbox/cms_refactor/lib

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Jul 26 07:24:56 PDT 2018


Author: jng
Date: 2018-07-26 07:24:56 -0700 (Thu, 26 Jul 2018)
New Revision: 3037

Modified:
   sandbox/cms_refactor/lib/fusion.js
Log:
Re-order the init so that we don't try to fetch the appdef if we already had it loaded.

Modified: sandbox/cms_refactor/lib/fusion.js
===================================================================
--- sandbox/cms_refactor/lib/fusion.js	2018-07-26 13:56:43 UTC (rev 3036)
+++ sandbox/cms_refactor/lib/fusion.js	2018-07-26 14:24:56 UTC (rev 3037)
@@ -384,17 +384,90 @@
                 this.sRedirectScript = 'redirect.php';
                 configUrl += '&method=get';
             }
-        
-            if (Fusion.configuration) {
-                //config.json loaded via single file build
-                this.serverSet();
+
+            var onAppDefFetched = OpenLayers.Function.bind(function() {
+                if (Fusion.configuration) {
+                    //config.json loaded via single file build
+                    this.serverSet();
+                } else {
+                    var options = {
+                        onSuccess: OpenLayers.Function.bind(this.getConfigCB, this),
+                        onFailure: OpenLayers.Function.bind(this.serverFailed, this),
+                        method: 'get'
+                    };
+                    this.ajaxRequest(configUrl, options);
+                }
+            }, this);
+
+            var mapAgentUrl = getAgentUrl();
+            var bAlreadyInit = (this.newTemplatePath === true && this.appDefJson != null);
+            var appDefUrl = Fusion.getQueryParam('ApplicationDefinition'); 
+            if (!bAlreadyInit &&
+                appDefUrl && (
+                appDefUrl.indexOf('Library') == 0 ||
+                appDefUrl.indexOf('Session') == 0)) {
+                
+                var fetchAppDef = function(appDefUrl, sessionId) {
+                    var xhr = getXmlHttpRequest();
+                    xhr.open("GET", mapAgentUrl + "?OPERATION=GETRESOURCECONTENT&VERSION=1.0.0&LOCALE=en&CLIENTAGENT=MapGuide+Developer&RESOURCEID=" + appDefUrl + "&FORMAT=text%2Fxml&SESSION="+ sessionId, false); 
+                    try {
+                        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 osmElement = appDefXML.getElementsByTagName("OpenStreetMapScript")[0];
+                            var stamenElement = appDefXML.getElementsByTagName("StamenScript")[0];
+
+                            addElement(googleElement); 
+                            addElement(yahooElement); 
+                            addElement(veElement);
+                            addElement(osmElement);
+                            addElement(stamenElement);
+
+                            var bingMapKeyElement = appDefXML.getElementsByTagName("BingMapKey")[0];
+                            if (bingMapKeyElement) {
+                                var bingMapKey = bingMapKeyElement.textContent;
+                                if (!bingMapKey)
+                                    bingMapKey = bingMapKeyElement.text;
+                                Fusion.bingMapKey = bingMapKey;
+                            }
+                            onAppDefFetched();
+                        }
+                    } catch (e) {
+                        if (xhr.statusText == "MgResourceNotFoundException") {
+                            alert("Failed to fetch Application Definition. The specified resource could not be found");
+                        } //Anything else we can't do anything about as TraceKit is probably not loaded yet
+                    }
+                };
+                
+                var getSiteVersion = function(sessionId) {
+                    var xhr = getXmlHttpRequest(); 
+                    var mapAgentUrl = getAgentUrl(); 
+                    xhr.open("GET", mapAgentUrl + "?OPERATION=GETSITEVERSION&VERSION=1.0.0&LOCALE=en&CLIENTAGENT=MapGuide+Developer&SESSION="+ sessionId, false); 
+                    xhr.send(null); 
+                    var verXML = xhr.responseXML.documentElement; 
+                    var el = verXML.getElementsByTagName("Version")[0];
+                    var version = el.textContent || el.text;
+                    var bits = version.split('.');
+                    return new Array(parseInt(bits[0]),
+                                    parseInt(bits[1]),
+                                    parseInt(bits[2]),
+                                    parseInt(bits[3]));
+                };
+                
+                var passedSessionId = Fusion.getQueryParam('Session'); 
+                if (passedSessionId == null || passedSessionId == "" ){
+                    createSessionId(Fusion.getQueryParam("Username"), Fusion.getQueryParam("Password"));
+                } else {
+                    Fusion.sessionId = passedSessionId;
+                    Fusion.siteVersion = getSiteVersion(passedSessionId);
+                }
+                fetchAppDef(appDefUrl, Fusion.sessionId);
             } else {
-                var options = {
-                    onSuccess: OpenLayers.Function.bind(this.getConfigCB, this),
-                    onFailure: OpenLayers.Function.bind(this.serverFailed, this),
-                    method: 'get'
-                };
-                this.ajaxRequest(configUrl, options);
+                onAppDefFetched();
             }
         },
     
@@ -647,8 +720,8 @@
          * r - {XMLHttpRequest} an XMLHttpRequest object
          */
         getConfigCB: function(r) {
-            if (r.responseText) {  
-                eval("this.configuration="+r.responseText);
+            if (r.responseText) { 
+                this.configuration = Fusion.parseJSON(r.responseText);
                 this.serverSet();
             } else {
                 //console.log('Error parsing configuration file, it is not valid somehow?');
@@ -1602,7 +1675,8 @@
         var xhr = getXmlHttpRequest(); 
         xhr.open("GET", fusionURL, false); 
         xhr.send(null); 
-    
+
+        //Can't use parseJSON as this JSON file will most likely have comments
         eval("Fusion.configuration=" + xhr.responseText); 
         var s = Fusion.configuration.mapguide.webTierUrl; 
         /* if it is set, use it ... otherwise assume fusion is installed in 
@@ -1683,71 +1757,4 @@
         };
         xhr.send(params);
     }
-
-    var appDefUrl = Fusion.getQueryParam('ApplicationDefinition'); 
-    if (appDefUrl && (
-        appDefUrl.indexOf('Library') == 0 ||
-        appDefUrl.indexOf('Session') == 0)) {
-        
-        var fetchAppDef = function(appDefUrl, sessionId) {
-            var xhr = 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="+ sessionId, false); 
-            try {
-                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 osmElement = appDefXML.getElementsByTagName("OpenStreetMapScript")[0];
-                    var stamenElement = appDefXML.getElementsByTagName("StamenScript")[0];
-
-                    addElement(googleElement); 
-                    addElement(yahooElement); 
-                    addElement(veElement);
-                    addElement(osmElement);
-                    addElement(stamenElement);
-
-                    var bingMapKeyElement = appDefXML.getElementsByTagName("BingMapKey")[0];
-                    if (bingMapKeyElement) {
-                        var bingMapKey = bingMapKeyElement.textContent;
-                        if (!bingMapKey)
-                            bingMapKey = bingMapKeyElement.text;
-                        Fusion.bingMapKey = bingMapKey;
-                    }
-                }
-            } catch (e) {
-                if (xhr.statusText == "MgResourceNotFoundException") {
-                    alert("Failed to fetch Application Definition. The specified resource could not be found");
-                } //Anything else we can't do anything about as TraceKit is probably not loaded yet
-            }
-        };
-        
-        var getSiteVersion = function(sessionId) {
-            var xhr = getXmlHttpRequest(); 
-            var mapAgentUrl = getAgentUrl(); 
-            xhr.open("GET", mapAgentUrl + "?OPERATION=GETSITEVERSION&VERSION=1.0.0&LOCALE=en&CLIENTAGENT=MapGuide+Developer&SESSION="+ sessionId, false); 
-            xhr.send(null); 
-            var verXML = xhr.responseXML.documentElement; 
-            var el = verXML.getElementsByTagName("Version")[0];
-            var version = el.textContent || el.text;
-            var bits = version.split('.');
-            return new Array(parseInt(bits[0]),
-                             parseInt(bits[1]),
-                             parseInt(bits[2]),
-                             parseInt(bits[3]));
-        };
-        
-        var passedSessionId = Fusion.getQueryParam('Session'); 
-        if (passedSessionId == null || passedSessionId == "" ){
-            createSessionId(Fusion.getQueryParam("Username"), Fusion.getQueryParam("Password"));
-        } else {
-            Fusion.sessionId = passedSessionId;
-            Fusion.siteVersion = getSiteVersion(passedSessionId);
-        }
-        fetchAppDef(appDefUrl, Fusion.sessionId);
-    }
-    
 })();



More information about the fusion-commits mailing list