[gnome-maps/wip/mlundblad/add-email-and-takeaway: 8/12] osmEditDialog: Add e-mail address




commit d43648f15226878f87851bd45f5c8df9e17789ae
Author: Marcus Lundblad <ml update uu se>
Date:   Thu Apr 29 23:00:07 2021 +0200

    osmEditDialog: Add e-mail address
    
    Add e-mail address as an editable field.

 src/osmEditDialog.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/src/osmEditDialog.js b/src/osmEditDialog.js
index 6e31803b..6859caef 100644
--- a/src/osmEditDialog.js
+++ b/src/osmEditDialog.js
@@ -85,6 +85,21 @@ var _osmPhoneRewriteFunc = function(text) {
     }
 };
 
+/* Reformat an e-mail address if it it looks like a mailto: URI
+ * strip off the leading mailto: protocol string and trailing parameters,
+ * following a ?
+ * otherwise return the string unmodified
+ */
+var _osmEmailRewriteFunc = function(text) {
+    if (GLib.uri_parse_scheme(text) === 'mailto') {
+        let afterMailto = text.replace('mailto:', '');
+
+        return Soup.uri_decode(afterMailto.split('?')[0]);
+    } else {
+        return text;
+    }
+}
+
 /*
  * specification of OSM edit fields
  * name: the label for the edit field (translatable)
@@ -136,6 +151,16 @@ const OSM_FIELDS = [
                 "starting with a + sign. Beware of local privacy " +
                 "laws, especially for private phone numbers.")
     },
+    {
+        name: _("E-mail"),
+        tag: 'email',
+        type: EditFieldType.TEXT,
+        validate: Utils.isValidEmail,
+        rewriteFunc: this._osmEmailRewriteFunc,
+        validateError: _("This is not a valid e-mail address. Make sure to not include the mailto: protocol 
prefix."),
+        hint: _("Contact e-mail address for inquiries." +
+                "Add only email addresses that are intended to be publicly used.")
+    },
     {
         name: _("Wikipedia"),
         tag: 'wikipedia',


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