mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 08:53:24 +08:00
Fixing up contact api
This commit is contained in:
parent
2c11550b30
commit
67a0b838ff
@ -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) {
|
|
||||||
this.firstName = "";
|
|
||||||
this.lastName = "";
|
|
||||||
this.name = "";
|
|
||||||
this.phones = {};
|
|
||||||
this.emails = {};
|
|
||||||
this.address = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact.prototype.displayName = function()
|
var ContactName = function()
|
||||||
{
|
{
|
||||||
// TODO: can be tuned according to prefs
|
this.formatted = "";
|
||||||
return this.name;
|
this.familyName = "";
|
||||||
|
this.givenName = "";
|
||||||
|
this.additionalNames = [];
|
||||||
|
this.prefixes = [];
|
||||||
|
this.suffixes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function ContactManager() {
|
|
||||||
// Dummy object to hold array of contacts
|
var ContactEmail = function()
|
||||||
this.contacts = [];
|
{
|
||||||
this.timestamp = new Date().getTime();
|
this.types = [];
|
||||||
|
this.address = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactManager.prototype.getAllContacts = function(successCallback, errorCallback, options) {
|
|
||||||
// Interface
|
var Contacts = function()
|
||||||
|
{
|
||||||
|
this.records = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
var Contacts.prototype.find = function(obj, win, fail)
|
||||||
if (typeof navigator.ContactManager == "undefined") navigator.ContactManager = new ContactManager();
|
{
|
||||||
});
|
if(obj.name)
|
||||||
ContactManager.prototype.getAllContacts = function(successCallback, errorCallback, options) {
|
{
|
||||||
this.win = successCallback;
|
ContactHook.search(name, "", "");
|
||||||
this.fail = errorCallback;
|
}
|
||||||
ContactHook.getContactsAndSendBack();
|
this.win = win;
|
||||||
|
this.fail = fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactManager.prototype.droidAddContact = function(name, phone, email)
|
var Contacts.prototype.droidFoundContact = function(name, npa, 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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user