update route editors when entity joins a relation
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / RouteEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:RelationMemberEditor
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
5         xmlns:flexlib="flexlib.controls.*"
6         verticalGap="0"
7         width="100%"
8         toolTip="{fieldDescription}"
9         initialize="addRoutes()">
10
11   <mx:Label text="{fieldName}:"/>
12   <mx:VBox verticalGap="0" width="100%" id="routeIcons"/>
13   <mx:LinkButton label="Add to route" click="addToRelation()" />
14
15   <mx:Script><![CDATA[
16     import net.systemeD.halcyon.connection.*;
17     import net.systemeD.potlatch2.*;
18     import mx.managers.PopUpManager;
19     import mx.core.*;
20    
21     public function addRoutes(event:Event=null):void {
22                 routeIcons.removeAllChildren();
23                 addEventListener("routes_changed", addRoutes);
24         for each(var relation:Object in matchedRelations) {
25             var icon:RouteIcon = new RouteIcon();
26             icon.setRoute(relation, RouteEditorFactory(_factory).icon);
27             
28             icon.addEventListener(MouseEvent.CLICK, routeClicked);
29             routeIcons.addChild(icon);
30         }
31     }
32     
33     public function routeClicked(event:Event):void {
34         var relation:Object = RouteIcon(event.currentTarget).route;
35         var panel:RelationEditorPanel = RelationEditorPanel(
36             PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
37         panel.setRelation(relation["relation"]);
38         PopUpManager.centerPopUp(panel);
39     }
40
41         public function addToRelation():void {
42                 new RelationSelectPanel().init(_entity, _factory.relationTags);        
43         }
44
45         override protected function relationsChanged(event:Event):void {
46                 dispatchEvent(new Event("routes_changed"));
47         }
48     
49   ]]></mx:Script>
50 </edit:RelationMemberEditor>
51