cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermw...@apache.org
Subject [01/21] git commit: save is linked with the proxy contact.name doesn't exist www/Contact.js#Contact.prototype.save check on which side is the error
Date Thu, 09 Jan 2014 20:10:36 GMT
Updated Branches:
  refs/heads/master 322753fe3 -> 3478011b5


save is linked with the proxy
contact.name doesn't exist www/Contact.js#Contact.prototype.save
check on which side is the error


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

Branch: refs/heads/master
Commit: 7ccd57e843eb8d32424c7dad5ea8d327543b40e2
Parents: c8a1c7b
Author: Piotr Zalewa <piotr@zalewa.info>
Authored: Thu Nov 7 15:04:11 2013 +0100
Committer: Piotr Zalewa <piotr@zalewa.info>
Committed: Thu Nov 7 15:04:11 2013 +0100

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 136 +++++++++++++++++++-----------------
 1 file changed, 70 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/7ccd57e8/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 6c074ce..550ddf7 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -25,83 +25,87 @@
 // http://cordova.apache.org/docs/en/2.5.0/cordova_contacts_contacts.md.html#Contact
 // FxOS contact definition:
 // https://developer.mozilla.org/en-US/docs/Web/API/mozContact
-function saveContact(contacts, success, fail) {
+function saveContacts(successCB, errorCB, contacts) {
     // success and fail will be called every time a contact is saved
     for (var contact in contacts) {
-        var moz = new mozContact(),
-            request;
+        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 exportContactFieldArray(contactFieldArray, key) {
+            if (!key) {
+                key = 'value';
+            }                 
             
-            function exportAddress (addresses) {
-                // TODO: check moz address format
-                var arr = [];
-                
-                for (var i in addresses) {
-                    var addr = {};
+            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;
-            } 
+            }                                 
             
-            // prepare mozContact object
-            // TODO: find a way to link existing mozContact and Contact 
-            // (by ID?)
-            moz.init({
-                name: [contact.name.familyName, 
-                       contact.name.givenName, 
-                       contact.name.middleName, 
-                       contact.name.nickname],
-                honorificPrefix: [contact.name.honorificPrefix],
-                givenName: [contact.name.givenName],
-                familyName: [contact.name.familyName],
-                honorificSuffix: [contact.name.honorificSuffix], 
-                nickname: [contact.nickname],
-                email: exportContactFieldArray(contact.emails),
-                // photo: Blob
-                // url: Array with metadata (?)
-                category: exportContactFieldArray(contact.categories),
-                adr: exportAddress(contact.addresses),
-                tel: exportContactFieldArray(contact.phoneNumbers),
-                org: exportContactFieldArray(contact.organizations, 'name'),
-                jobTitle: exportContactFieldArray(contact.organizations, 'title'),
-                bday: contact.birthday,
-                note: contact.note,
-                // impp: exportIM(contact.ims), TODO: find the moz impp definition
-                // anniversary
-                // sex
-                // genderIdentity
-                // key
-            });
-            
-            request = navigator.mozContacts.save(moz);
-            request.onsuccess = success;
-            request.onerror = fail;                
+            return arr;
+        } 
+
+        // 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],
+            honorificPrefix: [contact.name.honorificPrefix],
+            givenName: [contact.name.givenName],
+            familyName: [contact.name.familyName],
+            honorificSuffix: [contact.name.honorificSuffix], 
+            nickname: [contact.nickname],
+            email: exportContactFieldArray(contact.emails),
+            // photo: Blob
+            // url: Array with metadata (?)
+            category: exportContactFieldArray(contact.categories),
+            adr: exportAddress(contact.addresses),
+            tel: exportContactFieldArray(contact.phoneNumbers),
+            org: exportContactFieldArray(contact.organizations, 'name'),
+            jobTitle: exportContactFieldArray(contact.organizations, 'title'),
+            bday: contact.birthday,
+            note: contact.note,
+            // impp: exportIM(contact.ims), TODO: find the moz impp definition
+            // anniversary
+            // sex
+            // genderIdentity
+            // key
+        });
+        
+        request = navigator.mozContacts.save(moz);
+        request.onsuccess = success;
+        request.onerror = errorCB;                
     }
 }   
 
 module.exports = {
-    saveContact: saveContact,
-    cleanup: function(){}
+    save: saveContacts,
+    remove: function(){},
+    search: function(){},
 };    
     
 require("cordova/firefoxos/commandProxy").add("Contacts", module.exports); 


Mime
View raw message