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:37 UTC

[01/28] git commit: CB-5188:

Updated Branches:
  refs/heads/master c8a1c7b6b -> d610c8641


CB-5188:


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

Branch: refs/heads/master
Commit: 653f959943d461719546ffcaed797156749750d2
Parents: c8a1c7b
Author: Steven Gill <st...@gmail.com>
Authored: Mon Oct 28 12:27:13 2013 -0700
Committer: Steven Gill <st...@gmail.com>
Committed: Mon Oct 28 12:27:13 2013 -0700

----------------------------------------------------------------------
 plugin.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/653f9599/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 8c0f5a6..8b95183 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -4,7 +4,7 @@
     xmlns:rim="http://www.blackberry.com/ns/widgets"
     xmlns:android="http://schemas.android.com/apk/res/android"
     id="org.apache.cordova.contacts"
-    version="0.2.5">
+    version="0.2.6-dev">
 
     <name>Contacts</name>
     <description>Cordova Contacts Plugin</description>


[21/28] git commit: docs added

Posted by st...@apache.org.
docs added


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

Branch: refs/heads/master
Commit: 3a65011d6411b08ae9313ec8a0eb5cf545fd7b4f
Parents: 334080a
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Thu Nov 28 14:42:50 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:32:27 2013 -0800

----------------------------------------------------------------------
 README.md | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/3a65011d/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 22112eb..2c42361 100644
