Merge branch 'master' into snapshotserver
[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:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
6         xmlns:flexlib="flexlib.controls.*"
7         verticalGap="0"
8         width="100%"
9         toolTip="{fieldDescription}"
10         initialize="addTurnRestrictions()">
11
12   <mx:Label text="{fieldName}:"/>
13   <mx:VBox verticalGap="0" width="100%" id="turnRestrictionIcons"/>
14   <mx:LinkButton label="Add new turn restriction" click="addNewTurnRestriction()" />
15
16   <fx:Script><![CDATA[
17         import net.systemeD.halcyon.connection.*;
18         import net.systemeD.potlatch2.*;
19         import mx.core.*;
20
21         /* ** FIXME: some of this is common with RouteEditor.mxml. We can probably refactor */
22
23         public function addTurnRestrictions(event:Event=null):void {
24                 turnRestrictionIcons.removeAllChildren();
25                 addEventListener("relations_changed", addTurnRestrictions);
26                 for each(var relation:Object in matchedRelations) {
27                         var icon:TurnRestrictionIcon = new TurnRestrictionIcon();
28                         icon.setTurnRestriction(relation);
29                         turnRestrictionIcons.addChild(icon);
30                 }
31         }
32
33         public function addNewTurnRestriction():void {
34                 var relation:Relation = _entity.connection.createRelation(
35                         { type: 'restriction' }, 
36                         [ new RelationMember(_entity, 'via') ],
37             MainUndoStack.getGlobalStack().addAction);
38                 addTurnRestrictions();
39         }
40         
41   ]]></fx:Script>
42 </edit:RelationMemberEditor>
43