Merge branch 'refactor'
[potlatch2.git] / net / systemeD / halcyon / connection / XMLConnection.as
index 7fe45ec751d2346cc6cc62acbefdb58859e08f2d..3a4c5ef3bfaedb745ebfa39d1dd1d5f672b1db03 100644 (file)
@@ -16,14 +16,13 @@ package net.systemeD.halcyon.connection {
     */
        public class XMLConnection extends XMLBaseConnection {
 
     */
        public class XMLConnection extends XMLBaseConnection {
 
-               public function XMLConnection() {
+               public function XMLConnection(name:String,api:String,policy:String,initparams:Object) {
 
 
-                       if (Connection.policyURL!='')
-                Security.loadPolicyFile(Connection.policyURL);
-            var oauthPolicy:String = Connection.getParam("oauth_policy", "");
-            if ( oauthPolicy != "" ) {
-                Security.loadPolicyFile(oauthPolicy);
-            }
+                       super(name,api,policy,initparams);
+                       if (policyURL != "") Security.loadPolicyFile(policyURL);
+
+            var oauthPolicy:String = getParam("oauth_policy", "");
+            if (oauthPolicy != "") Security.loadPolicyFile(oauthPolicy);
                }
                
                override public function loadBbox(left:Number,right:Number,
                }
                
                override public function loadBbox(left:Number,right:Number,
@@ -40,14 +39,14 @@ package net.systemeD.halcyon.connection {
             var mapVars:URLVariables = new URLVariables();
             mapVars.bbox= left+","+bottom+","+right+","+top;
 
             var mapVars:URLVariables = new URLVariables();
             mapVars.bbox= left+","+bottom+","+right+","+top;
 
-            var mapRequest:URLRequest = new URLRequest(Connection.apiBaseURL+"map");
+            var mapRequest:URLRequest = new URLRequest(apiBaseURL+"map");
             mapRequest.data = mapVars;
 
             sendLoadRequest(mapRequest);
                }
 
                override public function loadEntityByID(type:String, id:Number):void {
             mapRequest.data = mapVars;
 
             sendLoadRequest(mapRequest);
                }
 
                override public function loadEntityByID(type:String, id:Number):void {
-                       var url:String=Connection.apiBaseURL + type + "/" + id;
+                       var url:String=apiBaseURL + type + "/" + id;
                        if (type=='way') url+="/full";
                        sendLoadRequest(new URLRequest(url));
                }
                        if (type=='way') url+="/full";
                        sendLoadRequest(new URLRequest(url));
                }
@@ -132,7 +131,7 @@ package net.systemeD.halcyon.connection {
               changesetXML.changeset.appendChild(tagXML);
             }        
 
               changesetXML.changeset.appendChild(tagXML);
             }        
 
-                       sendOAuthPut(Connection.apiBaseURL+"changeset/create",
+                       sendOAuthPut(apiBaseURL+"changeset/create",
                                                 changesetXML,
                                                 changesetCreateComplete, changesetCreateError, recordStatus);
            }
                                                 changesetXML,
                                                 changesetCreateComplete, changesetCreateError, recordStatus);
            }
@@ -142,7 +141,7 @@ package net.systemeD.halcyon.connection {
             var id:Number = Number(URLLoader(event.target).data);
             
             // which means we now have a new changeset!
             var id:Number = Number(URLLoader(event.target).data);
             
             // which means we now have a new changeset!
-            setActiveChangeset(new Changeset(id, lastUploadedChangesetTags));
+            setActiveChangeset(new Changeset(this, id, lastUploadedChangesetTags));
         }
 
         private function changesetCreateError(event:IOErrorEvent):void {
         }
 
         private function changesetCreateError(event:IOErrorEvent):void {
@@ -153,7 +152,7 @@ package net.systemeD.halcyon.connection {
             var cs:Changeset = getActiveChangeset();
                        if (!cs) return;
                        
             var cs:Changeset = getActiveChangeset();
                        if (!cs) return;
                        
-                       sendOAuthPut(Connection.apiBaseURL+"changeset/"+cs.id+"/close",
+                       sendOAuthPut(apiBaseURL+"changeset/"+cs.id+"/close",
                                                 null,
                                                 changesetCloseComplete, changesetCloseError, recordStatus);
                        closeActiveChangeset();
                                                 null,
                                                 changesetCloseComplete, changesetCloseError, recordStatus);
                        closeActiveChangeset();
@@ -199,7 +198,10 @@ package net.systemeD.halcyon.connection {
             loader.load(urlReq);
         }
 
             loader.load(urlReq);
         }
 
-        override public function uploadChanges():void {
+               /** Create XML changeset and send it to the server. Returns the XML string for use in the 'Show data' button.
+                   (We don't mind what's returned as long as it implements .toString() ) */
+
+        override public function uploadChanges():* {
             var changeset:Changeset = getActiveChangeset();
             var upload:XML = <osmChange version="0.6"/>
             upload.appendChild(addCreated(changeset, getAllNodeIDs, getNode, serialiseNode));
             var changeset:Changeset = getActiveChangeset();
             var upload:XML = <osmChange version="0.6"/>
             upload.appendChild(addCreated(changeset, getAllNodeIDs, getNode, serialiseNode));
@@ -217,7 +219,7 @@ package net.systemeD.halcyon.connection {
 
             // now actually upload them
             // make an OAuth query
 
             // now actually upload them
             // make an OAuth query
-            var url:String = Connection.apiBaseURL+"changeset/" + changeset.id + "/upload";
+            var url:String = apiBaseURL+"changeset/" + changeset.id + "/upload";
 
             // build the actual request
                        var serv:HTTPService=new HTTPService();
 
             // build the actual request
                        var serv:HTTPService=new HTTPService();
@@ -232,7 +234,8 @@ package net.systemeD.halcyon.connection {
                        serv.addEventListener(FaultEvent.FAULT, diffUploadIOError);
                        serv.send(upload);
                
                        serv.addEventListener(FaultEvent.FAULT, diffUploadIOError);
                        serv.send(upload);
                
-               dispatchEvent(new Event(SAVE_STARTED));
+                       dispatchEvent(new Event(SAVE_STARTED));
+                       return upload;
         }
 
         private function diffUploadComplete(event:ResultEvent):void {
         }
 
         private function diffUploadComplete(event:ResultEvent):void {
@@ -431,8 +434,7 @@ package net.systemeD.halcyon.connection {
             if (traces_loaded && !refresh) {
               dispatchEvent(new Event(TRACES_LOADED));
             } else {
             if (traces_loaded && !refresh) {
               dispatchEvent(new Event(TRACES_LOADED));
             } else {
-              sendOAuthGet(Connection.apiBaseURL+"user/gpx_files",
-                          tracesLoadComplete, errorOnMapLoad, mapLoadStatus); //needs error handlers
+              sendOAuthGet(apiBaseURL+"user/gpx_files", tracesLoadComplete, errorOnMapLoad, mapLoadStatus); //needs error handlers
               dispatchEvent(new Event(LOAD_STARTED)); //specific to map or reusable?
             }
         }
               dispatchEvent(new Event(LOAD_STARTED)); //specific to map or reusable?
             }
         }
@@ -441,7 +443,7 @@ package net.systemeD.halcyon.connection {
             clearTraces();
             var files:XML = new XML(URLLoader(event.target).data);
             for each(var traceData:XML in files.gpx_file) {
             clearTraces();
             var files:XML = new XML(URLLoader(event.target).data);
             for each(var traceData:XML in files.gpx_file) {
-              var t:Trace = new Trace().fromXML(traceData);
+              var t:Trace = new Trace(this).fromXML(traceData);
               addTrace(t);
             }
             traces_loaded = true;
               addTrace(t);
             }
             traces_loaded = true;
@@ -450,7 +452,7 @@ package net.systemeD.halcyon.connection {
         }
 
         override public function fetchTrace(id:Number, callback:Function):void {
         }
 
         override public function fetchTrace(id:Number, callback:Function):void {
-            sendOAuthGet(Connection.apiBaseURL+"gpx/"+id+"/data.xml", 
+            sendOAuthGet(apiBaseURL+"gpx/"+id+"/data.xml", 
                                function(e:Event):void { 
                        dispatchEvent(new Event(LOAD_COMPLETED));
                                        callback(e);
                                function(e:Event):void { 
                        dispatchEvent(new Event(LOAD_COMPLETED));
                                        callback(e);