Bug 963274 - Allow removing contacts by ID. r=gwagner

This commit is contained in:
Reuben Morais 2014-01-29 08:20:40 -05:00
parent 2383031d54
commit 8428c6980b
3 changed files with 31 additions and 4 deletions

View File

@ -391,14 +391,19 @@ ContactManager.prototype = {
}
},
remove: function removeContact(aRecord) {
remove: function removeContact(aRecordOrId) {
let request = this.createRequest();
if (!aRecord || !aRecord.id) {
let id;
if (typeof aRecordOrId === "string") {
id = aRecordOrId;
} else if (!aRecordOrId || !aRecordOrId.id) {
Services.DOMRequest.fireErrorAsync(request, true);
return request;
} else {
id = aRecordOrId.id;
}
let options = { id: aRecord.id };
let options = { id: id };
let allowCallback = function() {
cpmm.sendAsyncMessage("Contact:Remove", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options});
}.bind(this);

View File

@ -800,6 +800,28 @@ var steps = [
ok(!c.jobTitle, "jobTitle is not set");
next();
},
function() {
ok(true, "mozContacts.remove with an ID works");
var c = new mozContact({name: ["Ephemeral Jimmy"]});
req = navigator.mozContacts.save(c);
req.onsuccess = function() {
req = navigator.mozContacts.remove(c.id);
req.onsuccess = function() {
req = navigator.mozContacts.find({
filterBy: ["id"],
filterOp: "equals",
filterValue: c.id
});
req.onsuccess = function() {
ise(req.result.length, 0, "Successfully removed contact by ID");
next();
};
req.onerror = onFailure;
};
req.onerror = onFailure;
};
req.onerror = onFailure;
},
function () {
ok(true, "all done!\n");
SimpleTest.finish();

View File

@ -118,7 +118,7 @@ interface ContactManager : EventTarget {
DOMCursor getAll(optional ContactFindSortOptions options);
DOMRequest clear();
DOMRequest save(mozContact contact);
DOMRequest remove(mozContact contact);
DOMRequest remove((mozContact or DOMString) contactOrId);
DOMRequest getRevision();
DOMRequest getCount();