press S to save, C to close changeset
authorRichard Fairhurst <richard@systemed.net>
Thu, 2 Sep 2010 20:54:28 +0000 (20:54 +0000)
committerRichard Fairhurst <richard@systemed.net>
Thu, 2 Sep 2010 20:54:28 +0000 (20:54 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/controller/ControllerState.as

index c1e87aa..072dcb5 100755 (executable)
@@ -156,16 +156,6 @@ package net.systemeD.halcyon.connection {
             }
         }
 
-        protected function setActiveChangeset(changeset:Changeset):void {
-            this.changeset = changeset;
-                       changesetUpdated = new Date().getTime();
-            sendEvent(new EntityEvent(NEW_CHANGESET, changeset),false);
-        }
-
-               protected function freshenActiveChangeset():void {
-                       changesetUpdated = new Date().getTime();
-               }
-        
         public function getNode(id:Number):Node {
             return nodes[id];
         }
@@ -302,14 +292,6 @@ package net.systemeD.halcyon.connection {
                        return o;
                }
 
-        public function getActiveChangeset():Changeset {
-                       // ** FIXME - should be able to manually close changesets
-                       if (changeset && (new Date().getTime()) > (changesetUpdated+58*60*1000)) {
-                               changeset=null;
-                       }
-            return changeset;
-        }
-        
                public function purgeOutside(left:Number, right:Number, top:Number, bottom:Number):void {
                        return;
                        // ** this doesn't work - WayUIs stick around.
@@ -333,6 +315,30 @@ package net.systemeD.halcyon.connection {
                        return modified;
                }
 
+               // Changeset tracking
+
+        protected function setActiveChangeset(changeset:Changeset):void {
+            this.changeset = changeset;
+                       changesetUpdated = new Date().getTime();
+            sendEvent(new EntityEvent(NEW_CHANGESET, changeset),false);
+        }
+
+               protected function freshenActiveChangeset():void {
+                       changesetUpdated = new Date().getTime();
+               }
+               
+               protected function closeActiveChangeset():void {
+                       changeset = null;
+               }
+        
+        public function getActiveChangeset():Changeset {
+                       if (changeset && (new Date().getTime()) > (changesetUpdated+58*60*1000)) {
+                               closeActiveChangeset();
+                       }
+            return changeset;
+        }
+        
+
         // these are functions that the Connection implementation is expected to
         // provide. This class has some generic helpers for the implementation.
                public function loadBbox(left:Number, right:Number,
@@ -342,6 +348,7 @@ package net.systemeD.halcyon.connection {
            public function setAppID(id:Object):void {}
            public function setAuthToken(id:Object):void {}
            public function createChangeset(tags:Object):void {}
+               public function closeChangeset():void {}
            public function uploadChanges():void {}
     }
 
index 3ffb664..24ad774 100644 (file)
@@ -76,24 +76,9 @@ package net.systemeD.halcyon.connection {
               changesetXML.changeset.appendChild(tagXML);
             }        
 
-            // make an OAuth query
-            var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
-            var url:String = Connection.apiBaseURL+"changeset/create";
-            //var params:Object = { _method: "PUT" };
-            var oauthRequest:OAuthRequest = new OAuthRequest("PUT", url, null, appID, authToken);
-            var urlStr:Object = oauthRequest.buildRequest(sig, OAuthRequest.RESULT_TYPE_URL_STRING)
-
-            // build the actual request
-            var urlReq:URLRequest = new URLRequest(String(urlStr));
-            urlReq.method = "POST";
-            urlReq.data = changesetXML.toXMLString();
-            urlReq.contentType = "application/xml";
-            urlReq.requestHeaders = new Array(new URLRequestHeader("X_HTTP_METHOD_OVERRIDE", "PUT"));
-            var loader:URLLoader = new URLLoader();
-            loader.addEventListener(Event.COMPLETE, changesetCreateComplete);
-            loader.addEventListener(IOErrorEvent.IO_ERROR, changesetCreateError);
-            loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, recordStatus);
-               loader.load(urlReq);
+                       sendOAuthPut(Connection.apiBaseURL+"changeset/create",
+                                                changesetXML,
+                                                changesetCreateComplete, changesetCreateError, recordStatus);
            }
 
         private function changesetCreateComplete(event:Event):void {
@@ -107,6 +92,39 @@ package net.systemeD.halcyon.connection {
         private function changesetCreateError(event:IOErrorEvent):void {
             dispatchEvent(new Event(NEW_CHANGESET_ERROR));
         }
+
+               override public function closeChangeset():void {
+            var cs:Changeset = getActiveChangeset();
+                       if (!cs) return;
+                       
+                       sendOAuthPut(Connection.apiBaseURL+"changeset/"+cs.id+"/close",
+                                                null,
+                                                changesetCloseComplete, changesetCloseError, recordStatus);
+                       closeActiveChangeset();
+               }
+               
+               private function changesetCloseComplete(event:Event):void { }
+               private function changesetCloseError(event:Event):void { }
+               // ** TODO: when we get little floating warnings, we can send a happy or sad one up
+
+               private function sendOAuthPut(url:String, xml:XML, onComplete:Function, onError:Function, onStatus:Function):void {
+            // make an OAuth query
+            var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
+            var oauthRequest:OAuthRequest = new OAuthRequest("PUT", url, null, appID, authToken);
+            var urlStr:Object = oauthRequest.buildRequest(sig, OAuthRequest.RESULT_TYPE_URL_STRING)
+
+            // build the actual request
+            var urlReq:URLRequest = new URLRequest(String(urlStr));
+            urlReq.method = "POST";
+                       if (xml) { urlReq.data = xml.toXMLString(); } else { urlReq.data = true; }
+            urlReq.contentType = "application/xml";
+            urlReq.requestHeaders = new Array(new URLRequestHeader("X_HTTP_METHOD_OVERRIDE", "PUT"));
+            var loader:URLLoader = new URLLoader();
+            loader.addEventListener(Event.COMPLETE, onComplete);
+            loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
+            loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onStatus);
+               loader.load(urlReq);
+               }
         
         override public function uploadChanges():void {
             var changeset:Changeset = getActiveChangeset();
index f37f434..42ee032 100644 (file)
@@ -6,6 +6,7 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.EditController;
        import net.systemeD.halcyon.Globals;
+       import net.systemeD.potlatch2.save.SaveManager;
 
     public class ControllerState {
 
@@ -51,7 +52,9 @@ package net.systemeD.potlatch2.controller {
                
                protected function sharedKeyboardEvents(event:KeyboardEvent):ControllerState {
                        switch (event.keyCode) {
+                               case 67:        controller.connection.closeChangeset(); break;                                                  // C - close changeset
                                case 68:        controller.map.paint.alpha=1.3-controller.map.paint.alpha; return null; // D - dim
+                               case 83:        SaveManager.saveChanges(); break;                                                                               // S - save
                                case 84:        controller.tagViewer.togglePanel(); return null;                                                // T - toggle tags panel
                                case 87:        if (selectedWay) { return new SelectedWay(selectedWay); }; return null; // W - select way
                                case 90:        MainUndoStack.getGlobalStack().undo(); return null;                                             // Z - undo