You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by he...@apache.org on 2014/01/09 21:10:52 UTC

[17/21] git commit: added organizations and categories

added organizations and categories


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

Branch: refs/heads/master
Commit: e43a1a9f3782598737b575e4dacadd883ab62449
Parents: 0beadd2
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Thu Dec 19 15:56:29 2013 +0100
Committer: Piotr Zalewa <pi...@zalewa.info>
Committed: Thu Dec 19 15:56:29 2013 +0100

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


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/e43a1a9f/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 62dc6dd..6d06a13 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -163,6 +163,15 @@ Contact.prototype.updateFromMozilla = function(moz) {
         return contactFields;
     }
 
+    function makeContactFieldFromArray(data) {
+        var contactFields = [];
+        for (var i=0; i < data.length; i++) {
+            var itemData = new ContactField(null, data[i]);
+            contactFields.push(itemData);
+        }
+        return contactFields;
+    }
+
     function exportAddresses(addresses) {
         // TODO: check moz address format
         var arr = [];
@@ -183,6 +192,18 @@ Contact.prototype.updateFromMozilla = function(moz) {
         return arr;
     } 
 
+    function createOrganizations(orgs, jobs) {
+        orgs = (orgs) ? orgs : [];
+        jobs = (jobs) ? jobs : [];
+        var max_length = Math.max(orgs.length, jobs.length);
+        var organizations = [];
+        for (var i=0; i < max_length; i++) {
+            organizations.push(new ContactOrganization(
+                  null, null, orgs[i] || null, null, jobs[i] || null));
+        }
+        return organizations;
+    }
+
 
     if (moz.id) {
         this.id = moz.id;
@@ -214,6 +235,9 @@ Contact.prototype.updateFromMozilla = function(moz) {
         this.emails = exportContactField(moz.email);
     }
     // categories
+    if (moz.category) {
+        this.categories = makeContactFieldFromArray(moz.category);
+    }
 
     // addresses
     if (moz.adr) {
@@ -229,6 +253,9 @@ Contact.prototype.updateFromMozilla = function(moz) {
       this.birthday = Date.parse(moz.bday);
     }
     // organizations
+    if (moz.org || moz.jobTitle) {
+        this.organizations = createOrganizations(moz.org, moz.jobTitle);
+    }
 }