[gnome-maps/wip/jonasdn/osm-edit-address] osmEditDialog: Add address



commit 7fc721c682dd56a5ce6648ebe31b516e2457d8bc
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Mon Feb 22 19:49:30 2016 +0100

    osmEditDialog: Add address

 data/org.gnome.Maps.data.gresource.xml |    1 +
 data/ui/osm-edit-address.ui            |   30 +++++++++++
 src/osmConnection.js                   |    1 +
 src/osmEditDialog.js                   |   85 ++++++++++++++++++++++++++++++--
 4 files changed, 113 insertions(+), 4 deletions(-)
---
diff --git a/data/org.gnome.Maps.data.gresource.xml b/data/org.gnome.Maps.data.gresource.xml
index 70a43d9..2c9c82d 100644
--- a/data/org.gnome.Maps.data.gresource.xml
+++ b/data/org.gnome.Maps.data.gresource.xml
@@ -17,6 +17,7 @@
     <file preprocess="xml-stripblanks">ui/map-bubble.ui</file>
     <file preprocess="xml-stripblanks">ui/notification.ui</file>
     <file preprocess="xml-stripblanks">ui/osm-account-dialog.ui</file>
+    <file preprocess="xml-stripblanks">ui/osm-edit-address.ui</file>
     <file preprocess="xml-stripblanks">ui/osm-edit-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/osm-type-list-row.ui</file>
     <file preprocess="xml-stripblanks">ui/osm-type-search-entry.ui</file>
diff --git a/data/ui/osm-edit-address.ui b/data/ui/osm-edit-address.ui
new file mode 100644
index 0000000..8ae3df9
--- /dev/null
+++ b/data/ui/osm-edit-address.ui
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <template class="Gjs_OSMEditAddress" parent="GtkGrid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkEntry" id="street">
+        <property name="visible">True</property>
+        <property name="hexpand">True</property>
+        <property name="placeholder_text" translatable="yes">Street</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkEntry" id="number">
+        <property name="visible">True</property>
+        <property name="hexpand">True</property>
+        <property name="placeholder_text" translatable="yes">House number</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkEntry" id="post">
+        <property name="visible">True</property>
+        <property name="hexpand">True</property>
+        <property name="placeholder_text" translatable="yes">Postal code</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/osmConnection.js b/src/osmConnection.js
index cbddeea..39d4e17 100644
--- a/src/osmConnection.js
+++ b/src/osmConnection.js
@@ -78,6 +78,7 @@ const OSMConnection = new Lang.Class({
                                              message.response_body.length);
                 callback(true, message.status_code, object, type, null);
             } catch (e) {
+                Utils.debug(e);
                 callback(false, message.status_code, null, type, e);
             }
         }).bind(this));
diff --git a/src/osmEditDialog.js b/src/osmEditDialog.js
index 31cf210..eed28cb 100644
--- a/src/osmEditDialog.js
+++ b/src/osmEditDialog.js
@@ -103,6 +103,13 @@ const OSM_FIELDS = [
         hint: _("The official name. This is typically what appears on signs.")
     },
     {
+        name: _("Address"),
+        tag: 'addr',
+        subtags: ['addr:street', 'addr:housenumber', 'addr:postcode'],
+        type: EditFieldType.ADDRESS
+    },
+
+    {
         name: _("Website"),
         tag: 'website',
         type: EditFieldType.TEXT,
@@ -167,6 +174,37 @@ const OSM_FIELDS = [
                   ['service', _("Service")]]
     }];
 
+const OSMEditAddress = new Lang.Class({
+    Name: 'OSMEditAddress',
+    Extends: Gtk.Grid,
+    Template: 'resource:///org/gnome/Maps/ui/osm-edit-address.ui',
+    Children: [ 'street',
+                'number',
+                'post' ],
+
+    _init: function(params) {
+        let street = params.street;
+        delete params.street;
+
+        let number = params.number;
+        delete params.number;
+
+        let postCode = params.postCode;
+        delete params.postCode;
+
+        this.parent(params);
+
+        if (street)
+            this.street.text = street;
+
+        if (number)
+            this.number.text = number;
+
+        if (postCode)
+            this.post.text = postCode;
+    }
+});
+
 
 const OSMEditDialog = new Lang.Class({
     Name: 'OSMEditDialog',
@@ -604,6 +642,26 @@ const OSMEditDialog = new Lang.Class({
         this._currentRow++;
     },
 
+    _addOSMEditAddressEntry: function(fieldSpec, value) {
+        this._addOSMEditLabel(fieldSpec);
+
+        let addr = new OSMEditAddress({ street: value[0],
+                                           number: value[1],
+                                           postCode: value[2] });
+        let changedFunc = (function(entry, index) {
+            print("changed: %s %s".format(fieldSpec.subtags[index], entry.text));
+            this._osmObject.set_tag(fieldSpec.subtags[index], entry.text);
+            this._nextButton.sensitive = true;
+        }).bind(this);
+
+        addr.street.connect('changed', changedFunc.bind(this, addr.street, 0));
+        addr.number.connect('changed', changedFunc.bind(this, addr.number, 1));
+        addr.post.connect('changed', changedFunc.bind(this, addr.post, 2));
+
+        this._editorGrid.attach(addr, 1, this._currentRow, 1, 3);
+        this._currentRow += 3;
+    },
+
     /* update visible items in the "Add Field" popover */
     _updateAddFieldMenu: function() {
         /* clear old items */
@@ -618,9 +676,18 @@ const OSMEditDialog = new Lang.Class({
         /* add selectable items */
         for (let i = 0; i < OSM_FIELDS.length; i++) {
             let fieldSpec = OSM_FIELDS[i];
-            let value = this._osmObject.get_tag(fieldSpec.tag);
+            let hasValue = false;
+
+            if (fieldSpec.subtags) {
+                fieldSpec.subtags.forEach((function(tag) {
+                    if (this._osmObject.get_tag(tag))
+                        hasValue = true;
+                }).bind(this));
+            } else {
+                hasValue = this._osmObject.get_tag(fieldSpec.tag) !== null;
+            }
 
-            if (value === null) {
+            if (!hasValue) {
                 let button = new Gtk.Button({
                     visible: true, sensitive: true,
                     label: fieldSpec.name
@@ -636,7 +703,7 @@ const OSMEditDialog = new Lang.Class({
                     /* add a "placeholder" empty OSM tag to keep the add field
                      * menu updated, these tags will be filtered out if nothing
                      * is entered */
-                    this._osmObject.set_tag(fieldSpec.tag, '');
+                    this._osmObject.set_tag(fieldSpec.tag, null);
                     this._updateAddFieldMenu();
                 }).bind(this));
 
@@ -659,6 +726,9 @@ const OSMEditDialog = new Lang.Class({
         case EditFieldType.COMBO:
             this._addOSMEditComboEntry(fieldSpec, value);
             break;
+        case EditFieldType.ADDRESS:
+            this._addOSMEditAddressEntry(fieldSpec, value);
+            break;
         }
     },
 
@@ -671,8 +741,15 @@ const OSMEditDialog = new Lang.Class({
 
         for (let i = 0; i < OSM_FIELDS.length; i++) {
             let fieldSpec = OSM_FIELDS[i];
-            let value = osmObject.get_tag(fieldSpec.tag);
+            let value;
 
+            if (fieldSpec.subtags) {
+                value = fieldSpec.subtags.map(function(tag) {
+                    return osmObject.get_tag(tag);
+                });
+            } else {
+                value = osmObject.get_tag(fieldSpec.tag);
+            }
             if (value != null)
                 this._addOSMField(fieldSpec, value);
         }


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