Merge remote-tracking branch 'gravitystorm/choices'
[potlatch2.git] / net / systemeD / potlatch2 / 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()">
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" 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:Component>
21                         </mx:itemRenderer>
22                 </mx:DataGridColumn>
23     </mx:columns>
24   </mx:DataGrid>
25
26   <mx:HBox horizontalAlign="right" width="100%">
27     <mx:LinkButton label="Delete" click="removeSource()" enabled="{dataGrid.selectedItem != null? true : false}"/>
28     <mx:LinkButton label="Add" click="addNewSource()"/>
29   </mx:HBox>
30
31   <fx:Script><![CDATA[
32
33         /*
34                 Still to do:
35                 - editable source tag for each layer
36                 - editable bbox for each layer
37                 - ability to use this dialogue to select as well as edit
38                 - automatically select imagery once you've edited it (i.e. itemEditEnd)
39                 - edits should stick around, either in SharedObjects or OSM preferences
40         */
41
42     import mx.managers.PopUpManager;
43     import mx.events.CloseEvent;
44     import mx.core.Application;
45     import mx.core.FlexGlobals;
46         import mx.collections.ArrayCollection;
47         import mx.controls.List;
48         import net.systemeD.potlatch2.FunctionKeyManager;
49
50         public var dataCollection:ArrayCollection;
51         private var menu:List;
52         private var collection:Object;
53
54     public function init(title:String, menu:List, source:Object):void {
55                 this.title=title;
56                 this.menu=menu;
57                 collection=source;
58                 dataCollection=new ArrayCollection(source.collection);
59         PopUpManager.addPopUp(this, Application(FlexGlobals.topLevelApplication), true);
60         PopUpManager.centerPopUp(this);
61         this.addEventListener(CloseEvent.CLOSE, backgroundDialog_close);
62                 dataGrid.dataProvider=dataCollection;
63     }
64     
65     private function backgroundDialog_close(evt:CloseEvent):void {
66         PopUpManager.removePopUp(this);
67                 if (menu) { menu.invalidateList(); }
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>