cordova-plugin-contacts
Advanced tools
Comparing version 2.0.1 to 2.1.0
{ | ||
"name": "cordova-plugin-contacts", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Cordova Contacts Plugin", | ||
@@ -38,4 +38,11 @@ "cordova": { | ||
], | ||
"scripts": { | ||
"test": "npm run jshint", | ||
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests" | ||
}, | ||
"author": "Apache Software Foundation", | ||
"license": "Apache 2.0" | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"jshint": "^2.6.0" | ||
} | ||
} |
@@ -20,2 +20,4 @@ <!--- | ||
[![Build Status](https://travis-ci.org/apache/cordova-plugin-contacts.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-contacts) | ||
# cordova-plugin-contacts | ||
@@ -47,5 +49,5 @@ | ||
contact data helps avoid user confusion and perceived misuse of | ||
contact data. For more information, please see the Privacy Guide. | ||
contact data. For more information, please see the [Privacy Guide](http://cordova.apache.org/docs/en/latest/guide/appdev/privacy/index.html). | ||
:warning: Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Contacts%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC) | ||
Report issues with this plugin on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Contacts%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC) | ||
@@ -221,3 +223,2 @@ ## Installation | ||
- Windows Phone 8 | ||
- Windows 8 | ||
- Windows | ||
@@ -236,3 +237,3 @@ | ||
This plugin launches an external Activity for picking contacts. See the | ||
[Android Lifecycle Guide](http://cordova.apache.org/docs/en/dev/guide/platforms/android/lifecycle.html) | ||
[Android Lifecycle Guide](http://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#lifecycle-guide) | ||
for an explanation of how this affects your application. If the plugin returns | ||
@@ -313,3 +314,2 @@ its result in the `resume` event, then you must first wrap the returned object | ||
- Windows Phone 8 | ||
- Windows 8 | ||
- Windows | ||
@@ -362,3 +362,29 @@ | ||
### Removing phone number(s) from a saved contact | ||
// Example to create a contact with 3 phone numbers and then remove | ||
// 2 phone numbers. This example is for illustrative purpose only | ||
var myContact = navigator.contacts.create({"displayName": "Test User"}); | ||
var phoneNumbers = []; | ||
phoneNumbers[0] = new ContactField('work', '768-555-1234', false); | ||
phoneNumbers[1] = new ContactField('mobile', '999-555-5432', true); // preferred number | ||
phoneNumbers[2] = new ContactField('home', '203-555-7890', false); | ||
myContact.phoneNumbers = phoneNumbers; | ||
myContact.save(function (contact_obj) { | ||
var contactObjToModify = contact_obj.clone(); | ||
contact_obj.remove(function(){ | ||
var phoneNumbers = [contactObjToModify.phoneNumbers[0]]; | ||
contactObjToModify.phoneNumbers = phoneNumbers; | ||
contactObjToModify.save(function(c_obj){ | ||
console.log("All Done"); | ||
}, function(error){ | ||
console.log("Not able to save the cloned object: " + error); | ||
}); | ||
}, function(contactError) { | ||
console.log("Contact Remove Operation failed: " + contactError); | ||
}); | ||
}); | ||
### Android 2.X Quirks | ||
@@ -458,3 +484,2 @@ | ||
- Windows Phone 8 | ||
- Windows 8 | ||
- Windows | ||
@@ -524,6 +549,2 @@ | ||
### Windows 8 Quirks | ||
- __pref__: Not supported | ||
### Windows Quirks | ||
@@ -589,3 +610,2 @@ | ||
- Windows Phone 8 | ||
- Windows 8 | ||
- Windows | ||
@@ -624,6 +644,2 @@ | ||
### Windows8 Quirks | ||
- __pref__: Not supported, returning `false`. | ||
### Windows Quirks | ||
@@ -660,3 +676,2 @@ | ||
- Windows Phone 8 | ||
- Windows 8 | ||
- Windows | ||
@@ -714,3 +729,3 @@ | ||
### Windows 8 Quirks | ||
### Windows Quirks | ||
@@ -729,7 +744,3 @@ - __formatted__: This is the only name property, and is identical to `displayName`, and `nickname` | ||
### Windows Quirks | ||
- __formatted__: It is identical to `displayName` | ||
## ContactOrganization | ||
@@ -736,0 +747,0 @@ |
@@ -23,2 +23,18 @@ <!-- | ||
### 2.1.0 (Apr 15, 2016) | ||
* CB-11043 **Android** app crashes while trying to save contact with phone numbers array with deleted values | ||
* CB-10985 Android sets type to `-1` for ims Added a corresponding test | ||
* CB-11048 Fix spec27's inadvertant breakage that happened during logging rollback | ||
* CB-11041 `cordova-plugin-contacts` readme must be updated to include instructions on removing phone number from a contact | ||
* CB-11033 Appium tests: Increased the timeout for updating the contact | ||
* CB-10399 Added Appium tests | ||
* Replace `PermissionHelper.java` with `cordova-plugin-compat` | ||
* CB-8115 incorrect birthday saved to phonebook using Contacts Plugin | ||
* Changes to stop using global object - remove all created contacts from the emulator | ||
* CB-10881 Increase timeout for Spec22 | ||
* Fix for the specs 26&27 to use the newly created contacts for removal test | ||
* CB-10881 Remove test dependency on global object | ||
* CB-10632 Fixing jasmine test contact removal | ||
* CB-10636 Add `JSHint` for plugins | ||
### 2.0.1 (Jan 15, 2016) | ||
@@ -25,0 +41,0 @@ * CB-10159 **Android** Adding restore callback to handle Activity destruction |
@@ -21,3 +21,5 @@ /* | ||
*/ | ||
/* global ContactPickerOptions */ | ||
var self, | ||
@@ -24,0 +26,0 @@ ContactFindOptions = require("./ContactFindOptions"), |
@@ -16,24 +16,10 @@ /* | ||
*/ | ||
/* global PluginResult, JNEXT, escape */ | ||
var pimContacts, | ||
contactUtils = require("./contactUtils"), | ||
contactConsts = require("./contactConsts"), | ||
ContactError = require("./ContactError"), | ||
ContactName = require("./ContactName"), | ||
ContactFindOptions = require("./ContactFindOptions"), | ||
noop = function () {}; | ||
ContactFindOptions = require("./ContactFindOptions"); | ||
function getAccountFilters(options) { | ||
if (options.includeAccounts) { | ||
options.includeAccounts = options.includeAccounts.map(function (acct) { | ||
return acct.id.toString(); | ||
}); | ||
} | ||
if (options.excludeAccounts) { | ||
options.excludeAccounts = options.excludeAccounts.map(function (acct) { | ||
return acct.id.toString(); | ||
}); | ||
} | ||
} | ||
function populateSearchFields(fields) { | ||
@@ -62,17 +48,17 @@ var i, | ||
searchFieldsObject[ContactFindOptions.SEARCH_FIELD_EMAIL] = true; | ||
} else if (field === "addresses") { | ||
} else if (fields[i] === "addresses") { | ||
// not supported by Cascades | ||
} else if (field === "ims") { | ||
} else if (fields[i] === "ims") { | ||
// not supported by Cascades | ||
} else if (field === "organizations") { | ||
} else if (fields[i] === "organizations") { | ||
searchFieldsObject[ContactFindOptions.SEARCH_FIELD_ORGANIZATION_NAME] = true; | ||
} else if (field === "birthday") { | ||
} else if (fields[i] === "birthday") { | ||
// not supported by Cascades | ||
} else if (field === "note") { | ||
} else if (fields[i] === "note") { | ||
// not supported by Cascades | ||
} else if (field === "photos") { | ||
} else if (fields[i] === "photos") { | ||
// not supported by Cascades | ||
} else if (field === "categories") { | ||
} else if (fields[i] === "categories") { | ||
// not supported by Cascades | ||
} else if (field === "urls") { | ||
} else if (fields[i] === "urls") { | ||
// not supported by Cascades | ||
@@ -103,4 +89,3 @@ } | ||
function processJnextSaveData(result, JnextData) { | ||
var data = JnextData, | ||
birthdayInfo; | ||
var data = JnextData; | ||
@@ -130,4 +115,3 @@ if (data._success === true) { | ||
more = false, | ||
resultsObject = {}, | ||
birthdayInfo; | ||
resultsObject = {}; | ||
@@ -199,3 +183,2 @@ if (data.contacts) { | ||
result = new PluginResult(args, env), | ||
key, | ||
nativeEmails = []; | ||
@@ -294,3 +277,3 @@ | ||
JNEXT.invoke(self.m_id, "find " + JSON.stringify(jnextArgs)); | ||
} | ||
}; | ||
@@ -297,0 +280,0 @@ self.getContact = function (args) { |
@@ -22,2 +22,4 @@ /* | ||
/* global mozContact */ | ||
// Cordova contact definition: | ||
@@ -31,3 +33,2 @@ // http://cordova.apache.org/docs/en/2.5.0/cordova_contacts_contacts.md.html#Contact | ||
var ContactField = require('./ContactField'); | ||
var ContactAddress = require('./ContactAddress'); | ||
var ContactName = require('./ContactName'); | ||
@@ -51,9 +52,9 @@ | ||
key = 'value'; | ||
} | ||
} | ||
var arr = []; | ||
for (var i=0; i < contactFieldArray.length; i++) { | ||
arr.push(contactFieldArray[i][key]); | ||
}; | ||
} | ||
return arr; | ||
} | ||
} | ||
@@ -72,11 +73,11 @@ function exportAddress(addresses) { | ||
} else if (key == 'country') { | ||
addr['countryName'] = addresses[i][key]; | ||
addr.countryName = addresses[i][key]; | ||
} else { | ||
addr[key] = addresses[i][key]; | ||
addr[key] = addresses[i][key]; | ||
} | ||
} | ||
} | ||
arr.push(addr); | ||
} | ||
} | ||
return arr; | ||
} | ||
} | ||
@@ -106,3 +107,3 @@ function exportContactField(data) { | ||
var baseStringFields = []; | ||
var j = 0; while(field = nameFields[j++]) { | ||
var j = 0, field; while(field = nameFields[j++]) { // jshint ignore:line | ||
if (fromContact.name[field[0]]) { | ||
@@ -112,3 +113,3 @@ contact[field[1] || field[0]] = fromContact.name[field[0]].split(' '); | ||
} | ||
j = 0; while(field = baseArrayFields[j++]) { | ||
j = 0; while(field = baseArrayFields[j++]) { // jshint ignore:line | ||
if (fromContact[field[0]]) { | ||
@@ -118,3 +119,3 @@ contact[field[1] || field[0]] = fromContact[field[0]].split(' '); | ||
} | ||
j = 0; while(field = baseStringFields[j++]) { | ||
j = 0; while(field = baseStringFields[j++]) { // jshint ignore:line | ||
if (fromContact[field[0]]) { | ||
@@ -128,3 +129,3 @@ contact[field[1] || field[0]] = fromContact[field[0]]; | ||
if (fromContact.emails) { | ||
var emails = exportContactField(fromContact.emails) | ||
var emails = exportContactField(fromContact.emails); | ||
contact.email = emails; | ||
@@ -183,13 +184,13 @@ } | ||
if (key == 'countryName') { | ||
addr['country'] = addresses[i][key]; | ||
addr.country = addresses[i][key]; | ||
} else if (key == 'type') { | ||
addr[key] = addresses[i][key].join(' '); | ||
} else { | ||
addr[key] = addresses[i][key]; | ||
addr[key] = addresses[i][key]; | ||
} | ||
} | ||
} | ||
arr.push(addr); | ||
} | ||
return arr; | ||
} | ||
} | ||
@@ -233,3 +234,3 @@ function createOrganizations(orgs, jobs) { | ||
var name = new ContactName(); | ||
var j = 0; while(field = nameFields[j++]) { | ||
var j = 0, field; while(field = nameFields[j++]) { // jshint ignore:line | ||
if (moz[field[0]]) { | ||
@@ -240,3 +241,3 @@ name[field[1] || field[0]] = moz[field[0]].join(' '); | ||
this.name = name; | ||
j = 0; while(field = baseArrayFields[j++]) { | ||
j = 0; while(field = baseArrayFields[j++]) { // jshint ignore:line | ||
if (moz[field[0]]) { | ||
@@ -246,3 +247,3 @@ this[field[1] || field[0]] = moz[field[0]].join(' '); | ||
} | ||
j = 0; while(field = baseStringFields[j++]) { | ||
j = 0; while(field = baseStringFields[j++]) { // jshint ignore:line | ||
if (moz[field[0]]) { | ||
@@ -291,3 +292,3 @@ this[field[1] || field[0]] = moz[field[0]]; | ||
*/ | ||
} | ||
}; | ||
@@ -339,15 +340,17 @@ | ||
successCB(contact); | ||
} | ||
}; | ||
} | ||
var i=0; | ||
var contact; | ||
while(contact = contacts[i++]){ | ||
var moz = createMozillaFromCordova(function(moz) { | ||
var request = navigator.mozContacts.save(moz); | ||
// success and/or fail will be called every time a contact is saved | ||
request.onsuccess = makeSaveSuccessCB(moz); | ||
request.onerror = errorCB; | ||
/*jshint -W083 */ | ||
while(contact = contacts[i++]) { // jshint ignore:line | ||
createMozillaFromCordova(function(moz) { | ||
var request = navigator.mozContacts.save(moz); | ||
// success and/or fail will be called every time a contact is saved | ||
request.onsuccess = makeSaveSuccessCB(moz); | ||
request.onerror = errorCB; | ||
}, function() {}, contact); | ||
} | ||
} | ||
/*jshint +W083 */ | ||
} | ||
@@ -357,5 +360,5 @@ | ||
function remove(successCB, errorCB, ids) { | ||
var i=0; | ||
var id; | ||
for (var i=0; i < ids.length; i++){ | ||
var i; | ||
/*jshint -W083 */ | ||
for (i = 0; i < ids.length; i++){ | ||
// throw an error if no id provided | ||
@@ -383,2 +386,3 @@ if (!_hasId(ids[i])) { | ||
} | ||
/*jshint +W083 */ | ||
} | ||
@@ -464,3 +468,2 @@ | ||
var mozContacts = request.result; | ||
var moz = mozContacts[0]; | ||
for (var i=0; i < mozContacts.length; i++) { | ||
@@ -467,0 +470,0 @@ contacts.push(createCordovaFromMozilla(mozContacts[i])); |
@@ -22,2 +22,4 @@ /* | ||
/* global Windows, WinJS */ | ||
var ContactField = require('./ContactField'), | ||
@@ -52,3 +54,4 @@ ContactAddress = require('./ContactAddress'), | ||
var phoneSource = windowsContact.phoneNumbers || windowsContact.phones; | ||
for (var i = 0; i < phoneSource.size; i++) { | ||
var i; | ||
for (i = 0; i < phoneSource.size; i++) { | ||
var rawPhone = phoneSource[i]; | ||
@@ -62,3 +65,3 @@ var phone = new ContactField(rawPhone.category || rawPhone.kind, rawPhone.value || rawPhone.number); | ||
var emailSource = windowsContact.emails; | ||
for (var i = 0; i < emailSource.size; i++) { | ||
for (i = 0; i < emailSource.size; i++) { | ||
var rawEmail = emailSource[i]; | ||
@@ -72,3 +75,3 @@ var email = new ContactField(rawEmail.category || rawEmail.kind, rawEmail.value || rawEmail.address); | ||
var addressSource = windowsContact.locations || windowsContact.addresses; | ||
for (var i = 0; i < addressSource.size; i++) { | ||
for (i = 0; i < addressSource.size; i++) { | ||
var rawAddress = addressSource[i]; | ||
@@ -90,3 +93,3 @@ var address = new ContactAddress( | ||
var imSource = windowsContact.instantMessages || windowsContact.connectedServiceAccounts; | ||
for (var i = 0; i < imSource.size; i++) { | ||
for (i = 0; i < imSource.size; i++) { | ||
var rawIm = imSource[i]; | ||
@@ -282,3 +285,5 @@ var im = new ContactField(rawIm.category || rawIm.serviceName, rawIm.userName || rawIm.id); | ||
//We don't need to create Error object here since it will be created at navigator.contacts.find() method | ||
fail && fail(ContactError.NOT_SUPPORTED_ERROR); | ||
if (fail) { | ||
fail(ContactError.NOT_SUPPORTED_ERROR); | ||
} | ||
return; | ||
@@ -316,3 +321,5 @@ } | ||
//We don't need to create Error object here since it will be created at navigator.contacts.find() method | ||
fail && fail(ContactError.NOT_SUPPORTED_ERROR); | ||
if (fail) { | ||
fail(ContactError.NOT_SUPPORTED_ERROR); | ||
} | ||
return; | ||
@@ -390,3 +397,3 @@ } | ||
// see http://msdn.microsoft.com/en-us/library/windows/apps/dn624861.aspx for details | ||
var searchFields = options[0], | ||
var searchFields = options[0], // jshint ignore:line | ||
searchOptions = options[1], | ||
@@ -393,0 +400,0 @@ searchFilter = searchOptions.filter, |
@@ -22,2 +22,4 @@ /* | ||
/* global Windows */ | ||
var ContactField = require('./ContactField'), | ||
@@ -31,2 +33,3 @@ ContactAddress = require('./ContactAddress'), | ||
var contact = new Contact(); | ||
var i; | ||
@@ -42,3 +45,3 @@ // displayName & nickname | ||
contact.phoneNumbers = []; | ||
for (var i = 0; i < windowsContact.phoneNumbers.size; i++) { | ||
for (i = 0; i < windowsContact.phoneNumbers.size; i++) { | ||
var phone = new ContactField(windowsContact.phoneNumbers[i].category, windowsContact.phoneNumbers[i].value); | ||
@@ -50,3 +53,3 @@ contact.phoneNumbers.push(phone); | ||
contact.emails = []; | ||
for (var i = 0; i < windowsContact.emails.size; i++) { | ||
for (i = 0; i < windowsContact.emails.size; i++) { | ||
var email = new ContactField(windowsContact.emails[i].category, windowsContact.emails[i].value); | ||
@@ -58,3 +61,3 @@ contact.emails.push(email); | ||
contact.addresses = []; | ||
for (var i = 0; i < windowsContact.locations.size; i++) { | ||
for (i = 0; i < windowsContact.locations.size; i++) { | ||
var address = new ContactAddress(null, windowsContact.locations[i].category, | ||
@@ -69,3 +72,3 @@ windowsContact.locations[i].unstructuredAddress, windowsContact.locations[i].street, | ||
contact.ims = []; | ||
for (var i = 0; i < windowsContact.instantMessages.size; i++) { | ||
for (i = 0; i < windowsContact.instantMessages.size; i++) { | ||
var im = new ContactField(windowsContact.instantMessages[i].category, windowsContact.instantMessages[i].userName); | ||
@@ -76,8 +79,23 @@ contact.ims.push(im); | ||
return contact; | ||
}; | ||
} | ||
module.exports = { | ||
pickContact: function(win, fail, args) { | ||
var picker = new Windows.ApplicationModel.Contacts.ContactPicker(); | ||
var picker = new Windows.ApplicationModel.Contacts.ContactPicker(); | ||
function success(con) { | ||
// if contact was not picked | ||
if (!con) { | ||
if (fail) { | ||
setTimeout(function() { | ||
fail(new Error("User did not pick a contact.")); | ||
}, 0); | ||
} | ||
return; | ||
} | ||
// send em back | ||
win(convertToContact(con)); | ||
} | ||
picker.selectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.contacts; // select entire contact | ||
@@ -92,17 +110,2 @@ | ||
} else { | ||
function success(con) { | ||
// if contact was not picked | ||
if (!con) { | ||
fail && setTimeout(function() { | ||
fail(new Error("User did not pick a contact.")); | ||
}, 0); | ||
return; | ||
} | ||
// send em back | ||
win(convertToContact(con)); | ||
} | ||
picker.pickSingleContactAsync().done(success, fail); | ||
@@ -113,18 +116,24 @@ } | ||
save:function(win,fail,args){ | ||
console && console.error && console.error("Error : Windows 8 does not support creating/saving contacts"); | ||
fail && setTimeout(function () { | ||
fail(new Error("Contact create/save not supported on Windows 8")); | ||
}, 0); | ||
if (console && console.error) { | ||
console.error("Error : Windows 8 does not support creating/saving contacts"); | ||
} | ||
if (fail) { | ||
setTimeout(function () { | ||
fail(new Error("Contact create/save not supported on Windows 8")); | ||
}, 0); | ||
} | ||
}, | ||
search: function(win, fail, args) { | ||
console && console.error && console.error("Error : Windows 8 does not support searching contacts"); | ||
fail && setTimeout(function() { | ||
fail(new Error("Contact search not supported on Windows 8")); | ||
}, 0); | ||
if (console && console.error) { | ||
console.error("Error : Windows 8 does not support searching contacts"); | ||
} | ||
if (fail) { | ||
setTimeout(function() { | ||
fail(new Error("Contact search not supported on Windows 8")); | ||
}, 0); | ||
} | ||
} | ||
}; | ||
} | ||
require("cordova/exec/proxy").add("Contacts", module.exports); |
@@ -22,10 +22,21 @@ /* | ||
/* jshint jasmine: true */ | ||
/* global WinJS */ | ||
exports.defineAutoTests = function() { | ||
// 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, | ||
isWindowsPhone8 = cordova.platformId == 'windowsphone', | ||
isWindows = (cordova.platformId === "windows") || (cordova.platformId === "windows8"), | ||
isWindowsPhone81 = isWindows && WinJS.Utilities.isPhone; | ||
var isWindowsPhone8 = cordova.platformId == 'windowsphone'; | ||
var isWindows = (cordova.platformId === "windows") || (cordova.platformId === "windows8"); | ||
var isWindowsPhone81 = isWindows && WinJS.Utilities.isPhone; | ||
// Error callback spies should not be called | ||
var errorCallbacks = {}; | ||
errorCallbacks[ContactError.UNKNOWN_ERROR] = jasmine.createSpy('unknownErrorCallback'); | ||
errorCallbacks[ContactError.INVALID_ARGUMENT_ERROR] = jasmine.createSpy('invalidArgumentErrorCallback'); | ||
errorCallbacks[ContactError.TIMEOUT_ERROR] = jasmine.createSpy('timeoutErrorCallback'); | ||
errorCallbacks[ContactError.PENDING_OPERATION_ERROR] = jasmine.createSpy('pendingOperationErrorCallback'); | ||
errorCallbacks[ContactError.IO_ERROR] = jasmine.createSpy('ioErrorCallback'); | ||
errorCallbacks[ContactError.NOT_SUPPORTED_ERROR] = jasmine.createSpy('notSupportedErrorCallback'); | ||
errorCallbacks[ContactError.OPERATION_CANCELLED_ERROR] = jasmine.createSpy('operationCancelledErrorCallback'); | ||
errorCallbacks[ContactError.PERMISSION_DENIED_ERROR] = jasmine.createSpy('permissionDeniedErrorCallback'); | ||
var isIOSPermissionBlocked = false; | ||
@@ -39,5 +50,6 @@ | ||
var MEDIUM_TIMEOUT = 30000; | ||
var HIGH_TIMEOUT = 120000; | ||
var removeContact = function(done) { | ||
if (!gContactObj) { | ||
var removeContact = function(done, contactObj) { | ||
if (!contactObj) { | ||
done(); | ||
@@ -47,6 +59,17 @@ return; | ||
gContactObj.remove(function() { | ||
gContactObj = null; | ||
contactObj.remove(function() { | ||
done(); | ||
}, function() { | ||
}, function(contactError) { | ||
if (contactError) { | ||
if (errorCallbacks[contactError.code]) { | ||
errorCallbacks[contactError.code](); | ||
} else { | ||
fail(done); | ||
} | ||
} | ||
for (var error in errorCallbacks) { | ||
expect(errorCallbacks[error]).not.toHaveBeenCalled(); | ||
} | ||
done(); | ||
@@ -65,3 +88,3 @@ }); | ||
}); | ||
if (removes.length == 0) { | ||
if (removes.length === 0) { | ||
done(); | ||
@@ -71,3 +94,3 @@ return; | ||
var nextToRemove = undefined; | ||
var nextToRemove; | ||
if (removes.length > 0) { | ||
@@ -100,2 +123,4 @@ nextToRemove = removes.shift(); | ||
describe("Contacts (navigator.contacts)", function() { | ||
this.contactObj = null; | ||
it("contacts.spec.1 should exist", function() { | ||
@@ -159,3 +184,5 @@ expect(navigator.contacts).toBeDefined(); | ||
expect(function() { | ||
navigator.contacts.find(["displayName", "name", "emails", "phoneNumbers"], null, fail.bind(null, done), obj); | ||
navigator.contacts.find(["displayName", "name", "emails", "phoneNumbers"], null, function (err) { | ||
expect(err).toBeUndefined(); | ||
}, obj); | ||
}).toThrow(); | ||
@@ -182,3 +209,3 @@ }); | ||
afterEach(function (done) { | ||
removeContact(done); | ||
removeContact(done, this.contactObj); | ||
}); | ||
@@ -193,41 +220,44 @@ | ||
var specContext = this; | ||
specContext.contactObj = new Contact(); | ||
specContext.contactObj.name = new ContactName(); | ||
specContext.contactObj.name.familyName = "Delete"; | ||
var foundName = function(result) { | ||
var bFound = false; | ||
try { | ||
for (var i = 0; i < result.length; i++) { | ||
if (result[i].name.familyName == "Delete") { | ||
bFound = true; | ||
break; | ||
} | ||
var bFound = false; | ||
try { | ||
for (var i = 0; i < result.length; i++) { | ||
if (result[i].name.familyName == "Delete") { | ||
bFound = true; | ||
break; | ||
} | ||
} catch (e) { | ||
return false; | ||
} | ||
return bFound; | ||
}, | ||
test = function(savedContact) { | ||
// update so contact will get removed | ||
gContactObj = savedContact; | ||
// ---- | ||
// Find asserts | ||
// --- | ||
var findWin = function(object) { | ||
expect(object instanceof Array).toBe(true); | ||
expect(object.length >= 1).toBe(true); | ||
expect(foundName(object)).toBe(true); | ||
done(); | ||
}, | ||
findFail = fail, | ||
obj = new ContactFindOptions(); | ||
} catch (e) { | ||
return false; | ||
} | ||
return bFound; | ||
}; | ||
obj.filter = "Delete"; | ||
obj.multiple = true; | ||
var test = function(savedContact) { | ||
// update so contact will get removed | ||
specContext.contactObj = savedContact; | ||
// ---- | ||
// Find asserts | ||
// --- | ||
var findWin = function(object) { | ||
expect(object instanceof Array).toBe(true); | ||
expect(object.length >= 1).toBe(true); | ||
expect(foundName(object)).toBe(true); | ||
done(); | ||
}, | ||
findFail = fail, | ||
obj = new ContactFindOptions(); | ||
navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, findFail.bind(null, done), obj); | ||
}; | ||
obj.filter = "Delete"; | ||
obj.multiple = true; | ||
gContactObj = new Contact(); | ||
gContactObj.name = new ContactName(); | ||
gContactObj.name.familyName = "Delete"; | ||
gContactObj.save(test, fail.bind(null, done)); | ||
navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, findFail.bind(null, done), obj); | ||
}; | ||
specContext.contactObj.save(test, fail.bind(null, done)); | ||
}); | ||
@@ -390,3 +420,3 @@ }); | ||
afterEach(function (done) { | ||
removeContact(done); | ||
removeContact(done, this.contactObj); | ||
}); | ||
@@ -400,2 +430,3 @@ | ||
var specContext = this; | ||
var bDay = new Date(1976, 6, 4); | ||
@@ -418,2 +449,3 @@ var obj = { | ||
var saveSuccess = function(obj) { | ||
specContext.contactObj = obj; | ||
expect(obj).toBeDefined(); | ||
@@ -428,6 +460,5 @@ expect(obj.note).toBe('my note'); | ||
expect(obj.addresses).toBe(null); | ||
gContactObj = obj; | ||
done(); | ||
}, | ||
saveFail = fail.bind(null, done); | ||
}; | ||
var saveFail = fail.bind(null, done); | ||
@@ -445,7 +476,9 @@ navigator.contacts | ||
var specContext = this; | ||
var aDay = new Date(1976, 6, 4); | ||
var bDay; | ||
var noteText = "an UPDATED note"; | ||
var savedContact; | ||
var obj = { | ||
var contact = { | ||
"gender": "male", | ||
@@ -467,14 +500,6 @@ "note": "my note", | ||
var saveSuccess = function(obj) { | ||
gContactObj = obj; | ||
gContactObj.emails[1].value = ""; | ||
bDay = new Date(1975, 5, 4); | ||
gContactObj.birthday = bDay; | ||
gContactObj.note = noteText; | ||
gContactObj.save(updateSuccess, saveFail); | ||
}; | ||
var updateSuccess = function(obj) { | ||
function updateSuccess(obj) { | ||
specContext.contactObj = obj; | ||
expect(obj).toBeDefined(); | ||
expect(obj.id).toBe(gContactObj.id); | ||
expect(obj.id).toBe(savedContact.id); | ||
expect(obj.note).toBe(noteText); | ||
@@ -485,9 +510,19 @@ expect(obj.birthday.toDateString()).toBe(bDay.toDateString()); | ||
done(); | ||
} | ||
var saveSuccess = function(newContact) { | ||
specContext.contactObj = newContact; | ||
savedContact = newContact; | ||
newContact.emails[1].value = ""; | ||
bDay = new Date(1975, 5, 4); | ||
newContact.birthday = bDay; | ||
newContact.note = noteText; | ||
newContact.save(updateSuccess, saveFail); | ||
}; | ||
navigator.contacts | ||
.create(obj) | ||
.create(contact) | ||
.save(saveSuccess, saveFail); | ||
}, MEDIUM_TIMEOUT); | ||
}, HIGH_TIMEOUT); | ||
}); | ||
@@ -497,3 +532,3 @@ | ||
afterEach(function (done) { | ||
removeContact(done); | ||
removeContact(done, this.contactObj); | ||
}); | ||
@@ -529,10 +564,10 @@ | ||
describe("Round trip Contact tests (creating + save + delete + find)", function() { | ||
var saveAndFindBy = function (fields, filter, done) { | ||
var saveAndFindBy = function (contact, fields, filter, callback, specContext) { | ||
removeContactsByFields(["note"], "DeleteMe", function() { | ||
gContactObj.save(function(c_obj) { | ||
contact.save(function(c_obj) { | ||
specContext.contactObj = c_obj; | ||
var findWin = function(cs) { | ||
// update to have proper saved id | ||
gContactObj = cs[0]; | ||
expect(cs.length).toBe(1); | ||
done(); | ||
specContext.contactObj = cs[0]; | ||
callback(cs[0]); | ||
}; | ||
@@ -549,3 +584,3 @@ var findFail = fail; | ||
afterEach(function (done) { | ||
removeContact(done); | ||
removeContact(done, this.contactObj); | ||
}); | ||
@@ -559,10 +594,12 @@ | ||
var contactName = "DeleteMe"; | ||
gContactObj = new Contact(); | ||
gContactObj.name = new ContactName(); | ||
gContactObj.name.familyName = contactName; | ||
saveAndFindBy(["displayName", "name"], contactName, done); | ||
var contact = new Contact(); | ||
contact.name = new ContactName(); | ||
contact.name.familyName = contactName; | ||
contact.note = "DeleteMe"; | ||
saveAndFindBy(contact, ["displayName", "name"], contactName, done, this); | ||
}, MEDIUM_TIMEOUT); | ||
it("contacts.spec.26 Creating, saving, finding a contact should work, removing it should work", function(done) { | ||
// Save method is not supported on Windows platform | ||
var specContext = this; | ||
if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) { | ||
@@ -572,14 +609,16 @@ pending(); | ||
var contactName = "DeleteMe"; | ||
gContactObj = new Contact(); | ||
gContactObj.name = new ContactName(); | ||
gContactObj.name.familyName = contactName; | ||
saveAndFindBy(["displayName", "name"], contactName, function() { | ||
gContactObj.remove(function() { | ||
var contact = new Contact(); | ||
contact.name = new ContactName(); | ||
contact.name.familyName = contactName; | ||
contact.note = "DeleteMe"; | ||
saveAndFindBy(contact, ["displayName", "name"], contactName, function(savedContact) { | ||
savedContact.remove(function() { | ||
specContext.contactObj = null; | ||
done(); | ||
}, function(e) { | ||
throw ("Newly created contact's remove function invoked error callback. Test failed."); | ||
throw ("Newly created contact's remove function invoked error callback. Test failed: " + JSON.stringify(e)); | ||
}); | ||
}); | ||
}, this); | ||
}, MEDIUM_TIMEOUT); | ||
it("contacts.spec.27 Should not be able to delete the same contact twice", function(done) { | ||
@@ -590,12 +629,15 @@ // Save method is not supported on Windows platform | ||
} | ||
var contactName = "DeleteMe"; | ||
gContactObj = new Contact(); | ||
gContactObj.name = new ContactName(); | ||
gContactObj.name.familyName = contactName; | ||
saveAndFindBy(["displayName", "name"], contactName, function() { | ||
gContactObj.remove(function() { | ||
var specContext = this; | ||
var contactName = "DeleteMe2"; | ||
var contact = new Contact(); | ||
contact.name = new ContactName(); | ||
contact.name.familyName = contactName; | ||
contact.note = "DeleteMe2"; | ||
saveAndFindBy(contact, ["displayName", "name"], contactName, function(savedContact) { | ||
savedContact.remove(function() { | ||
specContext.contactObj = null; | ||
var findWin = function(seas) { | ||
expect(seas.length).toBe(0); | ||
gContactObj.remove(function() { | ||
throw ("Success callback called after non-existent Contact object called remove(). Test failed."); | ||
savedContact.remove(function(e) { | ||
throw ("Success callback called after non-existent Contact object called remove(). Test failed: " + JSON.stringify(e)); | ||
}, function(e) { | ||
@@ -611,3 +653,3 @@ expect(e.code).toBe(ContactError.UNKNOWN_ERROR); | ||
}, fail); | ||
}); | ||
}, this); | ||
}, MEDIUM_TIMEOUT); | ||
@@ -621,7 +663,7 @@ | ||
var contactName = "\u2602"; | ||
gContactObj = new Contact(); | ||
gContactObj.note = "DeleteMe"; | ||
gContactObj.name = new ContactName(); | ||
gContactObj.name.familyName = contactName; | ||
saveAndFindBy(["displayName", "name"], contactName, done); | ||
var contact = new Contact(); | ||
contact.note = "DeleteMe"; | ||
contact.name = new ContactName(); | ||
contact.name.familyName = contactName; | ||
saveAndFindBy(contact, ["displayName", "name"], contactName, done, this); | ||
}, MEDIUM_TIMEOUT); | ||
@@ -634,11 +676,56 @@ | ||
} | ||
gContactObj = new Contact(); | ||
var contact = new Contact(); | ||
var phoneNumbers = [1]; | ||
phoneNumbers[0] = new ContactField('work', '555-555-1234', true); | ||
gContactObj.phoneNumbers = phoneNumbers; | ||
saveAndFindBy(["phoneNumbers"], "555-555-1234", done); | ||
contact.phoneNumbers = phoneNumbers; | ||
saveAndFindBy(contact, ["phoneNumbers"], "555-555-1234", done, this); | ||
}, MEDIUM_TIMEOUT); | ||
it("contacts.spec.31 Find should return a contact with correct birthday field type", function(done) { | ||
// Save method is not supported on Windows platform | ||
if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) { | ||
pending(); | ||
} | ||
var contactName = "DeleteMe"; | ||
var bDay = new Date(1976, 7, 4); | ||
var contact = new Contact(); | ||
contact.name = new ContactName(); | ||
contact.name.familyName = contactName; | ||
contact.note = "DeleteMe"; | ||
contact.birthday = bDay; | ||
saveAndFindBy(contact, ["displayName", "name"], contactName, function(found) { | ||
expect(found.birthday).toEqual(jasmine.any(Date)); | ||
expect(found.birthday).toEqual(bDay); | ||
done(); | ||
}, done, this); | ||
}, MEDIUM_TIMEOUT); | ||
it("contacts.spec.32 Find should return a contact with correct IM field", function(done) { | ||
// Save method is not supported on Windows platform | ||
if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) { | ||
pending(); | ||
} | ||
var contactName = "DeleteMe"; | ||
var ims = [{ | ||
type: "Skype", | ||
value: "imValue" | ||
}]; | ||
var contact = new Contact(); | ||
contact.name = new ContactName(); | ||
contact.name.familyName = contactName; | ||
contact.note = "DeleteMe"; | ||
contact.ims = ims; | ||
saveAndFindBy(contact, ["displayName", "name"], contactName, function(found) { | ||
expect(found.ims).toEqual(jasmine.any(Array)); | ||
expect(found.ims[0]).toBeDefined(); | ||
if (found.ims[0]) { | ||
expect(found.ims[0].type).toEqual(ims[0].type); | ||
expect(found.ims[0].value).toEqual(ims[0].value); | ||
} | ||
done(); | ||
}, done, this); | ||
}, MEDIUM_TIMEOUT); | ||
}); | ||
@@ -675,3 +762,3 @@ | ||
var s = ""; | ||
if (contacts.length == 0) { | ||
if (contacts.length === 0) { | ||
s = "No contacts found"; | ||
@@ -687,3 +774,3 @@ } else { | ||
} | ||
s = s + "</td><td>" | ||
s = s + "</td><td>"; | ||
if (contact.emails && contact.emails.length > 0) { | ||
@@ -730,3 +817,3 @@ s = s + contact.emails[0].value; | ||
} | ||
function addContact(displayName, name, phoneNumber, birthday) { | ||
@@ -792,3 +879,3 @@ try { | ||
navigator.contacts.find(['displayName', 'name'], function(contacts) { | ||
if (contacts.length == 0) { | ||
if (contacts.length === 0) { | ||
results.innerHTML = 'No contacts to update.'; | ||
@@ -814,3 +901,3 @@ return; | ||
} | ||
}, obj) | ||
}, obj); | ||
} | ||
@@ -829,3 +916,3 @@ | ||
}); | ||
if (removes.length == 0) { | ||
if (removes.length === 0) { | ||
results.innerHTML = "No contacts to remove"; | ||
@@ -835,3 +922,3 @@ return; | ||
var nextToRemove = undefined; | ||
var nextToRemove; | ||
if (removes.length > 0) { | ||
@@ -869,11 +956,2 @@ nextToRemove = removes.shift(); | ||
} | ||
function nameMatches(contact, contactName) { | ||
if (contactName === null && (contact.name === null || contact.name.formatted === null)) { | ||
return true; | ||
} else if (contact.name && contact.name.formatted && contact.name.formatted.indexOf(contactName) > -1) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
@@ -880,0 +958,0 @@ /******************************************************************************/ |
@@ -25,43 +25,6 @@ /* | ||
ContactError = require('./ContactError'), | ||
utils = require('cordova/utils'); | ||
utils = require('cordova/utils'), | ||
convertUtils = require('./convertUtils'); | ||
/** | ||
* Converts primitives into Complex Object | ||
* Currently only used for Date fields | ||
*/ | ||
function convertIn(contact) { | ||
var value = contact.birthday; | ||
try { | ||
contact.birthday = new Date(parseFloat(value)); | ||
} catch (exception){ | ||
console.log("Cordova Contact convertIn error: exception creating date."); | ||
} | ||
return contact; | ||
} | ||
/** | ||
* Converts Complex objects into primitives | ||
* Only conversion at present is for Dates. | ||
**/ | ||
function convertOut(contact) { | ||
var value = contact.birthday; | ||
if (value !== null) { | ||
// try to make it a Date object if it is not already | ||
if (!utils.isDate(value)){ | ||
try { | ||
value = new Date(value); | ||
} catch(exception){ | ||
value = null; | ||
} | ||
} | ||
if (utils.isDate(value)){ | ||
value = value.valueOf(); // convert to milliseconds | ||
} | ||
contact.birthday = value; | ||
} | ||
return contact; | ||
} | ||
/** | ||
* Contains information about a single contact. | ||
@@ -165,3 +128,3 @@ * @constructor | ||
var fullContact = require('./contacts').create(result); | ||
successCB(convertIn(fullContact)); | ||
successCB(convertUtils.toCordovaFormat(fullContact)); | ||
} | ||
@@ -174,3 +137,3 @@ } | ||
}; | ||
var dupContact = convertOut(utils.clone(this)); | ||
var dupContact = convertUtils.toNativeFormat(utils.clone(this)); | ||
exec(success, fail, "Contacts", "save", [dupContact]); | ||
@@ -177,0 +140,0 @@ }; |
@@ -25,6 +25,5 @@ /* | ||
ContactError = require('./ContactError'), | ||
utils = require('cordova/utils'), | ||
Contact = require('./Contact'), | ||
fieldType = require('./ContactFieldType'); | ||
fieldType = require('./ContactFieldType'), | ||
convertUtils = require('./convertUtils'); | ||
@@ -45,13 +44,15 @@ /** | ||
*/ | ||
find:function(fields, successCB, errorCB, options) { | ||
find: function(fields, successCB, errorCB, options) { | ||
argscheck.checkArgs('afFO', 'contacts.find', arguments); | ||
if (!fields.length) { | ||
errorCB && errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR)); | ||
if (errorCB) { | ||
errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR)); | ||
} | ||
} else { | ||
// missing 'options' param means return all contacts | ||
options = options || {filter: '', multiple: true} | ||
options = options || { filter: '', multiple: true }; | ||
var win = function(result) { | ||
var cs = []; | ||
for (var i = 0, l = result.length; i < l; i++) { | ||
cs.push(contacts.create(result[i])); | ||
cs.push(convertUtils.toCordovaFormat(contacts.create(result[i]))); | ||
} | ||
@@ -76,3 +77,3 @@ successCB(cs); | ||
var contact = result instanceof Contact ? result : contacts.create(result); | ||
successCB(contact); | ||
successCB(convertUtils.toCordovaFormat(contact)); | ||
}; | ||
@@ -89,3 +90,3 @@ exec(win, errorCB, "Contacts", "pickContact", []); | ||
*/ | ||
create:function(properties) { | ||
create: function(properties) { | ||
argscheck.checkArgs('O', 'contacts.create', arguments); | ||
@@ -92,0 +93,0 @@ var contact = new Contact(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1030738
73
3799
859
1