Refactor markComplete to POST to /status, and implement for ways too. Don't kill...
[potlatch2.git] / net / systemeD / potlatch2 / utils / SnapshotConnection.as
1 package net.systemeD.potlatch2.utils {
2
3     import net.systemeD.halcyon.connection.*;
4     import flash.events.Event;
5     import flash.net.*;
6
7     public class SnapshotConnection extends XMLConnection {
8
9         public function SnapshotConnection(cname:String,api:String,policy:String,initparams:Object=null) {
10             super(cname,api,policy,initparams);
11             inlineStatus = true;
12         }
13
14         /** Send a "complete" call to the server, and remove it from the current layer */
15         public function markComplete(entity:Entity):void {
16             var urlReq:URLRequest;
17             var loader:URLLoader = new URLLoader();
18             if (entity is Node) {
19                 var node:Node = Node(entity);
20                 if (node == getNode(node.id)) { // confirm it's from this connection
21                     urlReq = new URLRequest(apiBaseURL+"node/"+node.id+"/status");
22                     urlReq.method = "POST";
23                     urlReq.data = 'complete';
24                     loader.addEventListener(Event.COMPLETE, function(e:Event):void { updateStatus(node, 'complete') });
25                     loader.load(urlReq);
26                 }
27
28             } else if (entity is Way) {
29                 var way:Way = Way(entity);
30                 if (way == getWay(way.id)) { // confirm it's from this connection
31                     urlReq = new URLRequest(apiBaseURL+"way/"+way.id+"/status");
32                     urlReq.method = "POST";
33                     urlReq.data = 'complete';
34                     loader.addEventListener(Event.COMPLETE, function(e:Event):void { updateStatus(way, 'complete') });
35                     loader.load(urlReq);
36                 }
37             }
38         }
39
40         private function updateStatus(e:Entity, s:String):void {
41             e.setStatus(s);
42         }
43
44     }
45 }