Merge remote-tracking branch 'gravitystorm/mygpx'
authorRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 15:32:41 +0000 (16:32 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 15:32:41 +0000 (16:32 +0100)
1  2 
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/dialogs/MyGpxDialog.mxml

index 2cd5f0958c2b210f8dc1778fa9d4fd53235307d6,52c5bc799b5bf7916a71c59b6f79dfd09d5081d3..30aef5e757b43fdc5f31c30a807ded7bff1e3c6e
@@@ -162,19 -162,11 +162,19 @@@ package net.systemeD.halcyon.connectio
            }
  
          private function changesetCreateComplete(event:Event):void {
 -            // response should be a Number changeset id
 -            var id:Number = Number(URLLoader(event.target).data);
 +            var result:String = URLLoader(event.target).data;
 +
 +            if (result.match(/^^\d+$/)) {
 +                // response should be a Number changeset id
 +                var id:Number = Number(URLLoader(event.target).data);
              
 -            // which means we now have a new changeset!
 -            setActiveChangeset(new Changeset(this, id, lastUploadedChangesetTags));
 +                // which means we now have a new changeset!
 +                setActiveChangeset(new Changeset(this, id, lastUploadedChangesetTags));
 +            } else {
 +                var results:XML = XML(result);
 +
 +                throwServerError(results.message);
 +            }
          }
  
          private function changesetCreateError(event:IOErrorEvent):void {
                                function(e:Event):void { 
                        dispatchEvent(new Event(LOAD_COMPLETED));
                                        callback(e);
-                               }, errorOnMapLoad, mapLoadStatus); // needs error handlers
+                               }, errorOnTraceLoad, mapLoadStatus); // needs error handlers
              dispatchEvent(new Event(LOAD_STARTED)); //specifc to map or reusable?
          }
+         private function errorOnTraceLoad(event:Event):void {
+             trace("Trace load error");
+             dispatchEvent(new Event(LOAD_COMPLETED));
+         }
        }
  }
index 019ab46561e3be61ddc81a191663fb195f8dbeb4,f024c27eb89fdde2fea8d3879b75597b0bf53c78..f024c27eb89fdde2fea8d3879b75597b0bf53c78
@@@ -1,11 -1,45 +1,45 @@@
  <?xml version="1.0" encoding="utf-8"?>
- <mx:TitleWindow
+ <s:TitleWindow
          xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:mx="library://ns.adobe.com/flex/mx"
-         layout="vertical" showCloseButton="true"
-         horizontalAlign="center" title="My tracks"
-         width="600" height="400"
-         verticalGap="0">
+         xmlns:s="library://ns.adobe.com/flex/spark"
+         title="My tracks"
+         width="600" height="400">
+   <s:layout>
+     <s:VerticalLayout />
+   </s:layout>
+    
+   <s:HGroup width="100%" horizontalAlign="center" verticalAlign="middle" paddingTop="5">
+     <s:RichText text="Traces" id="results" />
+   </s:HGroup>
+   <s:DataGrid dataProvider="{traces}" width="100%" height="100%" id="traceGrid">
+     <s:columns>
+       <s:ArrayCollection>
+         <s:GridColumn editable="false" dataField="id" headerText="id" width="45"/>
+         <s:GridColumn editable="false" dataField="filename" headerText="filename"/>
+         <s:GridColumn editable="false" dataField="description" headerText="description"/>
+         <s:GridColumn editable="false" dataField="tagsText" headerText="tags"/>
+         <s:GridColumn editable="false">
+           <s:itemRenderer>
+             <fx:Component>
+               <s:GridItemRenderer>
+                 <s:VGroup horizontalAlign="center" verticalAlign="middle" width="100%" height="100%">
+                   <s:Button label="Load"
+                       click="outerDocument.loadFile(data)"/>
+                 </s:VGroup>
+               </s:GridItemRenderer>
+             </fx:Component>
+           </s:itemRenderer>
+         </s:GridColumn>
+       </s:ArrayCollection>
+     </s:columns>
+   </s:DataGrid>
+   <s:controlBarContent>
+     <s:Button label="Refresh List" click="fetchList(true)" />
+   </s:controlBarContent>
    <fx:Script><![CDATA[
      import mx.managers.PopUpManager;
      import mx.events.CloseEvent;
@@@ -29,9 -63,9 +63,9 @@@
          PopUpManager.centerPopUp(this);
          this.addEventListener(CloseEvent.CLOSE, myGpxDialog_close);
  
-               // >>>> REFACTOR: really horrible way of getting both map and connection
+         // >>>> REFACTOR: really horrible way of getting both map and connection
          map = Globals.vars.root;
-               conn = map.editableLayer.connection;
+         conn = map.editableLayer.connection;
  
          conn.addEventListener(Connection.TRACES_LOADED, onTracesLoaded);
          SaveManager.ensureAccess(fetchList, conn);
  
      [Bindable(event="traces_loaded")]
      private function get traces():VectorCollection {
-               return new VectorCollection(conn.getTraces());
+         return new VectorCollection(conn.getTraces().sort(f).reverse());
      }
  
-     public function loadFile(t:Trace):void {
+     private function f(a:Trace, b:Trace):int {
+         return a.id - b.id
+     }
+     public function loadFile(o:Object):void {
+         var t:Trace = Trace(o);
          t.addToMap();
      }
  
      }
                ]]>
    </fx:Script>
-   <mx:Text text="Traces" id="results" />
-   <mx:DataGrid dataProvider="{traces}" width="100%" height="100%" id="traceGrid">
-     <mx:columns>
-             <mx:DataGridColumn editable="false" dataField="id" headerText="id" width="45"/>
-             <mx:DataGridColumn editable="false" dataField="filename" headerText="filename"/>
-             <mx:DataGridColumn editable="false" dataField="description" headerText="description"/>
-             <mx:DataGridColumn editable="false" dataField="tagsText" headerText="tags"/>
-             <mx:DataGridColumn editable="false">
-               <mx:itemRenderer>
-                 <fx:Component>
-                   <mx:VBox>
-                     <mx:Button label="Load"
-                       click="parentDocument.loadFile(data)"/>
-                   </mx:VBox>
-                 </fx:Component>
-               </mx:itemRenderer>
-             </mx:DataGridColumn>
-     </mx:columns>
-   </mx:DataGrid>
-   <mx:ControlBar>
-     <mx:Button label="Refresh List" click="fetchList(true)" />
-   </mx:ControlBar>
- </mx:TitleWindow>
+ </s:TitleWindow>