--- a/README.md
+++ b/README.md
@@ -3,3 +3,12 @@ cordova-plugin-contacts
 To install this plugin, follow the [Command-line Interface Guide](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
 
 If you are not using the Cordova Command-line Interface, follow [Using Plugman to Manage Plugins](http://cordova.apache.org/docs/en/edge/plugin_ref_plugman.md.html).
+
+## Using Contacts in Firefox OS
+
+Edit manifest.webapp and add permissions field as described in [Manifest Docs](https://developer.mozilla.org/en-US/Apps/Developing/Manifest#permissions).
+There is also a need to change the webapp type to "privileged"  - [Manifest Docs](https://developer.mozilla.org/en-US/Apps/Developing/Manifest#type).
+All privileged apps enforce [Content Security Policy](https://developer.mozilla.org/en-US/Apps/CSP) which forbids inline script. Initialize your application in another way (i.e. start it on document load in index.js)
+
+    document.onload = app.initialize;
+


[16/28] git commit: add/remove working

Posted by st...@apache.org.
add/remove working


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

Branch: refs/heads/master
Commit: 144d69af5a806abd3932b8f56094f490e5d9765b
Parents: 0f7ff41
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Fri Nov 15 13:44:21 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:28:35 2013 -0800

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 55 +++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/144d69af/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index c2ac0fd..bc5d871 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -25,20 +25,19 @@
 // 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 saveContacts(successCB, errorCB, contacts) {
-    // success and fail will be called every time a contact is saved
+    // success and/or fail will be called every time a contact is saved
+
     // a closure which is holding the object to be returned to sucessCB
     function makeSuccess(contact, moz) {
         return function(result) {
             // TODO modify contact so it will contain the link to moz
+            contact.id = moz.id;
             // call callback
             successCB(contact);
         }
     }
-    function error(e) {
-        console.log('BOO from moz');
-        errorCB(e);
-    }
         
     function exportContactFieldArray(contactFieldArray, key) {
         if (!key) {
@@ -73,11 +72,12 @@ function saveContacts(successCB, errorCB, contacts) {
     } 
     var i=0;
     var contact;
-
     while(contact = contacts[i++]){
-        var request;
         // prepare mozContact object
-        var translatedContact = {};
+        var moz = new mozContact();
+        if (contact.id) {
+            moz.id = contact.id;
+        }
         // building name
         var nameArray = [];
         var fields = ['honorificPrefix', 'familyName', 'givenName', 'middleName', 'nickname'];
@@ -86,32 +86,32 @@ function saveContacts(successCB, errorCB, contacts) {
                 nameArray.push(contact.name[field]);
             }
         }
-        translatedContact.name = nameArray.join(' ');
+        moz.name = nameArray.join(' ');
         // adding simple fields [contactField, eventualMozContactField]
         var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
             ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note']];
         j = 0; while(field = simpleFields[j++]) {
           if (contact.name[field[0]]) {
-            translatedContact[field[1] || field[0]] = contact.name[field[0]];
+            moz[field[1] || field[0]] = contact.name[field[0]];
           }
         }
         if (contact.emails) {
-            translatedContact.email = exportContactFieldArray(contact.emails);
+            moz.email = exportContactFieldArray(contact.emails);
         }
         if (contact.categories) {
-            translatedContact.category = exportContactFieldArray(contact.categories);
+            moz.category = exportContactFieldArray(contact.categories);
         }
         if (contact.addresses) {
-            translatedContact.adr = exportAddress(contact.addresses);
+            moz.adr = exportAddress(contact.addresses);
         }
         if (contact.phoneNumbers) {
-            translatedContact.tel = exportContactFieldArray(contact.phoneNumbers);
+            moz.tel = exportContactFieldArray(contact.phoneNumbers);
         }
         if (contact.organizations) {
-            translatedContact.org = exportContactFieldArray(contact.organizations, 'name');
-            translatedContact.jobTitle = exportContactFieldArray(contact.organizations, 'title');
+            moz.org = exportContactFieldArray(contact.organizations, 'name');
+            moz.jobTitle = exportContactFieldArray(contact.organizations, 'title');
         }
-        /* 
+        /*  Find out how to translate these parameters
             // photo: Blob
             // url: Array with metadata (?)
             // impp: exportIM(contact.ims), TODO: find the moz impp definition
@@ -119,19 +119,28 @@ 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);
-        request = navigator.mozContacts.save(moz);
+        var request = navigator.mozContacts.save(moz);
         request.onsuccess = makeSuccess(contact, moz);
-        request.onerror = error;                
+        request.onerror = errorCB;                
     }
 }   
 
+function remove(successCB, errorCB, ids) {
+    var i=0;
+    var id;
+    while(id = ids[i++]){
+        var moz = new mozContact();
+        moz.id = id;
+        var request = navigator.mozContacts.remove(moz);
+        request.onsuccess = successCB;
+        request.onerror = errorCB;
+    }
+}
+
 module.exports = {
     save: saveContacts,
-    remove: function(){},
+    remove: remove,
     search: function(){},
 };    
     


[10/28] git commit: [ubuntu] specify policy_group

Posted by st...@apache.org.
[ubuntu] specify policy_group


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

Branch: refs/heads/master
Commit: 00e94efe155f0ebdc2895885bcbb41af77d70c11
Parents: 47a9230
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Mon Nov 11 18:00:09 2013 +0400
Committer: Steven Gill <st...@gmail.com>
Committed: Mon Dec 2 15:44:38 2013 -0800

----------------------------------------------------------------------
 plugin.xml | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/00e94efe/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 304f04b..3ea3b6a 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -88,6 +88,11 @@
     
     <!-- ubuntu -->
     <platform name="ubuntu">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Camera">
+                <param policy_group="contacts" policy_version="1" />
+            </feature>
+        </config-file>
         <header-file src="src/ubuntu/contacts.h" />
         <source-file src="src/ubuntu/contacts.cpp" />
     </platform>


[27/28] git commit: Fix bad commit/merge

Posted by st...@apache.org.
Fix bad commit/merge


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

Branch: refs/heads/master
Commit: b9c995405831fb57fe37c67d2f7cfdc19ca5e937
Parents: 5e8f1cc
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Dec 4 11:15:11 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Dec 4 11:15:11 2013 -0800

----------------------------------------------------------------------
 src/wp/Contacts.cs | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/b9c99540/src/wp/Contacts.cs
----------------------------------------------------------------------
diff --git a/src/wp/Contacts.cs b/src/wp/Contacts.cs
index 50e4e08..5ae2144 100644
--- a/src/wp/Contacts.cs
+++ b/src/wp/Contacts.cs
@@ -675,11 +675,19 @@ namespace WPCordovaClassLib.Cordova.Commands
                                                EscapeJson(con.Notes.FirstOrDefault()),
                                                EscapeJson(Convert.ToString(con.Birthdays.FirstOrDefault())));
 
-            //Debug.WriteLine("jsonContact = " + jsonContact);
-            // JSON requires new line characters be escaped
+            return "{" + jsonContact + "}";
 
-            return "{" + jsonContact.Replace("\n", "\\n").Replace("\r","") + "}";
+        }
+
+        
+        private static string EscapeJson(string str)
+        {
+            if (String.IsNullOrEmpty(str))
+            {
+                return str;
+            }
 
+            return str.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t").Replace("\"", "\\\"").Replace("&", "\\&");
         }
     }
 }


[23/28] git commit: CB-3035 Fix issue with windows new line char \n\r

Posted by st...@apache.org.
CB-3035 Fix issue with windows new line char \n\r


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

Branch: refs/heads/master
Commit: 72e97f3078c1dc27aadb0d40efff192dc399bd66
Parents: 148774d
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Dec 2 14:02:15 2013 -0800
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:32:27 2013 -0800

----------------------------------------------------------------------
 src/wp/Contacts.cs | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/72e97f30/src/wp/Contacts.cs
----------------------------------------------------------------------
diff --git a/src/wp/Contacts.cs b/src/wp/Contacts.cs
index 8d35011..50e4e08 100644
--- a/src/wp/Contacts.cs
+++ b/src/wp/Contacts.cs
@@ -677,17 +677,9 @@ namespace WPCordovaClassLib.Cordova.Commands
 
             //Debug.WriteLine("jsonContact = " + jsonContact);
             // JSON requires new line characters be escaped
-            return "{" + jsonContact + "}";
-        }
 
-        private static string EscapeJson(string str)
-        {
-            if (String.IsNullOrEmpty(str))
-            {
-                return str;
-            }
+            return "{" + jsonContact.Replace("\n", "\\n").Replace("\r","") + "}";
 
-            return str.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t").Replace("\"", "\\\"").Replace("&", "\\&");
         }
     }
 }


[06/28] git commit: Merge branch 'dev' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts into dev

Posted by st...@apache.org.
Merge branch 'dev' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts into dev


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

Branch: refs/heads/master
Commit: bdcf090d0c63b2f811aa6f73748818a7676d01e4
Parents: 6138b8f acb6147
Author: purplecabbage <pu...@gmail.com>
Authored: Mon Nov 4 18:01:39 2013 -0800
Committer: purplecabbage <pu...@gmail.com>
Committed: Mon Nov 4 18:01:39 2013 -0800

----------------------------------------------------------------------
 plugin.xml                  |  6 +++---
 src/blackberry10/plugin.xml | 41 ----------------------------------------
 2 files changed, 3 insertions(+), 44 deletions(-)
----------------------------------------------------------------------



[03/28] git commit: CB-5198 [BlackBerry10] Update dependencies to point to registry

Posted by st...@apache.org.
CB-5198 [BlackBerry10] Update dependencies to point to registry


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

Branch: refs/heads/master
Commit: acb6147b4a85d9d018186e422d2d3b1f08333e89
Parents: 653f959
Author: Bryan Higgins <br...@bryanhiggins.net>
Authored: Wed Oct 30 12:25:55 2013 -0400
Committer: Bryan Higgins <br...@bryanhiggins.net>
Committed: Wed Oct 30 12:28:31 2013 -0400

----------------------------------------------------------------------
 plugin.xml                  |  4 ++--
 src/blackberry10/plugin.xml | 41 ----------------------------------------
 2 files changed, 2 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/acb6147b/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 8b95183..f1de200 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -113,8 +113,8 @@
         <source-file src="src/blackberry10/ContactOrganization.js" target-dir="Contacts"></source-file>
         <source-file src="src/blackberry10/ContactPhoto.js" target-dir="Contacts"></source-file>
         <source-file src="src/blackberry10/contactUtils.js" target-dir="Contacts"></source-file>
-        <dependency id="com.blackberry.utils" url="https://github.com/blackberry/cordova-blackberry-plugins.git" commit="plugins" subdir="plugin/com.blackberry.utils"/>
-        <dependency id="org.apache.cordova.blackberry10.pimlib" url="https://github.com/blackberry/cordova-blackberry-plugins.git" commit="plugins" subdir="/plugin/org.apache.cordova.blackberry10.pimlib/"/>
+        <dependency id="com.blackberry.utils" />
+        <dependency id="com.blackberry.pim.lib" />
     </platform>
 
     <!-- wp7 -->

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/acb6147b/src/blackberry10/plugin.xml
----------------------------------------------------------------------
diff --git a/src/blackberry10/plugin.xml b/src/blackberry10/plugin.xml
deleted file mode 100644
index 58b7f2b..0000000
--- a/src/blackberry10/plugin.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
-  software distributed under the License is distributed on an
-   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-     specific language governing permissions and limitations
-      under the License.
-
--->
-
-<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
-    id="org.apache.cordova.Contacts"
-    version="0.0.1">
-
-    <name>Contacts</name>
-
-    <platform name="blackberry10">
-        <config-file target="www/config.xml" parent="/widget">
-            <feature name="Contacts" value="Contacts"/>
-        </config-file>
-        <source-file src="src/blackberry10/index.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactActivity.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactAddress.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/contactConsts.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactError.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactField.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactFindOptions.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactName.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactNews.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactOrganization.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/ContactPhoto.js" target-dir="Contacts"></source-file>
-        <source-file src="src/blackberry10/contactUtils.js" target-dir="Contacts"></source-file>
-      </platform>
-</plugin>


[19/28] git commit: search added - no idea if this is working

Posted by st...@apache.org.
search added - no idea if this is working


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

Branch: refs/heads/master
Commit: 08e6dabf53a29247e61447091d5f721ec47c2f04
Parents: f10f666
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Tue Nov 26 16:36:36 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:28:36 2013 -0800

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 121 ++++++++++++++++++++++++++++++------
 1 file changed, 101 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/08e6dabf/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 0f0f0c9..cc8f9c1 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -29,6 +29,8 @@
 
 var Contact = require('./Contact');
 var ContactField = require('./ContactField');
+var ContactName = require('./ContactName');
+
 
 function createMozillaFromCordova(contact) {
     function exportContactFieldArray(contactFieldArray, key) {
@@ -36,7 +38,7 @@ function createMozillaFromCordova(contact) {
             key = 'value';
         }                 
         var arr = [];
-        for (var i in contactFieldArray) {
+        for (var i=0; i < contactFieldArray.length; i++) {
             arr.push(contactFieldArray[i][key]);
         };                                       
         return arr;
@@ -46,7 +48,7 @@ function createMozillaFromCordova(contact) {
         // TODO: check moz address format
         var arr = [];
         
-        for (var i in addresses) {
+        for (var i=0; i < addresses.length; i++) {
             var addr = {};
             for (var key in addresses[i]) {
                 addr[key] = addresses[i][key];    
@@ -58,7 +60,7 @@ function createMozillaFromCordova(contact) {
 
     function exportPhoneNumbers(phoneNumbers) {
         var mozNumbers = [];
-        for (var i in phoneNumbers) {
+        for (var i=0; i < phoneNumbers.length; i++) {
             var number = phoneNumbers[i];
             mozNumbers.push({
                 type: number.type,
@@ -74,18 +76,10 @@ function createMozillaFromCordova(contact) {
     if (contact.id) {
         moz.id = contact.id;
     }
-    // building name
-    var nameArray = [];
-    var fields = ['honorificPrefix', 'familyName', 'givenName', 'middleName', 'nickname'];
-    var j = 0, field; while(field = fields[j++]) {
-        if (contact.name[field]) {
-            nameArray.push(contact.name[field]);
-        }
-    }
-    moz.name = nameArray.join(' ');
     // adding simple fields [contactField, eventualMozContactField]
     var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
-        ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note']];
+        ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note'],
+        ['displayName', 'name']];
     j = 0; while(field = simpleFields[j++]) {
       if (contact.name[field[0]]) {
         moz[field[1] || field[0]] = contact.name[field[0]];
@@ -122,7 +116,7 @@ function createMozillaFromCordova(contact) {
 function createCordovaFromMozilla(moz) {
     function exportPhoneNumbers(mozNumbers) {
         var phoneNumbers = [];
-        for (var i in mozNumbers) {
+        for (var i=0; i < mozNumbers.length; i++) {
             var number = mozNumbers[i];
             phoneNumbers.push(
                 new ContactField( number.type, number.value, number.pref));
@@ -137,12 +131,15 @@ function createCordovaFromMozilla(moz) {
     }
     // adding simple fields [contactField, eventualCordovaContactField]
     var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
-        ['honorificSuffix'], ['nickname'], ['bday', 'birthday'], ['note']];
+        ['honorificSuffix'], ['nickname'], ['bday', 'birthday'], ['note'],
+        ['name', 'displayName']];
+    var name = new ContactName();
     j = 0; while(field = simpleFields[j++]) {
-      if (moz.name[field[0]]) {
-        contact[field[1] || field[0]] = moz.name[field[0]];
+      if (moz[field[0]]) {
+        name[field[1] || field[0]] = moz[field[0]];
       }
     }
+    contact.name = name;
     // emails
     // categories
     // addresses
@@ -176,22 +173,106 @@ function saveContacts(successCB, errorCB, contacts) {
     }
 }   
 
+
 function remove(successCB, errorCB, ids) {
     var i=0;
     var id;
-    while(id = ids[i++]){
+    for (var i=0; i < ids.length; i++){
         var moz = new mozContact();
-        moz.id = id;
+        moz.id = ids[i];
         var request = navigator.mozContacts.remove(moz);
         request.onsuccess = successCB;
         request.onerror = errorCB;
     }
 }
 
+
+var mozContactSearchFields = ['name', 'givenName', 'additionalName', 
+    'familyName', 'nickname', 'email', 'tel', 'jobTitle', 'note'];
+
+function search(successCB, errorCB, params) {
+    var options = params[1] || {}; 
+    var filter = [];
+    // filter out inallowed fields
+    for (var i=0; i < params[0].length; i++) {
+        if (mozContactSearchFields.indexOf([params[0][i]])) {
+            filter.push(params[0][i]);
+        } else if (params[0][i] == 'displayName') {
+            filter.push('name');
+        } else {
+            console.log('FXOS ContactProxy: inallowed field passed to search filtered out: ' + params[0][i]);
+        }
+    }
+
+    var request;
+    // TODO find out how to handle searching by numbers
+    // filterOp: The filter comparison operator to use. Possible values are 
+    //           equals, startsWith, and match, the latter being specific 
+    //           to telephone numbers.
+    var mozOptions = {filterBy: filter, filterOp: 'startsWith'};
+    if (!options.multiple) {
+        mozOptions.filterLimit = 1;
+    }
+    if (!options.filter) {
+        // this is returning 0 contacts
+        request = navigator.mozContacts.getAll({});
+    } else {
+        // XXX This is searching for regardless of the filterValue !!!
+        mozOptions.filterValue = options.filter;
+        console.log('mozoptions: filterBy: ' + mozOptions.filterBy.join(' ') + '; fiterValue: ' + mozOptions.filterValue);
+        request = navigator.mozContacts.find(mozOptions);
+    }
+    request.onsuccess = function() {
+        var contacts = [];
+        var mozContacts = request.result;
+        for (var i=0; i < mozContacts.length; i++) {
+            contacts.push(createCordovaFromMozilla(mozContacts[i]));
+        }
+        successCB(contacts);
+    };
+    request.onerror = errorCB;
+}
+
+
+/* navigator.mozContacts.find has issues - using getAll */
+function hackedSearch(successCB, errorCB, params) {
+    var options = params[1] || {}; 
+    var filter = [];
+    // filter out inallowed fields
+    for (var i=0; i < params[0].length; i++) {
+        if (mozContactSearchFields.indexOf([params[0][i]])) {
+            filter.push(params[0][i]);
+        } else if (params[0][i] == 'displayName') {
+            filter.push('name');
+        } else {
+            console.log('FXOS ContactProxy: inallowed field passed to search filtered out: ' + params[0][i]);
+        }
+    }
+    var getall = navigator.mozContacts.getAll({});
+    getall.onsuccess = function() {
+        var contacts = [];
+        var allContacts = getall.result;
+        for (var i=0; i < allContacts.length; i++) {
+            var mozContact = allContacts[i];
+            var valid = false;
+            for (var j=0; j < filter.length; j++) {
+                if (mozContact[filter[0]].indexOf(options.filter)) {
+                    valid = true;
+                }
+            }
+            if (valid) {
+                contacts.push(createCordovaFromMozilla(mozContact));
+            }
+        }
+        successCB(contacts);
+    };
+    getall.onerror = errorCB;
+}
+
 module.exports = {
     save: saveContacts,
     remove: remove,
-    search: function(){},
+    search: hackedSearch
 };    
     
 require("cordova/firefoxos/commandProxy").add("Contacts", module.exports); 


[26/28] git commit: Merge branch 'dev' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts into dev

Posted by st...@apache.org.
Merge branch 'dev' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts into dev


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

Branch: refs/heads/master
Commit: 5e8f1cc4a295bc54fd33203266184b7c1cf0182d
Parents: 1d4aee1 72e97f3
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Dec 3 14:51:03 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Dec 3 14:51:03 2013 -0800

----------------------------------------------------------------------
 README.md                      |   6 +
 src/firefoxos/ContactsProxy.js | 335 ++++++++++++++++++++++++++++--------
 src/wp/Contacts.cs             |  10 +-
 3 files changed, 271 insertions(+), 80 deletions(-)
----------------------------------------------------------------------



[12/28] git commit: fixed ubuntu policy error

Posted by st...@apache.org.
fixed ubuntu policy 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/7720e9d7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/7720e9d7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/7720e9d7

Branch: refs/heads/master
Commit: 7720e9d70ada386ad3b9a03f1aa045d9e2ec0c4f
Parents: 00e94ef
Author: Steven Gill <st...@gmail.com>
Authored: Mon Dec 2 15:45:16 2013 -0800
Committer: Steven Gill <st...@gmail.com>
Committed: Mon Dec 2 15:45:16 2013 -0800

----------------------------------------------------------------------
 plugin.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/7720e9d7/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 3ea3b6a..6b4cfbe 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -89,7 +89,7 @@
     <!-- ubuntu -->
     <platform name="ubuntu">
         <config-file target="config.xml" parent="/*">
-            <feature name="Camera">
+            <feature name="Contacts">
                 <param policy_group="contacts" policy_version="1" />
             </feature>
         </config-file>


[08/28] git commit: CB-5525 WP8. Contacts Api fails in case of there is special character in contact field

Posted by st...@apache.org.
CB-5525 WP8. Contacts Api fails in case of there is special character in contact field


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

Branch: refs/heads/master
Commit: 85c40309a22911db7f7f33ae1472ed6444e6ebdb
Parents: f815ff9
Author: sgrebnov <se...@gmail.com>
Authored: Mon Dec 2 18:01:01 2013 +0400
Committer: sgrebnov <se...@gmail.com>
Committed: Mon Dec 2 18:01:01 2013 +0400

----------------------------------------------------------------------
 src/wp/Contacts.cs | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/85c40309/src/wp/Contacts.cs
----------------------------------------------------------------------
diff --git a/src/wp/Contacts.cs b/src/wp/Contacts.cs
index d68b0b1..8d35011 100644
--- a/src/wp/Contacts.cs
+++ b/src/wp/Contacts.cs
@@ -549,7 +549,7 @@ namespace WPCordovaClassLib.Cordova.Commands
             {
                 string contactField = string.Format(contactFieldFormat,
                                                     address.Kind.ToString(),
-                                                    address.EmailAddress);
+                                                    EscapeJson(address.EmailAddress));
 
                 retVal += "{" + contactField + "},";
             }
@@ -568,18 +568,18 @@ namespace WPCordovaClassLib.Cordova.Commands
                           "\"postalCode\":\"{6}\"," +
                           "\"country\":\"{7}\"";
 
-            string formattedAddress = address.PhysicalAddress.AddressLine1 + " "
+            string formattedAddress = EscapeJson(address.PhysicalAddress.AddressLine1 + " "
                                     + address.PhysicalAddress.AddressLine2 + " "
                                     + address.PhysicalAddress.City + " "
                                     + address.PhysicalAddress.StateProvince + " "
                                     + address.PhysicalAddress.CountryRegion + " "
-                                    + address.PhysicalAddress.PostalCode;
+                                    + address.PhysicalAddress.PostalCode);
 
             string jsonAddress = string.Format(addressFormatString,
                                                isPrefered ? "\"true\"" : "\"false\"",
                                                address.Kind.ToString(),
                                                formattedAddress,
-                                               address.PhysicalAddress.AddressLine1 + " " + address.PhysicalAddress.AddressLine2,
+                                               EscapeJson(address.PhysicalAddress.AddressLine1 + " " + address.PhysicalAddress.AddressLine2),
                                                address.PhysicalAddress.City,
                                                address.PhysicalAddress.StateProvince,
                                                address.PhysicalAddress.PostalCode,
@@ -607,7 +607,7 @@ namespace WPCordovaClassLib.Cordova.Commands
             string retVal = "";
             foreach (string website in con.Websites)
             {
-                retVal += "\"" + website + "\",";
+                retVal += "\"" + EscapeJson(website) + "\",";
             }
             return retVal.TrimEnd(',');
         }
@@ -633,12 +633,12 @@ namespace WPCordovaClassLib.Cordova.Commands
             if (con.CompleteName != null)
             {
                 retVal = string.Format(formatStr,
-                                   con.CompleteName.FirstName + " " + con.CompleteName.LastName, // TODO: does this need suffix? middlename?
-                                   con.CompleteName.LastName,
-                                   con.CompleteName.FirstName,
-                                   con.CompleteName.MiddleName,
-                                   con.CompleteName.Title,
-                                   con.CompleteName.Suffix);
+                                   EscapeJson(con.CompleteName.FirstName + " " + con.CompleteName.LastName), // TODO: does this need suffix? middlename?
+                                   EscapeJson(con.CompleteName.LastName),
+                                   EscapeJson(con.CompleteName.FirstName),
+                                   EscapeJson(con.CompleteName.MiddleName),
+                                   EscapeJson(con.CompleteName.Title),
+                                   EscapeJson(con.CompleteName.Suffix));
             }
             else
             {
@@ -665,19 +665,29 @@ namespace WPCordovaClassLib.Cordova.Commands
 
             string jsonContact = String.Format(contactFormatStr,
                                                con.GetHashCode(),
-                                               con.DisplayName,
-                                               con.CompleteName != null ? con.CompleteName.Nickname : "",
+                                               EscapeJson(con.DisplayName),
+                                               EscapeJson(con.CompleteName != null ? con.CompleteName.Nickname : ""),
                                                FormatJSONPhoneNumbers(con),
                                                FormatJSONEmails(con),
                                                FormatJSONAddresses(con),
                                                FormatJSONWebsites(con),
                                                FormatJSONName(con),
-                                               con.Notes.FirstOrDefault(),
-                                               con.Birthdays.FirstOrDefault());
+                                               EscapeJson(con.Notes.FirstOrDefault()),
+                                               EscapeJson(Convert.ToString(con.Birthdays.FirstOrDefault())));
 
             //Debug.WriteLine("jsonContact = " + jsonContact);
             // JSON requires new line characters be escaped
-            return "{" + jsonContact.Replace("\n", "\\n") + "}";
+            return "{" + jsonContact + "}";
+        }
+
+        private static string EscapeJson(string str)
+        {
+            if (String.IsNullOrEmpty(str))
+            {
+                return str;
+            }
+
+            return str.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t").Replace("\"", "\\\"").Replace("&", "\\&");
         }
     }
 }


[14/28] 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

Posted by st...@apache.org.
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/5833bc0a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/5833bc0a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/5833bc0a

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

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


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/5833bc0a/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); 


