cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pplaque...@apache.org
Subject [12/21] js commit: [Tizen, Tizen SDK 2.0 (Magnolia)] - Contacts API
Date Fri, 17 May 2013 14:22:22 GMT
[Tizen, Tizen SDK 2.0 (Magnolia)] - Contacts API

Adapt the conversion functions both ways
 - cordova to tizen contact object
 - tizen to cordova contact objects

On the tizen side
 -"categories" were removed
 -Several fields were renamed
 -"isdefault" fields were added to mark as favorite (previously it was a 'pref' in a types
array
  (ContactPhoneAddress, ContactEmailAddress, ContactAddress)
 -"organization" was replaced by an array of "organizations"
 -"note" became "notes"
 - the addressbookId was added in the Contact object, so we can get the container address
book rather that hoping, or guessing, finding it in several address books when there are several
address book on a device or reducing to the default address book
 - ContactName object is now having a suffix that can be mapped to cordova contact name object
suffix


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/717ca76d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/717ca76d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/717ca76d

Branch: refs/heads/master
Commit: 717ca76dabd039e3b4021072f6cfcad6948dffe5
Parents: 92eb8d3
Author: pplaquette <pplaquette@apache.org>
Authored: Thu Apr 18 13:43:51 2013 +0200
Committer: pplaquette <pplaquette@apache.org>
Committed: Fri Apr 19 11:07:14 2013 +0200

----------------------------------------------------------------------
 lib/tizen/plugin/tizen/Contact.js      |  136 ++++++++++++++++-----------
 lib/tizen/plugin/tizen/ContactUtils.js |  112 ++++++++--------------
 2 files changed, 125 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/717ca76d/lib/tizen/plugin/tizen/Contact.js
----------------------------------------------------------------------
diff --git a/lib/tizen/plugin/tizen/Contact.js b/lib/tizen/plugin/tizen/Contact.js
index 45c3762..466cc1a 100644
--- a/lib/tizen/plugin/tizen/Contact.js
+++ b/lib/tizen/plugin/tizen/Contact.js
@@ -62,20 +62,30 @@ var findByUniqueId = function(id) {
 
 var traceTizenContact = function (tizenContact) {
     console.log("cordova/plugin/tizen/Contact/  tizenContact.id " + tizenContact.id);
+    console.log("cordova/plugin/tizen/Contact/  tizenContact.personId " + tizenContact.personId);
    //Tizen 2.0
+    console.log("cordova/plugin/tizen/Contact/  tizenContact.addressBookId " + tizenContact.addressBookId);
 //Tizen 2.0
+
     console.log("cordova/plugin/tizen/Contact/  tizenContact.lastUpdated " + tizenContact.lastUpdated);
+    console.log("cordova/plugin/tizen/Contact/  tizenContact.isFavorite " + tizenContact.isFavorite);
 //Tizen 2.0
+
     console.log("cordova/plugin/tizen/Contact/  tizenContact.name " + tizenContact.name);
-    console.log("cordova/plugin/tizen/Contact/  tizenContact.account " + tizenContact.account);
+
+    //console.log("cordova/plugin/tizen/Contact/  tizenContact.account " + tizenContact.account);
 //Tizen 2.0
+
     console.log("cordova/plugin/tizen/Contact/  tizenContact.addresses " + tizenContact.addresses);
     console.log("cordova/plugin/tizen/Contact/  tizenContact.photoURI " + tizenContact.photoURI);
     console.log("cordova/plugin/tizen/Contact/  tizenContact.phoneNumbers " + tizenContact.phoneNumbers);
     console.log("cordova/plugin/tizen/Contact/  tizenContact.emails " + tizenContact.emails);
     console.log("cordova/plugin/tizen/Contact/  tizenContact.birthday " + tizenContact.birthday);
-    console.log("cordova/plugin/tizen/Contact/  tizenContact.organization " + tizenContact.organization);
+    console.log("cordova/plugin/tizen/Contact/  tizenContact.anniversaries " + tizenContact.anniversaries);
+
+    console.log("cordova/plugin/tizen/Contact/  tizenContact.organizations " + tizenContact.organizations);
     console.log("cordova/plugin/tizen/Contact/  tizenContact.notes " + tizenContact.notes);
-    console.log("cordova/plugin/tizen/Contact/  tizenContact.urls " + tizenContact.isFavorite);
-    console.log("cordova/plugin/tizen/Contact/  tizenContact.isFavorite " + tizenContact.isFavorite);
+    console.log("cordova/plugin/tizen/Contact/  tizenContact.urls " + tizenContact.urls);
     console.log("cordova/plugin/tizen/Contact/  tizenContact.ringtonesURI " + tizenContact.ringtonesURI);
-    console.log("cordova/plugin/tizen/Contact/  tizenContact.categories " + tizenContact.categories);
+    console.log("cordova/plugin/tizen/Contact/  tizenContact.groupIds " + tizenContact.groupIds);
   //Tizen 2.0
+
+    //console.log("cordova/plugin/tizen/Contact/  tizenContact.categories " + tizenContact.categories);
 //Tizen 2.0
 };
 
 
@@ -174,6 +184,16 @@ var saveToDevice = function(contact) {
                 tizenContact.name.prefix = contact.name.honorificPrefix;
             }
         }
+
+        //Tizen 2.0
+        if (contact.name.honorificSuffix) {
+            if (tizenContact.name === null) {
+                tizenContact.name = new tizen.ContactName();
+            }
+            if (tizenContact.name !== null) {
+                tizenContact.name.suffix = contact.name.honorificSuffix;
+            }
+        }
     }
 
     // nickname
