Implement notComplete calls and refactor snapshotconnection a little
authorAndy Allan <andy@gravitystorm.co.uk>
Fri, 17 Jun 2011 13:15:32 +0000 (14:15 +0100)
committerAndy Allan <andy@gravitystorm.co.uk>
Fri, 17 Jun 2011 13:15:32 +0000 (14:15 +0100)
net/systemeD/potlatch2/panels/BackgroundPanel.mxml
net/systemeD/potlatch2/utils/SnapshotConnection.as

index 12bee5c..aaa44df 100644 (file)
@@ -79,7 +79,9 @@
       }
 
       private function markNotComplete():void {
-          // todo
+          if (selectedEntity.connection is SnapshotConnection) {
+              SnapshotConnection(selectedEntity.connection).markNotComplete(selectedEntity);
+          }
       }
       ]]>
   </mx:Script>
index e77ae3b..96322c2 100644 (file)
@@ -11,32 +11,53 @@ package net.systemeD.potlatch2.utils {
             inlineStatus = true;
         }
 
-        /** Send a "complete" call to the server, and remove it from the current layer */
+        // As it stands, the following two functions could be refactored further.
+
+        /** Post a status update call to the server and update entity.status if successful */
         public function markComplete(entity:Entity):void {
             var urlReq:URLRequest;
-            var loader:URLLoader = new URLLoader();
+
+            if (entity is Node) {
+                var node:Node = Node(entity);
+                if (node == getNode(node.id)) { // confirm it's from this connection
+                    makeRequest(entity, 'complete');
+                }
+
+            } else if (entity is Way) {
+                var way:Way = Way(entity);
+                if (way == getWay(way.id)) { // confirm it's from this connection
+                    makeRequest(entity, 'complete');
+                }
+            }
+        }
+
+        /** Send a "complete" call to the server and update entity.status if successful */
+        public function markNotComplete(entity:Entity):void {
+            var urlReq:URLRequest;
+
             if (entity is Node) {
                 var node:Node = Node(entity);
                 if (node == getNode(node.id)) { // confirm it's from this connection
-                    urlReq = new URLRequest(apiBaseURL+"node/"+node.id+"/status");
-                    urlReq.method = "POST";
-                    urlReq.data = 'complete';
-                    loader.addEventListener(Event.COMPLETE, function(e:Event):void { updateStatus(node, 'complete') });
-                    loader.load(urlReq);
+                    makeRequest(entity, 'incomplete');
                 }
 
             } else if (entity is Way) {
                 var way:Way = Way(entity);
                 if (way == getWay(way.id)) { // confirm it's from this connection
-                    urlReq = new URLRequest(apiBaseURL+"way/"+way.id+"/status");
-                    urlReq.method = "POST";
-                    urlReq.data = 'complete';
-                    loader.addEventListener(Event.COMPLETE, function(e:Event):void { updateStatus(way, 'complete') });
-                    loader.load(urlReq);
+                    makeRequest(entity, 'incomplete');
                 }
             }
         }
 
+        private function makeRequest(entity:Entity, status:String):void {
+            var urlReq:URLRequest = new URLRequest(apiBaseURL+entity.getType()+"/"+entity.id+"/status");
+            urlReq.method = "POST";
+            urlReq.data = status;
+            var loader:URLLoader = new URLLoader();
+            loader.addEventListener(Event.COMPLETE, function(e:Event):void { updateStatus(entity, status) });
+            loader.load(urlReq);
+        }
+
         private function updateStatus(e:Entity, s:String):void {
             e.setStatus(s);
         }