From 07837690910a5b74ece7ab55dfb2b4150902d8ed Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Sat, 2 Apr 2011 22:35:13 +0100 Subject: [PATCH] Complete support for loading relations by ID --- net/systemeD/halcyon/connection/Connection.as | 7 ++- .../halcyon/connection/XMLConnection.as | 6 +-- .../potlatch2/RelationLoaderPanel.mxml | 53 ++++++++++++++----- .../potlatch2/RelationSelectPanel.mxml | 1 + 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/net/systemeD/halcyon/connection/Connection.as b/net/systemeD/halcyon/connection/Connection.as index 0821a5b..1e9b6f9 100644 --- a/net/systemeD/halcyon/connection/Connection.as +++ b/net/systemeD/halcyon/connection/Connection.as @@ -544,7 +544,7 @@ package net.systemeD.halcyon.connection { public function loadBbox(left:Number, right:Number, top:Number, bottom:Number):void { } - public function loadEntity(entity:Entity):void {} + public function loadEntityByID(type:String, id:Number):void {} public function setAuthToken(id:Object):void {} public function setAccessToken(key:String, secret:String):void {} public function createChangeset(tags:Object):void {} @@ -553,6 +553,11 @@ package net.systemeD.halcyon.connection { public function fetchUserTraces(refresh:Boolean=false):void {} public function fetchTrace(id:Number, callback:Function):void {} public function hasAccessToken():Boolean { return false; } + + public function loadEntity(entity:Entity):void { + loadEntityByID(entity.getType(),entity.id); + } + } } diff --git a/net/systemeD/halcyon/connection/XMLConnection.as b/net/systemeD/halcyon/connection/XMLConnection.as index b94345b..20d5e43 100644 --- a/net/systemeD/halcyon/connection/XMLConnection.as +++ b/net/systemeD/halcyon/connection/XMLConnection.as @@ -46,9 +46,9 @@ package net.systemeD.halcyon.connection { sendLoadRequest(mapRequest); } - override public function loadEntity(entity:Entity):void { - var url:String=Connection.apiBaseURL + entity.getType() + "/" + entity.id; - if (entity is Way) url+="/full"; + override public function loadEntityByID(type:String, id:Number):void { + var url:String=Connection.apiBaseURL + type + "/" + id; + if (type=='way') url+="/full"; sendLoadRequest(new URLRequest(url)); } diff --git a/net/systemeD/potlatch2/RelationLoaderPanel.mxml b/net/systemeD/potlatch2/RelationLoaderPanel.mxml index b5c305e..53c9624 100644 --- a/net/systemeD/potlatch2/RelationLoaderPanel.mxml +++ b/net/systemeD/potlatch2/RelationLoaderPanel.mxml @@ -2,10 +2,11 @@ - + @@ -19,22 +20,46 @@ import net.systemeD.potlatch2.*; import mx.managers.PopUpManager; - // ** FIXME: should automatically focus on id field (like the Changeset dialogue) + private var entity:Entity; + private var relid:Number; + + public function setEntity(e:Entity):void { + entity=e; + } + + private function loadRelation():void { + relid = Number(requestedID.text); + PopUpManager.removePopUp(this); - public function loadRelation():void { - var conn:Connection = Connection.getConnectionInstance(); - var id:uint = uint(requestedID.text); - if (requestedID.text) { - var rel:Relation=conn.getRelation(id); - if (!rel) { - rel = conn.createRelation({}, [], MainUndoStack.getGlobalStack().addAction); - rel.renumber(id,1); + var conn:Connection = Connection.getConnectionInstance(); + if (!relid) return; + if (conn.getRelation(relid)) { + relationLoaded(null); + } else { + conn.loadEntityByID("relation",relid); + conn.addEventListener(Connection.LOAD_COMPLETED, relationLoaded); + } + } + + private function relationLoaded(event:Event):void { + var conn:Connection = Connection.getConnectionInstance(); + var relation:Relation = conn.getRelation(relid); + conn.removeEventListener(Connection.LOAD_COMPLETED, relationLoaded); + if (!relation) return; + + var undo:CompositeUndoableAction = new CompositeUndoableAction("Add to relation"); + if (entity is EntityCollection) { + for each (var e:Entity in EntityCollection(entity).entities) { + if (relation.findEntityMemberIndex(e)==-1) { + relation.appendMember(new RelationMember(e, ''), undo.push); + } } - conn.loadEntity(rel); - // add an eventListener of some sort to pop up the panel again once it's loaded + } else { + relation.appendMember(new RelationMember(entity, ''), undo.push); } - PopUpManager.removePopUp(this); + MainUndoStack.getGlobalStack().addAction(undo); } + ]]> diff --git a/net/systemeD/potlatch2/RelationSelectPanel.mxml b/net/systemeD/potlatch2/RelationSelectPanel.mxml index 8db158d..6cd409e 100644 --- a/net/systemeD/potlatch2/RelationSelectPanel.mxml +++ b/net/systemeD/potlatch2/RelationSelectPanel.mxml @@ -85,6 +85,7 @@ PopUpManager.removePopUp(this); var panel:RelationLoaderPanel = RelationLoaderPanel( PopUpManager.createPopUp(Application(Application.application), RelationLoaderPanel, true)); + panel.setEntity(entity); PopUpManager.centerPopUp(panel); } -- 2.17.1