Post changesets to Twitter
authorRichard Fairhurst <richard@systemeD.net>
Tue, 20 Aug 2013 10:46:20 +0000 (11:46 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Tue, 20 Aug 2013 10:46:20 +0000 (11:46 +0100)
net/systemeD/potlatch2/save/SaveDialog.mxml
styles/Application.css

index 826749b..f8ae078 100644 (file)
   </mx:ViewStack>
 
   <mx:ControlBar>
+    <mx:CheckBox id="twitter" selected="{getTwitter()}"
+                label="Post on Twitter"
+                change="setTwitter(twitter.selected)" />
+
     <mx:Button id="dataButton" label="View data" visible="false" click="processSequence.selectedChild=dataTab" styleName="titleWindowButton" />
     <mx:Spacer width="100%"/>
     <mx:Button id="cancelButton" label="Cancel" click="close();" styleName="titleWindowButton" />
        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; }
        }
 
         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) {
     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");
         _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();
+       }
+
   ]]></fx:Script>
 </mx:TitleWindow>
 
index 8e964e3..5721e22 100644 (file)
@@ -344,3 +344,7 @@ s|FormItem {
        selectedFillColors: haloBlue, black;
        color: white;
 }
+
+/* Misc */
+
+#twitter { color: white; textRollOverColor: white; }