Make text labels draggable too
[potlatch2.git] / net / systemeD / potlatch2 / panels / DragAndDropPanel.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <mx:VBox width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox"
4     xmlns:fx="http://ns.adobe.com/mxml/2009"
5         xmlns:controls="net.systemeD.controls.*"
6         xmlns:mx="library://ns.adobe.com/flex/mx">
7
8         <mx:Text id="dndPanelText" text="{dndPrompt}" width="100%" styleName="helpInfo" />
9         <mx:Repeater id="dndRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType('point')}" styleName="dndRepeater">
10                 <mx:HBox width="100%" styleName="dndPanelCategory">
11                         <mx:Label text="{dndRep.currentItem.name}:" styleName="dndPanelCategoryLabel"/>
12                 </mx:HBox>
13
14                 <mx:TileList dataProvider="{dndRep.currentItem.getFeaturesForType('point', true)}" width="100%" height="1"
15                              id="tl" dragEnabled="true" mouseDown="mouseDownHandler(event)" 
16                              rowHeight="32" columnWidth="100" updateComplete="resizePOIGrid(event)" styleName="dndPanelTileList">
17                         <mx:itemRenderer>
18                                 <fx:Component>
19                                         <mx:HBox toolTip="{data.name}" horizontalScrollPolicy="off" >
20                                                 <mx:Image id="foo" source="{data.dndimage}" height="24" width="24" toolTip="{data.name}" />
21                                                 <mx:Label text="{data.name}" />
22                                         </mx:HBox>
23                                 </fx:Component>
24                         </mx:itemRenderer>
25                 </mx:TileList>
26         </mx:Repeater>
27
28         <fx:Script><![CDATA[
29
30         import net.systemeD.potlatch2.mapfeatures.*;
31         import mx.core.DragSource;
32         import mx.managers.DragManager;
33         import mx.controls.Image;
34
35         [Bindable] public var dndPrompt:String="Add new points by dragging them onto the map";
36
37         private function mouseDownHandler(event:MouseEvent):void {
38                 var item:Feature=Feature(TileList(event.currentTarget).selectedItem);
39                 var dragInitiator:HBox = event.currentTarget.itemToItemRenderer(item);
40                 var dragSource:DragSource = new DragSource();
41                 dragSource.addData(item.tags, 'tags');
42                 dragSource.addData(event.currentTarget, 'container');
43
44                 var dragProxy:Image = new Image();
45                 dragProxy.source = item.dndimage;
46                 dragProxy.width = 24;   // must set width and height explicitly
47                 dragProxy.height = 24;  // for non-embedded images
48
49                 DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
50         }
51
52         private function resizePOIGrid(event:Event):void {
53                 var rows:Number=event.target.dataProvider.length/event.target.columnCount;
54                 if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }
55                 event.target.height=rows*(event.target.rowHeight+1);
56         }
57
58         ]]></fx:Script>
59
60 </mx:VBox>