fix(contacts): plugin rewrite

This commit is contained in:
Ibrahim Hadeed 2016-04-30 12:56:30 -04:00
parent 029a8c88ec
commit aada893f09

View File

@ -31,27 +31,80 @@ export interface ContactProperties {
urls?: ContactField[]; urls?: ContactField[];
} }
export interface Contact extends ContactProperties { // export interface Contact extends ContactProperties {
/** // /**
* Returns a new Contact object that is a deep copy of the calling object, with the id property set to null // * Returns a new Contact object that is a deep copy of the calling object, with the id property set to null
*/ // */
clone(): Contact; // clone(): Contact;
/** // /**
* Removes the contact from the device contacts database, otherwise executes an error callback with a ContactError object. // * Removes the contact from the device contacts database, otherwise executes an error callback with a ContactError object.
* @param onSuccess Success callback function invoked on success operation. // * @param onSuccess Success callback function invoked on success operation.
* @param onError Error callback function, invoked when an error occurs. // * @param onError Error callback function, invoked when an error occurs.
*/ // */
remove( // remove(
onSuccess?: () => void, // onSuccess?: () => void,
onError?: (error: Error) => void): void; // onError?: (error: Error) => void): void;
/** // /**
* Saves a new contact to the device contacts database, or updates an existing contact if a contact with the same id already exists. // * Saves a new contact to the device contacts database, or updates an existing contact if a contact with the same id already exists.
* @param onSuccess Success callback function invoked on success operation with che Contact object. // * @param onSuccess Success callback function invoked on success operation with che Contact object.
* @param onError Error callback function, invoked when an error occurs. // * @param onError Error callback function, invoked when an error occurs.
*/ // */
save( // save(
onSuccess?: (contact: Contact) => void, // onSuccess?: (contact: Contact) => void,
onError?: (error: Error) => void): void; // onError?: (error: Error) => void): void;
// }
export class Contact {
private _objectInstance: any;
get id(): string {
return this._objectInstance.id;
}
set id(val: string) {
this._objectInstance.id = val;
}
get displayName(): string {
return this._objectInstance.displayName;
}
set displayName(val: string){
this._objectInstance.displayName = val;
}
get name(): ContactName {
return this._objectInstance.name;
}
set name(val: ContactName){
this._objectInstance.name = val;
}
get nickname(): string {
return this._objectInstance.nickname;
}
set nickname(val: string){
this._objectInstance.nickname = val;
}
get phoneNumbers(): ContactField[] {
return this._objectInstance.phoneNumbers;
}
set phoneNumbers(val: ContactField[]){
this._objectInstance.phoneNumbers = val;
}
get emails(): ContactField[] {
return this._objectInstance.emails;
}
set emails(val: ContactField[]){
this._objectInstance.emails = val;
}
get addresses(): ContactAddress[] {
return this._objectInstance.addresses;
}
set addresses(val: ContactAddress[]){
this._objectInstance.addresses = val;
}
constructor () {
// creat eobj
}
} }
interface ContactError { interface ContactError {
@ -87,15 +140,30 @@ export interface ContactName {
honorificSuffix?: string; honorificSuffix?: string;
} }
declare var ContactName: { // declare var ContactName: {
/** Constructor for ContactName object */ // /** Constructor for ContactName object */
new(formatted?: string, // new(formatted?: string,
familyName?: string, // familyName?: string,
givenName?: string, // givenName?: string,
middleName?: string, // middleName?: string,
honorificPrefix?: string, // honorificPrefix?: string,
honorificSuffix?: string): ContactName // honorificSuffix?: string): ContactName
}; // };
export class ContactName {
private _objectInstance: any;
constructor() { }
public set givenName(val: string) {
this._objectInstance.givenName = val;
}
public set familyName(val: string) {
this._objectInstance.familyName = val;
}
public get givenName(): string {return this._objectInstance.givenName; }
public get familyName(): string {return this._objectInstance.familyName; }
}
export interface ContactField { export interface ContactField {
/** A string that indicates what type of field this is, home for example. */ /** A string that indicates what type of field this is, home for example. */
@ -183,9 +251,28 @@ declare var ContactFindOptions: {
desiredFields?: string[]): ContactFindOptions desiredFields?: string[]): ContactFindOptions
}; };
declare var Contact: { export class ContactFindOptions {
new(): Contact private _objectInstance: any;
}; public set filter(val: string) {
this._objectInstance.filter = val;
}
public set multiple(val: boolean) {
this._objectInstance.multiple = val;
}
public set desiredFields(val) {
this._objectInstance.desiredFields = val;
}
public set hasPhoneNumber(val: boolean) {
this._objectInstance.hasPhoneNumber = val;
}
}
// declare var Contact: {
// new(): Contact
// };
/** /**
* @name Contacts * @name Contacts
@ -215,17 +302,28 @@ declare var Contact: {
repo: 'https://github.com/apache/cordova-plugin-contacts' repo: 'https://github.com/apache/cordova-plugin-contacts'
}) })
export class Contacts { export class Contacts {
private _objectInstance: any;
public set displayName(val: string) {
this._objectInstance.displayName = val;
}
public set nickname(val: boolean) {
this._objectInstance.nickname = val;
}
get displayName() {return this._objectInstance.displayName; }
get nickname() {return this._objectInstance.nickname; }
/** /**
* Create a new Contact object. * Create a new Contact object.
* *
* @param options {Object} Object whose properties the created Contact should have. * @param options {Object} Object whose properties the created Contact should have.
* @return {Contact} Returns the created contact * @return {Contact} Returns the created contact
*/ */
@Cordova({ constructor (options?: ContactProperties) {
sync: true this._objectInstance = navigator.contacts(options);
})
static create(options: ContactProperties) {
return new Contact();
}; };
/** /**