Make the bug layer work with remote server - use POST, crossdomain.xml
[potlatch2.git] / net / systemeD / potlatch2 / BugLayer.as
1 package net.systemeD.potlatch2 {
2
3     import net.systemeD.halcyon.VectorLayer;
4     import net.systemeD.halcyon.Map;
5     import net.systemeD.halcyon.connection.Marker;
6     import flash.net.*;
7     import flash.events.*;
8
9     public class BugLayer extends VectorLayer {
10
11         private var baseUrl:String;
12         private var apiKey:String;
13
14         // as strings, since that's how they are in tags and http calls
15         private var BUG_STATUS_OPEN:String = "1";
16         private var BUG_STATUS_FIXED:String = "2";
17         private var BUG_STATUS_INVALID:String = "3"; // or 'non-reproduceable'
18
19         public function BugLayer(n:String, map:Map, s:String, baseUrl:String, apiKey:String) {
20             this.baseUrl = baseUrl;
21             this.apiKey = apiKey;
22             super(n,map,s);
23         }
24
25         public function closeBug(m:Marker):void {
26             var id:String = m.getTag('bug_id');
27             var status:String = BUG_STATUS_FIXED;
28             var comment:String = "NoComment";
29             var nickname:String = "NoName";
30
31             //TODO urlencode stuff
32             var urlReq:URLRequest = new URLRequest(baseUrl+"changeBugStatus?id="+id+"&status="+status+"&comment="+comment+"&nickname="+nickname+"&key="+apiKey);
33             urlReq.method = "POST";
34             urlReq.data = '    '; // dear Adobe, this is nuts, kthxbye (you can't POST with an empty payload)
35             var loader:URLLoader = new URLLoader();
36             loader.load(urlReq);
37             loader.addEventListener(Event.COMPLETE, bugClosed);
38         }
39
40         private function bugClosed(event:Event):void {
41             trace("bug closed");
42             // remove it from the layer, redraw, fix selection etc.
43         }
44     }
45 }