Refactor the connection loading of traces, to not reload every time.
[potlatch2.git] / net / systemeD / halcyon / connection / XMLConnection.as
index 63ea309344a49aff41dd12c7f503cb4a48898e00..30d3915a32c927d316e1e783cc9c2cd13ee5fc44 100644 (file)
@@ -320,10 +320,14 @@ package net.systemeD.halcyon.connection {
             }
         }
 
-        override public function fetchUserTraces():void {
-            sendOAuthGet(Connection.apiBaseURL+"user/gpx_files",
-                         tracesLoadComplete, errorOnMapLoad, mapLoadStatus); //needs error handlers
-            dispatchEvent(new Event(LOAD_STARTED)); //specific to map or reusable?
+        override public function fetchUserTraces(refresh:Boolean=false):void {
+            if (traces_loaded && !refresh) {
+              dispatchEvent(new Event(TRACES_LOADED));
+            } else {
+              sendOAuthGet(Connection.apiBaseURL+"user/gpx_files",
+                          tracesLoadComplete, errorOnMapLoad, mapLoadStatus); //needs error handlers
+              dispatchEvent(new Event(LOAD_STARTED)); //specific to map or reusable?
+            }
         }
 
         private function tracesLoadComplete(event:Event):void {
@@ -333,6 +337,7 @@ package net.systemeD.halcyon.connection {
               var t:Trace = new Trace().fromXML(traceData);
               addTrace(t);
             }
+            traces_loaded = true;
             dispatchEvent(new Event(LOAD_COMPLETED));
             dispatchEvent(new Event(TRACES_LOADED));
         }