[05/28] git commit: handle null filter when fields are specified. ( long standing pull-req from @kevfromireland )

Posted by st...@apache.org.
handle null filter when fields are specified. ( long standing pull-req from @kevfromireland )


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

Branch: refs/heads/master
Commit: 6138b8f018ccfa576ad54a315008531a4e09cb72
Parents: c8a1c7b
Author: purplecabbage <pu...@gmail.com>
Authored: Mon Nov 4 18:01:07 2013 -0800
Committer: purplecabbage <pu...@gmail.com>
Committed: Mon Nov 4 18:01:07 2013 -0800

----------------------------------------------------------------------
 src/wp/Contacts.cs | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/6138b8f0/src/wp/Contacts.cs
----------------------------------------------------------------------
diff --git a/src/wp/Contacts.cs b/src/wp/Contacts.cs
index 3678856..d68b0b1 100644
--- a/src/wp/Contacts.cs
+++ b/src/wp/Contacts.cs
@@ -1,10 +1,10 @@
-/*  
+/*
 	Licensed under the Apache License, Version 2.0 (the "License");
 	you may not use this file except in compliance with the License.
 	You may obtain a copy of the License at
-	
+
 	http://www.apache.org/licenses/LICENSE-2.0
-	
+
 	Unless required by applicable law or agreed to in writing, software
 	distributed under the License is distributed on an "AS IS" BASIS,
 	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -403,6 +403,10 @@ namespace WPCordovaClassLib.Cordova.Commands
                 searchParams.options.filter = "";
                 searchParams.options.multiple = true;
             }
+            else if (searchParams.options.filter == null)
+            {
+                searchParams.options.filter = "";
+            }
 
             DeviceContacts deviceContacts = new DeviceContacts();
             deviceContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
@@ -448,7 +452,8 @@ namespace WPCordovaClassLib.Cordova.Commands
             CompareOptions compare_option = CompareOptions.IgnoreCase;
 
             // if we have multiple search fields
-            if (searchParams.options.filter != null && searchParams.options.filter.Length > 0 && searchParams.fields.Count() > 1)
+
+            if (!String.IsNullOrEmpty(searchParams.options.filter) && searchParams.fields.Count() > 1)
             {
                 foundContacts = new List<Contact>();
                 if (searchParams.fields.Contains("emails"))


[18/28] git commit: createMozillaFromCordova and vice versa are used to translate contact objects from one API to another.

Posted by st...@apache.org.
createMozillaFromCordova and vice versa are used to translate contact objects
from one API to another.

phoneNumbers are now translated with more info


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

Branch: refs/heads/master
Commit: f10f66616708ea299bc74eb79d3fdc7e8e4965e9
Parents: 144d69a
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Mon Nov 18 14:14:40 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:28:35 2013 -0800

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 186 +++++++++++++++++++++++-------------
 1 file changed, 118 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/f10f6661/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index bc5d871..0f0f0c9 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -26,102 +26,152 @@
 // FxOS contact definition:
 // https://developer.mozilla.org/en-US/docs/Web/API/mozContact
 
-function saveContacts(successCB, errorCB, contacts) {
-    // success and/or fail will be called every time a contact is saved
 
-    // a closure which is holding the object to be returned to sucessCB
-    function makeSuccess(contact, moz) {
-        return function(result) {
-            // TODO modify contact so it will contain the link to moz
-            contact.id = moz.id;
-            // call callback
-            successCB(contact);
-        }
-    }
-        
+var Contact = require('./Contact');
+var ContactField = require('./ContactField');
+
+function createMozillaFromCordova(contact) {
     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) {
+
+    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];    
             } 
-            
             arr.push(addr);
-            
         }                                 
-        
         return arr;
     } 
-    var i=0;
-    var contact;
-    while(contact = contacts[i++]){
-        // prepare mozContact object
-        var moz = new mozContact();
-        if (contact.id) {
-            moz.id = contact.id;
-        }
-        // building name
-        var nameArray = [];
-        var fields = ['honorificPrefix', 'familyName', 'givenName', 'middleName', 'nickname'];
-        var j = 0, field; while(field = fields[j++]) {
-            if (contact.name[field]) {
-                nameArray.push(contact.name[field]);
-            }
-        }
-        moz.name = nameArray.join(' ');
-        // adding simple fields [contactField, eventualMozContactField]
-        var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
-            ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note']];
-        j = 0; while(field = simpleFields[j++]) {
-          if (contact.name[field[0]]) {
-            moz[field[1] || field[0]] = contact.name[field[0]];
-          }
-        }
-        if (contact.emails) {
-            moz.email = exportContactFieldArray(contact.emails);
-        }
-        if (contact.categories) {
-            moz.category = exportContactFieldArray(contact.categories);
+
+    function exportPhoneNumbers(phoneNumbers) {
+        var mozNumbers = [];
+        for (var i in phoneNumbers) {
+            var number = phoneNumbers[i];
+            mozNumbers.push({
+                type: number.type,
+                value: number.value,
+                pref: number.pref
+            });
         }
-        if (contact.addresses) {
-            moz.adr = exportAddress(contact.addresses);
+        return mozNumbers;
+    }
+
+    // prepare mozContact object
+    var moz = new mozContact();
+    if (contact.id) {
+        moz.id = contact.id;
+    }
+    // building name
+    var nameArray = [];
+    var fields = ['honorificPrefix', 'familyName', 'givenName', 'middleName', 'nickname'];
+    var j = 0, field; while(field = fields[j++]) {
+        if (contact.name[field]) {
+            nameArray.push(contact.name[field]);
         }
-        if (contact.phoneNumbers) {
-            moz.tel = exportContactFieldArray(contact.phoneNumbers);
+    }
+    moz.name = nameArray.join(' ');
+    // adding simple fields [contactField, eventualMozContactField]
+    var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
+        ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note']];
+    j = 0; while(field = simpleFields[j++]) {
+      if (contact.name[field[0]]) {
+        moz[field[1] || field[0]] = contact.name[field[0]];
+      }
+    }
+    if (contact.emails) {
+        moz.email = exportContactFieldArray(contact.emails);
+    }
+    if (contact.categories) {
+        moz.category = exportContactFieldArray(contact.categories);
+    }
+    if (contact.addresses) {
+        moz.adr = exportAddress(contact.addresses);
+    }
+    if (contact.phoneNumbers) {
+        moz.tel = exportPhoneNumbers(contact.phoneNumbers);
+    }
+    if (contact.organizations) {
+        moz.org = exportContactFieldArray(contact.organizations, 'name');
+        moz.jobTitle = exportContactFieldArray(contact.organizations, 'title');
+    }
+    /*  Find out how to translate these parameters
+        // photo: Blob
+        // url: Array with metadata (?)
+        // impp: exportIM(contact.ims), TODO: find the moz impp definition
+        // anniversary
+        // sex
+        // genderIdentity
+        // key
+    */
+    return moz;
+}
+
+function createCordovaFromMozilla(moz) {
+    function exportPhoneNumbers(mozNumbers) {
+        var phoneNumbers = [];
+        for (var i in mozNumbers) {
+            var number = mozNumbers[i];
+            phoneNumbers.push(
+                new ContactField( number.type, number.value, number.pref));
         }
-        if (contact.organizations) {
-            moz.org = exportContactFieldArray(contact.organizations, 'name');
-            moz.jobTitle = exportContactFieldArray(contact.organizations, 'title');
+        return phoneNumbers;
+    }
+
+    var contact = new Contact();
+
+    if (moz.id) {
+        contact.id = moz.id;
+    }
+    // adding simple fields [contactField, eventualCordovaContactField]
+    var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
+        ['honorificSuffix'], ['nickname'], ['bday', 'birthday'], ['note']];
+    j = 0; while(field = simpleFields[j++]) {
+      if (moz.name[field[0]]) {
+        contact[field[1] || field[0]] = moz.name[field[0]];
+      }
+    }
+    // emails
+    // categories
+    // addresses
+    if (moz.tel) {
+        contact.phoneNumbers = exportPhoneNumbers(moz.tel);
+    }
+    // organizations
+    return contact;
+}
+
+
+function saveContacts(successCB, errorCB, contacts) {
+    // a closure which is holding the right moz contact
+    function makeSaveSuccessCB(moz) {
+        return function(result) {
+            // create contact from FXOS contact (might be different than
+            // the original one due to differences in API)
+            var contact = createCordovaFromMozilla(moz);
+            // call callback
+            successCB(contact);
         }
-        /*  Find out how to translate these parameters
-            // photo: Blob
-            // url: Array with metadata (?)
-            // impp: exportIM(contact.ims), TODO: find the moz impp definition
-            // anniversary
-            // sex
-            // genderIdentity
-            // key
-        */
+    }
+    var i=0;
+    var contact;
+    while(contact = contacts[i++]){
+        var moz = createMozillaFromCordova(contact);
         var request = navigator.mozContacts.save(moz);
-        request.onsuccess = makeSuccess(contact, moz);
+        // success and/or fail will be called every time a contact is saved
+        request.onsuccess = makeSaveSuccessCB(moz);
         request.onerror = errorCB;                
     }
 }   


