Create a new panel for drag-and-drop POIs
[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                                      rowHeight="32" columnWidth="32" updateComplete="resizePOIGrid(event)" styleName="dndPanelTileList">
16                         <mx:itemRenderer>
17                                 <fx:Component>
18                                         <mx:VBox toolTip="{data.name}">
19                                                 <fx:Script><![CDATA[
20                                                         import mx.events.DragEvent;
21                                                         import mx.managers.DragManager;
22                                                         import mx.core.DragSource;
23                                                         import net.systemeD.potlatch2.TagViewer;
24
25                                                         private function dragPOI(event:MouseEvent, tags:Array):void {
26                                                                 var sidebar:TagViewer=parentDocument.parentDocument;
27                                                                 if (sidebar.controller.map.dragstate==sidebar.controller.map.DRAGGING) return;
28
29                                                                 // Get the drag initiator component from the event object.
30                                                                 var dragInitiator:Image = event.currentTarget as Image;
31                                                                 var dragSource:DragSource = new DragSource();
32                                                                 dragSource.addData(tags, 'tags');
33                                                                 dragSource.addData(event.target.parent.parent.parent.parent, 'container');
34
35                                                                 var dragProxy:Image = new Image();
36                                                                 dragProxy.source = dragInitiator.source;
37                                                                 dragProxy.width = dragInitiator.width;   // must set width and height explicitly
38                                                                 dragProxy.height = dragInitiator.height; // for non-embedded images
39                                                                 DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
40                                                         }
41
42                                                 ]]></fx:Script>
43                                                 <mx:Image id="foo" source="{data.dndimage}" height="24" width="24" mouseMove="dragPOI(event, data.tags)" toolTip="{data.name}" />
44                                         </mx:VBox>
45                                 </fx:Component>
46                         </mx:itemRenderer>
47                 </mx:TileList>
48         </mx:Repeater>
49
50         <fx:Script><![CDATA[
51
52         import net.systemeD.potlatch2.mapfeatures.*;
53
54         [Bindable] public var dndPrompt:String="Add new points by dragging them onto the map";
55
56         private function resizePOIGrid(event:Event):void {
57                 var rows:Number=event.target.dataProvider.length/event.target.columnCount;
58                 if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }
59                 event.target.height=rows*(event.target.rowHeight+1);
60         }
61
62         ]]></fx:Script>
63
64 </mx:VBox>