From c0737d6e7004f8174fc8e2587df9ceb0334a1807 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Tue, 20 Aug 2013 11:46:20 +0100 Subject: [PATCH] Post changesets to Twitter --- net/systemeD/potlatch2/save/SaveDialog.mxml | 32 +++++++++++++++++++-- styles/Application.css | 4 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/net/systemeD/potlatch2/save/SaveDialog.mxml b/net/systemeD/potlatch2/save/SaveDialog.mxml index 826749b3..f8ae078f 100644 --- a/net/systemeD/potlatch2/save/SaveDialog.mxml +++ b/net/systemeD/potlatch2/save/SaveDialog.mxml @@ -84,6 +84,10 @@ + + @@ -98,21 +102,25 @@ import mx.core.FlexGlobals; import mx.events.DataGridEvent; import mx.events.DataGridEventReason; - + import flash.net.*; + import net.systemeD.halcyon.connection.*; import net.systemeD.halcyon.AttentionEvent; private var _connection:Connection; private var doSkip:Boolean = false; - + private var newChangeset:Boolean = true; + [Bindable] private var failureText:String = ""; [Bindable] private var application:Object = FlexGlobals.topLevelApplication; public function setConnection(connection:Connection):void { _connection=connection; + newChangeset=true; } public function dontPrompt():void { + newChangeset=false; if (processSequence.initialized) { skipInput(); } else { doSkip=true; } } @@ -186,6 +194,7 @@ addStatus("Saving to changeset "+changeset.id); saveProgress.label = "Uploading changes"; + twitter.visible=false; twitter.includeInLayout=false; _connection.addEventListener(Connection.SAVE_COMPLETED, saveCompleted); var rawData:*=_connection.uploadChanges(); if (rawData) { @@ -201,6 +210,13 @@ private function saveCompleted(event:SaveCompleteEvent):void { if ( event.saveOK ) { _connection.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Changes successfully saved")); + if (twitter.selected && newChangeset) { + var url:String="https://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.openstreetmap.org%2Fbrowse%2Fchangeset%2F"; + url+=_connection.getActiveChangeset().id; + var comment:String=_connection.getActiveChangeset().getTag('comment') || "I just edited OpenStreetMap!"; + url+="&text="+encodeURIComponent(comment); + navigateToURL(new URLRequest(url), "_blank"); + } if (processSequence.selectedChild!=dataTab) close(); } else { fail("Failure when uploading data"); @@ -227,6 +243,18 @@ _connection.removeEventListener(Connection.SAVE_COMPLETED, saveCompleted); PopUpManager.removePopUp(this); } + + public function getTwitter():Boolean { + return SharedObject.getLocal('user_state','/').data['twitter']; + } + + public function setTwitter(v:Boolean):void { + var obj:SharedObject=SharedObject.getLocal("user_state","/"); + obj.setProperty('twitter',v); + try { obj.flush(); } catch (e:Error) {} + comment.setFocus(); + } + ]]> diff --git a/styles/Application.css b/styles/Application.css index 8e964e38..5721e22e 100644 --- a/styles/Application.css +++ b/styles/Application.css @@ -344,3 +344,7 @@ s|FormItem { selectedFillColors: haloBlue, black; color: white; } + +/* Misc */ + +#twitter { color: white; textRollOverColor: white; }