[25/28] git commit: Merge branch 'CB-5214' of https://github.com/sgrebnov/cordova-plugin-contacts into dev

Posted by st...@apache.org.
Merge branch 'CB-5214' of https://github.com/sgrebnov/cordova-plugin-contacts into dev


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

Branch: refs/heads/master
Commit: 1d4aee1b2db39e474d6a4e0660ffe7251155e257
Parents: c070a4f aea4c52
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Dec 3 14:49:46 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Dec 3 14:49:46 2013 -0800

----------------------------------------------------------------------
 test/autotest/tests/contacts.tests.js | 76 ++++++++++++++++++++++++++++--
 1 file changed, 71 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[20/28] git commit: search hacked via getAll

Posted by st...@apache.org.
search hacked via getAll


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

Branch: refs/heads/master
Commit: c2fb0d0d1a9950e5512d6542f3382a2a06c3955d
Parents: 08e6dab
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Wed Nov 27 15:46:26 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:31:28 2013 -0800

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/c2fb0d0d/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index cc8f9c1..10f0288 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -249,11 +249,11 @@ function hackedSearch(successCB, errorCB, params) {
         }
     }
     var getall = navigator.mozContacts.getAll({});
+    var contacts = [];
+    
     getall.onsuccess = function() {
-        var contacts = [];
-        var allContacts = getall.result;
-        for (var i=0; i < allContacts.length; i++) {
-            var mozContact = allContacts[i];
+        if (getall.result) {
+            var mozContact = getall.result;
             var valid = false;
             for (var j=0; j < filter.length; j++) {
                 if (mozContact[filter[0]].indexOf(options.filter)) {
@@ -263,8 +263,13 @@ function hackedSearch(successCB, errorCB, params) {
             if (valid) {
                 contacts.push(createCordovaFromMozilla(mozContact));
             }
+            
+            getall.continue();
+            
+        } else {
+            successCB(contacts);
         }
-        successCB(contacts);
+
     };
     getall.onerror = errorCB;
 }


[11/28] git commit: add ubuntu platform

Posted by st...@apache.org.
add ubuntu platform


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

Branch: refs/heads/master
Commit: 47a923063e4ebc716f960101a257bce829337db6
Parents: 12ac1fd
Author: Maxim Ermilov <er...@gmail.com>
Authored: Mon Sep 30 03:04:21 2013 +0400
Committer: Steven Gill <st...@gmail.com>
Committed: Mon Dec 2 15:44:38 2013 -0800

----------------------------------------------------------------------
 plugin.xml              |   6 +
 src/ubuntu/contacts.cpp | 576 +++++++++++++++++++++++++++++++++++++++++++
 src/ubuntu/contacts.h   |  70 ++++++
 3 files changed, 652 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/47a92306/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 1b6830f..304f04b 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -86,6 +86,12 @@
         <source-file src="src/android/ContactManager.java" target-dir="src/org/apache/cordova/contacts" />
     </platform>
     
+    <!-- ubuntu -->
+    <platform name="ubuntu">
+        <header-file src="src/ubuntu/contacts.h" />
+        <source-file src="src/ubuntu/contacts.cpp" />
+    </platform>
+
     <!-- ios -->
     <platform name="ios">
         <config-file target="config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/47a92306/src/ubuntu/contacts.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/contacts.cpp b/src/ubuntu/contacts.cpp
new file mode 100644
index 0000000..373a276
--- /dev/null
+++ b/src/ubuntu/contacts.cpp
@@ -0,0 +1,576 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#include "contacts.h"
+
+#if defined QTCONTACTS_USE_NAMESPACE
+QTCONTACTS_USE_NAMESPACE
+#endif
+
+Contacts::Contacts(Cordova *cordova): CPlugin(cordova) {
+    m_fieldNamePairs.clear();
+
+    m_fieldNamePairs["displayName"] = QContactDetail::TypeDisplayLabel;
+    m_fieldNamePairs["name"] = QContactDetail::TypeName;
+    m_fieldNamePairs["nickname"] = QContactDetail::TypeNickname;
+    m_fieldNamePairs["phoneNumbers"] = QContactDetail::TypePhoneNumber;
+    m_fieldNamePairs["emails"] = QContactDetail::TypeEmailAddress;
+    m_fieldNamePairs["addresses"] = QContactDetail::TypeAddress;
+    m_fieldNamePairs["ims"] = QContactDetail::TypeOnlineAccount;
+    m_fieldNamePairs["organizations"] = QContactDetail::TypeOrganization;
+    m_fieldNamePairs["birthday"] = QContactDetail::TypeBirthday;
+    m_fieldNamePairs["note"] = QContactDetail::TypeNote;
+    m_fieldNamePairs["photos"] = QContactDetail::TypeAvatar;
+    m_fieldNamePairs["urls"] = QContactDetail::TypeUrl;
+
+    m_notSupportedFields.clear();
+    m_notSupportedFields << "categories";
+    m_manager.clear();
+    m_manager = QSharedPointer<QContactManager>(new QContactManager());
+}
+
+void Contacts::save(int scId, int ecId, const QVariantMap &params) {
+    QContact result;
+    QList<QContactDetail *> detailsToDelete;
+
+    if (params.find("id") != params.end()) {
+        QString id = params.find("id")->toString();
+        if (!id.isEmpty()) {
+            result = m_manager->contact(QContactId::fromString(id));
+            result.clearDetails();
+        }
+    }
+
+    foreach (QString field, params.keys()) {
+        QContactDetail::DetailType qtDefinition = cordovaFieldNameToQtDefinition(field);
+        if (qtDefinition == QContactDetail::TypeUndefined)
+            continue;
+
+        if (field == "nickname") {
+            QContactNickname *detail = new QContactNickname;
+            detail->setNickname(params[field].toString());
+            detailsToDelete << detail;
+            result.saveDetail(detail);
+        } else if (field == "note") {
+            QContactNote *detail = new QContactNote;
+            detail->setNote(params[field].toString());
+            detailsToDelete << detail;
+            result.saveDetail(detail);
+        } else if (field == "phoneNumbers") {
+            if (params[field].type() != QVariant::List)
+                continue;
+            QVariantList phonesList = params[field].toList();
+            foreach (const QVariant &phoneDesc, phonesList) {
+                if (phoneDesc.type() != QVariant::Map)
+                    continue;
+                QContactPhoneNumber *detail = new QContactPhoneNumber;
+                detail->setNumber(phoneDesc.toMap()["value"].toString());
+                if (!phoneDesc.toMap()["type"].toString().isEmpty() &&
+                        phoneDesc.toMap()["type"].toString() != "phone")
+                    detail->setSubTypes(QList<int>() <<
+                                        subTypePhoneFromString(phoneDesc.toMap()["type"].toString()));
+                detailsToDelete << detail;
+                result.saveDetail(detail);
+            }
+        } else if (field == "emails") {
+            if (params[field].type() != QVariant::List)
+                continue;
+            QVariantList emailsList = params[field].toList();
+            foreach (const QVariant &emailDesc, emailsList) {
+                if (emailDesc.type() != QVariant::Map)
+                    continue;
+                if (emailDesc.toMap()["value"].toString().isEmpty())
+                    continue;
+                QContactEmailAddress *detail = new QContactEmailAddress;
+                detail->setEmailAddress(emailDesc.toMap()["value"].toString());
+                detailsToDelete << detail;
+                result.saveDetail(detail);
+            }
+        } else if (field == "ims") {
+            if (params[field].type() != QVariant::List)
+                continue;
+            QVariantList imsList = params[field].toList();
+            foreach (const QVariant &imDesc, imsList) {
+                if (imDesc.type() != QVariant::Map)
+                    continue;
+                QContactOnlineAccount *detail = new QContactOnlineAccount;
+                detail->setAccountUri(imDesc.toMap()["value"].toString());
+                if (!imDesc.toMap()["type"].toString().isEmpty())
+                    detail->setSubTypes(QList<int>() <<
+                                        subTypeOnlineAccountFromString(imDesc.toMap()["type"].toString()));
+                detailsToDelete << detail;
+                result.saveDetail(detail);
+            }
+        } else if (field == "photos") {
+            if (params[field].type() != QVariant::List)
+                continue;
+            QVariantList photosList = params[field].toList();
+            foreach (const QVariant &photoDesc, photosList) {
+                if (photoDesc.type() != QVariant::Map)
+                    continue;
+                //TODO: we need to decide should we support base64 images or not
+                if (photoDesc.toMap()["type"].toString() != "url")
+                    continue;
+                QContactAvatar *detail = new QContactAvatar;
+                detail->setImageUrl(QUrl(photoDesc.toMap()["value"].toString()));
+                detailsToDelete << detail;
+                result.saveDetail(detail);
+            }
+        } else if (field == "urls") {
+            if (params[field].type() != QVariant::List)
+                continue;
+            QVariantList urlsList = params[field].toList();
+            foreach (const QVariant &urlDesc, urlsList) {
+                if (urlDesc.type() != QVariant::Map)
+                    continue;
+                QContactUrl *detail = new QContactUrl;
+                detail->setUrl(urlDesc.toMap()["value"].toString());
+                if (!urlDesc.toMap()["type"].toString().isEmpty())
+                    detail->setSubType((QContactUrl::SubType) subTypeUrlFromString(urlDesc.toMap()["type"].toString()));
+                detailsToDelete << detail;
+                result.saveDetail(detail);
+            }
+        } else if (field == "birthday") {
+            QDateTime birthday;
+            birthday.setTime_t(params[field].toLongLong() / 1000);
+
+            QContactBirthday *detail = new QContactBirthday;
+            detail->setDateTime(birthday);
+            detailsToDelete << detail;
+            result.saveDetail(detail);
+        } else if (field == "organizations") {
+
+            if (params[field].type() != QVariant::List)
+                continue;
+            QVariantList organizationsList = params[field].toList();
+            foreach (const QVariant &organizationDesc, organizationsList) {
+                if (organizationDesc.type() != QVariant::Map)
+                    continue;
+                QContactOrganization *detail = new QContactOrganization;
+                detail->setName(organizationDesc.toMap()["name"].toString());
+                detail->setDepartment(QStringList() << organizationDesc.toMap()["department"].toString());
+                detail->setRole(organizationDesc.toMap()["title"].toString());
+                detailsToDelete << detail;
+                result.saveDetail(detail);
+            }
+
+        } else if (field == "name") {
+            QContactName *detail = new QContactName;
+            QVariantMap nameMap = params[field].toMap();
+            detail->setLastName(nameMap["familyName"].toString());
+            detail->setFirstName(nameMap["givenName"].toString());
+            detail->setMiddleName(nameMap["middleName"].toString());
+            detail->setPrefix(nameMap["honorificPrefix"].toString());
+            detail->setSuffix(nameMap["honorificSuffix"].toString());
+            detailsToDelete << detail;
+            result.saveDetail(detail);
+        }
+
+    }
+    if (!m_manager->saveContact(&result)) {
+        switch (m_manager->error()) {
+        case QContactManager::DoesNotExistError:
+        case QContactManager::AlreadyExistsError:
+        case QContactManager::InvalidDetailError:
+        case QContactManager::InvalidRelationshipError:
+        case QContactManager::BadArgumentError:
+        case QContactManager::InvalidContactTypeError:
+            callback(ecId, "ContactError.INVALID_ARGUMENT_ERROR");
+            break;
+        case QContactManager::DetailAccessError:
+        case QContactManager::PermissionsError:
+            callback(ecId, "ContactError.PERMISSION_DENIED_ERROR");
+            break;
+        case QContactManager::NotSupportedError:
+            callback(ecId, "ContactError.NOT_SUPPORTED_ERROR");
+            break;
+        case QContactManager::TimeoutError:
+            callback(ecId, "ContactError.TIMEOUT_ERROR");
+            break;
+        case QContactManager::UnspecifiedError:
+        case QContactManager::LockedError:
+        case QContactManager::OutOfMemoryError:
+        case QContactManager::VersionMismatchError:
+        case QContactManager::LimitReachedError:
+        case QContactManager::NoError:
+        default:
+            callback(ecId, "ContactError.UNKNOWN_ERROR");
+            break;
+        }
+    } else {
+        callback(scId, jsonedContact(result));
+    }
+    qDeleteAll(detailsToDelete);
+}
+
+void Contacts::remove(int scId, int ecId, const QString &localId) {
+    QContactId id = QContactId::fromString(localId);
+
+    if (!m_manager->removeContact(id)) {
+        switch (m_manager->error()) {
+        case QContactManager::AlreadyExistsError:
+        case QContactManager::InvalidDetailError:
+        case QContactManager::InvalidRelationshipError:
+        case QContactManager::BadArgumentError:
+        case QContactManager::InvalidContactTypeError:
+            callback(ecId, "ContactError.INVALID_ARGUMENT_ERROR");
+            break;
+        case QContactManager::DetailAccessError:
+        case QContactManager::PermissionsError:
+            callback(ecId, "ContactError.PERMISSION_DENIED_ERROR");
+            break;
+        case QContactManager::NotSupportedError:
+            callback(ecId, "ContactError.NOT_SUPPORTED_ERROR");
+            break;
+        case QContactManager::TimeoutError:
+            callback(ecId, "ContactError.TIMEOUT_ERROR");
+            break;
+        case QContactManager::UnspecifiedError:
+        case QContactManager::LockedError:
+        case QContactManager::OutOfMemoryError:
+        case QContactManager::VersionMismatchError:
+        case QContactManager::LimitReachedError:
+        case QContactManager::NoError:
+        case QContactManager::DoesNotExistError:
+        default:
+            callback(ecId, "ContactError.UNKNOWN_ERROR");
+            break;
+        }
+
+    } else {
+        cb(scId);
+    }
+}
+
+void Contacts::search(int scId, int ecId, const QStringList &fields, const QVariantMap &params) {
+    QString filter;
+    bool multiple = true;
+
+    if (params.find("filter") != params.end()) {
+        filter = params["filter"].toString();
+    }
+    if (params.find("multiple") != params.end()) {
+        multiple = params["multiple"].toBool();
+    }
+
+    findContacts(scId, ecId, fields, filter, multiple);
+}
+
+void Contacts::findContacts(int scId, int ecId, const QStringList &fields, const QString &filter, bool multiple) {
+    if (fields.length() <= 0){
+        callback(ecId, "new ContactError(ContactError.INVALID_ARGUMENT_ERROR)");
+    }
+
+    QContactUnionFilter unionFilter;
+
+    QMap<QContactDetail::DetailType, QList<int> > fieldNames;
+    fieldNames[QContactDetail::TypeDisplayLabel] << QContactDisplayLabel::FieldLabel;
+    fieldNames[QContactDetail::TypeName] << QContactName::FieldFirstName << QContactName::FieldLastName << QContactName::FieldMiddleName << QContactName::FieldPrefix << QContactName::FieldSuffix;
+    fieldNames[QContactDetail::TypeNickname] << QContactNickname::FieldNickname;
+    fieldNames[QContactDetail::TypePhoneNumber] << QContactPhoneNumber::FieldNumber;
+    fieldNames[QContactDetail::TypeEmailAddress] << QContactEmailAddress::FieldEmailAddress;
+    fieldNames[QContactDetail::TypeAddress] << QContactAddress::FieldCountry << QContactAddress::FieldLocality << QContactAddress::FieldPostcode << QContactAddress::FieldPostOfficeBox << QContactAddress::FieldRegion << QContactAddress::FieldStreet;
+    fieldNames[QContactDetail::TypeOnlineAccount] << QContactOnlineAccount::FieldAccountUri;
+    fieldNames[QContactDetail::TypeOrganization] << QContactOrganization::FieldAssistantName << QContactOrganization::FieldDepartment << QContactOrganization::FieldLocation << QContactOrganization::FieldName << QContactOrganization::FieldRole << QContactOrganization::FieldTitle;
+    fieldNames[QContactDetail::TypeBirthday] << QContactBirthday::FieldBirthday;
+    fieldNames[QContactDetail::TypeNote] << QContactNote::FieldNote;
+    fieldNames[QContactDetail::TypeUrl] << QContactUrl::FieldUrl;
+
+    foreach (const QContactDetail::DetailType &defName, fieldNames.keys()) {
+        foreach(int fieldName, fieldNames[defName]) {
+            QContactDetailFilter subFilter;
+            subFilter.setDetailType(defName, fieldName);
+            subFilter.setValue(filter);
+            subFilter.setMatchFlags(QContactFilter::MatchContains);
+            unionFilter.append(subFilter);
+        }
+    }
+
+    QList<QContact> contacts = m_manager->contacts(unionFilter);
+    if (contacts.empty()) {
+        callback(scId, "[]");
+    } else {
+        QStringList stringifiedContacts;
+        foreach (const QContact &contact, contacts) {
+            stringifiedContacts << jsonedContact(contact, fields);
+
+            if (!multiple)
+                break;
+        }
+        callback(scId, QString("[%1]").arg(stringifiedContacts.join(", ")));
+    }
+}
+
+QContactDetail::DetailType Contacts::cordovaFieldNameToQtDefinition(const QString &cordovaFieldName) const {
+    if (m_fieldNamePairs.contains(cordovaFieldName))
+        return m_fieldNamePairs[cordovaFieldName];
+
+    return QContactDetail::TypeUndefined;
+}
+
+int Contacts::subTypePhoneFromString(const QString &cordovaSubType) const
+{
+    QString preparedSubType = cordovaSubType.toLower();
+    if (preparedSubType == "mobile")
+        return QContactPhoneNumber::SubTypeMobile;
+    else if (preparedSubType == "fax")
+        return QContactPhoneNumber::SubTypeFax;
+    else if (preparedSubType == "pager")
+        return QContactPhoneNumber::SubTypePager;
+    else if (preparedSubType == "voice")
+        return QContactPhoneNumber::SubTypeVoice;
+    else if (preparedSubType == "modem")
+        return QContactPhoneNumber::SubTypeModem;
+    else if (preparedSubType == "video")
+        return QContactPhoneNumber::SubTypeVideo;
+    else if (preparedSubType == "car")
+        return QContactPhoneNumber::SubTypeCar;
+    else if (preparedSubType == "assistant")
+        return QContactPhoneNumber::SubTypeAssistant;
+    return QContactPhoneNumber::SubTypeLandline;
+}
+
+int Contacts::subTypeOnlineAccountFromString(const QString &cordovaSubType) const {
+    QString preparedSubType = cordovaSubType.toLower();
+    if (preparedSubType == "aim")
+        return QContactOnlineAccount::ProtocolAim;
+    else if (preparedSubType == "icq")
+        return QContactOnlineAccount::ProtocolIcq;
+    else if (preparedSubType == "irc")
+        return QContactOnlineAccount::ProtocolIrc;
+    else if (preparedSubType == "jabber")
+        return QContactOnlineAccount::ProtocolJabber;
+    else if (preparedSubType == "msn")
+        return QContactOnlineAccount::ProtocolMsn;
+    else if (preparedSubType == "qq")
+        return QContactOnlineAccount::ProtocolQq;
+    else if (preparedSubType == "skype")
+        return QContactOnlineAccount::ProtocolSkype;
+    else if (preparedSubType == "yahoo")
+        return QContactOnlineAccount::ProtocolYahoo;
+    return QContactOnlineAccount::ProtocolUnknown;
+}
+
+int Contacts::subTypeUrlFromString(const QString &cordovaSubType) const {
+    QString preparedSubType = cordovaSubType.toLower();
+    if (preparedSubType == "blog")
+        return QContactUrl::SubTypeBlog;
+    else if (preparedSubType == "favourite")
+        return QContactUrl::SubTypeFavourite;
+    return QContactUrl::SubTypeHomePage;
+}
+
+QString Contacts::subTypePhoneToString(int qtSubType) const {
+    if (qtSubType == QContactPhoneNumber::SubTypeMobile)
+        return "mobile";
+    else if (qtSubType == QContactPhoneNumber::SubTypeFax)
+        return "fax";
+    else if (qtSubType == QContactPhoneNumber::SubTypePager)
+        return "pager";
+    else if (qtSubType == QContactPhoneNumber::SubTypeVoice)
+        return "voice";
+    else if (qtSubType == QContactPhoneNumber::SubTypeModem)
+        return "modem";
+    else if (qtSubType == QContactPhoneNumber::SubTypeVideo)
+        return "video";
+    else if (qtSubType == QContactPhoneNumber::SubTypeCar)
+        return "car";
+    else if (qtSubType == QContactPhoneNumber::SubTypeAssistant)
+        return "assistant";
+    return "home";
+}
+
+QString Contacts::subTypeOnlineAccountToString(int qtSubType) const {
+    if (qtSubType == QContactOnlineAccount::ProtocolAim)
+        return "aim";
+    else if (qtSubType == QContactOnlineAccount::ProtocolIcq)
+        return "icq";
+    else if (qtSubType == QContactOnlineAccount::ProtocolIrc)
+        return "irc";
+    else if (qtSubType == QContactOnlineAccount::ProtocolJabber)
+        return "jabber";
+    else if (qtSubType == QContactOnlineAccount::ProtocolMsn)
+        return "msn";
+    else if (qtSubType == QContactOnlineAccount::ProtocolQq)
+        return "qq";
+    else if (qtSubType == QContactOnlineAccount::ProtocolSkype)
+        return "skype";
+    else if (qtSubType == QContactOnlineAccount::ProtocolYahoo)
+        return "yahoo";
+    return "unknown";
+}
+
+QString Contacts::subTypeUrlToString(int qtSubType) const {
+    if (qtSubType == QContactUrl::SubTypeBlog)
+        return "blog";
+    else if (qtSubType == QContactUrl::SubTypeFavourite)
+        return "favourite";
+    return "homepage";
+}
+
+QString Contacts::jsonedContact(const QContact &contact, const QStringList &fields) const {
+    QStringList resultingFields = fields;
+    if (resultingFields.empty())
+        resultingFields.append(m_fieldNamePairs.keys());
+    if (!resultingFields.contains("id"))
+        resultingFields << "id";
+    QStringList fieldValuesList;
+    foreach (const QString &field, resultingFields) {
+        QContactDetail::DetailType qtDefinitionName = cordovaFieldNameToQtDefinition(field);
+        if (field == "id") {
+            fieldValuesList << QString("%1: \"%2\"")
+                               .arg(field)
+                               .arg(contact.id().toString());
+        } else if (field == "displayName") {
+            QContactDisplayLabel detail = contact.detail(qtDefinitionName);
+            fieldValuesList << QString("%1: \"%2\"")
+                               .arg(field)
+                               .arg(detail.label());
+        } else if (field == "nickname") {
+            QContactNickname detail = contact.detail(qtDefinitionName);
+            fieldValuesList << QString("%1: \"%2\"")
+                               .arg(field)
+                               .arg(detail.nickname());
+        } else if (field == "note") {
+            QContactNote detail = contact.detail(qtDefinitionName);
+            fieldValuesList << QString("%1: \"%2\"")
+                               .arg(field)
+                               .arg(detail.note());
+        } else if (field == "phoneNumbers") {
+            QStringList fieldValues;
+            QList<QContactDetail> details = contact.details(qtDefinitionName);
+            foreach (const QContactDetail &detail, details) {
+                QContactPhoneNumber castedDetail = detail;
+                QStringList subTypes;
+                foreach (int subType, castedDetail.subTypes())
+                    subTypes << subTypePhoneToString(subType);
+
+                if (subTypes.isEmpty())
+                    subTypes << "phone";
+                foreach(const QString &subType, subTypes) {
+                    fieldValues << QString("{type: \"%1\", value: \"%2\", pref: %3}")
+                                   .arg(subType)
+                                   .arg(castedDetail.number())
+                                   .arg("false");
+                }
+            }
+            fieldValuesList << QString("%1: [%2]")
+                               .arg(field)
+                               .arg(fieldValues.join(", "));
+        } else if (field == "emails") {
+            QStringList fieldValues;
+            QList<QContactDetail> details = contact.details(qtDefinitionName);
+            foreach (const QContactDetail &detail, details) {
+                QContactEmailAddress castedDetail = detail;
+                fieldValues << QString("{type: \"%1\", value: \"%2\", pref: %3}")
+                               .arg("email")
+                               .arg(castedDetail.emailAddress())
+                               .arg("false");
+            }
+            fieldValuesList << QString("%1: [%2]")
+                               .arg(field)
+                               .arg(fieldValues.join(", "));
+        } else if (field == "ims") {
+            QStringList fieldValues;
+            QList<QContactDetail> details = contact.details(qtDefinitionName);
+            foreach (const QContactDetail &detail, details) {
+                QContactOnlineAccount castedDetail = detail;
+                QStringList subTypes;
+                foreach (int subType, castedDetail.subTypes())
+                    subTypes << subTypeOnlineAccountToString(subType);
+
+                if (subTypes.isEmpty())
+                    subTypes << "IM";
+                foreach(const QString &subType, subTypes) {
+                    fieldValues << QString("{type: \"%1\", value: \"%2\", pref: %3}")
+                                   .arg(subType)
+                                   .arg(castedDetail.accountUri())
+                                   .arg("false");
+                }
+            }
+            fieldValuesList << QString("%1: [%2]")
+                               .arg(field)
+                               .arg(fieldValues.join(", "));
+        } else if (field == "photos") {
+            QStringList fieldValues;
+            QList<QContactDetail> details = contact.details(qtDefinitionName);
+            foreach (const QContactDetail &detail, details) {
+                QContactAvatar castedDetail = detail;
+                fieldValues << QString("{type: \"%1\", value: \"%2\", pref: %3}")
+                               .arg("url")
+                               .arg(castedDetail.imageUrl().toString())
+                               .arg("false");
+            }
+            fieldValuesList << QString("%1: [%2]")
+                               .arg(field)
+                               .arg(fieldValues.join(", "));
+        } else if (field == "urls") {
+            QStringList fieldValues;
+            QList<QContactDetail> details = contact.details(qtDefinitionName);
+
+            foreach (const QContactDetail &detail, details) {
+                QContactUrl castedDetail = detail;
+                QString subType = subTypeUrlToString(castedDetail.subType());
+
+                fieldValues << QString("{type: \"%1\", value: \"%2\", pref: %3}")
+                               .arg(subType)
+                               .arg(castedDetail.url())
+                               .arg("false");
+            }
+            fieldValuesList << QString("%1: [%2]")
+                               .arg(field)
+                               .arg(fieldValues.join(", "));
+        } else if (field == "birthday") {
+            QContactBirthday detail = contact.detail(qtDefinitionName);
+            fieldValuesList << QString("%1: %2")
+                               .arg(field)
+                               .arg(detail.dateTime().toMSecsSinceEpoch());
+        } else if (field == "organizations") {
+            QStringList fieldValues;
+            QList<QContactDetail> details = contact.details(qtDefinitionName);
+            foreach (const QContactDetail &detail, details) {
+                QContactOrganization castedDetail = detail;
+                fieldValues << QString("{type: \"%1\", name: \"%2\", department: \"%3\", title: \"%4\", pref: %5}")
+                               .arg("organization")
+                               .arg(castedDetail.name())
+                               .arg(castedDetail.department().join(" "))
+                               .arg(castedDetail.role())
+                               .arg("false");
+            }
+            fieldValuesList << QString("%1: [%2]")
+                               .arg(field)
+                               .arg(fieldValues.join(", "));
+        } else if (field == "name") {
+            QContactName detail = contact.detail(qtDefinitionName);
+            fieldValuesList <<  QString("%1: {familyName: \"%2\", givenName: \"%3\", middleName: \"%4\", honorificPrefix: \"%5\", honorificSuffix: \"%6\"}")
+                                .arg(field)
+                                .arg(detail.lastName())
+                                .arg(detail.firstName())
+                                .arg(detail.middleName())
+                                .arg(detail.prefix())
+                                .arg(detail.suffix());
+        }
+
+
+    }
+
+    return QString("{%1}").arg(fieldValuesList.join(", "));
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/47a92306/src/ubuntu/contacts.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/contacts.h b/src/ubuntu/contacts.h
new file mode 100644
index 0000000..4c1343b
--- /dev/null
+++ b/src/ubuntu/contacts.h
@@ -0,0 +1,70 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#ifndef CONTACTS_H_SSSSSSS
+#define CONTACTS_H_SSSSSSS
+
+#include <cplugin.h>
+
+#include <QtContacts>
+#include <QtCore>
+
+QTCONTACTS_USE_NAMESPACE
+
+class Contacts : public CPlugin {
+    Q_OBJECT
+public:
+    explicit Contacts(Cordova *cordova);
+
+    virtual const QString fullName() override {
+        return Contacts::fullID();
+    }
+
+    virtual const QString shortName() override {
+        return "Contacts";
+    }
+
+    static const QString fullID() {
+        return "Contacts";
+    }
+
+public slots:
+    void save(int scId, int ecId, const QVariantMap &params);
+    void remove(int scId, int ecId, const QString &localId);
+    void search(int scId, int ecId, const QStringList &fields, const QVariantMap &params);
+
+private:
+    void findContacts(int scId, int ecId, const QStringList &fields, const QString &filter, bool multiple);
+    QContactDetail::DetailType cordovaFieldNameToQtDefinition(const QString &cordovaFieldName) const;
+    int subTypePhoneFromString(const QString &cordovaSubType) const;
+    int subTypeOnlineAccountFromString(const QString &cordovaSubType) const;
+    int subTypeUrlFromString(const QString &cordovaSubType) const;
+    QString subTypePhoneToString(int qtSubType) const;
+    QString subTypeOnlineAccountToString(int qtSubType) const;
+    QString subTypeUrlToString(int qtSubType) const;
+    QString jsonedContact(const QContact &contact, const QStringList &fields = QStringList()) const;
+
+    QHash<QString, QContactDetail::DetailType> m_fieldNamePairs;
+    QSet<QString> m_notSupportedFields;
+    QSharedPointer<QContactManager> m_manager;
+};
+
+#endif


[13/28] git commit: fix merger conflicts

Posted by st...@apache.org.
fix merger conflicts


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

Branch: refs/heads/master
Commit: c070a4fe671ebb20bb118fe57d21b5cf1b825196
Parents: 7720e9d 85c4030
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Dec 3 11:15:58 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Dec 3 11:15:58 2013 -0800

----------------------------------------------------------------------
 src/wp/Contacts.cs | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------



[02/28] git commit: CB-5214 Make mobile spec tests on WP8 to run w/o user interaction + Sync with cordova-mobile-spec

Posted by st...@apache.org.
CB-5214 Make mobile spec tests on WP8 to run w/o user interaction + Sync with cordova-mobile-spec


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

Branch: refs/heads/master
Commit: aea4c52bc70b77b34cf1ba974c8ce46fb74efa65
Parents: c8a1c7b
Author: sgrebnov <se...@gmail.com>
Authored: Wed Oct 30 18:15:28 2013 +0400
Committer: sgrebnov <se...@gmail.com>
Committed: Wed Oct 30 18:15:28 2013 +0400

----------------------------------------------------------------------
 test/autotest/tests/contacts.tests.js | 76 ++++++++++++++++++++++++++++--
 1 file changed, 71 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/aea4c52b/test/autotest/tests/contacts.tests.js
----------------------------------------------------------------------
diff --git a/test/autotest/tests/contacts.tests.js b/test/autotest/tests/contacts.tests.js
index 12520a4..de2955e 100644
--- a/test/autotest/tests/contacts.tests.js
+++ b/test/autotest/tests/contacts.tests.js
@@ -21,8 +21,9 @@
 
 // global to store a contact so it doesn't have to be created or retrieved multiple times
 // all of the setup/teardown test methods can reference the following variables to make sure to do the right cleanup
-var gContactObj = null;
-var gContactId = null;
+var gContactObj = null,
+    gContactId = null,
+    isWindowsPhone = cordova.platformId == 'windowsphone';
 
 var removeContact = function(){
     if (gContactObj) {
@@ -65,6 +66,26 @@ describe("Contacts (navigator.contacts)", function () {
             });
         });
 
+        it("success callback should be called with an array, even if partial ContactFindOptions specified", function () {
+            var win = jasmine.createSpy().andCallFake(function (result) {
+                expect(result).toBeDefined();
+                expect(result instanceof Array).toBe(true);
+            }),
+                fail = jasmine.createSpy();
+
+            runs(function () {
+                navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], win, fail, {
+                    multiple: true
+                });
+            });
+
+            waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+            runs(function () {
+                expect(fail).not.toHaveBeenCalled();
+            });
+        });
+
         it("contacts.spec.4 should throw an exception if success callback is empty", function() {
             var fail = function() {};
             var obj = new ContactFindOptions();
@@ -103,6 +124,10 @@ describe("Contacts (navigator.contacts)", function () {
             afterEach(removeContact);
 
             it("contacts.spec.6 should be able to find a contact by name", function() {
+
+                // this api requires manual user confirmation on WP7/8 so skip it
+                if (isWindowsPhone) return;
+
                 var foundName = jasmine.createSpy().andCallFake(function(result) {
                         var bFound = false;
                         try {
@@ -163,7 +188,7 @@ describe("Contacts (navigator.contacts)", function () {
 
     describe('create method', function() {
 
-        it("contacts.spec.1 should exist", function() {
+        it("contacts.spec.7 should exist", function() {
             expect(navigator.contacts.create).toBeDefined();
             expect(typeof navigator.contacts.create).toBe('function');
         });
@@ -302,6 +327,10 @@ describe("Contacts (navigator.contacts)", function () {
 
     describe('save method', function () {
         it("contacts.spec.20 should be able to save a contact", function() {
+
+            // this api requires manual user confirmation on WP7/8 so skip it
+            if (isWindowsPhone) return;
+
             var bDay = new Date(1976, 6,4);
             gContactObj = navigator.contacts.create({"gender": "male", "note": "my note", "name": {"familyName": "Delete", "givenName": "Test"}, "emails": [{"value": "here@there.com"}, {"value": "there@here.com"}], "birthday": bDay});
 
@@ -332,6 +361,10 @@ describe("Contacts (navigator.contacts)", function () {
          });
         // HACK: there is a reliance between the previous and next test. This is bad form.
         it("contacts.spec.21 update a contact", function() {
+
+            // this api requires manual user confirmation on WP7/8 so skip it
+            if (isWindowsPhone) return;
+
             expect(gContactObj).toBeDefined();
 
             var bDay = new Date(1975, 5,4);
@@ -408,9 +441,11 @@ describe("Contacts (navigator.contacts)", function () {
     });
 
     describe("Round trip Contact tests (creating + save + delete + find).", function () {
-        afterEach(removeContact);
-
         it("contacts.spec.24 Creating, saving, finding a contact should work, removing it should work, after which we should not be able to find it, and we should not be able to delete it again.", function() {
+
+            // this api requires manual user confirmation on WP7/8 so skip it
+            if (isWindowsPhone) return;
+
             var done = false;
             runs(function () {
                 gContactObj = new Contact();
@@ -469,4 +504,35 @@ describe("Contacts (navigator.contacts)", function () {
             expect(ContactError.PERMISSION_DENIED_ERROR).toBe(20);
         });
     });
+
+    describe("Contacts autotests cleanup", function () {
+        it("contacts.spec.26 Cleanup any DeleteMe contacts from Contacts tests.", function() {
+            var done = false;
+            var obj = new ContactFindOptions();
+            obj.filter="DeleteMe";
+            obj.multiple=true;
+            runs(function () {
+                var findSuccess = function (cs) {
+                    var contactObj = new Contact();
+                    if (cs.length>0){
+                        contactObj = cs[0];
+                        contactObj.remove(function(){
+                            console.log("[CONTACTS CLEANUP] DeleteMe contact successfully removed");
+                            navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findSuccess, findFail, obj);
+                        },function(){
+                            console.log("[CONTACTS CLEANUP ERROR]: failed to remove DeleteMe contact");
+                        });
+                    } else {
+                        done = true;
+                    }
+                };
+                var findFail = function(e) {
+                    throw("Failure callback invoked in navigator.contacts.find call, test failed.");
+                };
+                navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findSuccess, findFail, obj);
+            });
+            waitsFor(function () { return done; }, Tests.TEST_TIMEOUT);
+        });
+    });
+
 });


[24/28] git commit: FxOS name fields are arrays hackedSearch refactored search based on find commented out

Posted by st...@apache.org.
FxOS name fields are arrays
hackedSearch refactored
search based on find commented out


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

Branch: refs/heads/master
Commit: 334080aff9f0b04a615d4c4de47a615acbd8f7b0
Parents: c2fb0d0
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Thu Nov 28 14:28:53 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:32:27 2013 -0800

----------------------------------------------------------------------
 src/firefoxos/ContactsProxy.js | 137 ++++++++++++++++++++----------------
 1 file changed, 77 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/334080af/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 10f0288..afd43a4 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -77,9 +77,13 @@ function createMozillaFromCordova(contact) {
         moz.id = contact.id;
     }
     // adding simple fields [contactField, eventualMozContactField]
-    var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
-        ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note'],
-        ['displayName', 'name']];
+    var arrayFields = [['givenName'], ['familyName'], ['displayName', 'name']];
+    var simpleFields = [['honorificPrefix'], ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note']];
+    j = 0; while(field = arrayFields[j++]) {
+      if (contact.name[field[0]]) {
+        moz[field[1] || field[0]] = contact.name[field[0]].split(' ');
+      }
+    }
     j = 0; while(field = simpleFields[j++]) {
       if (contact.name[field[0]]) {
         moz[field[1] || field[0]] = contact.name[field[0]];
@@ -129,11 +133,14 @@ function createCordovaFromMozilla(moz) {
     if (moz.id) {
         contact.id = moz.id;
     }
-    // adding simple fields [contactField, eventualCordovaContactField]
-    var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
-        ['honorificSuffix'], ['nickname'], ['bday', 'birthday'], ['note'],
-        ['name', 'displayName']];
+    var arrayFields = [['givenName'], ['familyName'], ['name', 'displayName']];
+    var simpleFields = [['honorificPrefix'], ['honorificSuffix'], ['nickname'], ['bday', 'birthday'], ['note']];
     var name = new ContactName();
+    var j = 0; while(field = arrayFields[j++]) {
+      if (moz[field[0]]) {
+        name[field[1] || field[0]] = moz[field[0]].join(' ');
+      }
+    }
     j = 0; while(field = simpleFields[j++]) {
       if (moz[field[0]]) {
         name[field[1] || field[0]] = moz[field[0]];
@@ -190,52 +197,56 @@ function remove(successCB, errorCB, ids) {
 var mozContactSearchFields = ['name', 'givenName', 'additionalName', 
     'familyName', 'nickname', 'email', 'tel', 'jobTitle', 'note'];
 
-function search(successCB, errorCB, params) {
-    var options = params[1] || {}; 
-    var filter = [];
-    // filter out inallowed fields
-    for (var i=0; i < params[0].length; i++) {
-        if (mozContactSearchFields.indexOf([params[0][i]])) {
-            filter.push(params[0][i]);
-        } else if (params[0][i] == 'displayName') {
-            filter.push('name');
-        } else {
-            console.log('FXOS ContactProxy: inallowed field passed to search filtered out: ' + params[0][i]);
-        }
-    }
-
-    var request;
-    // TODO find out how to handle searching by numbers
-    // filterOp: The filter comparison operator to use. Possible values are 
-    //           equals, startsWith, and match, the latter being specific 
-    //           to telephone numbers.
-    var mozOptions = {filterBy: filter, filterOp: 'startsWith'};
-    if (!options.multiple) {
-        mozOptions.filterLimit = 1;
-    }
-    if (!options.filter) {
-        // this is returning 0 contacts
-        request = navigator.mozContacts.getAll({});
-    } else {
-        // XXX This is searching for regardless of the filterValue !!!
-        mozOptions.filterValue = options.filter;
-        console.log('mozoptions: filterBy: ' + mozOptions.filterBy.join(' ') + '; fiterValue: ' + mozOptions.filterValue);
-        request = navigator.mozContacts.find(mozOptions);
-    }
-    request.onsuccess = function() {
-        var contacts = [];
-        var mozContacts = request.result;
-        for (var i=0; i < mozContacts.length; i++) {
-            contacts.push(createCordovaFromMozilla(mozContacts[i]));
-        }
-        successCB(contacts);
-    };
-    request.onerror = errorCB;
-}
+// function search(successCB, errorCB, params) {
+//     var options = params[1] || {}; 
+//     var filter = [];
+//     // filter out inallowed fields
+//     for (var i=0; i < params[0].length; i++) {
+//         if (mozContactSearchFields.indexOf([params[0][i]])) {
+//             filter.push(params[0][i]);
+//         } else if (params[0][i] == 'displayName') {
+//             filter.push('name');
+//         } else {
+//             console.log('FXOS ContactProxy: inallowed field passed to search filtered out: ' + params[0][i]);
+//         }
+//     }
+// 
+//     var request;
+//     // TODO find out how to handle searching by numbers
+//     // filterOp: The filter comparison operator to use. Possible values are 
+//     //           equals, startsWith, and match, the latter being specific 
+//     //           to telephone numbers.
+//     var mozOptions = {filterBy: filter, filterOp: 'startsWith'};
+//     if (!options.multiple) {
+//         mozOptions.filterLimit = 1;
+//     }
+//     if (!options.filter) {
+//         // this is returning 0 contacts
+//         request = navigator.mozContacts.getAll({});
+//     } else {
+//         // XXX This is searching for regardless of the filterValue !!!
+//         mozOptions.filterValue = options.filter;
+//         console.log('mozoptions: filterBy: ' + mozOptions.filterBy.join(' ') + '; fiterValue: ' + mozOptions.filterValue);
+//         request = navigator.mozContacts.find(mozOptions);
+//     }
+//     request.onsuccess = function() {
+//         var contacts = [];
+//         var mozContacts = request.result;
+//         for (var i=0; i < mozContacts.length; i++) {
+//             contacts.push(createCordovaFromMozilla(mozContacts[i]));
+//         }
+//         successCB(contacts);
+//     };
+//     request.onerror = errorCB;
+// }
 
 
-/* navigator.mozContacts.find has issues - using getAll */
+/* navigator.mozContacts.find has issues - using getAll 
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=941008
+ */
 function hackedSearch(successCB, errorCB, params) {
+    // [contactField, eventualMozContactField]
+    var arrayFields = ['givenName', 'familyName', 'name'];
     var options = params[1] || {}; 
     var filter = [];
     // filter out inallowed fields
@@ -250,18 +261,24 @@ function hackedSearch(successCB, errorCB, params) {
     }
     var getall = navigator.mozContacts.getAll({});
     var contacts = [];
-    
+
+    function isValid(mozContact) {
+        if (!options.filter) {
+            // get all
+            return true;
+        }
+        for (var j=0; j < filter.length; j++) {
+            var field = filter[0];
+            var value = (arrayFields.indexOf(field) >= 0) ? mozContact[field].join(' ') : mozContact[field];
+            if (value.indexOf(options.filter) >= 0) {
+                return true;
+            }
+        }
+    }
     getall.onsuccess = function() {
         if (getall.result) {
-            var mozContact = getall.result;
-            var valid = false;
-            for (var j=0; j < filter.length; j++) {
-                if (mozContact[filter[0]].indexOf(options.filter)) {
-                    valid = true;
-                }
-            }
-            if (valid) {
-                contacts.push(createCordovaFromMozilla(mozContact));
+            if (isValid(getall.result)) {
+                contacts.push(createCordovaFromMozilla(getall.result));
             }
             
             getall.continue();


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

Posted by st...@apache.org.
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;                
     }
 }   
 


[07/28] git commit: Merge branch 'dev' of github.com:archananaik/cordova-plugin-contacts into dev

Posted by st...@apache.org.
Merge branch 'dev' of github.com:archananaik/cordova-plugin-contacts into dev


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

Branch: refs/heads/master
Commit: f815ff97d2c4e4be09da457eedb459bb3917db11
Parents: bdcf090 c828b41
Author: Steven Gill <st...@gmail.com>
Authored: Tue Nov 26 15:21:51 2013 -0800
Committer: Steven Gill <st...@gmail.com>
Committed: Tue Nov 26 15:21:51 2013 -0800

----------------------------------------------------------------------
 plugin.xml           | 19 +++++++++++++++++++
 test/cordova-incl.js |  6 ++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[09/28] git commit: CB-3035 Fix issue with windows new line char \n\r

Posted by st...@apache.org.
CB-3035 Fix issue with windows new line char \n\r


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

Branch: refs/heads/master
Commit: 12ac1fd036387968d3a13cf4ba1a94aa42336d10
Parents: f815ff9
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Dec 2 14:02:15 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon Dec 2 14:02:15 2013 -0800

----------------------------------------------------------------------
 src/wp/Contacts.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/12ac1fd0/src/wp/Contacts.cs
----------------------------------------------------------------------
diff --git a/src/wp/Contacts.cs b/src/wp/Contacts.cs
index d68b0b1..7883be2 100644
--- a/src/wp/Contacts.cs
+++ b/src/wp/Contacts.cs
@@ -677,7 +677,7 @@ namespace WPCordovaClassLib.Cordova.Commands
 
             //Debug.WriteLine("jsonContact = " + jsonContact);
             // JSON requires new line characters be escaped
-            return "{" + jsonContact.Replace("\n", "\\n") + "}";
+            return "{" + jsonContact.Replace("\n", "\\n").Replace("\r","") + "}";
         }
     }
 }


[04/28] git commit: 1. Added amazon-fireos platform. 2. Change to use amazon-fireos as the platform if user agent string contains 'cordova-amazon-fireos'.

Posted by st...@apache.org.
1. Added amazon-fireos platform.
2. Change to use amazon-fireos as the platform if user agent string contains 'cordova-amazon-fireos'.


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

Branch: refs/heads/master
Commit: c828b41683f7a4053c55fba8c8e1d46f3e5a3496
Parents: acb6147
Author: Archana Naik <na...@lab126.com>
Authored: Fri Oct 18 15:45:36 2013 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Wed Oct 30 11:58:30 2013 -0700

----------------------------------------------------------------------
 plugin.xml           | 19 +++++++++++++++++++
 test/cordova-incl.js |  6 ++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/c828b416/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index f1de200..1b6830f 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -67,6 +67,25 @@
         <source-file src="src/android/ContactManager.java" target-dir="src/org/apache/cordova/contacts" />
     </platform>
 
+    <!-- amazon-fireos -->
+    <platform name="amazon-fireos">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="Contacts">
+                <param name="android-package" value="org.apache.cordova.contacts.ContactManager"/>
+            </feature>
+        </config-file>
+
+        <config-file target="AndroidManifest.xml" parent="/*">
+            <uses-permission android:name="android.permission.READ_CONTACTS" />
+            <uses-permission android:name="android.permission.WRITE_CONTACTS" />
+            <uses-permission android:name="android.permission.GET_ACCOUNTS" />
+        </config-file>
+
+        <source-file src="src/android/ContactAccessor.java" target-dir="src/org/apache/cordova/contacts" />
+        <source-file src="src/android/ContactAccessorSdk5.java" target-dir="src/org/apache/cordova/contacts" />
+        <source-file src="src/android/ContactManager.java" target-dir="src/org/apache/cordova/contacts" />
+    </platform>
+    
     <!-- ios -->
     <platform name="ios">
         <config-file target="config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/c828b416/test/cordova-incl.js
----------------------------------------------------------------------
diff --git a/test/cordova-incl.js b/test/cordova-incl.js
index dbcd1a6..bc1dd7a 100644
--- a/test/cordova-incl.js
+++ b/test/cordova-incl.js
@@ -20,7 +20,9 @@
 */
 
 var PLAT;
-if (/Android/.exec(navigator.userAgent)) {
+if (/cordova-amazon-fireos/.exec(navigator.userAgent)) {
+    PLAT = 'amazon-fireos';
+}else if (/Android/.exec(navigator.userAgent)) {
     PLAT = 'android';
 } else if (/(iPad)|(iPhone)|(iPod)/.exec(navigator.userAgent)) {
     PLAT = 'ios';
@@ -61,7 +63,7 @@ if (!window._doNotWriteCordovaScript) {
 }
 
 function backHome() {
-	if (window.device && device.platform && device.platform.toLowerCase() == 'android') {
+	if (window.device && device.platform && (device.platform.toLowerCase() == 'android' || device.platform.toLowerCase() == 'amazon-fireos')) {
             navigator.app.backHistory();
 	}
 	else {


[22/28] git commit: wrong example given

Posted by st...@apache.org.
wrong example given


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

Branch: refs/heads/master
Commit: 148774d66a8f22db817e3f70effaf92de651eb9b
Parents: 3a65011
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Thu Nov 28 14:50:32 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:32:27 2013 -0800

----------------------------------------------------------------------
 README.md | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/148774d6/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 2c42361..f536c6e 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,4 @@ If you are not using the Cordova Command-line Interface, follow [Using Plugman t
 
 Edit manifest.webapp and add permissions field as described in [Manifest Docs](https://developer.mozilla.org/en-US/Apps/Developing/Manifest#permissions).
 There is also a need to change the webapp type to "privileged"  - [Manifest Docs](https://developer.mozilla.org/en-US/Apps/Developing/Manifest#type).
-All privileged apps enforce [Content Security Policy](https://developer.mozilla.org/en-US/Apps/CSP) which forbids inline script. Initialize your application in another way (i.e. start it on document load in index.js)
-
-    document.onload = app.initialize;
-
+All privileged apps enforce [Content Security Policy](https://developer.mozilla.org/en-US/Apps/CSP) which forbids inline script. Initialize your application in another way.


[17/28] git commit: save is working

Posted by st...@apache.org.
save is working


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

Branch: refs/heads/master
Commit: 0f7ff4195f4a1a29a3e4cc9bb3d8d5945d3cff0c
Parents: 35def21
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Wed Nov 13 19:28:47 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:28:35 2013 -0800

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


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/0f7ff419/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 7029541..c2ac0fd 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -27,10 +27,13 @@
 // 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
-    function success(result) {
-        // TODO: this will need to amend the result
-        console.log('SUCCESS from moz');
-        successCB(result);
+    // a closure which is holding the object to be returned to sucessCB
+    function makeSuccess(contact, moz) {
+        return function(result) {
+            // TODO modify contact so it will contain the link to moz
+            // call callback
+            successCB(contact);
+        }
     }
     function error(e) {
         console.log('BOO from moz');
@@ -75,36 +78,42 @@ function saveContacts(successCB, errorCB, contacts) {
         var request;
         // prepare mozContact object
         var translatedContact = {};
+        // building name
         var nameArray = [];
-        var j = 0;
-        var field;
         var fields = ['honorificPrefix', 'familyName', 'givenName', 'middleName', 'nickname'];
-        while(field = fields[j++]) {
+        var j = 0, field; 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;
+        // adding simple fields [contactField, eventualMozContactField]
+        var simpleFields = [['honorificPrefix'], ['givenName'], ['familyName'], 
+            ['honorificSuffix'], ['nickname'], ['birthday', 'bday'], ['note']];
+        j = 0; while(field = simpleFields[j++]) {
+          if (contact.name[field[0]]) {
+            translatedContact[field[1] || field[0]] = contact.name[field[0]];
+          }
+        }
+        if (contact.emails) {
+            translatedContact.email = exportContactFieldArray(contact.emails);
+        }
+        if (contact.categories) {
+            translatedContact.category = exportContactFieldArray(contact.categories);
+        }
+        if (contact.addresses) {
+            translatedContact.adr = exportAddress(contact.addresses);
         }
-        translatedContact.familyName = contact.name.familyName;
-        /*
-            honorificPrefix: [contact.name.honorificPrefix],
-            givenName: [contact.name.givenName],
-            familyName: [contact.name.familyName],
-            honorificSuffix: [contact.name.honorificSuffix], 
-            nickname: [contact.nickname],
-            email: exportContactFieldArray(contact.emails),
+        if (contact.phoneNumbers) {
+            translatedContact.tel = exportContactFieldArray(contact.phoneNumbers);
+        }
+        if (contact.organizations) {
+            translatedContact.org = exportContactFieldArray(contact.organizations, 'name');
+            translatedContact.jobTitle = exportContactFieldArray(contact.organizations, 'title');
+        }
+        /* 
             // 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
@@ -114,10 +123,8 @@ function saveContacts(successCB, errorCB, contacts) {
         */
         // 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.onsuccess = makeSuccess(contact, moz);
         request.onerror = error;                
     }
 }   


[28/28] git commit: [CB-5565] Updated version and RELEASENOTES.md for release 0.2.6

Posted by st...@apache.org.
[CB-5565] Updated version and RELEASENOTES.md for release 0.2.6


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

Branch: refs/heads/master
Commit: d610c86414917c613421626d84ed2b5e6409269c
Parents: b9c9954
Author: Steven Gill <st...@gmail.com>
Authored: Wed Dec 4 15:16:30 2013 -0800
Committer: Steven Gill <st...@gmail.com>
Committed: Wed Dec 4 15:16:30 2013 -0800

----------------------------------------------------------------------
 RELEASENOTES.md | 23 +++++++++++++++++++++++
 plugin.xml      |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/d610c864/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 2c3b6f4..249feea 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -42,3 +42,26 @@
  ### 0.2.5 (Oct 28, 2013)
 * CB-5128: added repo + issue tags for contacts
 * [CB-5010] Incremented plugin version on dev branch.
+
+### 0.2.6 (Dec 4, 2013)
+* Fix bad commit/merge
+* CB-3035 Fix issue with windows new line char \n\r
+* wrong example given
+* docs added
+* FxOS name fields are arrays hackedSearch refactored search based on find commented out
+* search hacked via getAll
+* search added - no idea if this is working
+* createMozillaFromCordova and vice versa are used to translate contact objects from one API to another.
+* add/remove working
+* save is working
+* attempt to save is failing trying to limit the translated contact fields to name and familyName, but still failing
+* save is linked with the proxy contact.name doesn't exist www/Contact.js#Contact.prototype.save check on which side is the error
+* CB-5214 Make mobile spec tests on WP8 to run w/o user interaction + Sync with cordova-mobile-spec
+* CB-5525 WP8. Contacts Api fails in case of there is special character in contact field
+* fixed ubuntu policy error
+* [ubuntu] specify policy_group
+* add ubuntu platform
+* CB-3035 Fix issue with windows new line char \n\r
+* 1. Added amazon-fireos platform. 2. Change to use amazon-fireos as the platform if user agent string contains 'cordova-amazon-fireos'.
+* CB-5198 [BlackBerry10] Update dependencies to point to registry
+* handle null filter when fields are specified. ( long standing pull-req from @kevfromireland )

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/d610c864/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 6b4cfbe..d224766 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -4,7 +4,7 @@
     xmlns:rim="http://www.blackberry.com/ns/widgets"
     xmlns:android="http://schemas.android.com/apk/res/android"
     id="org.apache.cordova.contacts"
-    version="0.2.6-dev">
+    version="0.2.6">
 
     <name>Contacts</name>
     <description>Cordova Contacts Plugin</description>