Merge branch 'master' of github.com:systemed/potlatch2
[potlatch2.git] / net / systemeD / potlatch2 / BookmarkSelector.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <s:BorderContainer
3     xmlns:controls="net.systemeD.controls.*"
4         xmlns:fx="http://ns.adobe.com/mxml/2009"
5     xmlns:s="library://ns.adobe.com/flex/spark" >
6
7     <s:layout>
8       <s:VerticalLayout
9           paddingLeft="5" paddingRight="5"
10           paddingTop="5" paddingBottom="5"/>
11     </s:layout>
12
13         <s:List width="100%" height="100%" id="bookmarkMenu"
14                 labelField="name"
15             itemRenderer="net.systemeD.controls.DeletableListItemRenderer"
16                 change="FlexGlobals.topLevelApplication.bookmarkButton.close(); goToBookmark(event);"
17             dataProvider="{bookmarks}">
18       <s:layout>
19         <s:VerticalLayout requestedRowCount="{bookmarks.length}" gap="0" rowHeight="20" variableRowHeight="false" horizontalAlign="contentJustify"/> 
20       </s:layout>
21     </s:List>
22
23         <s:HGroup horizontalAlign="center">
24                 <s:Button id="addButton" label="Add..." click="FlexGlobals.topLevelApplication.bookmarkButton.close(); addBookmark();" />
25                 <s:Button id="clearButton" label="Clear all" click="FlexGlobals.topLevelApplication.bookmarkButton.close(); clearBookmarks();" />
26         </s:HGroup>
27
28         <fx:Script><![CDATA[
29                 import net.systemeD.halcyon.*;
30                 import net.systemeD.halcyon.connection.*;
31                 import net.systemeD.potlatch2.*;
32                 import net.systemeD.potlatch2.collections.Stylesheets;
33                 import net.systemeD.potlatch2.dialogs.*;
34                 import net.systemeD.controls.DeletableListItemRenderer;
35                 import mx.core.*;
36         import spark.events.IndexChangeEvent;
37                 import mx.collections.ArrayCollection;
38         import mx.managers.PopUpManager;
39
40                 [Bindable]
41         public var bookmarks:ArrayCollection = new ArrayCollection([]);
42                 // of format { name: "Bookmark 1", lat: 53, lon: 0 }, { name: "Bookmark 2", lat: 54, lon: -1 }
43
44                 private var userState:SharedObject=SharedObject.getLocal("user_state","/");
45
46                 public function init():BookmarkSelector {
47                         if (userState.data['bookmarks']) {
48                                 bookmarks = new ArrayCollection(userState.data['bookmarks']);
49                         }
50                         return this;
51                 }
52
53                 private function goToBookmark(event:IndexChangeEvent):void {
54                         FlexGlobals.topLevelApplication.theController.map.moveMapFromLatLon(event.currentTarget.selectedItem.lat, event.currentTarget.selectedItem.lon);
55                 }
56                 
57                 private function addBookmark():void {
58                         var dialog:BookmarkNameDialog = BookmarkNameDialog(
59                             PopUpManager.createPopUp(Application(FlexGlobals.topLevelApplication), BookmarkNameDialog, true));
60                         PopUpManager.centerPopUp(dialog);
61                         // save to SharedObject
62                 userState.setProperty("bookmarks",bookmarks.source);
63                 try { userState.flush(); } catch (e:Error) {}
64                 }
65                 
66                 private function clearBookmarks():void {
67                         bookmarks.removeAll();
68                 userState.setProperty("bookmarks",bookmarks.source);
69                 try { userState.flush(); } catch (e:Error) {}
70                 }
71     ]]></fx:Script>
72 </s:BorderContainer>
73