Add user_check config option for deletion warning dialogues
authorRichard Fairhurst <richard@systemeD.net>
Wed, 19 Dec 2012 10:00:49 +0000 (10:00 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Wed, 19 Dec 2012 10:00:49 +0000 (10:00 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/potlatch2/save/SaveManager.as

index 8032969..2680353 100644 (file)
@@ -516,6 +516,24 @@ package net.systemeD.halcyon.connection {
                        return null;
                }
 
+               // Assess if user's changes are largely destructive
+               
+               public function changesAreDestructive():Boolean {
+                       var score:int=0;
+                       var entity:Entity;
+                       for each (entity in nodes) { score+=changeScore(entity); }
+                       for each (entity in ways) { score+=changeScore(entity)*10; }
+                       for each (entity in relations) { score+=changeScore(entity)*5; }
+                       return (score<-15);
+               }
+               
+               private function changeScore(entity:Entity):int {
+                       if (!entity.loaded) { return 0; }
+                       if (entity.id>0 &&  entity.deleted) { return -1; }
+                       if (entity.id<0 && !entity.deleted) { return  1; }
+                       return 0;
+               }
+
                // Error-handling
                
                protected function throwConflictError(entity:Entity,serverVersion:uint,message:String):void {
index 60ff4ab..6351594 100644 (file)
@@ -5,6 +5,8 @@ package net.systemeD.potlatch2.save {
     import mx.managers.PopUpManager;
     import mx.core.Application;
     import mx.core.FlexGlobals;
+    import mx.controls.Alert;
+    import mx.events.CloseEvent;
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.controller.*;
     import org.iotashan.oauth.*;
@@ -14,7 +16,21 @@ package net.systemeD.potlatch2.save {
         private static var instance:SaveManager = new SaveManager();
                private var _connection:Connection;
 
-        public static function saveChanges(connection:Connection):void {
+        public static function saveChanges(connection:Connection, accept:Boolean=false):void {
+                       if (connection.changesAreDestructive() && !accept) {
+                               var check:String=connection.getParam('user_check','');
+                               if (check=='warn') {
+                                       Alert.show("You are deleting data from OpenStreetMap. Remember, you are changing the map everyone sees, not just your own private map. Are you really sure?","Are you sure?",
+                                               Alert.CANCEL | Alert.YES, null, function(e:CloseEvent):void {
+                                                       if (e.detail==Alert.CANCEL) return;
+                                                       SaveManager.saveChanges(connection,true);
+                                               }, null, Alert.CANCEL);
+                                       return;
+                               } else if (check=='prevent') {
+                                       Alert.show("You are deleting too much data from OpenStreetMap - remember your changes affect the map everyone sees. If the data genuinely needs to be removed, please ask an experienced user to do it.","Deleting data",Alert.CANCEL);
+                                       return;
+                               }
+                       }
             instance.save(instance.saveData,connection);
         }