Fixing up contact api

This commit is contained in:
Joe Bowser 2009-12-01 11:48:10 -08:00
parent 2c11550b30
commit 67a0b838ff

View File

@ -1,52 +1,60 @@
/** var Contact = function(){
* This class provides access to the device contacts. this.name = null;
* @constructor this.emails = [];
*/ this.phones = [];
}
function Contact(jsonObject) { var ContactName = function()
this.firstName = ""; {
this.lastName = ""; this.formatted = "";
this.name = ""; this.familyName = "";
this.phones = {}; this.givenName = "";
this.emails = {}; this.additionalNames = [];
this.prefixes = [];
this.suffixes = [];
}
var ContactEmail = function()
{
this.types = [];
this.address = ""; this.address = "";
} }
Contact.prototype.displayName = function()
var Contacts = function()
{ {
// TODO: can be tuned according to prefs this.records = [];
return this.name;
} }
function ContactManager() { var Contacts.prototype.find = function(obj, win, fail)
// Dummy object to hold array of contacts {
this.contacts = []; if(obj.name)
this.timestamp = new Date().getTime(); {
ContactHook.search(name, "", "");
}
this.win = win;
this.fail = fail;
} }
ContactManager.prototype.getAllContacts = function(successCallback, errorCallback, options) { var Contacts.prototype.droidFoundContact = function(name, npa, email)
// Interface
}
PhoneGap.addConstructor(function() {
if (typeof navigator.ContactManager == "undefined") navigator.ContactManager = new ContactManager();
});
ContactManager.prototype.getAllContacts = function(successCallback, errorCallback, options) {
this.win = successCallback;
this.fail = errorCallback;
ContactHook.getContactsAndSendBack();
}
ContactManager.prototype.droidAddContact = function(name, phone, email)
{ {
var contact = new Contact(); var contact = new Contact();
contact.name = name; contact.name = new ContactName();
contact.phones.primary = phone; contact.name.formatted = name;
contact.emails.primary = email; contact.name.givenName = name;
this.contacts.push(contact); var mail = new ContactEmail();
mail.types.push("home");
mail.address = email;
contact.emails.push(mail);
phone = new ContactPhoneNumber();
phone.types.push("home");
phone.number = npa;
contact.phones.push(phone);
this.records.push(contact);
} }
ContactManager.prototype.droidDone = function() var Contacts.prototype.droidDone = function()
{ {
this.win(this.contacts); this.win(this.records);
} }