You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/07/18 23:05:45 UTC

[7/10] js commit: Contacts API updated

Contacts API updated


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

Branch: refs/heads/master
Commit: 9de3d71e74291c60648418dd698cc86c83b70d5d
Parents: 3436eb1
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Jul 17 14:11:47 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Jul 17 14:11:47 2012 -0700

----------------------------------------------------------------------
 lib/wp7/exec.js                |    6 ++--
 lib/wp7/platform.js            |   10 ++++++
 lib/wp7/plugin/wp7/contacts.js |   58 +++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9de3d71e/lib/wp7/exec.js
----------------------------------------------------------------------
diff --git a/lib/wp7/exec.js b/lib/wp7/exec.js
index f0af580..0b058b9 100644
--- a/lib/wp7/exec.js
+++ b/lib/wp7/exec.js
@@ -29,9 +29,6 @@ var NamedArgs =  {
         upload:["filePath", "server", "fileKey", "fileName", "mimeType", "params", "debug", "chunkedMode"],
         download:["url","filePath"]
     },
-    Contacts:{
-        search:["fields","options"]
-    },
     Media:{
         create:["id","src"],
         startPlayingAudio:["id","src","milliseconds"],
@@ -58,6 +55,9 @@ var NamedArgs =  {
         takePicture:["quality", "destinationType", "sourceType", "targetWidth", "targetHeight", "encodingType",
                      "mediaType", "allowEdit", "correctOrientation", "saveToPhotoAlbum" ]
     },
+    Contacts:{
+        search:["fields","options"]
+    },
 */
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9de3d71e/lib/wp7/platform.js
----------------------------------------------------------------------
diff --git a/lib/wp7/platform.js b/lib/wp7/platform.js
index 0636d2b..718830c 100644
--- a/lib/wp7/platform.js
+++ b/lib/wp7/platform.js
@@ -57,5 +57,15 @@ module.exports = {
         FileTransfer: {
             path: 'cordova/plugin/wp7/FileTransfer'
         }
+    },
+    merges:{
+        navigator: {
+            children: {
+                contacts:{
+                    path:"cordova/plugin/wp7/contacts"
+                }
+            }
+        }
     }
+    
 };

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9de3d71e/lib/wp7/plugin/wp7/contacts.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/contacts.js b/lib/wp7/plugin/wp7/contacts.js
new file mode 100644
index 0000000..2d867d9
--- /dev/null
+++ b/lib/wp7/plugin/wp7/contacts.js
@@ -0,0 +1,58 @@
+var exec = require('cordova/exec'),
+    ContactError = require('cordova/plugin/ContactError'),
+    utils = require('cordova/utils'),
+    Contact = require('cordova/plugin/Contact');
+
+/**
+* Represents a group of Contacts.
+* @constructor
+*/
+var contacts = {
+    /**
+     * Returns an array of Contacts matching the search criteria.
+     * @param fields that should be searched
+     * @param successCB success callback
+     * @param errorCB error callback
+     * @param {ContactFindOptions} options that can be applied to contact searching
+     * @return array of Contacts matching search criteria
+     */
+    find:function(fields, successCB, errorCB, options) {
+        if (!successCB) {
+            throw new TypeError("You must specify a success callback for the find command.");
+        }
+        if (!fields || (utils.isArray(fields) && fields.length === 0)) {
+            if (typeof errorCB === "function") {
+                errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
+            }
+        } else {
+            var win = function(result) {
+                var cs = [];
+                for (var i = 0, l = result.length; i < l; i++) {
+                    cs.push(contacts.create(result[i]));
+                }
+                successCB(cs);
+            };
+            exec(win, errorCB, "Contacts", "search", [{"fields":fields, "options":options}]);
+        }
+    },
+
+    /**
+     * This function creates a new contact, but it does not persist the contact
+     * to device storage. To persist the contact to device storage, invoke
+     * contact.save().
+     * @param properties an object who's properties will be examined to create a new Contact
+     * @returns new Contact object
+     */
+    create:function(properties) {
+        var i;
+        var contact = new Contact();
+        for (i in properties) {
+            if (typeof contact[i] !== 'undefined' && properties.hasOwnProperty(i)) {
+                contact[i] = properties[i];
+            }
+        }
+        return contact;
+    }
+};
+
+module.exports = contacts;