Remove licence status display
[potlatch2.git] / net / systemeD / halcyon / connection / StatusFetcher.as
1 package net.systemeD.halcyon.connection {
2
3     import flash.net.*;
4     import flash.events.*;
5     import net.systemeD.halcyon.AttentionEvent;
6
7         public class StatusFetcher {
8
9                 /* Class to fetch the status for newly loaded objects.
10                    Not currently functional.
11                 */
12
13                 public var _url:String;
14                 public var conn:Connection;
15                 
16                 private static var STATUSES:Array=["no","partial","unsure",''];
17                 
18                 public function StatusFetcher(url:String, connection:Connection) {
19                         _url=url;
20                         conn=connection;
21                 }
22
23                 public function fetch(entities:Array):void {
24                         if (entities.length==0) return;
25                         // Create URL request
26             var vars:URLVariables = new URLVariables();
27                         vars.nodes='';
28                         vars.ways='';
29                         vars.relations='';
30                         for each (var entity:Entity in entities) {
31                                 if (entity is Node) vars.nodes+=entity.id+",";
32                                 else if (entity is Way) vars.ways+=entity.id+",";
33                                 else if (entity is Relation) vars.relations+=entity.id+",";
34                         }
35                         if (vars.ways.substr(vars.ways.length-1,1)==',') vars.ways=vars.ways.substr(0,vars.ways.length-1);
36                         if (vars.nodes.substr(vars.nodes.length-1,1)==',') vars.nodes=vars.nodes.substr(0,vars.nodes.length-1);
37                         if (vars.relations.substr(vars.relations.length-1,1)==',') vars.relations=vars.relations.substr(0,vars.relations.length-1);
38             var request:URLRequest = new URLRequest(_url);
39             request.data = vars;
40                         request.method = "POST";
41
42                         // Make request
43                         var loader:URLLoader = new URLLoader();
44                         loader.addEventListener(Event.COMPLETE, loadedFetch);
45                         loader.addEventListener(IOErrorEvent.IO_ERROR, errorOnFetchLoad);
46                         loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, fetchLoadStatus);
47                         loader.load(request);
48                 }
49                 
50                 private function loadedFetch(event:Event):void {
51                         var xml:XML=new XML(URLLoader(event.target).data);
52                         var entity:Entity, status:String;
53
54                         for each (var exml:XML in xml.*) {
55                                 switch (exml.name().localName) {
56                                         case "way":             entity=conn.getWay(exml.@id); break;
57                                         case "relation":entity=conn.getRelation(exml.@id); break;
58                                         case "node":    entity=conn.getNode(exml.@id); break;
59                                 }
60
61                                 // FIXME: needs some code to parse the XML, and set 'status' accordingly
62                                 entity.setStatus(status);
63                         }
64                 }
65
66         private function errorOnFetchLoad(event:Event):void {
67                         conn.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Couldn't load status information"));
68         }
69         private function fetchLoadStatus(event:HTTPStatusEvent):void { }
70
71         }
72 }