more
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / TurnRestrictionEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:RelationMemberEditor
3         xmlns:fx="http://ns.adobe.com/mxml/2009"
4         xmlns:mx="library://ns.adobe.com/flex/mx"
5     xmlns:s="library://ns.adobe.com/flex/spark"
6         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
7         xmlns:flexlib="flexlib.controls.*"
8         verticalGap="0"
9         width="100%"
10         toolTip="{fieldDescription}"
11         initialize="addTurnRestrictions()">
12
13   <s:FormItem label="{fieldName}">
14     <mx:VBox verticalGap="0" width="100%" id="turnRestrictionIcons"/>
15     <mx:LinkButton label="Add new turn restriction" click="addNewTurnRestriction()" />
16   </s:FormItem>
17
18   <fx:Script><![CDATA[
19         import net.systemeD.halcyon.connection.*;
20         import net.systemeD.potlatch2.*;
21         import mx.core.*;
22
23         /* ** FIXME: some of this is common with RouteEditor.mxml. We can probably refactor */
24
25         public function addTurnRestrictions(event:Event=null):void {
26                 turnRestrictionIcons.removeAllChildren();
27                 addEventListener("relations_changed", addTurnRestrictions);
28                 for each(var relation:Object in matchedRelations) {
29                         var icon:TurnRestrictionIcon = new TurnRestrictionIcon();
30                         icon.setTurnRestriction(relation);
31                         turnRestrictionIcons.addChild(icon);
32                 }
33         }
34
35         public function addNewTurnRestriction():void {
36                 var relation:Relation = _entity.connection.createRelation(
37                         { type: 'restriction' }, 
38                         [ new RelationMember(_entity, 'via') ],
39             MainUndoStack.getGlobalStack().addAction);
40                 addTurnRestrictions();
41         }
42         
43   ]]></fx:Script>
44 </edit:RelationMemberEditor>
45