icon_width is circumference, not radius
[potlatch2.git] / net / systemeD / potlatch2 / dialogs / BackgroundDialog.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:TitleWindow
3         xmlns:fx="http://ns.adobe.com/mxml/2009"
4         xmlns:mx="library://ns.adobe.com/flex/mx"
5         layout="vertical" showCloseButton="true"
6         horizontalAlign="center" 
7         width="500" height="300" verticalGap="0">
8
9   <mx:DataGrid editable="true" width="100%" height="100%" id="dataGrid" itemEditEnd="updateSource()" dataProvider="{dataCollection}">
10     <mx:columns>
11         <mx:DataGridColumn editable="true"  dataField="name" headerText="Name"/>
12         <mx:DataGridColumn editable="true"  dataField="url" headerText="URL"/>
13         <mx:DataGridColumn editable="false" dataField="name" headerText="Key" width="70">
14                         <mx:itemRenderer>
15                                 <fx:Component>
16                                         <mx:ComboBox
17                                                 selectedItem="{FunctionKeyManager.instance().getKeyFor(outerDocument.title,data.name)}"
18                                             dataProvider="{FunctionKeyManager.fkeysCollection}"
19                                                 change="FunctionKeyManager.instance().setKeyFromFString(selectedItem as String,outerDocument.title,data.name)">
20                                                 <fx:Script><![CDATA[ import net.systemeD.potlatch2.FunctionKeyManager; ]]></fx:Script>
21                                         </mx:ComboBox>
22                                 </fx:Component>
23                         </mx:itemRenderer>
24                 </mx:DataGridColumn>
25     </mx:columns>
26   </mx:DataGrid>
27
28   <mx:HBox horizontalAlign="right" width="100%">
29     <mx:LinkButton label="Delete" click="removeSource()" enabled="{dataGrid.selectedItem != null? true : false}"/>
30     <mx:LinkButton label="Add" click="addNewSource()"/>
31   </mx:HBox>
32
33   <fx:Script><![CDATA[
34
35         /*
36                 Still to do:
37                 - editable source tag for each layer
38                 - editable bbox for each layer
39                 - ability to use this dialogue to select as well as edit
40                 - automatically select imagery once you've edited it (i.e. itemEditEnd)
41                 - edits should stick around, either in SharedObjects or OSM preferences
42         */
43
44     import mx.managers.PopUpManager;
45     import mx.events.CloseEvent;
46     import mx.core.Application;
47     import mx.core.FlexGlobals;
48         import mx.collections.ArrayCollection;
49         import spark.components.List;
50         import net.systemeD.potlatch2.FunctionKeyManager;
51
52         [Bindable] public var dataCollection:ArrayCollection;
53         private var menu:List;
54         private var collection:Object;
55
56     public function init(title:String, menu:List, source:Object):void {
57                 this.title=title;
58                 this.menu=menu;
59                 collection=source;
60                 dataCollection = source.getCollection();
61         PopUpManager.addPopUp(this, Application(FlexGlobals.topLevelApplication), true);
62         PopUpManager.centerPopUp(this);
63         this.addEventListener(CloseEvent.CLOSE, backgroundDialog_close);
64     }
65     
66     private function backgroundDialog_close(evt:CloseEvent):void {
67         PopUpManager.removePopUp(this);
68     }
69
70         private function addNewSource():void {
71                 dataCollection.addItemAt( {name:'(new name)',url:'(new URL)'} , dataCollection.length);
72                 dataGrid.validateNow();
73                 dataGrid.verticalScrollPosition=dataGrid.maxVerticalScrollPosition;
74                 dataGrid.editedItemPosition = {rowIndex: dataCollection.length-1, columnIndex: 0};
75         }
76         private function removeSource():void {
77                 dataCollection.removeItemAt(dataGrid.selectedIndex);
78         }
79         public function updateSource():void {
80                 collection.dispatchEvent(new Event("collection_changed"));
81         }
82
83   ]]>
84   </fx:Script>
85
86 </mx:TitleWindow>