You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/12/05 01:56:51 UTC

[15/28] git commit: attempt to save is failing trying to limit the translated contact fields to name and familyName, but still failing

attempt to save is failing
trying to limit the translated contact fields to name and familyName,
but still failing


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/35def21d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/35def21d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/35def21d

Branch: refs/heads/master
Commit: 35def21d258710b8275df88077e4c0b1b290a9d3
Parents: 5833bc0
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Thu Nov 7 16:27:04 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:28:35 2013 -0800

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 108 +++++++++++++++++++++---------------
 1 file changed, 64 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/35def21d/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 550ddf7..7029541 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -27,53 +27,69 @@
 // https://developer.mozilla.org/en-US/docs/Web/API/mozContact
 function saveContacts(successCB, errorCB, contacts) {
     // success and fail will be called every time a contact is saved
-    for (var contact in contacts) {
-        var request;
-
-        function success(result) {
-            // TODO: this will need to amend the result
-            successCB(result);
-        }
-            
-        function exportContactFieldArray(contactFieldArray, key) {
-            if (!key) {
-                key = 'value';
-            }                 
-            
-            var arr = [];
-            
-            for (var i in contactFieldArray) {
-                arr.push(contactFieldArray[i][key]);
-            };                                       
-            
-            return arr;
-        }              
+    function success(result) {
+        // TODO: this will need to amend the result
+        console.log('SUCCESS from moz');
+        successCB(result);
+    }
+    function error(e) {
+        console.log('BOO from moz');
+        errorCB(e);
+    }
         
-        function exportAddress (addresses) {
-            // TODO: check moz address format
-            var arr = [];
-            
-            for (var i in addresses) {
-                var addr = {};
+    function exportContactFieldArray(contactFieldArray, key) {
+        if (!key) {
+            key = 'value';
+        }                 
+        
+        var arr = [];
+        
+        for (var i in contactFieldArray) {
+            arr.push(contactFieldArray[i][key]);
+        };                                       
+        
+        return arr;
+    }              
+    
+    function exportAddress (addresses) {
+        // TODO: check moz address format
+        var arr = [];
+        
+        for (var i in addresses) {
+            var addr = {};
+        
+            for (var key in addresses[i]) {
+                addr[key] = addresses[i][key];    
+            } 
             
-                for (var key in addresses[i]) {
-                    addr[key] = addresses[i][key];    
-                } 
-                
-                arr.push(addr);
-                
-            }                                 
+            arr.push(addr);
             
-            return arr;
-        } 
+        }                                 
+        
+        return arr;
+    } 
+    var i=0;
+    var contact;
 
+    while(contact = contacts[i++]){
+        var request;
         // prepare mozContact object
-        // TODO: find a way to link existing mozContact and Contact by ID
-        var moz = new mozContact({
-            name: [contact.name.familyName, 
-                   contact.name.givenName, 
-                   contact.name.middleName, 
-                   contact.name.nickname],
+        var translatedContact = {};
+        var nameArray = [];
+        var j = 0;
+        var field;
+        var fields = ['honorificPrefix', 'familyName', 'givenName', 'middleName', 'nickname'];
+        while(field = fields[j++]) {
+            if (contact.name[field]) {
+                nameArray.push(contact.name[field]);
+            }
+        }
+        translatedContact.name = nameArray.join(' ');
+        if (contact.name.honorificPrefix) {
+            translatedContact.honorificPrefix = contact.name.honorificPrefix;
+        }
+        translatedContact.familyName = contact.name.familyName;
+        /*
             honorificPrefix: [contact.name.honorificPrefix],
             givenName: [contact.name.givenName],
             familyName: [contact.name.familyName],
@@ -94,11 +110,15 @@ function saveContacts(successCB, errorCB, contacts) {
             // sex
             // genderIdentity
             // key
-        });
+        }
+        */
+        // TODO: find a way to link existing mozContact and Contact by ID
+        var moz = new mozContact(translatedContact);
+        // XXX: moz.name is undefined
         
         request = navigator.mozContacts.save(moz);
         request.onsuccess = success;
-        request.onerror = errorCB;                
+        request.onerror = error;                
     }
 }