@@ -193,18 +213,18 @@ var saveToDevice = function(contact) {
         tizenContact.name.nicknames = [];
     }
 
-    // note
+    // notes - Tizen 2.0 (was note)
     if (contact.note !== null) {
-        if (tizenContact.note === null) {
-            tizenContact.note = [];
+        if (tizenContact.notes === null) {
+            tizenContact.notes = [];
         }
-        if (tizenContact.note !== null) {
-            tizenContact.note[0] = contact.note;
+        if (tizenContact.notes !== null) {
+            tizenContact.notes[0] = contact.note;
         }
     }
 
     // photos
-    if (contact.photos && utils.isArray(contact.emails) && contact.emails.length
> 0) {
+    if (contact.photos && utils.isArray(contact.photos) && contact.photos.length
> 0) {
         tizenContact.photoURI = contact.photos[0];
     }
 
@@ -217,7 +237,7 @@ var saveToDevice = function(contact) {
         }
     }
 
-    // Tizen supports many addresses
+    // Tizen supports many email addresses
     if (utils.isArray(contact.emails)) {
 
         // if this is an update, re initialize email addresses
@@ -232,15 +252,12 @@ var saveToDevice = function(contact) {
 
             emailTypes.push (contact.emails[i].type);
 
-            if (contact.emails[i].pref) {
-                emailTypes.push ("PREF");
-            }
-
             emails.push(
                 new tizen.ContactEmailAddress(
                     contact.emails[i].value,
-                    emailTypes)
-            );
+                    emailTypes,
+                    contact.emails[i].pref));    //Tizen 2.0
+
         }
         tizenContact.emails = emails.length > 0 ? emails : [];
     }
@@ -259,26 +276,25 @@ var saveToDevice = function(contact) {
 
         for (i = 0; i < contact.phoneNumbers.length; i += 1) {
 
-            if (!contact.phoneNumbers[i] || !contact.phoneNumbers[i].value) {
+            if (!contact.phoneNumbers[i]) {
                 continue;
             }
 
-             var phoneTypes = [];
-             phoneTypes.push (contact.phoneNumbers[i].type);
+            var phoneTypes = [];
+            phoneTypes.push (contact.phoneNumbers[i].type);
 
-             if (contact.phoneNumbers[i].pref) {
-                 phoneTypes.push ("PREF");
-             }
 
             phoneNumbers.push(
                 new tizen.ContactPhoneNumber(
                     contact.phoneNumbers[i].value,
-                    phoneTypes)
+                    phoneTypes,
+                    contact.phoneNumbers[i].pref)    //Tizen 2.0
             );
         }
 
         tizenContact.phoneNumbers = phoneNumbers.length > 0 ? phoneNumbers : [];
-    } else {
+    }
+    else {
         tizenContact.phoneNumbers = [];
     }
 
