cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermw...@apache.org
Subject [16/21] git commit: addresses added to the Proxy
Date Thu, 09 Jan 2014 20:10:51 GMT
addresses added to the Proxy


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/0beadd24
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/0beadd24
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/0beadd24

Branch: refs/heads/master
Commit: 0beadd247ed7f5bb2fc084888eee566f86335c94
Parents: 24eed63
Author: Piotr Zalewa <piotr@zalewa.info>
Authored: Thu Dec 19 14:59:26 2013 +0100
Committer: Piotr Zalewa <piotr@zalewa.info>
Committed: Thu Dec 19 14:59:26 2013 +0100

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/0beadd24/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index ecdd0fb..62dc6dd 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -63,7 +63,15 @@ mozContact.prototype.updateFromCordova = function(contact) {
         for (var i=0; i < addresses.length; i++) {
             var addr = {};
             for (var key in addresses[i]) {
-                addr[key] = addresses[i][key];    
+                if (key == 'formatted' || key == 'id') {
+                    continue;
+                } else if (key == 'type') {
+                    addr[key] = [addresses[i][key]];
+                } else if (key == 'country') {
+                    addr['countryName'] = addresses[i][key];
+                } else {
+                    addr[key] = addresses[i][key];    
+                }
             } 
             arr.push(addr);
         }                                 
@@ -155,6 +163,26 @@ Contact.prototype.updateFromMozilla = function(moz) {
         return contactFields;
     }
 
+    function exportAddresses(addresses) {
+        // TODO: check moz address format
+        var arr = [];
+        
+        for (var i=0; i < addresses.length; i++) {
+            var addr = {};
+            for (var key in addresses[i]) {
+                if (key == 'countryName') {
+                    addr['country'] = addresses[i][key];
+                } else if (key == 'type') {
+                    addr[key] = addresses[i][key].join(' ');
+                } else {
+                    addr[key] = addresses[i][key];    
+                }
+            } 
+            arr.push(addr);
+        }
+        return arr;
+    } 
+
 
     if (moz.id) {
         this.id = moz.id;
@@ -186,7 +214,13 @@ Contact.prototype.updateFromMozilla = function(moz) {
         this.emails = exportContactField(moz.email);
     }
     // categories
+
     // addresses
+    if (moz.adr) {
+        this.addresses = exportAddresses(moz.adr);
+    }
+
+    // phoneNumbers
     if (moz.tel) {
         this.phoneNumbers = exportContactField(moz.tel);
     }


Mime
View raw message