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