Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cordova-plugin-contacts

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-plugin-contacts - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

src/android/PermissionHelper.java

2

package.json
{
"name": "cordova-plugin-contacts",
"version": "2.0.0",
"version": "2.0.1",
"description": "Cordova Contacts Plugin",

@@ -5,0 +5,0 @@ "cordova": {

@@ -148,2 +148,4 @@ <!---

Supported values for both __contactFields__ and __contactFindOptions.desiredFields__ parameters are enumerated in [`ContactFieldType`](#contactfieldtype) object.
### Parameters

@@ -229,2 +231,23 @@

### Android Quirks
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)
for an explanation of how this affects your application. If the plugin returns
its result in the `resume` event, then you must first wrap the returned object
in a `Contact` object before using it. Here is an example:
```javascript
function onResume(resumeEvent) {
if(resumeEvent.pendingResult) {
if(resumeEvent.pendingResult.pluginStatus === "OK") {
var contact = navigator.contacts.create(resumeEvent.pendingResult.result);
successCallback(contact);
} else {
failCallback(resumeEvent.pendingResult.result);
}
}
}
```
## Contact

@@ -460,2 +483,3 @@

options.filter = "";
options.multiple = true;
var filter = ["displayName", "addresses"];

@@ -522,2 +546,3 @@ navigator.contacts.find(filter, onSuccess, onError, options);

- `ContactError.NOT_SUPPORTED_ERROR` (code 5)
- `ContactError.OPERATION_CANCELLED_ERROR` (code 6)
- `ContactError.PERMISSION_DENIED_ERROR` (code 20)

@@ -651,2 +676,3 @@

options.filter = "";
options.multiple = true;
filter = ["displayName", "name"];

@@ -749,2 +775,3 @@ navigator.contacts.find(filter, onSuccess, onError, options);

options.filter = "";
options.multiple = true;
filter = ["displayName", "organizations"];

@@ -796,1 +823,32 @@ navigator.contacts.find(filter, onSuccess, onError, options);

- __type__: Not supported, returning `null`.
## ContactFieldType
The `ContactFieldType` object is an enumeration of possible field types, such as `'phoneNumbers'` or `'emails'`, that could be used to control which contact properties must be returned back from `contacts.find()` method (see `contactFindOptions.desiredFields`), or to specify fields to search in (through `contactFields` parameter). Possible values are:
- `navigator.contacts.fieldType.addresses`
- `navigator.contacts.fieldType.birthday`
- `navigator.contacts.fieldType.categories`
- `navigator.contacts.fieldType.country`
- `navigator.contacts.fieldType.department`
- `navigator.contacts.fieldType.displayName`
- `navigator.contacts.fieldType.emails`
- `navigator.contacts.fieldType.familyName`
- `navigator.contacts.fieldType.formatted`
- `navigator.contacts.fieldType.givenName`
- `navigator.contacts.fieldType.honorificPrefix`
- `navigator.contacts.fieldType.honorificSuffix`
- `navigator.contacts.fieldType.id`
- `navigator.contacts.fieldType.ims`
- `navigator.contacts.fieldType.locality`
- `navigator.contacts.fieldType.middleName`
- `navigator.contacts.fieldType.name`
- `navigator.contacts.fieldType.nickname`
- `navigator.contacts.fieldType.note`
- `navigator.contacts.fieldType.organizations`
- `navigator.contacts.fieldType.phoneNumbers`
- `navigator.contacts.fieldType.photos`
- `navigator.contacts.fieldType.postalCode`
- `navigator.contacts.fieldType.region`
- `navigator.contacts.fieldType.streetAddress`
- `navigator.contacts.fieldType.title`
- `navigator.contacts.fieldType.urls`

@@ -23,2 +23,22 @@ <!--

### 2.0.1 (Jan 15, 2016)
* CB-10159 **Android** Adding restore callback to handle Activity destruction
* CB-10319 **Android** Adding reflective helper methods for permission requests
* CB-10117 Added new tests
* CB-10131 Fixed null contact creation.
* CB-10053 Documents `ContactFieldType` enumeration.
* CB-10148 **Android** Added `READ_CONTACTS` permission request when picking a contact
* CB-10053 Accept assets `URIs` for contact photos
* CB-8115 Save contact birthday properly
* CB-6979 Don't create duplicates for extracted contacts photos
* CB-5308 Makes contacts save specs passing
* CB-5308 Return `rawId` instead of id when modifying existing contact
* CB-4921 Corrects examples by adding missing `multiple` option where multiple contacts are expected
* CB-10094 **Android** Fixed empty string comparison
* CB-3950 Adds support for custom labels
* CB-9770 Request user permissions before picking a contact
* CB-8156 Call error callback on `pickContact` cancellation
* CB-7906 Prevent app crash when `desiredFields` option has undefined items
* CB-7021 Adds manual test for `pickContact`
### 2.0.0 (Nov 18, 2015)

@@ -25,0 +45,0 @@ * [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated `RELEASENOTES` to be newest to oldest

@@ -245,3 +245,5 @@ /*

if (!contact) {
fail && fail(new Error("User did not pick a contact."));
var cancelledError = new ContactError(ContactError.OPERATION_CANCELLED_ERROR);
cancelledError.message = "User did not pick a contact.";
fail(cancelledError);
return;

@@ -248,0 +250,0 @@ }

@@ -26,3 +26,2 @@ /*

var gContactObj = null,
gContactId = null,
isWindowsPhone8 = cordova.platformId == 'windowsphone',

@@ -41,10 +40,56 @@ isWindows = (cordova.platformId === "windows") || (cordova.platformId === "windows8"),

var removeContact = function() {
if (gContactObj) {
gContactObj.remove(function() {}, function() {
console.log("[CONTACTS ERROR]: removeContact cleanup method failed to clean up test artifacts.");
var removeContact = function(done) {
if (!gContactObj) {
done();
return;
}
gContactObj.remove(function() {
gContactObj = null;
done();
}, function() {
done();
});
};
function removeContactsByFields(fields, filter, done) {
var obj = new ContactFindOptions();
obj.filter = filter;
obj.multiple = true;
navigator.contacts.find(fields, function(contacts) {
var removes = [];
contacts.forEach(function(contact) {
removes.push(contact);
});
if (removes.length == 0) {
done();
return;
}
var nextToRemove = undefined;
if (removes.length > 0) {
nextToRemove = removes.shift();
}
function removeNext(item) {
if (typeof item === 'undefined') {
done();
return;
}
if (removes.length > 0) {
nextToRemove = removes.shift();
} else {
nextToRemove = undefined;
}
item.remove(function removeSucceeded() {
removeNext(nextToRemove);
}, function removeFailed() {
removeNext(nextToRemove);
});
gContactObj = null;
}
};
removeNext(nextToRemove);
}, done, obj);
}

@@ -55,2 +100,3 @@ describe("Contacts (navigator.contacts)", function() {

});
it("contacts.spec.2 should contain a find function", function() {

@@ -60,2 +106,3 @@ expect(navigator.contacts.find).toBeDefined();

});
describe("find method", function() {

@@ -86,3 +133,4 @@ it("contacts.spec.3 success callback should be called with an array", function(done) {

});
it("success callback should be called with an array, even if partial ContactFindOptions specified", function(done) {
it("contacts.spec.4 success callback should be called with an array, even if partial ContactFindOptions specified", function(done) {
// Find method is not supported on Windows platform

@@ -103,3 +151,4 @@ if ((isWindows && !isWindowsPhone81) || isIOSPermissionBlocked) {

});
it("contacts.spec.4 should throw an exception if success callback is empty", function() {
it("contacts.spec.5 should throw an exception if success callback is empty", function() {
var obj = new ContactFindOptions();

@@ -113,3 +162,4 @@ obj.filter = "";

});
it("contacts.spec.5 error callback should be called when no fields are specified", function(done) {
it("contacts.spec.6 error callback should be called when no fields are specified", function(done) {
var win = fail,

@@ -128,7 +178,10 @@ // we don't want this to be called

});
describe("with newly-created contact", function() {
afterEach(removeContact);
afterEach(function (done) {
removeContact(done);
});
it("contacts.spec.6 should be able to find a contact by name", function(done) {
it("contacts.spec.7 should be able to find a contact by name", function(done) {
// Find method is not supported on Windows Store apps.

@@ -181,10 +234,11 @@ // also this test will be skipped for Windows Phone 8.1 because function "save" not supported on WP8.1

});
});
});
describe('create method', function() {
it("contacts.spec.1 should exist", function() {
it("contacts.spec.8 should exist", function() {
expect(navigator.contacts.create).toBeDefined();
expect(typeof navigator.contacts.create).toBe('function');
});
it("contacts.spec.8 should return a Contact object", function() {
it("contacts.spec.9 should return a Contact object", function() {
var bDay = new Date(1976, 7, 4);

@@ -219,3 +273,3 @@ var obj = navigator.contacts.create({

describe("Contact object", function() {
it("contacts.spec.9 should be able to create instance", function() {
it("contacts.spec.10 should be able to create instance", function() {
var contact = new Contact("a", "b", new ContactName("a", "b", "c", "d", "e", "f"), "c", [], [], [], [], [], "f", "i", [], [], []);

@@ -238,3 +292,4 @@ expect(contact).toBeDefined();

});
it("contacts.spec.10 should be able to define a ContactName object", function() {
it("contacts.spec.11 should be able to define a ContactName object", function() {
var contactName = new ContactName("Dr. First Last Jr.", "Last", "First", "Middle", "Dr.", "Jr.");

@@ -249,3 +304,4 @@ expect(contactName).toBeDefined();

});
it("contacts.spec.11 should be able to define a ContactField object", function() {
it("contacts.spec.12 should be able to define a ContactField object", function() {
var contactField = new ContactField("home", "8005551212", true);

@@ -257,3 +313,4 @@ expect(contactField).toBeDefined();

});
it("contacts.spec.12 ContactField object should coerce type and value properties to strings", function() {
it("contacts.spec.13 ContactField object should coerce type and value properties to strings", function() {
var contactField = new ContactField(12345678, 12345678, true);

@@ -263,3 +320,4 @@ expect(contactField.type).toBe("12345678");

});
it("contacts.spec.13 should be able to define a ContactAddress object", function() {
it("contacts.spec.14 should be able to define a ContactAddress object", function() {
var contactAddress = new ContactAddress(true, "home", "a", "b", "c", "d", "e", "f");

@@ -276,3 +334,4 @@ expect(contactAddress).toBeDefined();

});
it("contacts.spec.14 should be able to define a ContactOrganization object", function() {
it("contacts.spec.15 should be able to define a ContactOrganization object", function() {
var contactOrg = new ContactOrganization(true, "home", "a", "b", "c", "d", "e", "f", "g");

@@ -286,3 +345,4 @@ expect(contactOrg).toBeDefined();

});
it("contacts.spec.15 should be able to define a ContactFindOptions object", function() {
it("contacts.spec.16 should be able to define a ContactFindOptions object", function() {
var contactFindOptions = new ContactFindOptions("a", true, "b");

@@ -293,3 +353,4 @@ expect(contactFindOptions).toBeDefined();

});
it("contacts.spec.16 should contain a clone function", function() {
it("contacts.spec.17 should contain a clone function", function() {
var contact = new Contact();

@@ -299,3 +360,4 @@ expect(contact.clone).toBeDefined();

});
it("contacts.spec.17 clone function should make deep copy of Contact Object", function() {
it("contacts.spec.18 clone function should make deep copy of Contact Object", function() {
var contact = new Contact();

@@ -320,3 +382,4 @@ contact.id = 1;

});
it("contacts.spec.18 should contain a save function", function() {
it("contacts.spec.19 should contain a save function", function() {
var contact = new Contact();

@@ -326,3 +389,4 @@ expect(contact.save).toBeDefined();

});
it("contacts.spec.19 should contain a remove function", function() {
it("contacts.spec.20 should contain a remove function", function() {
var contact = new Contact();

@@ -333,4 +397,10 @@ expect(contact.remove).toBeDefined();

});
describe('save method', function() {
it("contacts.spec.20 should be able to save a contact", function(done) {
afterEach(function (done) {
removeContact(done);
});
it("contacts.spec.21 should be able to save a contact", function(done) {
// Save method is not supported on Windows platform

@@ -342,3 +412,3 @@ if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {

var bDay = new Date(1976, 6, 4);
gContactObj = navigator.contacts.create({
var obj = {
"gender": "male",

@@ -356,3 +426,3 @@ "note": "my note",

"birthday": bDay
});
};

@@ -369,12 +439,13 @@ var saveSuccess = function(obj) {

expect(obj.addresses).toBe(null);
// must store returned object in order to have id for update test below
gContactObj = obj;
done();
},
saveFail = fail;
saveFail = fail.bind(null, done);
gContactObj.save(saveSuccess, saveFail);
navigator.contacts
.create(obj)
.save(saveSuccess, saveFail);
});
// HACK: there is a reliance between the previous and next test. This is bad form.
it("contacts.spec.21 update a contact", function(done) {
it("contacts.spec.22 update a contact", function(done) {
// Save method is not supported on Windows platform

@@ -385,45 +456,65 @@ if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {

expect(gContactObj).toBeDefined();
var bDay = new Date(1975, 5, 4);
var aDay = new Date(1976, 6, 4);
var bDay;
var noteText = "an UPDATED note";
var win = function(obj) {
expect(obj).toBeDefined();
expect(obj.id).toBe(gContactObj.id);
expect(obj.note).toBe(noteText);
expect(obj.birthday.toDateString()).toBe(bDay.toDateString());
expect(obj.emails.length).toBe(1);
expect(obj.emails[0].value).toBe('here@there.com');
removeContact(); // Clean up contact object
done();
var obj = {
"gender": "male",
"note": "my note",
"name": {
"familyName": "Delete",
"givenName": "Test"
},
fail = function() {
removeContact();
fail(done);
};
"emails": [{
"value": "here@there.com"
}, {
"value": "there@here.com"
}],
"birthday": aDay
};
// remove an email
gContactObj.emails[1].value = "";
// change birthday
gContactObj.birthday = bDay;
// update note
gContactObj.note = noteText;
gContactObj.save(win, fail);
var saveFail = fail.bind(null, done);
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) {
expect(obj).toBeDefined();
expect(obj.id).toBe(gContactObj.id);
expect(obj.note).toBe(noteText);
expect(obj.birthday.toDateString()).toBe(bDay.toDateString());
expect(obj.emails.length).toBe(1);
expect(obj.emails[0].value).toBe('here@there.com');
done();
};
navigator.contacts
.create(obj)
.save(saveSuccess, saveFail);
}, MEDIUM_TIMEOUT);
});
describe('Contact.remove method', function(done) {
afterEach(removeContact);
afterEach(function (done) {
removeContact(done);
});
it("contacts.spec.22 calling remove on a contact has an id of null should return ContactError.UNKNOWN_ERROR", function(done) {
var win = function() {};
var fail = function(result) {
expect(result.code).toBe(ContactError.UNKNOWN_ERROR);
done();
};
it("contacts.spec.23 calling remove on a contact that has an id of null should return ContactError.UNKNOWN_ERROR", function(done) {
var expectedFail = function(result) {
expect(result.code).toBe(ContactError.UNKNOWN_ERROR);
done();
};
var rmContact = new Contact();
rmContact.remove(win, fail);
rmContact.remove(fail.bind(null, done), expectedFail);
});
it("contacts.spec.23 calling remove on a contact that does not exist should return ContactError.UNKNOWN_ERROR", function(done) {
it("contacts.spec.24 calling remove on a contact that does not exist should return ContactError.UNKNOWN_ERROR", function(done) {
// remove method is not supported on Windows platform

@@ -433,9 +524,8 @@ if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {

}
var rmWin = fail;
var rmWin = fail.bind(null, done);
var rmFail = function(result) {
expect(result.code).toBe(ContactError.UNKNOWN_ERROR);
done();
};
expect(result.code).toBe(ContactError.UNKNOWN_ERROR);
done();
};
var rmContact = new Contact();
// this is a bit risky as some devices may have contact ids that large

@@ -446,6 +536,27 @@ var contact = new Contact("this string is supposed to be a unique identifier that will never show up on a device");

});
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(done) {
describe("Round trip Contact tests (creating + save + delete + find)", function() {
var saveAndFindBy = function (fields, filter, done) {
removeContactsByFields(["note"], "DeleteMe", function() {
gContactObj.save(function(c_obj) {
var findWin = function(cs) {
// update to have proper saved id
gContactObj = cs[0];
expect(cs.length).toBe(1);
done();
};
var findFail = fail;
var obj = new ContactFindOptions();
obj.filter = filter;
obj.multiple = true;
navigator.contacts.find(fields, findWin, findFail, obj);
}, fail);
});
};
afterEach(function (done) {
removeContact(done);
});
it("contacts.spec.25 Creating, saving, finding a contact should work", function(done) {
// Save method is not supported on Windows platform

@@ -455,49 +566,86 @@ if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {

}
// First, count already existing 'DeleteMe' contacts, if any
var initialCount = 0;
var initialSearchOptions = new ContactFindOptions();
initialSearchOptions.filter = "DeleteMe";
initialSearchOptions.multiple = true;
navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], function(initialContacts) {
initialCount = initialContacts.length;
gContactObj = new Contact();
gContactObj.name = new ContactName();
gContactObj.name.familyName = "DeleteMe";
gContactObj.save(function(c_obj) {
var findWin = function(cs) {
expect(cs.length).toBe(initialCount + 1);
// update to have proper saved id
gContactObj = cs[0];
gContactObj.remove(function() {
var findWinAgain = function(seas) {
expect(seas.length).toBe(initialCount);
gContactObj.remove(function() {
throw ("success callback called after non-existent Contact object called remove(). Test failed.");
}, function(e) {
expect(e.code).toBe(ContactError.UNKNOWN_ERROR);
done();
});
};
var findFailAgain = function(e) {
throw ("find error callback invoked after delete, test failed.");
};
var obj = new ContactFindOptions();
obj.filter = "DeleteMe";
obj.multiple = true;
navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWinAgain, findFailAgain, obj);
}, function(e) {
throw ("Newly created contact's remove function invoked error callback. Test failed.");
});
};
var findFail = fail;
var contactName = "DeleteMe";
gContactObj = new Contact();
gContactObj.name = new ContactName();
gContactObj.name.familyName = contactName;
saveAndFindBy(["displayName", "name"], contactName, done);
}, 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
if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {
pending();
}
var contactName = "DeleteMe";
gContactObj = new Contact();
gContactObj.name = new ContactName();
gContactObj.name.familyName = contactName;
saveAndFindBy(["displayName", "name"], contactName, function() {
gContactObj.remove(function() {
done();
}, function(e) {
throw ("Newly created contact's remove function invoked error callback. Test failed.");
});
});
}, MEDIUM_TIMEOUT);
it("contacts.spec.27 Should not be able to delete the same contact twice", function(done) {
// Save method is not supported on Windows platform
if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {
pending();
}
var contactName = "DeleteMe";
gContactObj = new Contact();
gContactObj.name = new ContactName();
gContactObj.name.familyName = contactName;
saveAndFindBy(["displayName", "name"], contactName, function() {
gContactObj.remove(function() {
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.");
}, function(e) {
expect(e.code).toBe(ContactError.UNKNOWN_ERROR);
done();
});
};
var obj = new ContactFindOptions();
obj.filter = "DeleteMe";
obj.filter = contactName;
obj.multiple = true;
navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, findFail, obj);
navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, fail, obj);
}, fail);
}, function() {}, initialSearchOptions);
});
}, MEDIUM_TIMEOUT);
it("contacts.spec.28 should find a contact with unicode name", function (done) {
// Save method is not supported on Windows platform
if (isWindows || isWindowsPhone8) {
pending();
}
var contactName = "\u2602";
gContactObj = new Contact();
gContactObj.note = "DeleteMe";
gContactObj.name = new ContactName();
gContactObj.name.familyName = contactName;
saveAndFindBy(["displayName", "name"], contactName, done);
}, MEDIUM_TIMEOUT);
it("contacts.spec.29 should find a contact without a name", function (done) {
// Save method is not supported on Windows platform
if (isWindows || isWindowsPhone8) {
pending();
}
gContactObj = new Contact();
var phoneNumbers = [1];
phoneNumbers[0] = new ContactField('work', '555-555-1234', true);
gContactObj.phoneNumbers = phoneNumbers;
saveAndFindBy(["phoneNumbers"], "555-555-1234", done);
}, MEDIUM_TIMEOUT);
});
describe('ContactError interface', function() {
it("contacts.spec.25 ContactError constants should be defined", function() {
it("contacts.spec.30 ContactError constants should be defined", function() {
expect(ContactError.UNKNOWN_ERROR).toBe(0);

@@ -509,2 +657,3 @@ expect(ContactError.INVALID_ARGUMENT_ERROR).toBe(1);

expect(ContactError.NOT_SUPPORTED_ERROR).toBe(5);
expect(ContactError.OPERATION_CANCELLED_ERROR).toBe(6);
expect(ContactError.PERMISSION_DENIED_ERROR).toBe(20);

@@ -521,6 +670,8 @@ });

exports.defineManualTests = function(contentEl, createActionButton) {
function getContacts() {
function getContacts(filter) {
var results = document.getElementById('contact_results');
obj = new ContactFindOptions();
// show all contacts, so don't filter
var obj = new ContactFindOptions();
if (filter) {
obj.filter = filter;
}
obj.multiple = true;

@@ -535,3 +686,4 @@ navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails", "urls", "note"], function(contacts) {

var contact = contacts[i];
s = s + "<tr><td>" + contact.name.formatted + "</td><td>";
var contactNameTag = contact.name ? "<tr><td>" + contact.name.formatted + "</td><td>" : "<tr><td>(No Name)</td><td>";
s = s + contactNameTag;
if (contact.phoneNumbers && contact.phoneNumbers.length > 0) {

@@ -559,26 +711,37 @@ s = s + contact.phoneNumbers[0].value;

function addContact() {
function filterContacts() {
var filter = document.getElementById('searchstring');
getContacts(filter.value);
}
function pickContact() {
var results = document.getElementById('contact_results');
navigator.contacts.pickContact(
function (contact) {
results.innerHTML = contact ?
"Picked contact: <pre>" + JSON.stringify(contact, null, 4) + "</pre>" :
"No contacts found";
},
function (e) {
results.innerHTML = (e && e.code === ContactError.NOT_SUPPORTED_ERROR) ?
"Searching for contacts is not supported." :
(e && e.code === ContactError.OPERATION_CANCELLED_ERROR) ?
"Pick cancelled" :
"Pick failed: error " + (e && e.code);
}
);
}
function addContact(displayName, name, phoneNumber, birthday) {
try {
var contact = navigator.contacts.create({
"displayName": "Dooney Evans"
});
var contactName = {
formatted: "Dooney Evans",
familyName: "Evans",
givenName: "Dooney",
middleName: ""
};
var results = document.getElementById('contact_results');
var contact = navigator.contacts.create({ "displayName": displayName, "name": name, "birthday": birthday, "note": "DeleteMe" });
contact.name = contactName;
var phoneNumbers = [1];
phoneNumbers[0] = new ContactField('work', '512-555-1234', true);
phoneNumbers[0] = new ContactField('work', phoneNumber, true);
contact.phoneNumbers = phoneNumbers;
contact.save(
function() {
results.innerHTML = "Contact saved.";
contact.save(function() {
results.innerHTML = (displayName || "Nameless contact") + " saved.";
}, function(e) {

@@ -592,16 +755,82 @@ if (e.code === ContactError.NOT_SUPPORTED_ERROR) {

} catch (e) {
alert(e);
console.error(e.message);
}
}
function removeDooneyEvans() {
function addDooneyEvans() {
var displayName = "Dooney Evans";
var contactName = {
formatted: "Dooney Evans",
familyName: "Evans",
givenName: "Dooney",
middleName: ""
};
var phoneNumber = '512-555-1234';
var birthday = new Date(1985, 0, 23);
addContact(displayName, contactName, phoneNumber, birthday);
}
function addNamelessContact() {
addContact();
}
function addUnicodeContact() {
var displayName = "Н€йромонах \nФеофаЊ";
var contactName = {
formatted: "Н€йромонах \nФеофаЊ",
familyName: "\nФеофаЊ",
givenName: "Н€йромонах",
middleName: ""
};
addContact(displayName, contactName);
}
function renameDooneyEvans() {
var results = document.getElementById('contact_results');
var obj = new ContactFindOptions();
obj.filter = 'Dooney Evans';
obj.multiple = false;
navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails", "urls", "note"], function(contacts) {
navigator.contacts.find(['displayName', 'name'], function(contacts) {
if (contacts.length == 0) {
results.innerHTML = 'No contacts to update.';
return;
}
var contact = contacts[0];
contact.displayName = "Urist McContact";
var name = new ContactName();
name.givenName = "Urist";
name.familyName = "McContact";
contact.name = name;
contact.save(function(updated) {
results.innerHTML = 'Contact updated.';
},function(e) {
results.innerHTML = 'Update failed: error ' + e.code;
});
}, function(e) {
if (e.code === ContactError.NOT_SUPPORTED_ERROR) {
results.innerHTML = 'Searching for contacts is not supported.';
} else {
results.innerHTML = 'Search failed: error ' + e.code;
}
}, obj)
}
function removeTestContacts() {
var results = document.getElementById('contact_results');
results.innerHTML = "";
var obj = new ContactFindOptions();
obj.filter = 'DeleteMe';
obj.multiple = true;
navigator.contacts.find(['note'], function(contacts) {
var removes = [];
contacts.forEach(function(contact) {
if (contact.name.formatted.indexOf('Dooney Evans') > -1) {
removes.push(contact);
}
removes.push(contact);
});
if (removes.length == 0) {
results.innerHTML = "No contacts to remove";
return;
}

@@ -614,3 +843,5 @@ var nextToRemove = undefined;

function removeNext(item) {
if (typeof item === 'undefined') return;
if (typeof item === 'undefined') {
return;
}

@@ -624,6 +855,6 @@ if (removes.length > 0) {

item.remove(function removeSucceeded() {
results.innerHTML += '<br>Removed contact with ID ' + item.id;
results.innerHTML += "Removed a contact with ID " + item.id + "<br/>";
removeNext(nextToRemove);
}, function removeFailed(e) {
results.innerHTML += '<br>Remove failed contact with ID ' + item.id;
}, function removeFailed() {
results.innerHTML += "Failed to remove a contact with ID " + item.id + "<br/>";
removeNext(nextToRemove);

@@ -639,8 +870,32 @@ });

}
})
}, obj);
}
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;
}
/******************************************************************************/
contentEl.innerHTML = '<div id="info">' + '<b>Results:</b><br>' + '<div id="contact_results"></div>' + '</div>' + '<div id="get_contacts"></div>' + 'Expected result: Status box will show number of contacts and list them. May be empty on a fresh device until you click Add.' + '</p> <div id="add_contact"></div>' + 'Expected result: Will add a new contact. Log will say "Contact saved." or "Saving contacts not supported." if not supported on current platform. Verify by running Get phone contacts again' + '<div id="remove_dooney_evans"></div>' + '<p>Expected result: Will remove any contacts named "Dooney Evans". Log will output success or failure, plus ID, or fail like getting contacts will fail.</p>';
contentEl.innerHTML = '<div id="info">' +
'<b>Results:</b><br>' +
'<div id="contact_results"></div>' +
'</div>' +
'<div id="get_contacts"></div>' +
'<p>Expected result: Status box will show number of contacts and list them. May be empty on a fresh device until you click Add.</p>' +
'<div id="filter_contacts">Search: <input type="text" id="searchstring"></div>' +
'<p>Expected result: Will return only contacts which contain specified string</p>' +
'<div id="pick_contact"></div>' +
'<p>Expected result: Device\'s address book will be shown. After picking a contact status box will show Contact object, passed to success callback</p>' +
'<div id="add_contact"></div>' +
'<p>Expected result: Will add a new contact. Log will say "Contact saved." or "Saving contacts not supported." if not supported on current platform. Verify by running Get phone contacts again</p>' +
'<div id="update_contact"></div>' +
'<p>Expected result: Will rename "Dooney Evans" to "Urist McContact".</p>' +
'<div id="remove_contacts"></div>' +
'<p>Expected result: Will remove all contacts created by these tests. Log will output success or failure and ID of the deleted contacts.</p>';

@@ -651,9 +906,29 @@ createActionButton("Get phone's contacts", function() {

createActionButton("Filter contacts", function() {
filterContacts();
}, 'filter_contacts');
createActionButton("Pick contact", function() {
pickContact();
}, 'pick_contact');
createActionButton("Add a new contact 'Dooney Evans'", function() {
addContact();
addDooneyEvans();
}, 'add_contact');
createActionButton("Delete all 'Dooney Evans'", function() {
removeDooneyEvans();
}, 'remove_dooney_evans');
createActionButton("Add new nameless contact", function() {
addNamelessContact();
}, 'add_contact');
createActionButton("Add new unicode contact", function() {
addUnicodeContact();
}, 'add_contact');
createActionButton("Rename 'Dooney Evans'", function() {
renameDooneyEvans();
}, 'update_contact');
createActionButton("Delete all test contacts", function() {
removeTestContacts();
}, 'remove_contacts');
};

@@ -40,4 +40,5 @@ /*

ContactError.NOT_SUPPORTED_ERROR = 5;
ContactError.OPERATION_CANCELLED_ERROR = 6;
ContactError.PERMISSION_DENIED_ERROR = 20;
module.exports = ContactError;

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc