Retain preferences even when .swf filename has changed
[potlatch2.git] / net / systemeD / potlatch2 / find / FindDialog.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" title="Search"
7         width="458" height="350" verticalGap="0" creationComplete="txtFind.setFocus()">
8         <fx:Script><![CDATA[
9         import flash.events.Event;
10                 import mx.core.Application;
11                 import mx.core.FlexGlobals;
12                 import mx.events.CloseEvent;
13                 import mx.events.FlexEvent;
14                 import mx.managers.PopUpManager;
15                 import mx.rpc.events.ResultEvent;
16                 import mx.rpc.http.HTTPService;
17                 import mx.controls.Alert;
18         import mx.events.ListEvent;
19                         
20                 import net.systemeD.halcyon.Globals;
21                 
22                 private var nominatim:HTTPService = new HTTPService;
23                 private var nominatimURL:String = "http://open.mapquestapi.com/nominatim/v1/search?";   // ** FIXME - this should be user-configurable
24                 private var nomOptions:Object = { addressdetails:"1", limit:"10", format:"xml" };
25         private var selectedResult:Object = {lat: "0", lon: "0"};
26
27                 [Bindable]
28         private var searchResults:XMLList;
29                                 
30                 
31                 public function init():void {
32                         PopUpManager.addPopUp(this, Application(FlexGlobals.topLevelApplication), true);
33                         PopUpManager.centerPopUp(this);
34                         this.addEventListener(CloseEvent.CLOSE, findDialog_close);
35                         
36                         var obj:SharedObject = SharedObject.getLocal("user_state","/");
37         
38                 }
39                 
40                 private function findDialog_close(evt:CloseEvent):void {
41                         PopUpManager.removePopUp(this);
42                 }
43
44                 private function goFetch(q:String):void {
45
46                         var searchCall:String = nominatimURL;
47                         for (var item:String in nomOptions) {
48                                 searchCall += item + "="; 
49                                 searchCall += nomOptions[item] + "&";
50                         }
51                         searchCall += "q=" + q;
52                         this.nominatim.url = searchCall
53                         this.nominatim.addEventListener(ResultEvent.RESULT, goneFetched);
54                         this.nominatim.resultFormat = 'e4x';
55
56                         this.nominatim.send();
57                         
58                 }
59                 
60                 private function goneFetched(e:ResultEvent):void {
61                         searchResults = e.result.* as XMLList;
62                 }
63
64                 protected function btnFind_clickHandler(event:MouseEvent):void {
65                         goFetch(txtFind.text);
66                 }
67
68
69                 protected function txtFind_enterHandler(event:FlexEvent):void {
70                         goFetch(txtFind.text);
71                 }
72
73         private function setSelected(evt:ListEvent):void {
74             //Alert.show(evt.itemRenderer.data.@lat);
75             selectedResult = { lat: evt.itemRenderer.data.@lat, lon: evt.itemRenderer.data.@lon };
76         }
77         
78         private function goToSelected():void {
79             FlexGlobals.topLevelApplication.theMap.moveMapFromLatLon(selectedResult.lat, selectedResult.lon);
80             //FlexGlobals.topLevelApplication.theMap.redraw();
81             PopUpManager.removePopUp(this);
82         }
83         
84         
85         ]]>
86         </fx:Script>
87
88         <mx:HBox horizontalAlign="left" width="100%">
89                 <mx:Label text="Enter place name: " />
90                 <mx:TextInput id="txtFind" width="100%" enter="txtFind_enterHandler(event)"/>
91                 <mx:Button label="Search" id="btnFind" click="btnFind_clickHandler(event)"/>            
92         </mx:HBox>
93         
94         <mx:Spacer height="10"/>
95         
96         <mx:DataGrid id="dgResults" dataProvider="{searchResults}" change="setSelected(event)" width="100%" height="100%">
97                 <mx:columns>
98                         <mx:DataGridColumn headerText="Name" dataField="@display_name" minWidth="200" />
99                         <mx:DataGridColumn headerText="Type" dataField="@type"/>
100                         <mx:DataGridColumn headerText="Class" dataField="@class"/>            
101                         <mx:DataGridColumn headerText="ID" dataField="@osm_id"/>
102         </mx:columns>
103         </mx:DataGrid>
104
105     <mx:ControlBar>
106         <mx:Label text="Results from Nominatim" />
107         <mx:Spacer width="100%"/>
108         <mx:Button label="Cancel" click="PopUpManager.removePopUp(this);" styleName="titleWindowButton" />
109         <mx:Button label="Jump to" click="goToSelected();" styleName="titleWindowButton" enabled="{dgResults.selectedItem != null? true : false}" />        
110     </mx:ControlBar>
111     
112 </mx:TitleWindow>