cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/3] git commit: CB-1291 Windows8 added some contact conversion, console.error on save because it is not supported
Date Fri, 14 Mar 2014 05:59:09 GMT
CB-1291 Windows8 added some contact conversion, console.error on save because it is not supported


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

Branch: refs/heads/master
Commit: b1ec0bc49ca291c559d8a9b583ee8b192c21ca75
Parents: 04b96dc
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Thu Mar 13 22:56:54 2014 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Thu Mar 13 22:56:54 2014 -0700

----------------------------------------------------------------------
 src/windows8/ContactProxy.js | 61 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/b1ec0bc4/src/windows8/ContactProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/ContactProxy.js b/src/windows8/ContactProxy.js
index 888047a..db54a09 100644
--- a/src/windows8/ContactProxy.js
+++ b/src/windows8/ContactProxy.js
@@ -1,3 +1,4 @@
+// cordova.define("org.apache.cordova.contacts.ContactProxy", function (require, exports,
module) {
 /*
  *
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -25,13 +26,69 @@ module.exports = {
     search:function(win,fail,args){
         var fields = args[0];
         var options = args[1];
+
+        var filter = options.filter;
+        var multiple = options.multiple;
+
+        var picker = new Windows.ApplicationModel.Contacts.ContactPicker();
+        picker.selectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.contacts;
+        picker.pickSingleContactAsync().done(function (res) {
+
+            var contact = {
+                id:"",
+                name: { formatted: res.name },  // ContactName
+                displayName: res.name,          // DOMString
+                nickname: res.name,             // DOMString
+                phoneNumbers: res.phoneNumbers, // ContactField[]
+                addresses: res.locations,       // ContactAddress[]
+                emails: [],                     // ContactField
+                ims: res.instantMessages,       // ContactField[]
+                organizations: [],              // ContactOrganization[]
+                birthday: null,                 // Date
+                note: "",                       // DOMString
+                photos: [],                     // ContactField[]
+                categories: [],                 // ContactField[]
+                urls: []                        // ContactField[]
+            };
+
+            if (contact.phoneNumbers && contact.phoneNumbers.length) {
+                contact.phoneNumbers[0].pref = true; // cordova contact field needs a 'prefered'
property on  a contact
+            }
+
+            if (contact.addresses && contact.addresses.length) {
+                contact.addresses[0].pref = true;
+                // convert addresses/locations to Cordova.ContactAddresses
+                // pref: Set to true if this ContactAddress contains the user's preferred
value. (boolean)
+                // type: A string indicating what type of field this is, home for example.
(DOMString)
+                // formatted: The full address formatted for display. (DOMString)
+                // streetAddress: The full street address. (DOMString)
+                // locality: The city or locality. (DOMString)
+                // region: The state or region. (DOMString)
+                // postalCode: The zip code or postal code. (DOMString)
+                // country: The country name. (DOMString)
+            }
+            // Maybe, seems the types are compatible -jm
+            // convert ims to ContactField
+            //if (contact.ims && contact.ims.length) {
+            //    // MS ContactInstantMessageField has : displayText, launchUri, service,
userName, category, type
+            //    for (var n = 0; n < contact.ims.length; n++) {
+            //        contact.ims[n] = new ContactField(contact.ims[n].type,contact.ims[n].value,
false);
+            //        }
+            //    }
+            //}
+            win([contact]);
+        });
     },
 
     save:function(win,fail,args){
-        var contact = args[0];
+        console.error && console.error("Windows 8 does not support creating/saving
contacts");
+        fail && setTimeout(function(){
+            fail(new Error("Contact create/save not supported on Windows8"));
+        },0);
     }
 
 
 }
 
-require("cordova/windows8/commandProxy").add("Contacts",module.exports);
\ No newline at end of file
+require("cordova/windows8/commandProxy").add("Contacts",module.exports);
+


Mime
View raw message