@@ -293,17 +309,13 @@ var saveToDevice = function(contact) {
         for ( i = 0; i < contact.addresses.length; i += 1) {
             address = contact.addresses[i];
 
-            if (!address || address.id === undefined || address.pref === undefined || address.type
=== undefined || address.formatted === undefined) {
+            if (!address) {
                 continue;
             }
 
             var addressTypes = [];
             addressTypes.push (address.type);
 
-            if (address.pref) {
-                addressTypes.push ("PREF");
-            }
-
             addresses.push(
                 new tizen.ContactAddress({
                          country:                   address.country,
@@ -312,17 +324,19 @@ var saveToDevice = function(contact) {
                          streetAddress:             address.streetAddress,
                          additionalInformation:     "",
                          postalCode:                address.postalCode,
+                         isDefault:                    address.pref, //Tizen 2.0
                          types :                    addressTypes
                 }));
 
         }
         tizenContact.addresses = addresses.length > 0 ? addresses : [];
 
-    } else{
+    }
+    else{
         tizenContact.addresses = [];
     }
 
-    // copy first url found to BlackBerry 'webpage' field
+    // copy first url found to cordova 'urls' field
     if (utils.isArray(contact.urls)) {
         // if this is an update, re-initialize web page
         if (update) {
@@ -341,22 +355,41 @@ var saveToDevice = function(contact) {
             urls.push( new tizen.ContactWebSite(url.value, url.type));
         }
         tizenContact.urls = urls.length > 0 ? urls : [];
-    } else{
+    }
+    else{
         tizenContact.urls = [];
     }
 
-    if (utils.isArray(contact.organizations && contact.organizations.length >
0) ) {
-        // if this is an update, re-initialize org attributes
-        var organization = contact.organizations[0];
-
-         tizenContact.organization = new tizen.ContacOrganization({
-             name:          organization.name,
-             department:    organization.department,
-             office:        "",
-             title:         organization.title,
-             role:          "",
-             logoURI:       ""
-         });
+    if (utils.isArray(contact.organizations) && contact.organizations.length >
0 ) {
+         // if this is an update, re-initialize addresses
+        if (update) {
+        }
+
+        var organizations = [],
+            organization = null;
+
+        for ( i = 0; i < contact.organizations.length; i += 1) {
+            organization = contact.organizations[i];
+
+            if (!organization) {
+                continue;
+            }
+
+            organizations.push(
+                new tizen.ContactOrganization({
+                    name:          organization.name,
+                    department:    organization.department,
+                    title:         organization.title,
+                    role:          "",
+                    logoURI:       ""
+                }));
+
+        }
+        tizenContact.organizations = organizations.length > 0 ? organizations : [];
+
+    }
+    else{
+        tizenContact.organizations = [];
     }
 
     // categories
@@ -408,7 +441,6 @@ var createTizenAddress = function(address) {
         return null;
     }
 
-
     var tizenAddress = new tizen.ContactAddress();
 
     if (tizenAddress === null) {
@@ -417,15 +449,12 @@ var createTizenAddress = function(address) {
 
     typesAr.push(address.type);
 
-    if (address.pref) {
-        typesAr.push("PREF");
-    }
-
     tizenAddress.country = address.country || "";
     tizenAddress.region = address.region || "";
     tizenAddress.city = address.locality || "";
     tizenAddress.streetAddress = address.streetAddress || "";
     tizenAddress.postalCode = address.postalCode || "";
+    tizenAddress.isDefault = address.pref || false;   //Tizen SDK 2.0
     tizenAddress.types = typesAr || "";
 
     return tizenAddress;
@@ -482,11 +511,12 @@ module.exports = {
                 tizenContact = findByUniqueId(this.id);
             }
 
-
             // if contact was found, remove it
             if (tizenContact) {
+                //var addressBook =  tizen.contact.getDefaultAddressBook();
+                var addressBook =  tizen.contact.getAddressBook(tizenContact.addressBookId);
  //Tizen SDk 2.0
 
-                tizen.contact.getDefaultAddressBook().remove(tizenContact.id);
+                addressBook.remove(tizenContact.id);
 
                 if (typeof success === 'function') {
                     successCB(this);

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/717ca76d/lib/tizen/plugin/tizen/ContactUtils.js
----------------------------------------------------------------------
diff --git a/lib/tizen/plugin/tizen/ContactUtils.js b/lib/tizen/plugin/tizen/ContactUtils.js
index de1c7aa..ca81a15 100644
--- a/lib/tizen/plugin/tizen/ContactUtils.js
+++ b/lib/tizen/plugin/tizen/ContactUtils.js
@@ -47,11 +47,10 @@ var fieldMappings = {
     "phoneNumbers" : ["phoneNumbers.number","phoneNumbers.types"],
     "emails" : ["emails.types", "emails.email"],
     "addresses" : ["addresses.country","addresses.region","addresses.city","addresses.streetAddress","addresses.postalCode","addresses.country","addresses.types"],
-    "organizations" : ["organization.name","organization.department","organization.office",
"organization.title"],
+    "organizations" : ["organizations.name","organizations.department","organizations.office",
"organizations.title"],
     "birthday" : ["birthday"],
     "note" : ["notes"],
     "photos" : ["photoURI"],
-    "categories" : ["categories"],
     "urls" : ["urls.url", "urls.type"]
 };
 
@@ -82,14 +81,17 @@ var createContactAddress = function(type, tizenAddress) {
         return null;
     }
 
+    var isDefault = tizenAddress.isDefault;            //Tizen 2.0
     var streetAddress = tizenAddress.streetAddress;
     var locality = tizenAddress.city || "";
     var region = tizenAddress.region || "";
     var postalCode = tizenAddress.postalCode || "";
     var country = tizenAddress.country || "";
+
+    //TODO improve formatted
     var formatted = streetAddress + ", " + locality + ", " + region + ", " + postalCode +
", " + country;
 
-    var contact = new ContactAddress(null, type, formatted, streetAddress, locality, region,
postalCode, country);
+    var contact = new ContactAddress(isDefault, type, formatted, streetAddress, locality,
region, postalCode, country);
 
     return contact;
 };
@@ -170,7 +172,6 @@ module.exports = {
     },
 
 
-
     /**
      * Creates a Contact object from a Tizen Contact object, copying only
      * the fields specified.
@@ -200,7 +201,8 @@ module.exports = {
         // nothing to do
         if (!fields || !(utils.isArray(fields)) || fields.length === 0) {
             return contact;
-        } else if (fields.length === 1 && fields[0] === "*") {
+        }
+        else if (fields.length === 1 && fields[0] === "*") {
             // Cordova enhancement to allow fields value of ["*"] to indicate
             // all supported fields.
             fields = allFields;
@@ -218,7 +220,6 @@ module.exports = {
 
             // name
             if (field.indexOf('name') === 0) {
-
                 var formattedName = (tizenContact.name.prefix || "");
 
                 if (tizenContact.name.firstName) {
@@ -236,67 +237,64 @@ module.exports = {
                     formattedName += (tizenContact.name.lastName || "");
                 }
 
+                //Tizen 2.0
+                if (tizenContact.name.suffix) {
+                    formattedName += ' ';
+                    formattedName += (tizenContact.name.suffix || "");
+                }
+
                 contact.name = new ContactName(
                         formattedName,
                         tizenContact.name.lastName,
                         tizenContact.name.firstName,
                         tizenContact.name.middleName,
                         tizenContact.name.prefix,
-                        null);
+                        tizenContact.name.suffix);
             }
-
-            // phoneNumbers
+            // phoneNumbers - Tizen 2.0
             else if (field.indexOf('phoneNumbers') === 0) {
-
                 var phoneNumbers = [];
 
                 for (index = 0 ; index < tizenContact.phoneNumbers.length ; ++index) {
-
                     phoneNumbers.push(
-                            new ContactField(
-                                    'PHONE',
-                                    tizenContact.phoneNumbers[index].number,
-                                    ((tizenContact.phoneNumbers[index].types[1]) &&
 (tizenContact.emails[index].types[1] === "PREF") ) ? true : false));
+                        new ContactField(
+                            'PHONE',
+                            tizenContact.phoneNumbers[index].number,
+                            tizenContact.phoneNumbers[index].isDefault));
                 }
-
-
                 contact.phoneNumbers = phoneNumbers.length > 0 ? phoneNumbers : null;
             }
 
-            // emails
+            // emails - Tizen 2.0
             else if (field.indexOf('emails') === 0) {
-
                 var emails = [];
 
                 for (index = 0 ; index < tizenContact.emails.length ; ++index) {
-
                     emails.push(
                         new ContactField(
                             'EMAILS',
                             tizenContact.emails[index].email,
-                            ((tizenContact.emails[index].types[1]) &&  (tizenContact.emails[index].types[1]
=== "PREF") ) ? true : false));
+                            tizenContact.emails[index].isDefault));
                 }
                 contact.emails = emails.length > 0 ? emails : null;
             }
 
-            // addresses
+            // addresses Tizen 2.0
             else if (field.indexOf('addresses') === 0) {
-
                 var addresses = [];
+                
                 for (index = 0 ; index < tizenContact.addresses.length ; ++index) {
-
                     addresses.push(
-                            new ContactAddress(
-                                    ((tizenContact.addresses[index].types[1] && 
tizenContact.addresses[index].types[1] === "PREF") ? true : false),
-                                    tizenContact.addresses[index].types[0] ? tizenContact.addresses[index].types[0]
: "HOME",
-                                    null,
-                                    tizenContact.addresses[index].streetAddress,
-                                    tizenContact.addresses[index].city,
-                                    tizenContact.addresses[index].region,
-                                    tizenContact.addresses[index].postalCode,
-                                    tizenContact.addresses[index].country ));
+                         new ContactAddress(
+                            tizenContact.addresses[index].isDefault,
+                            tizenContact.addresses[index].types[0] ? tizenContact.addresses[index].types[0]
: "HOME",
+                            null,
+                            tizenContact.addresses[index].streetAddress,
+                            tizenContact.addresses[index].city,
+                            tizenContact.addresses[index].region,
+                            tizenContact.addresses[index].postalCode,
+                            tizenContact.addresses[index].country ));
                 }
-
                 contact.addresses = addresses.length > 0 ? addresses : null;
             }
 
@@ -307,52 +305,28 @@ module.exports = {
                 }
             }
 
-            // note only one in Tizen Contact
+            // note only one in Tizen Contact -Tizen 2.0
             else if (field.indexOf('note') === 0) {
-                if (tizenContact.note) {
-                    contact.note = tizenContact.note[0];
+                if (tizenContact.notes) {
+                    contact.note = tizenContact.notes[0];
                 }
             }
-
-            // organizations
+            // organizations Tizen 2.0
             else if (field.indexOf('organizations') === 0) {
-
                 var organizations = [];
-
-                // there's only one organization in a Tizen Address
-
-                if (tizenContact.organization) {
+                
+                for (index = 0 ; index < tizenContact.organizations.length ; ++index)
{
                     organizations.push(
                             new ContactOrganization(
-                                    true,
+                                    (index === 0),
                                     'WORK',
-                                    tizenContact.organization.name,
-                                    tizenContact.organization.department,
-                                    tizenContact.organization.jobTitle));
+                                    tizenContact.organizations.name,
+                                    tizenContact.organizations.department,
+                                    tizenContact.organizations.jobTitle));
                 }
-
                 contact.organizations = organizations.length > 0 ? organizations : null;
             }
 
-            // categories
-            else if (field.indexOf('categories') === 0) {
-
-                var categories = [];
-
-                if (tizenContact.categories) {
-
-                    for (index = 0 ; index < tizenContact.categories.length ; ++index)
{
-                        categories.push(
-                                new ContactField(
-                                        'MAIN',
-                                        tizenContact.categories,
-                                        (index === 0) ));
-                    }
-
-                    contact.categories = categories.length > 0 ? categories : null;
-                }
-            }
-
             // urls
             else if (field.indexOf('urls') === 0) {
                 var urls = [];
@@ -366,7 +340,6 @@ module.exports = {
                                         (index === 0)));
                     }
                 }
-
                 contact.urls = urls.length > 0 ? urls : null;
             }
 
@@ -377,7 +350,6 @@ module.exports = {
                 if (tizenContact.photoURI) {
                     photos.push(new ContactField('URI', tizenContact.photoURI, true));
                 }
-
                 contact.photos = photos.length > 0 ? photos : null;
             }
         }


Mime
View raw message