[gnome-maps/wip/osm-edit: 3/10] osmEdit: Hook up edit button in the place bubble



commit fb6f560c57da011c0d847eef3e13c32be5302a97
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Oct 19 21:47:01 2015 +0200

    osmEdit: Hook up edit button in the place bubble
    
    Add the Edit button (this should later be reworked to invoke the account
    setup if the user has not yet added an OSM account).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726628

 src/application.js |    3 +++
 src/mapBubble.js   |    7 +++++--
 src/placeBubble.js |   43 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 92b2448..d21826d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -35,6 +35,7 @@ const GeocodeService = imports.geocodeService;
 const MainWindow = imports.mainWindow;
 const Maps = imports.gi.GnomeMaps;
 const NotificationManager = imports.notificationManager;
+const OSMEdit = imports.osmEdit;
 const PlaceStore = imports.placeStore;
 const RouteService = imports.routeService;
 const Settings = imports.settings;
@@ -51,6 +52,7 @@ let geocodeService = null;
 let networkMonitor = null;
 let checkInManager = null;
 let contactStore = null;
+let osmEdit = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -225,6 +227,7 @@ const Application = new Lang.Class({
         checkInManager = new CheckIn.CheckInManager();
         contactStore = new Maps.ContactStore();
         contactStore.load();
+        osmEdit = new OSMEdit.OSMEdit();
     },
 
     _createWindow: function() {
diff --git a/src/mapBubble.js b/src/mapBubble.js
index 3a8ebb7..2803eb6 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -37,7 +37,8 @@ const Button = {
     ROUTE: 2,
     SEND_TO: 4,
     FAVORITE: 8,
-    CHECK_IN: 16
+    CHECK_IN: 16,
+    EDIT: 32
 };
 
 const MapBubble = new Lang.Class({
@@ -76,9 +77,11 @@ const MapBubble = new Lang.Class({
                                                    'bubble-send-to-button',
                                                    'bubble-favorite-button',
                                                    'bubble-check-in-button',
-                                                   'bubble-favorite-button-image']);
+                                                   'bubble-favorite-button-image',
+                                                   'bubble-edit-button']);
         this._image = ui.bubbleImage;
         this._content = ui.bubbleContentArea;
+        this._editButton = ui.bubbleEditButton;
 
         if (!buttonFlags)
             ui.bubbleButtonArea.visible = false;
diff --git a/src/placeBubble.js b/src/placeBubble.js
index 4759b68..8fd87de 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -26,6 +26,8 @@ const Lang = imports.lang;
 const Application = imports.application;
 const ContactPlace = imports.contactPlace;
 const MapBubble = imports.mapBubble;
+const OSMEditDialog = imports.osmEditDialog;
+const OSMUtils = imports.osmUtils;
 const Overpass = imports.overpass;
 const Place = imports.place;
 const PlaceFormatter = imports.placeFormatter;
@@ -41,7 +43,8 @@ const PlaceBubble = new Lang.Class({
                                                      'box-content',
                                                      'label-title']);
         params.buttons = (MapBubble.Button.ROUTE |
-                          MapBubble.Button.SEND_TO);
+                          MapBubble.Button.SEND_TO |
+                          MapBubble.Button.EDIT);
 
         if (params.place.store)
             params.buttons |= MapBubble.Button.FAVORITE;
@@ -79,6 +82,8 @@ const PlaceBubble = new Lang.Class({
             this._populate(this.place);
         }
         this.content.add(this._stack);
+
+        this._initEditButton(this._editButton);
     },
 
     _formatWikiLink: function(wiki) {
@@ -134,5 +139,41 @@ const PlaceBubble = new Lang.Class({
         }).bind(this));
 
         this._stack.visible_child = this._boxContent;
+    },
+
+    // clear the view widgets to be able to re-populate an updated place
+    _clearView: function() {
+        let widgets = this._boxContent.get_children();
+
+        /* remove the dynamically added content, the title label
+           has position 0 in the box */
+        for (let i = 1; i < widgets.length; i++) {
+            this._boxContent.remove(widgets[i]);
+        }
+    },
+
+    _initEditButton: function(button) {
+        button.visible = true;
+        button.connect('clicked', this._onEditClicked.bind(this));
+    },
+
+    _onEditClicked: function() {
+        let response =
+            Application.osmEdit.showEditDialog(this.get_toplevel(), this._place);
+
+        switch (response) {
+        case OSMEditDialog.Response.UPLOADED:
+            if (!Application.osmEdit.useTestApi) {
+                // update place
+                let object = Application.osmEdit.object;
+                OSMUtils.updatePlaceFromOSMObject(this._place, object);
+                // refresh place view
+                this._clearView();
+                this._populate(this._place);
+            }
+            break;
+        default:
+            break;
+        }
     }
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]